From aaa4e93ca8d97f384fe22ef235257c6643dce963 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 6 May 2018 10:40:02 -0700 Subject: [PATCH] Debugger: Use a lock for memory reallocs. Simpler this way, no need to remember to lock memory. --- Core/Core.h | 4 ++++ Core/Debugger/WebSocket.cpp | 3 +++ Core/Debugger/WebSocket/DisasmSubscriber.cpp | 3 --- Core/MemMap.cpp | 14 ++++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Core/Core.h b/Core/Core.h index 84fe707792b7..0b87f2b393e2 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -45,6 +45,10 @@ enum class CoreLifecycle { STOPPING, // Guaranteed call after STOPPING. STOPPED, + + // Sometimes called for save states. Guaranteed sequence, and never during STARTING or STOPPING. + MEMORY_REINITING, + MEMORY_REINITED, }; typedef void (* CoreLifecycleFunc)(CoreLifecycle stage); diff --git a/Core/Debugger/WebSocket.cpp b/Core/Debugger/WebSocket.cpp index 3ae93962a8ce..f477746c7898 100644 --- a/Core/Debugger/WebSocket.cpp +++ b/Core/Debugger/WebSocket.cpp @@ -20,6 +20,7 @@ #include "thread/threadutil.h" #include "Core/Debugger/WebSocket.h" #include "Core/Debugger/WebSocket/WebSocketUtils.h" +#include "Core/MemMap.h" // This WebSocket (connected through the same port as disc sharing) allows API/debugger access to PPSSPP. // Currently, the only subprotocol "debugger.ppsspp.org" uses a simple JSON based interface. @@ -88,6 +89,7 @@ static void WebSocketNotifyLifecycle(CoreLifecycle stage) { switch (stage) { case CoreLifecycle::STARTING: case CoreLifecycle::STOPPING: + case CoreLifecycle::MEMORY_REINITING: if (debuggersConnected > 0) { DEBUG_LOG(SYSTEM, "Waiting for debugger to complete on shutdown"); } @@ -96,6 +98,7 @@ static void WebSocketNotifyLifecycle(CoreLifecycle stage) { case CoreLifecycle::START_COMPLETE: case CoreLifecycle::STOPPED: + case CoreLifecycle::MEMORY_REINITED: lifecycleLock.unlock(); if (debuggersConnected > 0) { DEBUG_LOG(SYSTEM, "Debugger ready for shutdown"); diff --git a/Core/Debugger/WebSocket/DisasmSubscriber.cpp b/Core/Debugger/WebSocket/DisasmSubscriber.cpp index 84d0692ae2e4..95dddcebb820 100644 --- a/Core/Debugger/WebSocket/DisasmSubscriber.cpp +++ b/Core/Debugger/WebSocket/DisasmSubscriber.cpp @@ -256,7 +256,6 @@ void WebSocketDisasmState::Base(DebuggerRequest &req) { // - params: formatted parameters for the instruction. // - (other info about the disassembled line.) void WebSocketDisasmState::Disasm(DebuggerRequest &req) { - auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } @@ -339,7 +338,6 @@ void WebSocketDisasmState::Disasm(DebuggerRequest &req) { // Response (same event name): // - address: number address of match or null if none was found. void WebSocketDisasmState::SearchDisasm(DebuggerRequest &req) { - auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } @@ -417,7 +415,6 @@ void WebSocketDisasmState::SearchDisasm(DebuggerRequest &req) { // Response (same event name): // - encoding: resulting encoding at this address. Always returns one value, even for macros. void WebSocketDisasmState::Assemble(DebuggerRequest &req) { - auto memLock = Memory::Lock(); if (!currentDebugMIPS->isAlive() || !Memory::IsActive()) { return req.Fail("CPU not started"); } diff --git a/Core/MemMap.cpp b/Core/MemMap.cpp index 8282aac3dbbc..0fc1355ae0a9 100644 --- a/Core/MemMap.cpp +++ b/Core/MemMap.cpp @@ -291,6 +291,14 @@ void Init() { base, m_pPhysicalRAM, m_pUncachedRAM); } +void Reinit() { + _assert_msg_(SYSTEM, PSP_IsInited(), "Cannot reinit during startup/shutdown"); + Core_NotifyLifecycle(CoreLifecycle::MEMORY_REINITING); + Shutdown(); + Init(); + Core_NotifyLifecycle(CoreLifecycle::MEMORY_REINITED); +} + void DoState(PointerWrap &p) { auto s = p.Section("Memory", 1, 3); if (!s) @@ -308,8 +316,7 @@ void DoState(PointerWrap &p) { if (!g_RemasterMode) { g_MemorySize = g_PSPModel == PSP_MODEL_FAT ? RAM_NORMAL_SIZE : RAM_DOUBLE_SIZE; if (oldMemorySize < g_MemorySize) { - Shutdown(); - Init(); + Reinit(); } } } else { @@ -320,8 +327,7 @@ void DoState(PointerWrap &p) { p.DoMarker("PSPModel"); p.Do(g_MemorySize); if (oldMemorySize != g_MemorySize) { - Shutdown(); - Init(); + Reinit(); } }