8257828: SafeFetch may crash if invoked in non-JavaThreads

Reviewed-by: mdoerr, kbarrett, coleenp, dholmes
This commit is contained in:
Thomas Stuefe 2020-12-15 07:00:54 +00:00
parent 381021aebf
commit 3ab1dfeb8f
12 changed files with 114 additions and 95 deletions

View file

@ -2242,30 +2242,25 @@ int os::signal_wait() {
LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo,
address handler) {
Thread* thread = Thread::current_or_null();
// Save pc in thread
#if defined(_M_ARM64)
// Do not blow up if no thread info available.
if (thread) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Pc);
}
// Set pc to handler
exceptionInfo->ContextRecord->Pc = (DWORD64)handler;
#define PC_NAME Pc
#elif defined(_M_AMD64)
// Do not blow up if no thread info available.
if (thread != NULL) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Rip);
}
// Set pc to handler
exceptionInfo->ContextRecord->Rip = (DWORD64)handler;
#define PC_NAME Rip
#elif defined(_M_IX86)
#define PC_NAME Eip
#else
// Do not blow up if no thread info available.
if (thread != NULL) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->Eip);
}
// Set pc to handler
exceptionInfo->ContextRecord->Eip = (DWORD)(DWORD_PTR)handler;
#error unknown architecture
#endif
// Save pc in thread
if (thread != nullptr && thread->is_Java_thread()) {
thread->as_Java_thread()->set_saved_exception_pc((address)(DWORD_PTR)exceptionInfo->ContextRecord->PC_NAME);
}
// Set pc to handler
exceptionInfo->ContextRecord->PC_NAME = (DWORD64)handler;
// Continue the execution
return EXCEPTION_CONTINUE_EXECUTION;
}