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 __sanitizer { 41 42 void Die() { 43 _exit(1); 44 } 45 46 } // namespace __sanitizer 47 48 namespace __tsan { 49 50 ScopedInRtl::ScopedInRtl() { 51 } 52 53 ScopedInRtl::~ScopedInRtl() { 54 } 55 56 uptr GetShadowMemoryConsumption() { 57 return 0; 58 } 59 60 void FlushShadowMemory() { 61 } 62 63 void InitializeShadowMemory() { 64 uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg, 65 kLinuxShadowEnd - kLinuxShadowBeg); 66 if (shadow != kLinuxShadowBeg) { 67 TsanPrintf("FATAL: ThreadSanitizer can not mmap the shadow memory\n"); 68 TsanPrintf("FATAL: Make sure to compile with -fPIE and " 69 "to link with -pie.\n"); 70 Die(); 71 } 72 DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n", 73 kLinuxShadowBeg, kLinuxShadowEnd, 74 (kLinuxShadowEnd - kLinuxShadowBeg) >> 30); 75 DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n", 76 kLinuxAppMemBeg, kLinuxAppMemEnd, 77 (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30); 78 } 79 80 const char *InitializePlatform() { 81 void *p = 0; 82 if (sizeof(p) == 8) { 83 // Disable core dumps, dumping of 16TB usually takes a bit long. 84 // The following magic is to prevent clang from replacing it with memset. 85 volatile rlimit lim; 86 lim.rlim_cur = 0; 87 lim.rlim_max = 0; 88 setrlimit(RLIMIT_CORE, (rlimit*)&lim); 89 } 90 91 return getenv("TSAN_OPTIONS"); 92 } 93 94 void FinalizePlatform() { 95 fflush(0); 96 } 97 98 uptr GetTlsSize() { 99 return 0; 100 } 101 102 void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size, 103 uptr *tls_addr, uptr *tls_size) { 104 *stk_addr = 0; 105 *stk_size = 0; 106 *tls_addr = 0; 107 *tls_size = 0; 108 } 109 110 } // namespace __tsan 111 112 #endif // #ifdef __APPLE__ 113