summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorSepalani <sepalani@hotmail.fr>2017-03-28 17:45:17 +0100
committerSepalani <sepalani@hotmail.fr>2017-04-29 20:08:25 +0100
commit3f2f3679cdff1509fb8c8908fbe2a413c0904e2a (patch)
treea2dddb5b0de7d823ce54d1cfc34a6e540d84ab2f /Source/Core
parenta2cba6d72f049e86460491c875353584e167d613 (diff)
PPCAnalyst: Prevent PanicAlert due to invalid read
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/PowerPC/PPCAnalyst.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/Source/Core/Core/PowerPC/PPCAnalyst.cpp b/Source/Core/Core/PowerPC/PPCAnalyst.cpp
index 4399bc445f..ab2344e56d 100644
--- a/Source/Core/Core/PowerPC/PPCAnalyst.cpp
+++ b/Source/Core/Core/PowerPC/PPCAnalyst.cpp
@@ -94,7 +94,6 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size)
if (func.size >= CODEBUFFER_SIZE * 4) // weird
return false;
- const UGeckoInstruction instr = PowerPC::HostRead_Instruction(addr);
if (max_size && func.size > max_size)
{
func.address = startAddr;
@@ -104,7 +103,9 @@ bool AnalyzeFunction(u32 startAddr, Symbol& func, int max_size)
func.flags |= FFLAG_STRAIGHT;
return true;
}
- if (PPCTables::IsValidInstruction(instr))
+ const PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(addr);
+ const UGeckoInstruction instr = read_result.hex;
+ if (read_result.valid && PPCTables::IsValidInstruction(instr))
{
if (instr.hex == 0x4e800020) // 4e800021 is blrl, not the end of a function
{
@@ -271,9 +272,10 @@ static void FindFunctionsFromBranches(u32 startAddr, u32 endAddr, SymbolDB* func
{
for (u32 addr = startAddr; addr < endAddr; addr += 4)
{
- const UGeckoInstruction instr = PowerPC::HostRead_Instruction(addr);
+ const PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(addr);
+ const UGeckoInstruction instr = read_result.hex;
- if (PPCTables::IsValidInstruction(instr))
+ if (read_result.valid && PPCTables::IsValidInstruction(instr))
{
switch (instr.OPCD)
{
@@ -309,11 +311,15 @@ static void FindFunctionsAfterBLR(PPCSymbolDB* func_db)
{
while (true)
{
- // skip zeroes that sometimes pad function to 16 byte boundary (e.g. Donkey Kong Country
+ // Skip zeroes that sometimes pad function to 16 byte boundary (e.g. Donkey Kong Country
// Returns)
- while (PowerPC::HostRead_Instruction(location) == 0 && ((location & 0xf) != 0))
+ PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(location);
+ while (read_result.valid && read_result.hex == 0 && (location & 0xf) != 0)
+ {
location += 4;
- if (PPCTables::IsValidInstruction(PowerPC::HostRead_Instruction(location)))
+ read_result = PowerPC::TryReadInstruction(location);
+ }
+ if (read_result.valid && PPCTables::IsValidInstruction(read_result.hex))
{
// check if this function is already mapped
Symbol* f = func_db->AddFunction(location);