1 //===-- tsan_platform_mac.cc ----------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //
12 // Mac-specific code.
13 //===----------------------------------------------------------------------===//
14
15 #ifdef __APPLE__
16
17 #include "sanitizer_common/sanitizer_common.h"
18 #include "sanitizer_common/sanitizer_libc.h"
19 #include "sanitizer_common/sanitizer_procmaps.h"
20 #include "tsan_platform.h"
21 #include "tsan_rtl.h"
22 #include "tsan_flags.h"
23
24 #include <pthread.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdarg.h>
30 #include <sys/mman.h>
31 #include <sys/syscall.h>
32 #include <sys/time.h>
33 #include <sys/types.h>
34 #include <sys/resource.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 #include <errno.h>
38 #include <sched.h>
39
40 namespace __tsan {
41
ScopedInRtl()42 ScopedInRtl::ScopedInRtl() {
43 }
44
~ScopedInRtl()45 ScopedInRtl::~ScopedInRtl() {
46 }
47
GetShadowMemoryConsumption()48 uptr GetShadowMemoryConsumption() {
49 return 0;
50 }
51
FlushShadowMemory()52 void FlushShadowMemory() {
53 }
54
55 #ifndef TSAN_GO
InitializeShadowMemory()56 void InitializeShadowMemory() {
57 uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg,
58 kLinuxShadowEnd - kLinuxShadowBeg);
59 if (shadow != kLinuxShadowBeg) {
60 Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
61 Printf("FATAL: Make sure to compile with -fPIE and "
62 "to link with -pie.\n");
63 Die();
64 }
65 DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n",
66 kLinuxShadowBeg, kLinuxShadowEnd,
67 (kLinuxShadowEnd - kLinuxShadowBeg) >> 30);
68 DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n",
69 kLinuxAppMemBeg, kLinuxAppMemEnd,
70 (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30);
71 }
72 #endif
73
InitializePlatform()74 const char *InitializePlatform() {
75 void *p = 0;
76 if (sizeof(p) == 8) {
77 // Disable core dumps, dumping of 16TB usually takes a bit long.
78 // The following magic is to prevent clang from replacing it with memset.
79 volatile rlimit lim;
80 lim.rlim_cur = 0;
81 lim.rlim_max = 0;
82 setrlimit(RLIMIT_CORE, (rlimit*)&lim);
83 }
84
85 return GetEnv(kTsanOptionsEnv);
86 }
87
FinalizePlatform()88 void FinalizePlatform() {
89 fflush(0);
90 }
91
GetThreadStackAndTls(bool main,uptr * stk_addr,uptr * stk_size,uptr * tls_addr,uptr * tls_size)92 void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
93 uptr *tls_addr, uptr *tls_size) {
94 *stk_addr = 0;
95 *stk_size = 0;
96 *tls_addr = 0;
97 *tls_size = 0;
98 }
99
100 } // namespace __tsan
101
102 #endif // #ifdef __APPLE__
103