1 //===-- tsan_platform_mac.cc ----------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
11 //===----------------------------------------------------------------------===//
13 #include "sanitizer_common/sanitizer_platform.h"
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"
21 #include "tsan_flags.h"
30 #include <sys/syscall.h>
32 #include <sys/types.h>
33 #include <sys/resource.h>
41 uptr
GetShadowMemoryConsumption() {
45 void FlushShadowMemory() {
48 void WriteMemoryProfile(char *buf
, uptr buf_size
, uptr nthread
, uptr nlive
) {
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");
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);
74 void InitializePlatform() {
75 DisableCoreDumperIfNecessary();
78 void FinalizePlatform() {
83 int call_pthread_cancel_with_cleanup(int(*fn
)(void *c
, void *m
,
84 void *abstime
), void *c
, void *m
, void *abstime
,
85 void(*cleanup
)(void *arg
), void *arg
) {
86 // pthread_cleanup_push/pop are hardcore macros mess.
87 // We can't intercept nor call them w/o including pthread.h.
89 pthread_cleanup_push(cleanup
, arg
);
90 res
= fn(c
, m
, abstime
);
91 pthread_cleanup_pop(0);
98 #endif // SANITIZER_MAC