* gcc.target/i386/fuse-caller-save-xmm.c (dg-options): Use
[official-gcc.git] / libsanitizer / tsan / tsan_platform_mac.cc
blobc3d4d905219cbe0d5b7dd3597bf292c8db3f55ae
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 uptr GetShadowMemoryConsumption() {
42 return 0;
45 void FlushShadowMemory() {
48 void WriteMemoryProfile(char *buf, uptr buf_size) {
51 uptr GetRSS() {
52 return 0;
55 #ifndef TSAN_GO
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();
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);
72 #endif
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);
85 return GetEnv(kTsanOptionsEnv);
88 void FinalizePlatform() {
89 fflush(0);
92 #ifndef TSAN_GO
93 int call_pthread_cancel_with_cleanup(int(*fn)(void *c, void *m,
94 void *abstime), void *c, void *m, void *abstime,
95 void(*cleanup)(void *arg), void *arg) {
96 // pthread_cleanup_push/pop are hardcore macros mess.
97 // We can't intercept nor call them w/o including pthread.h.
98 int res;
99 pthread_cleanup_push(cleanup, arg);
100 res = fn(c, m, abstime);
101 pthread_cleanup_pop(0);
102 return res;
104 #endif
106 } // namespace __tsan
108 #endif // SANITIZER_MAC