]> git.ipfire.org Git - thirdparty/gcc.git/blame - libsanitizer/tsan/tsan_platform_mac.cc
[libsanitizer] merge from upstream r168514
[thirdparty/gcc.git] / libsanitizer / tsan / tsan_platform_mac.cc
CommitLineData
cd0be65c
WM
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#ifdef __APPLE__
14
15#include "sanitizer_common/sanitizer_common.h"
16#include "sanitizer_common/sanitizer_libc.h"
17#include "sanitizer_common/sanitizer_procmaps.h"
18#include "tsan_platform.h"
19#include "tsan_rtl.h"
20#include "tsan_flags.h"
21
22#include <pthread.h>
23#include <signal.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <stdarg.h>
28#include <sys/mman.h>
29#include <sys/syscall.h>
30#include <sys/time.h>
31#include <sys/types.h>
32#include <sys/resource.h>
33#include <sys/stat.h>
34#include <unistd.h>
35#include <errno.h>
36#include <sched.h>
37
38namespace __tsan {
39
40ScopedInRtl::ScopedInRtl() {
41}
42
43ScopedInRtl::~ScopedInRtl() {
44}
45
46uptr GetShadowMemoryConsumption() {
47 return 0;
48}
49
50void FlushShadowMemory() {
51}
52
e297eb60 53#ifndef TSAN_GO
cd0be65c
WM
54void InitializeShadowMemory() {
55 uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg,
56 kLinuxShadowEnd - kLinuxShadowBeg);
57 if (shadow != kLinuxShadowBeg) {
e297eb60
KS
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");
cd0be65c
WM
61 Die();
62 }
63 DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n",
64 kLinuxShadowBeg, kLinuxShadowEnd,
65 (kLinuxShadowEnd - kLinuxShadowBeg) >> 30);
66 DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n",
67 kLinuxAppMemBeg, kLinuxAppMemEnd,
68 (kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30);
69}
e297eb60 70#endif
cd0be65c
WM
71
72const char *InitializePlatform() {
73 void *p = 0;
74 if (sizeof(p) == 8) {
75 // Disable core dumps, dumping of 16TB usually takes a bit long.
76 // The following magic is to prevent clang from replacing it with memset.
77 volatile rlimit lim;
78 lim.rlim_cur = 0;
79 lim.rlim_max = 0;
80 setrlimit(RLIMIT_CORE, (rlimit*)&lim);
81 }
82
e297eb60 83 return getenv(kTsanOptionsEnv);
cd0be65c
WM
84}
85
86void FinalizePlatform() {
87 fflush(0);
88}
89
90uptr GetTlsSize() {
91 return 0;
92}
93
94void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
95 uptr *tls_addr, uptr *tls_size) {
96 *stk_addr = 0;
97 *stk_size = 0;
98 *tls_addr = 0;
99 *tls_size = 0;
100}
101
102} // namespace __tsan
103
104#endif // #ifdef __APPLE__