Skip to content
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

Unfatal Segfaults #9663

Merged
merged 1 commit into from Jan 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 12 additions & 20 deletions Utilities/Thread.cpp
Expand Up @@ -1403,7 +1403,6 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
// Hack: allocate memory in case the emulator is stopping
const auto hack_alloc = [&]()
{
// If failed the value remains true and std::terminate should be called
g_tls_access_violation_recovered = true;

const auto area = vm::reserve_map(vm::any, addr & -0x10000, 0x10000);
Expand Down Expand Up @@ -1529,7 +1528,8 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no

if (sending_error)
{
vm_log.fatal("Unknown error 0x%x while trying to pass page fault.", +sending_error);
vm_log.error("Unknown error 0x%x while trying to pass page fault.", +sending_error);
return false;
}
else
{
Expand All @@ -1548,7 +1548,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
// Reschedule, test cpu state and try recovery if stopped
if (cpu->test_stopped() && !hack_alloc())
{
std::terminate();
return false;
}

return true;
Expand All @@ -1569,7 +1569,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no

if (cpu->check_state() && !hack_alloc())
{
std::terminate();
return false;
}

return true;
Expand Down Expand Up @@ -1606,7 +1606,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no

if (Emu.IsStopped() && !hack_alloc())
{
std::terminate();
return false;
}

return true;
Expand Down Expand Up @@ -1676,8 +1676,6 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept
if (thread_ctrl::get_current())
{
fmt::append(msg, "Emu Thread Name: '%s'.\n", thread_ctrl::get_name());

sys_log.notice("\n%s", dump_useful_thread_info());
}

// TODO: Report full thread name if not an emu thread
Expand Down Expand Up @@ -1739,14 +1737,7 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept

// TODO: print registers and the callstack

sys_log.fatal("\n%s", msg);

if (!IsDebuggerPresent())
{
report_fatal_error(msg);
}

return EXCEPTION_CONTINUE_SEARCH;
thread_ctrl::emergency_exit(msg);
elad335 marked this conversation as resolved.
Show resolved Hide resolved
}

const bool s_exception_handler_set = []() -> bool
Expand Down Expand Up @@ -1810,24 +1801,25 @@ static void signal_handler(int sig, siginfo_t* info, void* uct) noexcept
if (thread_ctrl::get_current())
{
fmt::append(msg, "Emu Thread Name: '%s'.\n", thread_ctrl::get_name());
sys_log.notice("\n%s", dump_useful_thread_info());
}

// TODO: Report full thread name if not an emu thread

fmt::append(msg, "Thread id = %s.\n", std::this_thread::get_id());

sys_log.fatal("\n%s", msg);
std::fprintf(stderr, "%s\n", msg.c_str());

if (IsDebuggerPresent())
{
sys_log.fatal("\n%s", msg);
std::fprintf(stderr, "%s\n", msg.c_str());

sys_log.notice("\n%s", dump_useful_thread_info());

// Convert to SIGTRAP
raise(SIGTRAP);
return;
}

report_fatal_error(msg);
thread_ctrl::emergency_exit(msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to be more careful with non-windows path. raise(SIGTRAP) was more tested than plain int3.

Copy link
Contributor Author

@elad335 elad335 Jan 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, remained unchanged for now. (until proper testing is done)

}

void sigpipe_signaling_handler(int)
Expand Down