diff --git a/Core/Debugger/DisassemblyManager.cpp b/Core/Debugger/DisassemblyManager.cpp index a4d5bbbad3..39e03307ab 100644 --- a/Core/Debugger/DisassemblyManager.cpp +++ b/Core/Debugger/DisassemblyManager.cpp @@ -44,7 +44,7 @@ bool isInInterval(u32 start, u32 size, u32 value) { } bool IsLikelyStringAt(uint32_t addr) { - uint32_t maxLen = Memory::ValidSize(addr, 128); + uint32_t maxLen = Memory::ClampValidSizeAt(addr, 128); if (maxLen <= 1) return false; const char *p = Memory::GetCharPointer(addr); @@ -92,7 +92,7 @@ static HashType computeHash(u32 address, u32 size) if (!Memory::IsValidAddress(address)) return 0; - size = Memory::ValidSize(address, size); + size = Memory::ClampValidSizeAt(address, size); #if PPSSPP_ARCH(AMD64) return XXH3_64bits(Memory::GetPointerUnchecked(address), size); #else diff --git a/Core/Debugger/WebSocket/MemorySubscriber.cpp b/Core/Debugger/WebSocket/MemorySubscriber.cpp index e5930aab44..14674bd37d 100644 --- a/Core/Debugger/WebSocket/MemorySubscriber.cpp +++ b/Core/Debugger/WebSocket/MemorySubscriber.cpp @@ -261,7 +261,7 @@ void WebSocketMemoryReadString(DebuggerRequest &req) { // Let's try to avoid crashing and get a safe length. const uint8_t *p = Memory::GetPointerUnchecked(addr); - size_t longest = Memory::ValidSize(addr, Memory::g_MemorySize); + size_t longest = Memory::ClampValidSizeAt(addr, Memory::g_MemorySize); size_t len = strnlen((const char *)p, longest); JsonWriter &json = req.Respond(); diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 1b2f99283d..b3712fc960 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -907,7 +907,7 @@ void SavedataParam::LoadFile(const std::string& dirPath, const std::string& file return; u8 *buf = fileData->buf; - u32 size = Memory::ValidSize(fileData->buf.ptr, fileData->bufSize); + u32 size = Memory::ClampValidSizeAt(fileData->buf.ptr, fileData->bufSize); s64 readSize = -1; if (ReadPSPFile(filePath, &buf, size, &readSize)) { fileData->size = readSize; diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 86c0179e48..c7a6d3d7f8 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -430,7 +430,7 @@ int ISOFileSystem::Ioctl(u32 handle, u32 cmd, u32 indataPtr, u32 inlen, u32 outd return SCE_KERNEL_ERROR_ERRNO_INVALID_ARGUMENT; } else { int block = (u16)desc.firstLETableSector; - u32 size = Memory::ValidSize(outdataPtr, (u32)desc.pathTableLength); + u32 size = Memory::ClampValidSizeAt(outdataPtr, (u32)desc.pathTableLength); u8 *out = Memory::GetPointerWriteRange(outdataPtr, size); int blocks = size / blockDevice->GetBlockSize(); diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index b11420932f..944098fab7 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -1044,7 +1044,7 @@ size_t hleFormatLogArgs(char *message, size_t sz, const char *argmask) { case 's': if (Memory::IsValidAddress(regval)) { const char *s = Memory::GetCharPointer(regval); - const int safeLen = Memory::ValidSize(regval, 128); + const int safeLen = Memory::ClampValidSizeAt(regval, 128); if (strnlen(s, safeLen) >= safeLen) { APPEND_FMT("%.*s...", safeLen, Memory::GetCharPointer(regval)); } else { diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index e565cc543f..381f9c1900 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -418,7 +418,7 @@ static int Replace_memset_jak() { } static uint32_t SafeStringLen(const uint32_t ptr, uint32_t maxLen = 0x07FFFFFF) { - maxLen = Memory::ValidSize(ptr, 0x07FFFFFF); + maxLen = Memory::ClampValidSizeAt(ptr, 0x07FFFFFF); const uint8_t *p = Memory::GetPointerRange(ptr, maxLen); if (!p) return 0; diff --git a/Core/HLE/sceDeflt.cpp b/Core/HLE/sceDeflt.cpp index 21b1a3720c..529f4f7126 100644 --- a/Core/HLE/sceDeflt.cpp +++ b/Core/HLE/sceDeflt.cpp @@ -39,7 +39,7 @@ static int CommonDecompress(int windowBits, u32 OutBuffer, int OutBufferLength, u8 *outBufferPtr = Memory::GetPointerWrite(OutBuffer); stream.next_in = (Bytef*)Memory::GetPointer(InBuffer); // We don't know the available length, just let it use as much as it wants. - stream.avail_in = (uInt)Memory::ValidSize(InBuffer, Memory::g_MemorySize); + stream.avail_in = (uInt)Memory::ClampValidSizeAt(InBuffer, Memory::g_MemorySize); stream.next_out = outBufferPtr; stream.avail_out = (uInt)OutBufferLength; diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 036f31b132..ce7b93cd8e 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1081,7 +1081,7 @@ static bool __IoRead(int &result, int id, u32 data_addr, int size, int &us) { const std::string tag = "IoRead/" + IODetermineFilename(f); NotifyMemInfo(MemBlockFlags::WRITE, data_addr, size, tag.c_str(), tag.size()); u8 *data = (u8 *)Memory::GetPointerUnchecked(data_addr); - u32 validSize = Memory::ValidSize(data_addr, size); + u32 validSize = Memory::ClampValidSizeAt(data_addr, size); if (f->npdrm) { result = npdrmRead(f, data, validSize); currentMIPS->InvalidateICache(data_addr, validSize); @@ -1197,7 +1197,7 @@ static bool __IoWrite(int &result, int id, u32 data_addr, int size, int &us) { } const void *data_ptr = Memory::GetPointer(data_addr); - const u32 validSize = Memory::ValidSize(data_addr, size); + const u32 validSize = Memory::ClampValidSizeAt(data_addr, size); // Let's handle stdout/stderr specially. if (id == PSP_STDOUT || id == PSP_STDERR) { const char *str = (const char *) data_ptr; diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index a83731553b..b255425715 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -924,7 +924,7 @@ static u32 sysclib_strncpy(u32 dest, u32 src, u32 size) { // This is just regular strncpy, but being explicit to avoid warnings/safety fixes on missing null. u32 i = 0; - u32 srcSize = Memory::ValidSize(src, size); + u32 srcSize = Memory::ClampValidSizeAt(src, size); const u8 *srcp = Memory::GetPointerUnchecked(src); u8 *destp = Memory::GetPointerWriteUnchecked(dest); for (i = 0; i < srcSize; ++i) { @@ -934,7 +934,7 @@ static u32 sysclib_strncpy(u32 dest, u32 src, u32 size) { *destp++ = c; } - u32 destSize = Memory::ValidSize(dest, size); + u32 destSize = Memory::ClampValidSizeAt(dest, size); for (; i < destSize; ++i) { *destp++ = 0; } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 58f25c4ee9..091cac4c46 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -762,7 +762,7 @@ void PSPModule::Cleanup() { if (memoryBlockAddr != 0 && nm.text_addr != 0 && memoryBlockSize >= nm.data_size + nm.bss_size + nm.text_size) { DEBUG_LOG(Log::Loader, "Zeroing out module %s memory: %08x - %08x", nm.name, memoryBlockAddr, memoryBlockAddr + memoryBlockSize); - u32 clearSize = Memory::ValidSize(nm.text_addr, (u32)nm.text_size + 3); + u32 clearSize = Memory::ClampValidSizeAt(nm.text_addr, (u32)nm.text_size + 3); for (u32 i = 0; i < clearSize; i += 4) { Memory::WriteUnchecked_U32(MIPS_MAKE_BREAK(1), nm.text_addr + i); } diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index a808f1c97d..5d01e0f655 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -581,7 +581,7 @@ static int sceMpegQueryStreamOffset(u32 mpeg, u32 bufferAddr, u32 offsetAddr) } // Kinda destructive, no? Shouldn't this just do what sceMpegQueryStreamSize does? - AnalyzeMpeg(Memory::GetPointerWriteUnchecked(bufferAddr), Memory::ValidSize(bufferAddr, 32768), ctx); + AnalyzeMpeg(Memory::GetPointerWriteUnchecked(bufferAddr), Memory::ClampValidSizeAt(bufferAddr, 32768), ctx); if (ctx->mpegMagic != PSMF_MAGIC) { Memory::WriteUnchecked_U32(0, offsetAddr); @@ -608,7 +608,7 @@ static u32 sceMpegQueryStreamSize(u32 bufferAddr, u32 sizeAddr) ctx.mediaengine = nullptr; // makes sure we don't actually load the stream. ctx.isAnalyzed = false; - AnalyzeMpeg(Memory::GetPointerWriteUnchecked(bufferAddr), Memory::ValidSize(bufferAddr, 32768), &ctx); + AnalyzeMpeg(Memory::GetPointerWriteUnchecked(bufferAddr), Memory::ClampValidSizeAt(bufferAddr, 32768), &ctx); if (ctx.mpegMagic != PSMF_MAGIC) { Memory::WriteUnchecked_U32(0, sizeAddr); @@ -1405,7 +1405,7 @@ void PostPutAction::run(MipsCall &call) { // TODO: Faster / less wasteful validation. auto demuxer = std::make_unique(packetsAddedThisRound * 2048, 0); int readOffset = ringbuffer->packetsRead % (s32)ringbuffer->packets; - uint32_t bufSize = Memory::ValidSize(ringbuffer->data + readOffset * 2048, packetsAddedThisRound * 2048); + uint32_t bufSize = Memory::ClampValidSizeAt(ringbuffer->data + readOffset * 2048, packetsAddedThisRound * 2048); const u8 *buf = Memory::GetPointer(ringbuffer->data + readOffset * 2048); bool invalid = false; for (uint32_t i = 0; i < bufSize / 2048; ++i) { @@ -1442,7 +1442,7 @@ void PostPutAction::run(MipsCall &call) { packetsAddedThisRound = ringbuffer->packets - ringbuffer->packetsAvail; } const u8 *data = Memory::GetPointer(ringbuffer->data + writeOffset * 2048); - uint32_t dataSize = Memory::ValidSize(ringbuffer->data + writeOffset * 2048, packetsAddedThisRound * 2048); + uint32_t dataSize = Memory::ClampValidSizeAt(ringbuffer->data + writeOffset * 2048, packetsAddedThisRound * 2048); int actuallyAdded = ctx->mediaengine == NULL ? 8 : ctx->mediaengine->addStreamData(data, dataSize) / 2048; if (actuallyAdded != packetsAddedThisRound) { WARN_LOG_REPORT(Log::Mpeg, "sceMpegRingbufferPut(): unable to enqueue all added packets, going to overwrite some frames."); diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index e8ff6905cd..7a9474d1a0 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -292,7 +292,7 @@ public: const u32 EP_MAP_STRIDE = 1 + 1 + 4 + 4; if (psmf->headerOffset != 0 && !Memory::IsValidRange(psmf->headerOffset, psmf->EPMapOffset + EP_MAP_STRIDE * psmf->EPMapEntriesNum)) { ERROR_LOG(Log::ME, "Invalid PSMF EP map entry count: %d", psmf->EPMapEntriesNum); - psmf->EPMapEntriesNum = Memory::ValidSize(psmf->headerOffset + psmf->EPMapOffset, EP_MAP_STRIDE * psmf->EPMapEntriesNum) / EP_MAP_STRIDE; + psmf->EPMapEntriesNum = Memory::ClampValidSizeAt(psmf->headerOffset + psmf->EPMapOffset, EP_MAP_STRIDE * psmf->EPMapEntriesNum) / EP_MAP_STRIDE; } psmf->EPMap.clear(); @@ -372,7 +372,7 @@ Psmf::Psmf(const u8 *ptr, u32 data) { if (data != 0 && !Memory::IsValidRange(data, 0x82 + numStreams * 16)) { ERROR_LOG(Log::ME, "Invalid PSMF stream count: %d", numStreams); - numStreams = Memory::ValidSize(data + 0x82, numStreams * 16) / 16; + numStreams = Memory::ClampValidSizeAt(data + 0x82, numStreams * 16) / 16; } for (int i = 0; i < numStreams; i++) { diff --git a/Core/MIPS/MIPSAnalyst.cpp b/Core/MIPS/MIPSAnalyst.cpp index 590d605b6a..89705675f8 100644 --- a/Core/MIPS/MIPSAnalyst.cpp +++ b/Core/MIPS/MIPSAnalyst.cpp @@ -956,7 +956,7 @@ skip: // We assume the furthest jumpback is within the func. u32 furthestJumpbackAddr = INVALIDTARGET; - const u32 scanEnd = fromAddr + Memory::ValidSize(fromAddr, MAX_AHEAD_SCAN); + const u32 scanEnd = fromAddr + Memory::ClampValidSizeAt(fromAddr, MAX_AHEAD_SCAN); for (u32 ahead = fromAddr; ahead < scanEnd; ahead += 4) { MIPSOpcode aheadOp = Memory::Read_Instruction(ahead, true); u32 target = GetBranchTargetNoRA(ahead, aheadOp); diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index 20939f205a..41d1d1c553 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -177,7 +177,7 @@ public: bool getMemoryValue(uint32_t address, int size, uint32_t& dest, std::string *error) override { // We allow, but ignore, bad access. // If we didn't, log/condition statements that reference registers couldn't be configured. - uint32_t valid = Memory::ValidSize(address, size); + uint32_t valid = Memory::ClampValidSizeAt(address, size); uint8_t buf[4]{}; if (valid != 0) memcpy(buf, Memory::GetPointerUnchecked(address), valid); diff --git a/Core/MemMap.h b/Core/MemMap.h index f327ab4c38..33a31bd9d5 100644 --- a/Core/MemMap.h +++ b/Core/MemMap.h @@ -356,17 +356,17 @@ inline bool IsValidNullTerminatedString(const u32 address) { return false; } -inline u32 ValidSize(const u32 address, const u32 requested_size) { +inline u32 ClampValidSizeAt(const u32 address, const u32 requestedSize) { u32 max_size = MaxSizeAtAddress(address); - if (requested_size > max_size) { + if (requestedSize > max_size) { return max_size; } - return requested_size; + return requestedSize; } // NOTE: If size == 0, any address will be accepted. This may not be ideal for all cases. inline bool IsValidRange(const u32 address, const u32 size) { - return ValidSize(address, size) == size; + return ClampValidSizeAt(address, size) == size; } // NOTE: If size == 0, any address will be accepted. This may not be ideal for all cases. @@ -375,7 +375,7 @@ inline bool IsValid4AlignedRange(const u32 address, const u32 size) { if (address & 3) { return false; } - return ValidSize(address, size) == size; + return ClampValidSizeAt(address, size) == size; } // Used for auto-converted char * parameters, which can sometimes legitimately be null - diff --git a/Core/MemMapFunctions.cpp b/Core/MemMapFunctions.cpp index 4859339201..6f39b1b006 100644 --- a/Core/MemMapFunctions.cpp +++ b/Core/MemMapFunctions.cpp @@ -56,7 +56,7 @@ const u8 *GetPointer(const u32 address) { u8 *GetPointerWriteRange(const u32 address, const u32 size) { u8 *ptr = GetPointerWrite(address); if (ptr) { - if (ValidSize(address, size) != size) { + if (ClampValidSizeAt(address, size) != size) { // That's a memory exception! TODO: Adjust reported address to the end of the range? Core_MemoryException(address, size, currentMIPS->pc, MemoryExceptionType::WRITE_BLOCK); return nullptr; @@ -72,7 +72,7 @@ u8 *GetPointerWriteRange(const u32 address, const u32 size) { const u8 *GetPointerRange(const u32 address, const u32 size) { const u8 *ptr = GetPointer(address); if (ptr) { - if (ValidSize(address, size) != size) { + if (ClampValidSizeAt(address, size) != size) { // That's a memory exception! TODO: Adjust reported address to the end of the range? Core_MemoryException(address, size, currentMIPS->pc, MemoryExceptionType::READ_BLOCK); return nullptr; diff --git a/GPU/Common/GPUDebugInterface.cpp b/GPU/Common/GPUDebugInterface.cpp index 3959107c25..41212b64c6 100644 --- a/GPU/Common/GPUDebugInterface.cpp +++ b/GPU/Common/GPUDebugInterface.cpp @@ -930,7 +930,7 @@ ExpressionType GEExpressionFunctions::getFieldType(GECmdFormat fmt, GECmdField f bool GEExpressionFunctions::getMemoryValue(uint32_t address, int size, uint32_t &dest, std::string *error) { // We allow, but ignore, bad access. // If we didn't, log/condition statements that reference registers couldn't be configured. - uint32_t valid = Memory::ValidSize(address, size); + uint32_t valid = Memory::ClampValidSizeAt(address, size); uint8_t buf[4]{}; if (valid != 0) memcpy(buf, Memory::GetPointerUnchecked(address), valid); diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index c1d8e067a4..82763457d6 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1437,7 +1437,7 @@ void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes, GPURecord::Record } // It's possible for a game to load CLUT outside valid memory without crashing, should result in zeroes. - u32 bytes = Memory::ValidSize(clutAddr, loadBytes); + u32 bytes = Memory::ClampValidSizeAt(clutAddr, loadBytes); _assert_(bytes <= 2048); bool performDownload = PSP_CoreParameter().compat.flags().AllowDownloadCLUT; if (recorder->IsActive()) @@ -1685,7 +1685,7 @@ static CheckAlphaResult DecodeDXTBlocks(uint8_t *out, int outPitch, uint32_t tex if (!Memory::IsValidRange(texaddr, ((h + 3) / 4) * (bufw / 4) * sizeof(DXTBlock))) { ERROR_LOG_REPORT(Log::G3D, "DXT%d texture extends beyond valid RAM: %08x + %d x %d", n, texaddr, bufw, h); - uint32_t limited = Memory::ValidSize(texaddr, (h / 4) * (bufw / 4) * sizeof(DXTBlock)); + uint32_t limited = Memory::ClampValidSizeAt(texaddr, (h / 4) * (bufw / 4) * sizeof(DXTBlock)); // This might possibly be 0, but try to decode what we can (might even be how the PSP behaves.) h = (((int)limited / sizeof(DXTBlock)) / (bufw / 4)) * 4; } diff --git a/GPU/Debugger/Record.cpp b/GPU/Debugger/Record.cpp index d36b0883b2..38e3f86807 100644 --- a/GPU/Debugger/Record.cpp +++ b/GPU/Debugger/Record.cpp @@ -400,7 +400,7 @@ void Recorder::EmitTextureData(int level, u32 texaddr) { CommandType type = CommandType((int)CommandType::TEXTURE0 + level); const u8 *p = Memory::GetPointerUnchecked(texaddr); - u32 bytes = Memory::ValidSize(texaddr, sizeInRAM); + u32 bytes = Memory::ClampValidSizeAt(texaddr, sizeInRAM); std::vector framebufData; if (Memory::IsVRAMAddress(texaddr)) { @@ -506,10 +506,10 @@ void Recorder::EmitTransfer(u32 op) { int bpp = gstate.getTransferBpp(); u32 srcBytes = ((srcY + height - 1) * srcStride + (srcX + width)) * bpp; - srcBytes = Memory::ValidSize(srcBasePtr, srcBytes); + srcBytes = Memory::ClampValidSizeAt(srcBasePtr, srcBytes); u32 dstBytes = ((dstY + height - 1) * dstStride + (dstX + width)) * bpp; - dstBytes = Memory::ValidSize(dstBasePtr, dstBytes); + dstBytes = Memory::ClampValidSizeAt(dstBasePtr, dstBytes); if (srcBytes != 0) { EmitCommandWithRAM(CommandType::TRANSFERSRC, Memory::GetPointerUnchecked(srcBasePtr), srcBytes, 16); @@ -530,7 +530,7 @@ void Recorder::EmitClut(u32 op) { // Actually should only be 0x3F, but we allow enhanced CLUTs. See #15727. u32 blocks = (op & 0x7F) == 0x40 ? 0x40 : (op & 0x3F); u32 bytes = blocks * 32; - bytes = Memory::ValidSize(addr, bytes); + bytes = Memory::ClampValidSizeAt(addr, bytes); if (bytes != 0) { // Send the original address so VRAM can be reasoned about. @@ -690,7 +690,7 @@ void Recorder::NotifyMemcpy(u32 dest, u32 src, u32 sz) { memcpy(pushbuf.data() + cmd.ptr, &dest, sizeof(dest)); commands.push_back(cmd); - sz = Memory::ValidSize(dest, sz); + sz = Memory::ClampValidSizeAt(dest, sz); if (sz != 0) { EmitCommandWithRAM(CommandType::MEMCPYDATA, Memory::GetPointerUnchecked(dest), sz, 1); UpdateLastVRAM(dest, sz); @@ -712,7 +712,7 @@ void Recorder::NotifyMemset(u32 dest, int v, u32 sz) { }; if (Memory::IsVRAMAddress(dest)) { - sz = Memory::ValidSize(dest, sz); + sz = Memory::ClampValidSizeAt(dest, sz); MemsetCommand data{ dest, v, sz }; FlushRegisters(); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 0e6ee486e8..de296a151e 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1813,8 +1813,8 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { u32 dstLinePos = dstLineStartAddr; for (u32 i = 0; i < bytesToCopy; i += 64) { u32 chunk = i + 64 > bytesToCopy ? bytesToCopy - i : 64; - u32 srcValid = Memory::ValidSize(srcLinePos, chunk); - u32 dstValid = Memory::ValidSize(dstLinePos, chunk); + u32 srcValid = Memory::ClampValidSizeAt(srcLinePos, chunk); + u32 dstValid = Memory::ClampValidSizeAt(dstLinePos, chunk); // First chunk, for which both are valid. u32 bothSize = std::min(srcValid, dstValid); @@ -1849,14 +1849,14 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { if (notifyAll) { if (srcWraps) { - u32 validSize = Memory::ValidSize(src, srcSize); + u32 validSize = Memory::ClampValidSizeAt(src, srcSize); NotifyMemInfo(MemBlockFlags::READ, src, validSize, tag, tagSize); NotifyMemInfo(MemBlockFlags::READ, PSP_GetVidMemBase(), srcSize - validSize, tag, tagSize); } else { NotifyMemInfo(MemBlockFlags::READ, src, srcSize, tag, tagSize); } if (dstWraps) { - u32 validSize = Memory::ValidSize(dst, dstSize); + u32 validSize = Memory::ClampValidSizeAt(dst, dstSize); NotifyMemInfo(MemBlockFlags::WRITE, dst, validSize, tag, tagSize); NotifyMemInfo(MemBlockFlags::WRITE, PSP_GetVidMemBase(), dstSize - validSize, tag, tagSize); } else { diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index fd12c17110..f4b79a2b0e 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -1003,7 +1003,7 @@ void SoftGPU::Execute_LoadClut(u32 op, u32 diff) { bool changed = false; if (Memory::IsValidAddress(clutAddr)) { - u32 validSize = Memory::ValidSize(clutAddr, clutTotalBytes); + u32 validSize = Memory::ClampValidSizeAt(clutAddr, clutTotalBytes); changed = memcmp(clut, Memory::GetPointerUnchecked(clutAddr), validSize) != 0; if (changed) Memory::MemcpyUnchecked(clut, clutAddr, validSize); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 582272a2b3..6602385913 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -2118,7 +2118,7 @@ void ImWatchWindow::Draw(ImConfig &cfg, ImControl &control, MIPSDebugInterface * break; case WatchFormat::STR: if (Memory::IsValidAddress(value)) { - uint32_t len = Memory::ValidSize(value, 255); + uint32_t len = Memory::ClampValidSizeAt(value, 255); ImGui::Text("%.*s", len, Memory::GetCharPointer(value)); } else { ImGui::Text("%08x", value); diff --git a/UI/ImDebugger/ImGe.cpp b/UI/ImDebugger/ImGe.cpp index 31abd49a90..f8912dd80c 100644 --- a/UI/ImDebugger/ImGe.cpp +++ b/UI/ImDebugger/ImGe.cpp @@ -464,7 +464,7 @@ void ImGePixelViewer::UpdateTexture(Draw::DrawContext *draw) { if (stride > width) { srcBytes -= stride - width; } - if (Memory::ValidSize(addr, srcBytes) != srcBytes) { + if (Memory::ClampValidSizeAt(addr, srcBytes) != srcBytes) { // TODO: Show a message that the address is out of bounds. return; } diff --git a/UI/ImDebugger/ImMemView.cpp b/UI/ImDebugger/ImMemView.cpp index e2af463be6..55bbe5f72f 100644 --- a/UI/ImDebugger/ImMemView.cpp +++ b/UI/ImDebugger/ImMemView.cpp @@ -111,7 +111,7 @@ void ImMemView::Draw(ImDrawList *drawList) { uint32_t words[4]; uint8_t bytes[16]; } memory; - int valid = debugger_ != nullptr && debugger_->isAlive() ? Memory::ValidSize(address, 16) / 4 : 0; + int valid = debugger_ != nullptr && debugger_->isAlive() ? Memory::ClampValidSizeAt(address, 16) / 4 : 0; for (int i = 0; i < valid; ++i) { memory.words[i] = debugger_->readMemory(address + i * 4); } @@ -995,7 +995,7 @@ void ImMemDumpWindow::Draw(ImConfig &cfg, MIPSDebugInterface *debug) { } if (ImGui::Button(mode_ == MemDumpMode::Raw ? "Dump to file" : "Disassemble to file")) { - uint32_t validSize = Memory::ValidSize(address_, size_); + uint32_t validSize = Memory::ClampValidSizeAt(address_, size_); if (validSize != size_) { errorMsg_ = "Address range out of bounds"; if (Memory::IsValidAddress(address_)) { diff --git a/Windows/Debugger/CtrlMemView.cpp b/Windows/Debugger/CtrlMemView.cpp index c059dc1f14..1a6d022592 100644 --- a/Windows/Debugger/CtrlMemView.cpp +++ b/Windows/Debugger/CtrlMemView.cpp @@ -241,7 +241,7 @@ void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam) { uint32_t words[4]; uint8_t bytes[16]; } memory; - int valid = debugger_ != nullptr && debugger_->isAlive() ? Memory::ValidSize(address, 16) / 4 : 0; + int valid = debugger_ != nullptr && debugger_->isAlive() ? Memory::ClampValidSizeAt(address, 16) / 4 : 0; for (int i = 0; i < valid; ++i) { memory.words[i] = debugger_->readMemory(address + i * 4); } diff --git a/Windows/Debugger/Debugger_Lists.cpp b/Windows/Debugger/Debugger_Lists.cpp index de88105da9..2d738fd6ae 100644 --- a/Windows/Debugger/Debugger_Lists.cpp +++ b/Windows/Debugger/Debugger_Lists.cpp @@ -913,7 +913,7 @@ void CtrlWatchList::GetColumnText(wchar_t *dest, size_t destSize, int row, int c break; case WatchFormat::STR: if (Memory::IsValidAddress(value)) { - uint32_t len = Memory::ValidSize(value, 255); + uint32_t len = Memory::ClampValidSizeAt(value, 255); swprintf_s(dest, destSize, L"%.*S", len, Memory::GetCharPointer(value)); } else { wsprintf(dest, L"(0x%08X)", value); diff --git a/unittest/UnitTest.cpp b/unittest/UnitTest.cpp index 942fc82b4f..35b6e4aa73 100644 --- a/unittest/UnitTest.cpp +++ b/unittest/UnitTest.cpp @@ -683,23 +683,23 @@ static bool TestMemMap() { EXPECT_FALSE(Memory::IsValidAddress(base + range.size)); EXPECT_FALSE(Memory::IsValidAddress(base - 1)); - EXPECT_EQ_HEX(Memory::ValidSize(base, range.size), range.size); - EXPECT_EQ_HEX(Memory::ValidSize(base, range.size + 1), range.size); - EXPECT_EQ_HEX(Memory::ValidSize(base, range.size - 1), range.size - 1); - EXPECT_EQ_HEX(Memory::ValidSize(base, 0), 0); - EXPECT_EQ_HEX(Memory::ValidSize(base, 0x80000001), range.size); - 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::ClampValidSizeAt(base, range.size), range.size); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, range.size + 1), range.size); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, range.size - 1), range.size - 1); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, 0), 0); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, 0x80000001), range.size); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, 0x40000001), range.size); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, 0x20000001), range.size); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base, 0x10000001), range.size); - EXPECT_EQ_HEX(Memory::ValidSize(base + range.size - 0x10, 0x20000001), 0x10); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(base + range.size - 0x10, 0x20000001), 0x10); } } EXPECT_FALSE(Memory::IsValidAddress(0x00015000)); EXPECT_FALSE(Memory::IsValidAddress(0x04900000)); - EXPECT_EQ_HEX(Memory::ValidSize(0x00015000, 4), 0); - EXPECT_EQ_HEX(Memory::ValidSize(0x04900000, 4), 0); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(0x00015000, 4), 0); + EXPECT_EQ_HEX(Memory::ClampValidSizeAt(0x04900000, 4), 0); return true; }