Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow to unpause after fatal error occured in emulation #10833

Merged
merged 2 commits into from Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Utilities/Thread.cpp
Expand Up @@ -1580,7 +1580,7 @@ bool handle_access_violation(u32 addr, bool is_writing, x64_context* context) no
}
}

Emu.Pause();
Emu.Pause(true);

if (!g_tls_access_violation_recovered)
{
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/SPURecompiler.cpp
Expand Up @@ -9489,7 +9489,6 @@ struct spu_llvm_worker
else
{
spu_log.fatal("[0x%05x] Compilation failed.", func.entry_point);
Emu.Pause();
return;
}

Expand Down
32 changes: 28 additions & 4 deletions rpcs3/Emu/System.cpp
Expand Up @@ -1289,6 +1289,11 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
{
ppu_exec.set_error(elf_error::header_type);
}
else
{
// Preserve emulation state for OVL excutable
Pause(true);
}

if (ppu_exec != elf_error::ok)
{
Expand All @@ -1306,13 +1311,15 @@ game_boot_result Emulator::Load(const std::string& title_id, bool add_only, bool
GetCallbacks().on_ready();
g_fxo->init(false);
ppu_load_prx(ppu_prx, m_path);
Pause(true);
}
else if (spu_exec.open(elf_file) == elf_error::ok)
{
// SPU executable (experimental)
GetCallbacks().on_ready();
g_fxo->init(false);
spu_load_exec(spu_exec);
Pause(true);
}
else
{
Expand Down Expand Up @@ -1404,17 +1411,27 @@ void Emulator::Run(bool start_playtime)
}
}

bool Emulator::Pause()
bool Emulator::Pause(bool freeze_emulation)
{
const u64 start = get_system_time();

const system_state pause_state = freeze_emulation ? system_state::frozen : system_state::paused;

// Try to pause
if (!m_state.compare_and_swap_test(system_state::running, system_state::paused))
if (!m_state.compare_and_swap_test(system_state::running, pause_state))
{
if (!m_state.compare_and_swap_test(system_state::ready, system_state::paused))
if (!freeze_emulation)
{
return false;
}

if (!m_state.compare_and_swap_test(system_state::ready, pause_state))
{
if (!m_state.compare_and_swap_test(system_state::paused, pause_state))
{
return false;
}
}
}

// Signal profilers to print results (if enabled)
Expand All @@ -1424,7 +1441,14 @@ bool Emulator::Pause()

static atomic_t<u32> pause_mark = 0;

sys_log.success("Emulation is being paused... (mark=%u)", pause_mark++);
if (freeze_emulation)
{
sys_log.warning("Emulation has been frozen! You can either use debugger tools to inspect current emulation state or terminate it.");
}
else
{
sys_log.success("Emulation is being paused... (mark=%u)", pause_mark++);
}
Megamouse marked this conversation as resolved.
Show resolved Hide resolved

// Update pause start time
if (m_pause_start_time.exchange(start))
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Emu/System.h
Expand Up @@ -26,6 +26,7 @@ enum class system_state : u32
running,
stopped,
paused,
frozen, // paused but cannot resume
ready,
};

Expand Down Expand Up @@ -221,7 +222,7 @@ class Emulator final

game_boot_result Load(const std::string& title_id = "", bool add_only = false, bool force_global_config = false, bool is_disc_patch = false);
void Run(bool start_playtime);
bool Pause();
bool Pause(bool freeze_emulation = false);
void Resume();
void Stop(bool restart = false);
void Restart() { Stop(true); }
Expand All @@ -232,7 +233,7 @@ class Emulator final
bool IsPaused() const { return m_state >= system_state::paused; } // ready is also considered paused by this function
bool IsStopped() const { return m_state == system_state::stopped; }
bool IsReady() const { return m_state == system_state::ready; }
auto GetStatus() const { return m_state.load(); }
auto GetStatus() const { system_state state = m_state; return state == system_state::frozen ? system_state::paused : state; }

bool HasGui() const { return m_has_gui; }
void SetHasGui(bool has_gui) { m_has_gui = has_gui; }
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/main.cpp
Expand Up @@ -221,7 +221,7 @@ struct fatal_error_listener final : logs::listener
}
#endif
// Pause emulation if fatal error encountered
Emu.Pause();
Emu.Pause(true);
}
}
};
Expand Down