diff options
author | Alexander Potapenko <glider@google.com> | 2014-02-03 16:42:29 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2014-02-03 16:42:29 +0000 |
commit | b69ac7dbb0c9e533530e9b560c6df94486de1509 (patch) | |
tree | 7d56d9c53d1c2c3432c66476fa29e07d46ba7cbb /lib/sanitizer_common/sanitizer_mac.cc | |
parent | 5908c95f6f8833147fcb769a575ee23416026cb4 (diff) |
[libsanitizer] Workaround for https://code.google.com/p/address-sanitizer/issues/detail?id=261
If pthread_get_stacksize_np() returns 512K for the main thread on Mavericks, obtain the stack size from the current stack rlimit.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@200703 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_mac.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_mac.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_mac.cc b/lib/sanitizer_common/sanitizer_mac.cc index 77864f4b1..747513de5 100644 --- a/lib/sanitizer_common/sanitizer_mac.cc +++ b/lib/sanitizer_common/sanitizer_mac.cc @@ -144,6 +144,20 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top, CHECK(stack_top); CHECK(stack_bottom); uptr stacksize = pthread_get_stacksize_np(pthread_self()); + // pthread_get_stacksize_np() returns an incorrect stack size for the main + // thread on Mavericks. See + // https://code.google.com/p/address-sanitizer/issues/detail?id=261 + if ((GetMacosVersion() == MACOS_VERSION_MAVERICKS) && at_initialization && + stacksize == (1 << 19)) { + struct rlimit rl; + CHECK_EQ(getrlimit(RLIMIT_STACK, &rl), 0); + // Most often rl.rlim_cur will be the desired 8M. + if (rl.rlim_cur < kMaxThreadStackSize) { + stacksize = rl.rlim_cur; + } else { + stacksize = kMaxThreadStackSize; + } + } void *stackaddr = pthread_get_stackaddr_np(pthread_self()); *stack_top = (uptr)stackaddr; *stack_bottom = *stack_top - stacksize; |