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//===----------------------------------------------------------------------===// 12 13#include "sanitizer_common/sanitizer_platform.h" 14#if SANITIZER_MAC 15 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" 22 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> 38 39namespace __tsan { 40 41uptr GetShadowMemoryConsumption() { 42 return 0; 43} 44 45void FlushShadowMemory() { 46} 47 48void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) { 49} 50 51uptr GetRSS() { 52 return 0; 53} 54 55#ifndef TSAN_GO 56void InitializeShadowMemory() { 57 uptr shadow = (uptr)MmapFixedNoReserve(kShadowBeg, 58 kShadowEnd - kShadowBeg); 59 if (shadow != kShadowBeg) { 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("kShadow %zx-%zx (%zuGB)\n", 66 kShadowBeg, kShadowEnd, 67 (kShadowEnd - kShadowBeg) >> 30); 68 DPrintf("kAppMem %zx-%zx (%zuGB)\n", 69 kAppMemBeg, kAppMemEnd, 70 (kAppMemEnd - kAppMemBeg) >> 30); 71} 72#endif 73 74void InitializePlatform() { 75 DisableCoreDumperIfNecessary(); 76} 77 78#ifndef TSAN_GO 79int call_pthread_cancel_with_cleanup(int(*fn)(void *c, void *m, 80 void *abstime), void *c, void *m, void *abstime, 81 void(*cleanup)(void *arg), void *arg) { 82 // pthread_cleanup_push/pop are hardcore macros mess. 83 // We can't intercept nor call them w/o including pthread.h. 84 int res; 85 pthread_cleanup_push(cleanup, arg); 86 res = fn(c, m, abstime); 87 pthread_cleanup_pop(0); 88 return res; 89} 90#endif 91 92} // namespace __tsan 93 94#endif // SANITIZER_MAC 95