Skip to content

Commit

Permalink
Merge pull request #14325 from unknownbrackets/mem-validsize
Browse files Browse the repository at this point in the history
Core: Unbreak Memory::ValidSize limit
  • Loading branch information
hrydgard committed Mar 29, 2021
2 parents 233b0a8 + f830689 commit 848c7fc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Core/MIPS/MIPSAnalyst.cpp
Expand Up @@ -983,7 +983,8 @@ namespace MIPSAnalyst {
// We assume the furthest jumpback is within the func.
u32 furthestJumpbackAddr = INVALIDTARGET;

for (u32 ahead = fromAddr; ahead < fromAddr + MAX_AHEAD_SCAN; ahead += 4) {
const u32 scanEnd = fromAddr + Memory::ValidSize(fromAddr, MAX_AHEAD_SCAN);
for (u32 ahead = fromAddr; ahead < scanEnd; ahead += 4) {
MIPSOpcode aheadOp = Memory::Read_Instruction(ahead, true);
u32 target = GetBranchTargetNoRA(ahead, aheadOp);
if (target == INVALIDTARGET && ((aheadOp & 0xFC000000) == 0x08000000)) {
Expand Down
8 changes: 4 additions & 4 deletions Core/MemMap.h
Expand Up @@ -313,13 +313,13 @@ inline bool IsValidAddress(const u32 address) {
inline u32 ValidSize(const u32 address, const u32 requested_size) {
u32 max_size;
if ((address & 0x3E000000) == 0x08000000) {
max_size = 0x08000000 + g_MemorySize - (address & 0x3E000000);
max_size = 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF);
} else if ((address & 0x3F800000) == 0x04000000) {
max_size = 0x04800000 - (address & 0x3F800000);
max_size = 0x04800000 - (address & 0x3FFFFFFF);
} else if ((address & 0xBFFF0000) == 0x00010000) {
max_size = 0x00014000 - (address & 0xBFFF0000);
max_size = 0x00014000 - (address & 0xBFFFFFFF);
} else if ((address & 0x3F000000) >= 0x08000000 && (address & 0x3F000000) < 0x08000000 + g_MemorySize) {
max_size = 0x08000000 + g_MemorySize - (address & 0x3F000000);
max_size = 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF);
} else {
max_size = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion Core/System.cpp
Expand Up @@ -122,7 +122,8 @@ void UpdateUIState(GlobalUIState newState) {
// Never leave the EXIT state.
if (globalUIState != newState && globalUIState != UISTATE_EXIT) {
globalUIState = newState;
host->UpdateDisassembly();
if (host)
host->UpdateDisassembly();
const char *state = nullptr;
switch (globalUIState) {
case UISTATE_EXIT: state = "exit"; break;
Expand Down
5 changes: 2 additions & 3 deletions Windows/Debugger/Debugger_MemoryDlg.cpp
Expand Up @@ -131,9 +131,8 @@ void CMemoryDlg::searchBoxRedraw(std::vector<u32> results) {
}


void CMemoryDlg::NotifyMapLoaded()
{
if (m_hDlg)
void CMemoryDlg::NotifyMapLoaded() {
if (m_hDlg && g_symbolMap)
g_symbolMap->FillSymbolListBox(symListHdl, ST_DATA);
Update();
}
Expand Down
3 changes: 3 additions & 0 deletions Windows/EmuThread.cpp
Expand Up @@ -263,6 +263,9 @@ void MainThreadFunc() {
if (!Core_IsActive())
UpdateUIState(UISTATE_MENU);
Core_Run(g_graphicsContext);
if (coreState == CORE_BOOT_ERROR) {
break;
}
}
}
Core_Stop();
Expand Down
3 changes: 3 additions & 0 deletions unittest/UnitTest.cpp
Expand Up @@ -567,6 +567,8 @@ static bool TestMemMap() {
EXPECT_EQ_HEX(Memory::ValidSize(base, 0x40000001), range.size);
EXPECT_EQ_HEX(Memory::ValidSize(base, 0x20000001), range.size);
EXPECT_EQ_HEX(Memory::ValidSize(base, 0x10000001), range.size);

EXPECT_EQ_HEX(Memory::ValidSize(base + range.size - 0x10, 0x20000001), 0x10);
}
}

Expand Down Expand Up @@ -607,6 +609,7 @@ TestItem availableTests[] = {
TEST_ITEM(ParseLBN),
TEST_ITEM(QuickTexHash),
TEST_ITEM(CLZ),
TEST_ITEM(MemMap),
TEST_ITEM(ShaderGenerators),
};

Expand Down

0 comments on commit 848c7fc

Please sign in to comment.