mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Rename ValidSize to ClampValidSizeAt
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
+1
-1
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<MpegDemux>(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.");
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+5
-5
@@ -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 -
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<u8> 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();
|
||||
|
||||
+4
-4
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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_)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+11
-11
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user