-
Notifications
You must be signed in to change notification settings - Fork 10
Improve robustness of the crash signal handler #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| #include <fstream> | ||
| #include <memory> | ||
| #include <set> | ||
| #include <signal.h> | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
@@ -883,16 +884,6 @@ void Profiler::disableEngines() { | |
| _wall_engine->enableEvents(false); | ||
| } | ||
|
|
||
| void Profiler::trapHandlerEntry(int signo, siginfo_t *siginfo, void *ucontext) { | ||
| Profiler::instance()->trapHandler(signo, siginfo, ucontext); | ||
| } | ||
|
|
||
| void Profiler::trapHandler(int signo, siginfo_t *siginfo, void *ucontext) { | ||
| if (orig_trapHandler != NULL) { | ||
| orig_trapHandler(signo, siginfo, ucontext); | ||
| } | ||
| } | ||
|
|
||
| void Profiler::segvHandler(int signo, siginfo_t *siginfo, void *ucontext) { | ||
| if (!crashHandler(signo, siginfo, ucontext)) { | ||
| orig_segvHandler(signo, siginfo, ucontext); | ||
|
|
@@ -906,14 +897,30 @@ void Profiler::busHandler(int signo, siginfo_t *siginfo, void *ucontext) { | |
| } | ||
|
|
||
| bool Profiler::crashHandler(int signo, siginfo_t *siginfo, void *ucontext) { | ||
| ProfiledThread* thrd = ProfiledThread::current(); | ||
| if (thrd != nullptr && !thrd->enterCrashHandler()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this puts some weight on the thread object to be always valid or null |
||
| // we are already in a crash handler; don't recurse! | ||
| return false; | ||
| } | ||
| uintptr_t fault_address = (uintptr_t)siginfo->si_addr; | ||
| StackFrame frame(ucontext); | ||
| uintptr_t pc = frame.pc(); | ||
| if (pc == fault_address) { | ||
jbachorik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // it is 'pc' that is causing the fault; can not access it safely | ||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| uintptr_t length = SafeAccess::skipLoad(pc); | ||
| if (length > 0) { | ||
| // Skip the fault instruction, as if it successfully loaded NULL | ||
| frame.pc() += length; | ||
| frame.retval() = 0; | ||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -922,35 +929,44 @@ bool Profiler::crashHandler(int signo, siginfo_t *siginfo, void *ucontext) { | |
| // Act as if the load returned default_value argument | ||
| frame.pc() += length; | ||
| frame.retval() = frame.arg1(); | ||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (WX_MEMORY && Trap::isFaultInstruction(pc)) { | ||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| if (VM::isHotspot()) { | ||
| // the following checks require vmstructs and therefore HotSpot | ||
| StackWalker::checkFault(); | ||
|
|
||
| // this check can longjmp to a completely different location - need to call exitCrashHandler() before | ||
| StackWalker::checkFault(thrd); | ||
|
|
||
| // Workaround for JDK-8313796. Setting cstack=dwarf also helps | ||
| if (VMStructs::isInterpretedFrameValidFunc((const void *)pc) && | ||
| frame.skipFaultInstruction()) { | ||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if (thrd != nullptr) { | ||
| thrd->exitCrashHandler(); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| void Profiler::setupSignalHandlers() { | ||
| orig_trapHandler = | ||
| OS::installSignalHandler(SIGTRAP, Profiler::trapHandlerEntry); | ||
| if (orig_trapHandler == (void *)SIG_DFL || | ||
| orig_trapHandler == (void *)SIG_IGN) { | ||
| orig_trapHandler = NULL; | ||
| } | ||
| if (VM::java_version() > 0) { | ||
| // do not re-run the signal setup (run only when VM has not been loaded yet) | ||
| if (VM::java_version() > 0 && !VM::loaded()) { | ||
r1viollet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // HotSpot and J9 tolerate interposed SIGSEGV/SIGBUS handler; other JVMs | ||
| // probably not | ||
| orig_segvHandler = OS::replaceSigsegvHandler(segvHandler); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,9 +454,12 @@ int StackWalker::walkVM(void *ucontext, ASGCT_CallFrame *frames, int max_depth, | |
| return depth; | ||
| } | ||
|
|
||
| void StackWalker::checkFault() { | ||
| void StackWalker::checkFault(ProfiledThread* thrd) { | ||
| VMThread *vm_thread = VMThread::current(); | ||
| if (vm_thread != NULL && sameStack(vm_thread->exception(), &vm_thread)) { | ||
| if (thrd) { | ||
| thrd->exitCrashHandler(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not work, we are doing a longjmp, so we should reset before exiting. Here the increments will build up. |
||
| } | ||
| longjmp(*(jmp_buf *)vm_thread->exception(), 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.