os_[Un]InstallFaultHandler. Uninstall fault handler at shutdown
This commit is contained in:
parent
4a77f847b4
commit
c458a8f5e7
|
@ -54,8 +54,6 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/core/version.h.in" "${CMAKE_CURRENT_
|
|||
|
||||
if(NINTENDO_SWITCH)
|
||||
set(USE_VULKAN OFF)
|
||||
set(USE_GLES OFF)
|
||||
set(USE_GLES2 OFF)
|
||||
enable_language(ASM)
|
||||
|
||||
if(LIBRETRO)
|
||||
|
@ -67,6 +65,9 @@ if(NINTENDO_SWITCH)
|
|||
add_executable(${PROJECT_NAME} core/emulator.cpp)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE EGL_NO_PLATFORM_SPECIFIC_TYPES)
|
||||
endif()
|
||||
if(USE_GLES)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE GLES)
|
||||
endif()
|
||||
|
||||
elseif(LIBRETRO)
|
||||
add_library(${PROJECT_NAME} SHARED core/emulator.cpp)
|
||||
|
@ -285,6 +286,11 @@ if(PKG_CONFIG_FOUND AND NOT ANDROID AND NOT APPLE AND NOT LIBRETRO)
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(NINTENDO_SWITCH AND USE_GLES)
|
||||
pkg_check_modules(GLESV2 IMPORTED_TARGET glesv2)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::GLESV2)
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT APPLE AND NOT ANDROID)
|
||||
if(USE_GLES2)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE GLES GLES2)
|
||||
|
@ -681,7 +687,6 @@ endif()
|
|||
if(WIN32)
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
core/windows/fault_handler.cpp
|
||||
core/windows/fault_handler.h
|
||||
core/windows/win_vmem.cpp)
|
||||
else()
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "emulator.h"
|
||||
#include "rend/mainui.h"
|
||||
#include "oslib/directory.h"
|
||||
#include "oslib/oslib.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <csignal>
|
||||
|
@ -368,6 +369,7 @@ int main(int argc, char* argv[])
|
|||
#if defined(__SWITCH__)
|
||||
socketInitializeDefault();
|
||||
nxlinkStdio();
|
||||
//appletSetFocusHandlingMode(AppletFocusHandlingMode_NoSuspend);
|
||||
#endif // __SWITCH__
|
||||
|
||||
LogManager::Init();
|
||||
|
@ -401,6 +403,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
dc_term();
|
||||
|
||||
os_UninstallFaultHandler();
|
||||
|
||||
#if defined(USE_EVDEV)
|
||||
input_evdev_close();
|
||||
#endif
|
||||
|
|
|
@ -85,7 +85,7 @@ void fault_handler (int sn, siginfo_t * si, void *segfault_ctx)
|
|||
}
|
||||
#undef HOST_CTX_READY
|
||||
|
||||
void install_fault_handler()
|
||||
void os_InstallFaultHandler()
|
||||
{
|
||||
#ifndef __SWITCH__
|
||||
struct sigaction act, segv_oact;
|
||||
|
@ -103,9 +103,29 @@ void install_fault_handler()
|
|||
sigaction(SIGILL, &act, &segv_oact);
|
||||
#endif
|
||||
}
|
||||
|
||||
void os_UninstallFaultHandler()
|
||||
{
|
||||
#ifndef __SWITCH__
|
||||
struct sigaction act{};
|
||||
act.sa_handler = SIG_DFL;
|
||||
sigemptyset(&act.sa_mask);
|
||||
sigaction(SIGSEGV, &act, nullptr);
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
sigaction(SIGBUS, &act, nullptr);
|
||||
sigaction(SIGILL, &act, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else // !defined(TARGET_NO_EXCEPTIONS)
|
||||
// No exceptions/nvmem dummy handlers.
|
||||
void install_fault_handler() {}
|
||||
|
||||
void os_InstallFaultHandler()
|
||||
{
|
||||
}
|
||||
void os_UninstallFaultHandler()
|
||||
{
|
||||
}
|
||||
#endif // !defined(TARGET_NO_EXCEPTIONS)
|
||||
|
||||
double os_GetSeconds()
|
||||
|
@ -178,7 +198,7 @@ void common_linux_setup()
|
|||
linux_rpi2_init();
|
||||
|
||||
enable_runfast();
|
||||
install_fault_handler();
|
||||
os_InstallFaultHandler();
|
||||
signal(SIGINT, exit);
|
||||
|
||||
DEBUG_LOG(BOOT, "Linux paging: %ld %08X %08X", sysconf(_SC_PAGESIZE), PAGE_SIZE, PAGE_MASK);
|
||||
|
|
|
@ -7,6 +7,8 @@ double os_GetSeconds();
|
|||
void os_DoEvents();
|
||||
void os_CreateWindow();
|
||||
void os_SetupInput();
|
||||
void os_InstallFaultHandler();
|
||||
void os_UninstallFaultHandler();
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h>
|
||||
|
|
|
@ -14,13 +14,16 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "fault_handler.h"
|
||||
#include "oslib/oslib.h"
|
||||
#include "hw/sh4/dyna/blockmanager.h"
|
||||
#include "hw/sh4/dyna/ngen.h"
|
||||
#include <windows.h>
|
||||
|
||||
bool VramLockedWrite(u8* address);
|
||||
bool BM_LockedWrite(u8* address);
|
||||
|
||||
static PVOID vectoredHandler;
|
||||
|
||||
static void readContext(const EXCEPTION_POINTERS *ep, host_context_t &context)
|
||||
{
|
||||
#if HOST_CPU == CPU_X86
|
||||
|
@ -178,6 +181,26 @@ void setup_seh()
|
|||
}
|
||||
#endif
|
||||
|
||||
void os_InstallFaultHandler()
|
||||
{
|
||||
#ifdef _WIN64
|
||||
vectoredHandler = AddVectoredExceptionHandler(1, exceptionHandler);
|
||||
setup_seh();
|
||||
#else
|
||||
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exceptionHandler);
|
||||
#endif
|
||||
}
|
||||
|
||||
void os_UninstallFaultHandler()
|
||||
{
|
||||
#ifdef _WIN64
|
||||
RemoveVectoredExceptionHandler(vectoredHandler);
|
||||
RtlDeleteFunctionTable(Table);
|
||||
#else
|
||||
SetUnhandledExceptionFilter(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
double os_GetSeconds()
|
||||
{
|
||||
static double qpfd = []() {
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
This file is part of Flycast.
|
||||
|
||||
Flycast is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Flycast is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Flycast. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <windows.h>
|
||||
|
||||
LONG exceptionHandler(EXCEPTION_POINTERS *ep);
|
||||
void setup_seh();
|
|
@ -32,7 +32,6 @@
|
|||
#include "rend/mainui.h"
|
||||
#include "../shell/windows/resource.h"
|
||||
#include "rawinput.h"
|
||||
#include "fault_handler.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
@ -707,23 +706,18 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
|||
reserveBottomMemory();
|
||||
setupPath();
|
||||
findKeyboardLayout();
|
||||
#ifdef _WIN64
|
||||
AddVectoredExceptionHandler(1, exceptionHandler);
|
||||
#else
|
||||
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exceptionHandler);
|
||||
#endif
|
||||
|
||||
if (reicast_init(argc, argv) != 0)
|
||||
die("Flycast initialization failed");
|
||||
|
||||
#ifdef _WIN64
|
||||
setup_seh();
|
||||
#endif
|
||||
os_InstallFaultHandler();
|
||||
|
||||
mainui_loop();
|
||||
|
||||
dc_term();
|
||||
|
||||
SetUnhandledExceptionFilter(0);
|
||||
os_UninstallFaultHandler();
|
||||
|
||||
#ifdef USE_SDL
|
||||
sdl_window_destroy();
|
||||
#else
|
||||
|
|
|
@ -59,9 +59,6 @@
|
|||
#include "cfg/option.h"
|
||||
#include "wsi/gl_context.h"
|
||||
#include "version.h"
|
||||
#ifdef _WIN32
|
||||
#include "windows/fault_handler.h"
|
||||
#endif
|
||||
|
||||
constexpr char slash = path_default_slash_c();
|
||||
|
||||
|
@ -277,17 +274,8 @@ void retro_init()
|
|||
|
||||
if (!_vmem_reserve())
|
||||
ERROR_LOG(VMEM, "Cannot reserve memory space");
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN64
|
||||
AddVectoredExceptionHandler(1, exceptionHandler);
|
||||
setup_seh();
|
||||
#else
|
||||
SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exceptionHandler);
|
||||
#endif
|
||||
#else
|
||||
void install_fault_handler();
|
||||
install_fault_handler();
|
||||
#endif
|
||||
|
||||
os_InstallFaultHandler();
|
||||
}
|
||||
|
||||
void retro_deinit()
|
||||
|
@ -300,6 +288,7 @@ void retro_deinit()
|
|||
{
|
||||
std::lock_guard<std::mutex> lock(mtx_serialization);
|
||||
}
|
||||
os_UninstallFaultHandler();
|
||||
libretro_supports_bitmasks = false;
|
||||
LogManager::Shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue