From 28feea0447a544ce2be70123d73bcb23c95a8897 Mon Sep 17 00:00:00 2001 From: Eladash Date: Wed, 27 Jan 2021 17:50:39 +0200 Subject: [PATCH] Unfatal Segfaults --- Utilities/Thread.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index 7013c383b9..61451b8cf0 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -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); @@ -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 { @@ -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; @@ -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; @@ -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; @@ -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 @@ -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); } const bool s_exception_handler_set = []() -> bool @@ -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); } void sigpipe_signaling_handler(int)