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 #include "sanitizer_common/sanitizer_platform.h" 16 #if SANITIZER_MAC 17 18 #include "sanitizer_common/sanitizer_common.h" 19 #include "sanitizer_common/sanitizer_libc.h" 20 #include "sanitizer_common/sanitizer_procmaps.h" 21 #include "tsan_platform.h" 22 #include "tsan_rtl.h" 23 #include "tsan_flags.h" 24 25 #include <pthread.h> 26 #include <signal.h> 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 #include <stdarg.h> 31 #include <sys/mman.h> 32 #include <sys/syscall.h> 33 #include <sys/time.h> 34 #include <sys/types.h> 35 #include <sys/resource.h> 36 #include <sys/stat.h> 37 #include <unistd.h> 38 #include <errno.h> 39 #include <sched.h> 40 41 namespace __tsan { 42 43 ScopedInRtl::ScopedInRtl() { 44 } 45 46 ScopedInRtl::~ScopedInRtl() { 47 } 48 49 uptr GetShadowMemoryConsumption() { 50 return 0; 51 } 52 53 void FlushShadowMemory() { 54 } 55 56 #ifndef TSAN_GO 57 void InitializeShadowMemory() { 58 uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg, 59 kLinuxShadowEnd - kLinuxShadowBeg); 60 if (shadow != kLinuxShadowBeg) { 61 Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n"); 62 Printf("FATAL: Make sure to compile with -fPIE and " 63 "to link with -pie.\n"); 64 Die(); 65 } 66 DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n", 67 kLinuxShadowBeg, kLinuxShadowEnd, 68 (kLinuxShadowEnd - kLinuxShadowBeg) >> 30); 69 DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n", 70 kLinuxAppMemBeg, kLinuxAppMemEnd, 71 (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30); 72 } 73 #endif 74 75 const char *InitializePlatform() { 76 void *p = 0; 77 if (sizeof(p) == 8) { 78 // Disable core dumps, dumping of 16TB usually takes a bit long. 79 // The following magic is to prevent clang from replacing it with memset. 80 volatile rlimit lim; 81 lim.rlim_cur = 0; 82 lim.rlim_max = 0; 83 setrlimit(RLIMIT_CORE, (rlimit*)&lim); 84 } 85 86 return GetEnv(kTsanOptionsEnv); 87 } 88 89 void FinalizePlatform() { 90 fflush(0); 91 } 92 93 } // namespace __tsan 94 95 #endif // SANITIZER_MAC 96