-
-
Notifications
You must be signed in to change notification settings - Fork 416
Bug 6376: Segfault on Mac OS X 10.7 when throwing #42
Conversation
…gfault or memory error due to ASLR on Mac OS X 10.7 Reducing the DefaultTraceInfo's buffer size from 4096 to 2028 apparently fixes the problem. Don't ask me why.
…d, and fix the _d_throwc's signature to match the Windows one.
Before I'm comfortable with this change, we'll need to understand why it On Mon, 25 Jul 2011, kennytm wrote:
|
Maybe I'm missing something obvious, but do you have any idea how a bug fixed this could be related to ASLR? I'll test the workaround with my code and report back. |
@braddr, @klickverbot: I agree, but I don't know the reason yet. For now I can only say, experimentally, when the TraceInfo's class instance size exceeds 2048, the Just for completeness, my test case: import core.stdc.stdio;
import core.stdc.stdlib;
version = ChangeClassInfo;
extern (C) void rt_setTraceHandler(Throwable.TraceInfo function(void* ptr));
class DefaultTraceInfo : Throwable.TraceInfo {
override int opApply( scope int delegate(ref char[]) dg ) {
return 0;
}
override int opApply( scope int delegate(ref size_t, ref char[]) dg ) {
return 0;
}
override string toString() {
return "lol";
}
version(ChangeClassInfo)
ubyte[2037] fixbuf;
else
ubyte[2036] fixbuf;
}
Throwable.TraceInfo defaultTraceHandler2( void* ptr = null ) {
return new DefaultTraceInfo;
}
void main() {
auto f = &defaultTraceHandler2;
rt_setTraceHandler(f);
auto g = new Exception("");
auto gptr = cast(void***) g;
printf("sizeof(DefaultTraceInfo) == %zu\n", __traits(classInstanceSize, DefaultTraceInfo));
printf("%p; deref=%p, deref2=%p, classinfo=%p\n", gptr, *gptr, **gptr, g.classinfo);
try {
throw g;
} finally {
printf("%p; deref=%p, deref2=%p, classinfo=%p\n", gptr, *gptr, **gptr, g.classinfo);
exit(0);
}
} Example of normal (2048) result:
Example of corrupted (2052) result:
The 2048 case without ASLR:
The 2052 case without ASLR:
|
Looks like the deeper cause is the GC. The following code path is triggered only when ASLR is enabled and the class instance size is > 2048. The
|
Superseded by pull #43. |
add _d_eh_enter_catch to support exception chaining
Fixes (?) bug 6376: Throwing exception or assertion failure causes segfault or memory error due to ASLR on Mac OS X 10.7.
The patch reduces the size of the
DefaultTraceInfo
class from > 4 KiB to 2 KiB (can be less), which mysteriously allow the program not segfault anymore (at least for the druntime and Phobos unit tests). I don't know why this happens, but _probably_ because if it is longer, the class instance starts to override the original Throwable'sclassinfo
.The actual fix is commit 15706b2, the other one (8bce1bd) is just some changes to make the files compilable without
-d
and fix some signatures, which is not necessary.