From e7b968be7314b90d71532c558b24bdc08079aa1a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 3 Feb 2021 00:09:21 -0800 Subject: [PATCH] Debugger: Notate Memcpys directly as well. --- Core/CwCheat.cpp | 5 +++-- Core/Dialog/PSPMsgDialog.cpp | 2 +- Core/Dialog/PSPNetconfDialog.cpp | 2 +- Core/Dialog/PSPSaveDialog.cpp | 2 +- Core/HLE/HLEHelperThread.cpp | 2 +- Core/HLE/sceDmac.cpp | 3 ++- Core/HLE/sceKernelModule.cpp | 4 ++-- Core/HLE/sceKernelMsgPipe.cpp | 8 ++++---- Core/HLE/sceKernelThread.cpp | 11 +++++------ Core/HLE/sceKernelVTimer.cpp | 2 +- Core/HLE/sceMpeg.cpp | 4 ++-- Core/MemMapHelpers.h | 17 +++++++---------- Core/Util/PPGeDraw.cpp | 2 +- 13 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index c886d3c369..8243d2fcc2 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -11,6 +11,7 @@ #include "Core/CwCheat.h" #include "Core/Config.h" #include "Core/Host.h" +#include "Core/MemMapHelpers.h" #include "Core/MIPS/MIPS.h" #include "Core/ELF/ParamSFO.h" #include "Core/System.h" @@ -924,7 +925,7 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, InvalidateICache(op.addr, op.val); InvalidateICache(op.copyBytesFrom.destAddr, op.val); - Memory::MemcpyUnchecked(op.copyBytesFrom.destAddr, op.addr, op.val); + Memory::Memcpy(op.copyBytesFrom.destAddr, op.addr, op.val, "CwCheat"); } break; @@ -1106,7 +1107,7 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat, if (Memory::IsValidRange(dstAddr, val) && Memory::IsValidRange(srcAddr, val)) { InvalidateICache(dstAddr, val); InvalidateICache(srcAddr, val); - Memory::MemcpyUnchecked(dstAddr, srcAddr, val); + Memory::Memcpy(dstAddr, srcAddr, val, "CwCheat"); } // Don't perform any further action. type = -1; diff --git a/Core/Dialog/PSPMsgDialog.cpp b/Core/Dialog/PSPMsgDialog.cpp index 8361adbc3e..abfe39d7a0 100755 --- a/Core/Dialog/PSPMsgDialog.cpp +++ b/Core/Dialog/PSPMsgDialog.cpp @@ -344,7 +344,7 @@ int PSPMsgDialog::Update(int animSpeed) { messageDialog.result = 0; } - Memory::Memcpy(messageDialogAddr, &messageDialog ,messageDialog.common.size); + Memory::Memcpy(messageDialogAddr, &messageDialog, messageDialog.common.size, "MsgDialogParam"); return 0; } diff --git a/Core/Dialog/PSPNetconfDialog.cpp b/Core/Dialog/PSPNetconfDialog.cpp index f92385de0e..ee3bb1b739 100644 --- a/Core/Dialog/PSPNetconfDialog.cpp +++ b/Core/Dialog/PSPNetconfDialog.cpp @@ -465,7 +465,7 @@ int PSPNetconfDialog::Update(int animSpeed) { } if (GetStatus() == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED) - Memory::Memcpy(requestAddr, &request, request.common.size); + Memory::Memcpy(requestAddr, &request, request.common.size, "NetConfDialogParam"); return 0; } diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 43877f69fc..7dd52c8965 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -1032,7 +1032,7 @@ int PSPSaveDialog::Update(int animSpeed) } if (ReadStatus() == SCE_UTILITY_STATUS_FINISHED || pendingStatus == SCE_UTILITY_STATUS_FINISHED) - Memory::Memcpy(requestAddr, &request, request.common.size); + Memory::Memcpy(requestAddr, &request, request.common.size, "SaveDialogParam"); return 0; } diff --git a/Core/HLE/HLEHelperThread.cpp b/Core/HLE/HLEHelperThread.cpp index 1a35395c39..5c8a0278fb 100644 --- a/Core/HLE/HLEHelperThread.cpp +++ b/Core/HLE/HLEHelperThread.cpp @@ -33,7 +33,7 @@ HLEHelperThread::HLEHelperThread(const char *threadName, u32 instructions[], u32 u32 instrBytes = instrCount * sizeof(u32); u32 totalBytes = instrBytes + sizeof(u32) * 2; AllocEntry(totalBytes); - Memory::Memcpy(entry_, instructions, instrBytes); + Memory::Memcpy(entry_, instructions, instrBytes, "HelperMIPS"); // Just to simplify things, we add the return here. Memory::Write_U32(MIPS_MAKE_JR_RA(), entry_ + instrBytes + 0); diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index 4f186facfe..4defe951ca 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -50,7 +50,8 @@ static int __DmacMemcpy(u32 dst, u32 src, u32 size) { skip = gpu->PerformMemoryCopy(dst, src, size); } if (!skip) { - Memory::Memcpy(dst, Memory::GetPointer(src), size); + // TODO: InvalidateICache src before copy? + Memory::Memcpy(dst, Memory::GetPointer(src), size, "DmacMemcpy"); currentMIPS->InvalidateICache(dst, size); } diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index e3906ea6c8..bbcf706d00 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1738,13 +1738,13 @@ bool __KernelLoadExec(const char *filename, u32 paramPtr, std::string *error_str if (param.args > 0) { u32 argpAddr = param.argp; param_argp = new u8[param.args]; - Memory::Memcpy(param_argp, argpAddr, param.args); + Memory::Memcpy(param_argp, argpAddr, param.args, "KernelLoadParam"); } if (param.keyp != 0) { u32 keyAddr = param.keyp; size_t keylen = strlen(Memory::GetCharPointer(keyAddr))+1; param_key = new u8[keylen]; - Memory::Memcpy(param_key, keyAddr, (u32)keylen); + Memory::Memcpy(param_key, keyAddr, (u32)keylen, "KernelLoadParam"); } __KernelLoadReset(); diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index 7ff5e423d5..24d538609e 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -105,7 +105,7 @@ struct MsgPipeWaitingThread void ReadBuffer(u32 destPtr, u32 len) { - Memory::Memcpy(destPtr, bufAddr + bufSize - freeSize, len); + Memory::Memcpy(destPtr, bufAddr + bufSize - freeSize, len, "MsgPipeReadBuffer"); freeSize -= len; if (transferredBytes.IsValid()) *transferredBytes += len; @@ -113,7 +113,7 @@ struct MsgPipeWaitingThread void WriteBuffer(u32 srcPtr, u32 len) { - Memory::Memcpy(bufAddr + (bufSize - freeSize), srcPtr, len); + Memory::Memcpy(bufAddr + (bufSize - freeSize), srcPtr, len, "MsgPipeWriteBuffer"); freeSize -= len; if (transferredBytes.IsValid()) *transferredBytes += len; @@ -399,7 +399,7 @@ static int __KernelSendMsgPipe(MsgPipe *m, u32 sendBufAddr, u32 sendSize, int wa if (bytesToSend != 0) { - Memory::Memcpy(m->buffer + (m->nmp.bufSize - m->nmp.freeSize), sendBufAddr, bytesToSend); + Memory::Memcpy(m->buffer + (m->nmp.bufSize - m->nmp.freeSize), sendBufAddr, bytesToSend, "MsgPipeSend"); m->nmp.freeSize -= bytesToSend; curSendAddr += bytesToSend; sendSize -= bytesToSend; @@ -492,7 +492,7 @@ static int __KernelReceiveMsgPipe(MsgPipe *m, u32 receiveBufAddr, u32 receiveSiz u32 bytesToReceive = std::min(receiveSize, m->GetUsedSize()); if (bytesToReceive != 0) { - Memory::Memcpy(curReceiveAddr, m->buffer, bytesToReceive); + Memory::Memcpy(curReceiveAddr, m->buffer, bytesToReceive, "MsgPipeReceive"); m->nmp.freeSize += bytesToReceive; memmove(Memory::GetPointer(m->buffer), Memory::GetPointer(m->buffer) + bytesToReceive, m->GetUsedSize()); curReceiveAddr += bytesToReceive; diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index eca32da94b..e4b7d91e65 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -940,7 +940,7 @@ void __KernelThreadingInit() lastSwitchCycles = 0; idleThreadHackAddr = kernelMemory.Alloc(blockSize, false, "threadrethack"); - Memory::Memcpy(idleThreadHackAddr, idleThreadCode, sizeof(idleThreadCode)); + Memory::Memcpy(idleThreadHackAddr, idleThreadCode, sizeof(idleThreadCode), "ThreadMIPS"); u32 pos = idleThreadHackAddr + sizeof(idleThreadCode); for (size_t i = 0; i < ARRAY_SIZE(threadHacks); ++i) { @@ -1288,7 +1288,7 @@ u32 sceKernelReferThreadStatus(u32 threadID, u32 statusPtr) t->nt.nativeSize = THREADINFO_SIZE_AFTER_260; if (wantedSize != 0) - Memory::Memcpy(statusPtr, &t->nt, std::min(wantedSize, (u32)sizeof(t->nt))); + Memory::Memcpy(statusPtr, &t->nt, std::min(wantedSize, (u32)sizeof(t->nt)), "ThreadStatus"); // TODO: What is this value? Basic tests show 0... if (wantedSize > sizeof(t->nt)) Memory::Memset(statusPtr + sizeof(t->nt), 0, wantedSize - sizeof(t->nt), "ThreadStatus"); @@ -1296,7 +1296,7 @@ u32 sceKernelReferThreadStatus(u32 threadID, u32 statusPtr) t->nt.nativeSize = THREADINFO_SIZE; u32 sz = std::min(THREADINFO_SIZE, wantedSize); if (sz != 0) - Memory::Memcpy(statusPtr, &t->nt, sz); + Memory::Memcpy(statusPtr, &t->nt, sz, "ThreadStatus"); } hleEatCycles(1400); @@ -1939,7 +1939,7 @@ SceUID __KernelSetupRootThread(SceUID moduleID, int args, const char *argp, int u32 location = currentMIPS->r[MIPS_REG_SP]; currentMIPS->r[MIPS_REG_A1] = location; if (argp) - Memory::Memcpy(location, argp, args); + Memory::Memcpy(location, argp, args, "ThreadParam"); // Let's assume same as starting a new thread, 64 bytes for safety/kernel. currentMIPS->r[MIPS_REG_SP] -= 64; @@ -2044,8 +2044,7 @@ int __KernelStartThread(SceUID threadToStartID, int argSize, u32 argBlockPtr, bo // Now copy argument to stack. if (!forceArgs && Memory::IsValidAddress(argBlockPtr)) { - Memory::Memcpy(sp, argBlockPtr, argSize); - NotifyMemInfo(MemBlockFlags::WRITE, argBlockPtr, argSize, "ThreadStartArgs"); + Memory::Memcpy(sp, argBlockPtr, argSize, "ThreadStartArgs"); } // On the PSP, there's an extra 64 bytes of stack eaten after the args. diff --git a/Core/HLE/sceKernelVTimer.cpp b/Core/HLE/sceKernelVTimer.cpp index 245db8a395..63efc53eda 100644 --- a/Core/HLE/sceKernelVTimer.cpp +++ b/Core/HLE/sceKernelVTimer.cpp @@ -514,7 +514,7 @@ u32 sceKernelReferVTimerStatus(SceUID uid, u32 statusAddr) { NativeVTimer status = vt->nvt; u32 size = Memory::Read_U32(statusAddr); status.current = __getVTimerCurrentTime(vt); - Memory::Memcpy(statusAddr, &status, std::min(size, (u32)sizeof(status))); + Memory::Memcpy(statusAddr, &status, std::min(size, (u32)sizeof(status)), "VTimerStatus"); } return 0; diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 87ab458172..0128edef79 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -524,8 +524,8 @@ static u32 sceMpegCreate(u32 mpegAddr, u32 dataPtr, u32 size, u32 ringbufferAddr Memory::Write_U32(mpegHandle, mpegAddr); // Initialize fake mpeg struct. - Memory::Memcpy(mpegHandle, "LIBMPEG\0", 8); - Memory::Memcpy(mpegHandle + 8, "001\0", 4); + Memory::Memcpy(mpegHandle, "LIBMPEG\0", 8, "Mpeg"); + Memory::Memcpy(mpegHandle + 8, "001\0", 4, "Mpeg"); Memory::Write_U32(-1, mpegHandle + 12); if (ringbuffer.IsValid()) { Memory::Write_U32(ringbufferAddr, mpegHandle + 16); diff --git a/Core/MemMapHelpers.h b/Core/MemMapHelpers.h index 451c723707..0983abdf9b 100644 --- a/Core/MemMapHelpers.h +++ b/Core/MemMapHelpers.h @@ -28,31 +28,28 @@ extern MIPSState *currentMIPS; namespace Memory { -inline void Memcpy(const u32 to_address, const void *from_data, const u32 len) -{ +inline void Memcpy(const u32 to_address, const void *from_data, const u32 len, const std::string &tag = "Memcpy") { u8 *to = GetPointer(to_address); if (to) { memcpy(to, from_data, len); - NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, "Memcpy"); + NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag); } // if not, GetPointer will log. } -inline void Memcpy(void *to_data, const u32 from_address, const u32 len) -{ +inline void Memcpy(void *to_data, const u32 from_address, const u32 len, const std::string &tag = "Memcpy") { const u8 *from = GetPointer(from_address); if (from) { memcpy(to_data, from, len); - NotifyMemInfo(MemBlockFlags::READ, from_address, len, "Memcpy"); + NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag); } // if not, GetPointer will log. } -inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len) -{ +inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len, const std::string &tag = "Memcpy") { Memcpy(GetPointer(to_address), from_address, len); - NotifyMemInfo(MemBlockFlags::READ, from_address, len, "Memcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, "Memcpy"); + NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag); + NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag); } void Memset(const u32 _Address, const u8 _Data, const u32 _iLength, const std::string &tag = "Memset"); diff --git a/Core/Util/PPGeDraw.cpp b/Core/Util/PPGeDraw.cpp index 391f3aaf9c..19041449ac 100644 --- a/Core/Util/PPGeDraw.cpp +++ b/Core/Util/PPGeDraw.cpp @@ -1260,7 +1260,7 @@ bool PPGeImage::Load() { return false; } - Memory::Memcpy(texture_, textureData, dataSize); + Memory::Memcpy(texture_, textureData, dataSize, "PPGeTex"); Memory::Memset(texture_ + dataSize, 0, texSize - dataSize, "PPGeTexClear"); free(textureData);