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

Commit b69ac7d

Browse files
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
1 parent 5908c95 commit b69ac7d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

lib/sanitizer_common/sanitizer_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const uptr kCacheLineSize = 64;
3131

3232
const uptr kMaxPathLength = 512;
3333

34+
const uptr kMaxThreadStackSize = 1 << 30; // 1Gb
35+
3436
extern const char *SanitizerToolName; // Can be changed by the tool.
3537

3638
uptr GetPageSize();

lib/sanitizer_common/sanitizer_linux_libcdep.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ int internal_sigaction(int signum, const void *act, void *oldact) {
6262

6363
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
6464
uptr *stack_bottom) {
65-
static const uptr kMaxThreadStackSize = 1 << 30; // 1Gb
6665
CHECK(stack_top);
6766
CHECK(stack_bottom);
6867
if (at_initialization) {

lib/sanitizer_common/sanitizer_mac.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
144144
CHECK(stack_top);
145145
CHECK(stack_bottom);
146146
uptr stacksize = pthread_get_stacksize_np(pthread_self());
147+
// pthread_get_stacksize_np() returns an incorrect stack size for the main
148+
// thread on Mavericks. See
149+
// https://code.google.com/p/address-sanitizer/issues/detail?id=261
150+
if ((GetMacosVersion() == MACOS_VERSION_MAVERICKS) && at_initialization &&
151+
stacksize == (1 << 19)) {
152+
struct rlimit rl;
153+
CHECK_EQ(getrlimit(RLIMIT_STACK, &rl), 0);
154+
// Most often rl.rlim_cur will be the desired 8M.
155+
if (rl.rlim_cur < kMaxThreadStackSize) {
156+
stacksize = rl.rlim_cur;
157+
} else {
158+
stacksize = kMaxThreadStackSize;
159+
}
160+
}
147161
void *stackaddr = pthread_get_stackaddr_np(pthread_self());
148162
*stack_top = (uptr)stackaddr;
149163
*stack_bottom = *stack_top - stacksize;

0 commit comments

Comments
 (0)