From 2071addce07df2542b055f6286ad523332e568c7 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 4 Dec 2023 21:21:53 +1000 Subject: [PATCH] CPU/NewRec: Fix OOB reads on InstructionInfo --- src/core/cpu_newrec_compiler.cpp | 4 +++- src/core/cpu_newrec_compiler.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/cpu_newrec_compiler.cpp b/src/core/cpu_newrec_compiler.cpp index f3042e0d6..9e62bd3b9 100644 --- a/src/core/cpu_newrec_compiler.cpp +++ b/src/core/cpu_newrec_compiler.cpp @@ -111,7 +111,7 @@ const void* CPU::NewRec::Compiler::CompileBlock(CodeCache::Block* block, u32* ho { CompileInstruction(); - if (iinfo->is_last_instruction || m_block_ended) + if (m_block_ended || iinfo->is_last_instruction) { if (!m_block_ended) { @@ -1111,6 +1111,7 @@ void CPU::NewRec::Compiler::BackupHostState() bu.dirty_gte_done_cycle = m_dirty_gte_done_cycle; bu.block_ended = m_block_ended; bu.inst = inst; + bu.iinfo = iinfo; bu.current_instruction_pc = m_current_instruction_pc; bu.current_instruction_delay_slot = m_current_instruction_branch_delay_slot; bu.const_regs_valid = m_constant_regs_valid; @@ -1139,6 +1140,7 @@ void CPU::NewRec::Compiler::RestoreHostState() m_current_instruction_branch_delay_slot = bu.current_instruction_delay_slot; m_current_instruction_pc = bu.current_instruction_pc; inst = bu.inst; + iinfo = bu.iinfo; m_block_ended = bu.block_ended; m_dirty_gte_done_cycle = bu.dirty_gte_done_cycle; m_dirty_instruction_bits = bu.dirty_instruction_bits; diff --git a/src/core/cpu_newrec_compiler.h b/src/core/cpu_newrec_compiler.h index 894c2b625..6164ecefb 100644 --- a/src/core/cpu_newrec_compiler.h +++ b/src/core/cpu_newrec_compiler.h @@ -436,7 +436,7 @@ protected: bool dirty_gte_done_cycle; bool block_ended; const Instruction* inst; - const CodeCache::InstructionInfo* iinfo; + CodeCache::InstructionInfo* iinfo; u32 current_instruction_pc; bool current_instruction_delay_slot; std::bitset(Reg::count)> const_regs_valid;