Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Bug 6376: core.thread.thread_scanAll doesn't scan the stack due to ASLR #43

Merged
merged 2 commits into from
Aug 2, 2011
Merged

Bug 6376: core.thread.thread_scanAll doesn't scan the stack due to ASLR #43

merged 2 commits into from
Aug 2, 2011

Conversation

kennytm
Copy link
Contributor

@kennytm kennytm commented Jul 26, 2011

Fixes bug 6376: core.thread.thread_scanAll doesn't scan the stack due to ASLR on Mac OS X 10.7

When ASLR is enabled, the stack address of Mac OS X is no longer fixed at 0xc000_0000 — actually, often higher than this. Previously, the function rt.memory.rt_stackBottom returns a hard-coded value of 0xc000_0000, which is no longer valid with ASLR. Functions which rely on this function could no longer work properly. In particular, core.thread.thread_scanAll cannot scan the main thread's stack since the stack pointer bounds are reversed. The GC, which marks whether pointers shouldn't be freed yet, will miss all the objects on stack as thread_scanAll is used. This causes pre-mature deallocation when a GC collection is invoked. In particular, when throwing an exception (the pointer is on stack), the TraceInfo allocated is > 2 KiB, which will cause a page allocation that invokes the GC. This makes the exception object be destroyed before checking its type, making it totally uncatchable and ignored, thus previously unreachable statements after the 'throw' will now be reachable, and other undefined behavior will arise.

… to ASLR on Mac OS X 10.7

When ASLR is enabled, the stack address of Mac OS X is no longer fixed at 0xc000_0000 -- actually, often higher than this.
Previously, the function rt.memory.rt_stackBottom returns a hard-coded value of 0xc000_0000, which is no longer valid with ASLR.
Functions which rely on this function could no longer work properly.
In particular, core.thread.thread_scanAll cannot scan the main thread's stack since the stack pointer bounds are reversed.
The GC, which marks whether pointers shouldn't be freed yet, will miss all the objects on stack as thread_scanAll is used.
This causes pre-mature deallocation when a GC collection is invoked.
In particular, when throwing an exception (the pointer is on stack), the TraceInfo allocated is > 2 KiB, which will cause a page allocation that invokes the GC.
This makes the exception object be destroyed before checking its type, making it totally uncatchable and ignored, thus previously unreachable statements after the 'throw' will now be reachable, and other undefined behavior will arise.
@dnadlinger
Copy link
Member

I can confirm that using pthread_get_stackaddr_np to get the stack bottom address solves the ASLR-related crashes I reported on the NG. Also, I am pretty sure that it existed since the beginning of OS X, @WalterBright.

@WalterBright
Copy link
Member

Thanks, all, for getting this done.

@dnadlinger
Copy link
Member

Could we please try to clear out the remaining issues, if any, and merge this to master as soon as possible? Without any concrete numbers at hand, I'd guess that a non-negligible part of the Mac developer community has already switched to Lion or at least has a Lion instance for testing lying around.

WalterBright added a commit that referenced this pull request Aug 2, 2011
Bug 6376: core.thread.thread_scanAll doesn't scan the stack due to ASLR
@WalterBright WalterBright merged commit 9252837 into dlang:master Aug 2, 2011
redstar pushed a commit to redstar/druntime that referenced this pull request Jan 10, 2016
MSVCx86: replace __vcrt_getptd with __processing_throw
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants