Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
[libsanitizer] Workaround for https://code.google.com/p/address-sanit…
Browse files Browse the repository at this point in the history
…izer/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
  • Loading branch information
ramosian-glider committed Feb 3, 2014
1 parent 5908c95 commit b69ac7d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/sanitizer_common/sanitizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const uptr kCacheLineSize = 64;

const uptr kMaxPathLength = 512;

const uptr kMaxThreadStackSize = 1 << 30; // 1Gb

extern const char *SanitizerToolName; // Can be changed by the tool.

uptr GetPageSize();
Expand Down
1 change: 0 additions & 1 deletion lib/sanitizer_common/sanitizer_linux_libcdep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int internal_sigaction(int signum, const void *act, void *oldact) {

void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom) {
static const uptr kMaxThreadStackSize = 1 << 30; // 1Gb
CHECK(stack_top);
CHECK(stack_bottom);
if (at_initialization) {
Expand Down
14 changes: 14 additions & 0 deletions lib/sanitizer_common/sanitizer_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b69ac7d

Please sign in to comment.