]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/tsan/rtl/tsan_platform_mac.cc
MFV r284412: 5911 ZFS "hangs" while deleting file
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / tsan / rtl / tsan_platform_mac.cc
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 uptr GetShadowMemoryConsumption() {
44   return 0;
45 }
46
47 void FlushShadowMemory() {
48 }
49
50 void WriteMemoryProfile(char *buf, uptr buf_size, uptr nthread, uptr nlive) {
51 }
52
53 #ifndef SANITIZER_GO
54 void InitializeShadowMemory() {
55   uptr shadow = (uptr)MmapFixedNoReserve(kShadowBeg,
56     kShadowEnd - kShadowBeg);
57   if (shadow != kShadowBeg) {
58     Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
59     Printf("FATAL: Make sure to compile with -fPIE and "
60            "to link with -pie.\n");
61     Die();
62   }
63   if (common_flags()->use_madv_dontdump)
64     DontDumpShadowMemory(kShadowBeg, kShadowEnd - kShadowBeg);
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
74 void InitializePlatform() {
75   DisableCoreDumperIfNecessary();
76 }
77
78 #ifndef SANITIZER_GO
79 int 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