diff --git a/CMakeLists.txt b/CMakeLists.txt index b38efb728..13374092e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index b6b6d2b7b..91e8743da 100644 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -6,6 +6,7 @@ #include "emulator.h" #include "rend/mainui.h" #include "oslib/directory.h" +#include "oslib/oslib.h" #include #include @@ -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 diff --git a/core/linux/common.cpp b/core/linux/common.cpp index 9eed8afdf..b2fd99a5b 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -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); diff --git a/core/oslib/oslib.h b/core/oslib/oslib.h index bf8092d3d..fcf80354c 100644 --- a/core/oslib/oslib.h +++ b/core/oslib/oslib.h @@ -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 diff --git a/core/windows/fault_handler.cpp b/core/windows/fault_handler.cpp index 7991d0af8..55d329876 100644 --- a/core/windows/fault_handler.cpp +++ b/core/windows/fault_handler.cpp @@ -14,13 +14,16 @@ You should have received a copy of the GNU General Public License along with Flycast. If not, see . */ -#include "fault_handler.h" +#include "oslib/oslib.h" #include "hw/sh4/dyna/blockmanager.h" #include "hw/sh4/dyna/ngen.h" +#include 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 = []() { diff --git a/core/windows/fault_handler.h b/core/windows/fault_handler.h deleted file mode 100644 index f3be4ae17..000000000 --- a/core/windows/fault_handler.h +++ /dev/null @@ -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 . -*/ -#include - -LONG exceptionHandler(EXCEPTION_POINTERS *ep); -void setup_seh(); diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index de76e40da..63caff8f4 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -32,7 +32,6 @@ #include "rend/mainui.h" #include "../shell/windows/resource.h" #include "rawinput.h" -#include "fault_handler.h" #include #include @@ -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 diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index 1636323b3..b4f23a29d 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -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 lock(mtx_serialization); } + os_UninstallFaultHandler(); libretro_supports_bitmasks = false; LogManager::Shutdown(); }