From 617bbcfb87ac8256f6336c5faf4edab948808d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 19 Jul 2020 17:52:41 +0200 Subject: [PATCH] Step 1 of removing PanicAlert --- Common/ArmEmitter.cpp | 6 ++---- Common/ChunkFile.cpp | 2 +- Common/CodeBlock.h | 7 ++----- Common/Common.h | 2 +- Common/ExceptionHandlerSetup.cpp | 20 ++++++-------------- Common/MemArenaAndroid.cpp | 5 +---- Common/MemArenaPosix.cpp | 8 ++------ Common/MemoryUtil.cpp | 3 +-- 8 files changed, 16 insertions(+), 37 deletions(-) diff --git a/Common/ArmEmitter.cpp b/Common/ArmEmitter.cpp index 596fff7aae..9c713c8aab 100644 --- a/Common/ArmEmitter.cpp +++ b/Common/ArmEmitter.cpp @@ -905,14 +905,12 @@ void ARMXEmitter::WriteSignedMultiply(u32 Op, u32 Op2, u32 Op3, ARMReg dest, ARM } void ARMXEmitter::UDIV(ARMReg dest, ARMReg dividend, ARMReg divisor) { - if (!cpu_info.bIDIVa) - PanicAlert("Trying to use integer divide on hardware that doesn't support it. Bad programmer."); + _assert_(cpu_info.bIDIVa, "Trying to use integer divide on hardware that doesn't support it. Bad programmer."); WriteSignedMultiply(3, 0xF, 0, dest, divisor, dividend); } void ARMXEmitter::SDIV(ARMReg dest, ARMReg dividend, ARMReg divisor) { - if (!cpu_info.bIDIVa) - PanicAlert("Trying to use integer divide on hardware that doesn't support it. Bad programmer."); + _assert_(cpu_info.bIDIVa, "Trying to use integer divide on hardware that doesn't support it. Bad programmer."); WriteSignedMultiply(1, 0xF, 0, dest, divisor, dividend); } diff --git a/Common/ChunkFile.cpp b/Common/ChunkFile.cpp index 760dbc1855..cbfec7ffe7 100644 --- a/Common/ChunkFile.cpp +++ b/Common/ChunkFile.cpp @@ -168,7 +168,7 @@ void PointerWrap::DoMarker(const char *prevName, u32 arbitraryNumber) { u32 cookie = arbitraryNumber; Do(cookie); if (mode == PointerWrap::MODE_READ && cookie != arbitraryNumber) { - PanicAlert("Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); + _assert_msg_(false, "Error: After \"%s\", found %d (0x%X) instead of save marker %d (0x%X). Aborting savestate load...", prevName, cookie, cookie, arbitraryNumber, arbitraryNumber); SetError(ERROR_FAILURE); } } diff --git a/Common/CodeBlock.h b/Common/CodeBlock.h index 777fb164a4..c4023d4a8e 100644 --- a/Common/CodeBlock.h +++ b/Common/CodeBlock.h @@ -85,11 +85,8 @@ public: // If you don't specify a size and we later encounter an executable non-writable block, we're screwed. // These CANNOT be nested. We rely on the memory protection starting at READ|WRITE after start and reset. void BeginWrite(size_t sizeEstimate = 1) { -#ifdef _DEBUG - if (writeStart_) { - PanicAlert("Can't nest BeginWrite calls"); - } -#endif + _dbg_assert_msg_(!writeStart_, "Can't nest BeginWrite calls"); + // In case the last block made the current page exec/no-write, let's fix that. if (PlatformIsWXExclusive()) { writeStart_ = GetCodePtr(); diff --git a/Common/Common.h b/Common/Common.h index ec69b6022b..afd4176a10 100644 --- a/Common/Common.h +++ b/Common/Common.h @@ -64,7 +64,7 @@ #if defined(_DEBUG) #include #undef CHECK_HEAP_INTEGRITY - #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) PanicAlert("memory corruption detected. see log.");} + #define CHECK_HEAP_INTEGRITY() {if (!_CrtCheckMemory()) _assert_msg_(false, "Memory corruption detected. See log.");} #endif #else diff --git a/Common/ExceptionHandlerSetup.cpp b/Common/ExceptionHandlerSetup.cpp index 0f541333a7..9ff5255237 100644 --- a/Common/ExceptionHandlerSetup.cpp +++ b/Common/ExceptionHandlerSetup.cpp @@ -98,9 +98,7 @@ void UninstallExceptionHandler() { #elif defined(__APPLE__) static void CheckKR(const char* name, kern_return_t kr) { - if (kr) { - PanicAlert("%s failed: kr=%x", name, kr); - } + _assert_msg_(kr == 0, "%s failed: kr=%x", name, kr); } static void ExceptionThread(mach_port_t port) { @@ -147,15 +145,8 @@ static void ExceptionThread(mach_port_t port) { return; } - if (msg_in.Head.msgh_id != 2406) { - PanicAlert("unknown message received"); - return; - } - - if (msg_in.flavor != x86_THREAD_STATE64) { - PanicAlert("unknown flavor %d (expected %d)", msg_in.flavor, x86_THREAD_STATE64); - return; - } + _assert_msg_(msg_in.Head.msgh_id == 2406, "unknown message received"); + _assert_msg_(msg_in.flavor == x86_THREAD_STATE64, "unknown flavor %d (expected %d)", msg_in.flavor, x86_THREAD_STATE64); x86_thread_state64_t* state = (x86_thread_state64_t*)msg_in.old_state; @@ -299,8 +290,9 @@ void InstallExceptionHandler(BadAccessHandler badAccessHandler) { #endif signal_stack.ss_size = SIGSTKSZ; signal_stack.ss_flags = 0; - if (sigaltstack(&signal_stack, nullptr)) - PanicAlert("sigaltstack failed"); + if (sigaltstack(&signal_stack, nullptr)) { + _assert_msg_(false, "sigaltstack failed"); + } struct sigaction sa; sa.sa_handler = nullptr; sa.sa_sigaction = &sigsegv_handler; diff --git a/Common/MemArenaAndroid.cpp b/Common/MemArenaAndroid.cpp index a0b8614f19..67e1861e5a 100644 --- a/Common/MemArenaAndroid.cpp +++ b/Common/MemArenaAndroid.cpp @@ -156,10 +156,7 @@ u8* MemArena::Find4GBBase() { #else // Address masking is used in 32-bit mode, so we can get away with less memory. void* base = mmap(0, 0x10000000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); - if (base == MAP_FAILED) { - PanicAlert("Failed to map 256 MB of memory space: %s", strerror(errno)); - return 0; - } + _assert_msg_(base != MAP_FAILED, "Failed to map 256 MB of memory space: %s", strerror(errno)); munmap(base, 0x10000000); return static_cast(base); #endif diff --git a/Common/MemArenaPosix.cpp b/Common/MemArenaPosix.cpp index 5ee371ed17..15647b147a 100644 --- a/Common/MemArenaPosix.cpp +++ b/Common/MemArenaPosix.cpp @@ -124,12 +124,8 @@ u8* MemArena::Find4GBBase() { } #else size_t size = 0x10000000; - void* base = mmap(0, size, PROT_READ | PROT_WRITE, - MAP_ANON | MAP_SHARED, -1, 0); - if (base == MAP_FAILED) { - PanicAlert("Failed to map 256 MB of memory space: %s", strerror(errno)); - return 0; - } + void* base = mmap(0, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); + _assert_msg_(base != MAP_FAILED, "Failed to map 256 MB of memory space: %s", strerror(errno)); munmap(base, size); return static_cast(base); #endif diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index 519bfc6bd5..8e3ba5c56d 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -292,8 +292,7 @@ bool ProtectMemoryPages(const void* ptr, size_t size, uint32_t memProtFlags) { if (PlatformIsWXExclusive()) { if ((memProtFlags & (MEM_PROT_WRITE | MEM_PROT_EXEC)) == (MEM_PROT_WRITE | MEM_PROT_EXEC)) { - ERROR_LOG(MEMMAP, "Bad memory protection %d!", memProtFlags); - PanicAlert("Bad memory protect : W^X is in effect, can't both write and exec"); + _assert_msg_(false, "Bad memory protect flags %d: W^X is in effect, can't both write and exec", memProtFlags); } } // Note - VirtualProtect will affect the full pages containing the requested range.