2013-12-10 Janus Weil <janus@gcc.gnu.org>
[official-gcc.git] / libsanitizer / tsan / tsan_platform_mac.cc
blob3dca611dc928884e4b24e1be834ac1f149755954
1 //===-- tsan_platform_mac.cc ----------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 // Mac-specific code.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_platform.h"
14 #if SANITIZER_MAC
16 #include "sanitizer_common/sanitizer_common.h"
17 #include "sanitizer_common/sanitizer_libc.h"
18 #include "sanitizer_common/sanitizer_procmaps.h"
19 #include "tsan_platform.h"
20 #include "tsan_rtl.h"
21 #include "tsan_flags.h"
23 #include <pthread.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29 #include <sys/mman.h>
30 #include <sys/syscall.h>
31 #include <sys/time.h>
32 #include <sys/types.h>
33 #include <sys/resource.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <errno.h>
37 #include <sched.h>
39 namespace __tsan {
41 ScopedInRtl::ScopedInRtl() {
44 ScopedInRtl::~ScopedInRtl() {
47 uptr GetShadowMemoryConsumption() {
48 return 0;
51 void FlushShadowMemory() {
54 #ifndef TSAN_GO
55 void InitializeShadowMemory() {
56 uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg,
57 kLinuxShadowEnd - kLinuxShadowBeg);
58 if (shadow != kLinuxShadowBeg) {
59 Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
60 Printf("FATAL: Make sure to compile with -fPIE and "
61 "to link with -pie.\n");
62 Die();
64 DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n",
65 kLinuxShadowBeg, kLinuxShadowEnd,
66 (kLinuxShadowEnd - kLinuxShadowBeg) >> 30);
67 DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n",
68 kLinuxAppMemBeg, kLinuxAppMemEnd,
69 (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30);
71 #endif
73 const char *InitializePlatform() {
74 void *p = 0;
75 if (sizeof(p) == 8) {
76 // Disable core dumps, dumping of 16TB usually takes a bit long.
77 // The following magic is to prevent clang from replacing it with memset.
78 volatile rlimit lim;
79 lim.rlim_cur = 0;
80 lim.rlim_max = 0;
81 setrlimit(RLIMIT_CORE, (rlimit*)&lim);
84 return GetEnv(kTsanOptionsEnv);
87 void FinalizePlatform() {
88 fflush(0);
91 } // namespace __tsan
93 #endif // SANITIZER_MAC