diff --git a/engine/server/library/serverScript/src/shared/JavaLibrary.cpp b/engine/server/library/serverScript/src/shared/JavaLibrary.cpp index f5f415b7..ecfedd95 100755 --- a/engine/server/library/serverScript/src/shared/JavaLibrary.cpp +++ b/engine/server/library/serverScript/src/shared/JavaLibrary.cpp @@ -781,16 +781,26 @@ void JavaLibrary::fatalHandler(int signum) { // try to see if our call stack came from C or Java void *frameAddress = __builtin_frame_address(0); - // the address that generated the segfault is stored at an offset of 0x44 from - // the frame address - // @todo: find documentation on the offset to verify it is stable - void *crashAddress1 = *((void**)((static_cast(frameAddress)) + 0x44)); + // pass the crash address to addr2line to get the file name where the crash occurred + // These are zero initialized because the strstr() checks below read them + // whenever a lookup fails. static const int BUFLEN = 2048; - char lib1[BUFLEN], lib2[BUFLEN]; - char file1[BUFLEN], file2[BUFLEN]; - int line1, line2; - bool result1 = DebugHelp::lookupAddress(reinterpret_cast(crashAddress1), lib1, file1, BUFLEN, line1); + char lib1[BUFLEN] = { '\0' }, lib2[BUFLEN] = { '\0' }; + char file1[BUFLEN] = { '\0' }, file2[BUFLEN] = { '\0' }; + int line1 = 0, line2 = 0; + bool result1 = false; + + // The faulting address used to be read from a fixed 0x44 byte offset into + // this frame. That constant describes the 32-bit x86 frame layout only; on + // x86-64 it is both misaligned and meaningless, and dereferencing it from + // inside a SIGSEGV handler risks a recursive fault that loses the crash + // report entirely. The __builtin_return_address() probe below is portable + // and already covers this case. +#if defined(__i386__) + void *crashAddress1 = *((void**)((static_cast(frameAddress)) + 0x44)); + result1 = DebugHelp::lookupAddress(reinterpret_cast(crashAddress1), lib1, file1, BUFLEN, line1); +#endif // do a second test based on the return address // it turns out that in some java crashes we don't even have 2 return