2012-07-16 21:02:40 +08:00
|
|
|
//===-- tsan_platform_mac.cc ----------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
2012-07-17 17:39:59 +08:00
|
|
|
// Mac-specific code.
|
2012-07-16 21:02:40 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-03-19 22:33:38 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform.h"
|
2012-07-16 21:25:47 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2012-07-16 21:02:40 +08:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
#include "sanitizer_common/sanitizer_procmaps.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
|
|
|
ScopedInRtl::ScopedInRtl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedInRtl::~ScopedInRtl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr GetShadowMemoryConsumption() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlushShadowMemory() {
|
|
|
|
}
|
|
|
|
|
2012-11-07 00:00:16 +08:00
|
|
|
#ifndef TSAN_GO
|
2012-07-16 21:02:40 +08:00
|
|
|
void InitializeShadowMemory() {
|
|
|
|
uptr shadow = (uptr)MmapFixedNoReserve(kLinuxShadowBeg,
|
|
|
|
kLinuxShadowEnd - kLinuxShadowBeg);
|
|
|
|
if (shadow != kLinuxShadowBeg) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("FATAL: ThreadSanitizer can not mmap the shadow memory\n");
|
|
|
|
Printf("FATAL: Make sure to compile with -fPIE and "
|
|
|
|
"to link with -pie.\n");
|
2012-07-16 21:02:40 +08:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
DPrintf("kLinuxShadow %zx-%zx (%zuGB)\n",
|
|
|
|
kLinuxShadowBeg, kLinuxShadowEnd,
|
|
|
|
(kLinuxShadowEnd - kLinuxShadowBeg) >> 30);
|
|
|
|
DPrintf("kLinuxAppMem %zx-%zx (%zuGB)\n",
|
|
|
|
kLinuxAppMemBeg, kLinuxAppMemEnd,
|
|
|
|
(kLinuxAppMemEnd - kLinuxAppMemBeg) >> 30);
|
|
|
|
}
|
2012-11-07 00:00:16 +08:00
|
|
|
#endif
|
2012-07-16 21:02:40 +08:00
|
|
|
|
|
|
|
const char *InitializePlatform() {
|
|
|
|
void *p = 0;
|
|
|
|
if (sizeof(p) == 8) {
|
|
|
|
// Disable core dumps, dumping of 16TB usually takes a bit long.
|
|
|
|
// The following magic is to prevent clang from replacing it with memset.
|
|
|
|
volatile rlimit lim;
|
|
|
|
lim.rlim_cur = 0;
|
|
|
|
lim.rlim_max = 0;
|
|
|
|
setrlimit(RLIMIT_CORE, (rlimit*)&lim);
|
|
|
|
}
|
|
|
|
|
2013-02-19 16:19:13 +08:00
|
|
|
return GetEnv(kTsanOptionsEnv);
|
2012-07-16 21:02:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FinalizePlatform() {
|
|
|
|
fflush(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetThreadStackAndTls(bool main, uptr *stk_addr, uptr *stk_size,
|
|
|
|
uptr *tls_addr, uptr *tls_size) {
|
|
|
|
*stk_addr = 0;
|
|
|
|
*stk_size = 0;
|
|
|
|
*tls_addr = 0;
|
|
|
|
*tls_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __tsan
|
2012-07-16 21:25:47 +08:00
|
|
|
|
|
|
|
#endif // #ifdef __APPLE__
|