From 32feb82d16945264673cca9235c95d765aa831de Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 2 Sep 2023 22:55:45 -0700 Subject: [PATCH] HLE: Capture better allocation names. We know which FPL, so don't just say "FPL". --- Core/HLE/sceAtrac.cpp | 2 +- Core/HLE/sceHeap.cpp | 3 ++- Core/HLE/sceKernelHeap.cpp | 3 ++- Core/HLE/sceKernelMemory.cpp | 6 +++--- Core/HLE/sceKernelMsgPipe.cpp | 2 +- Core/HLE/sceKernelThread.cpp | 25 ++++++++++--------------- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index bf16281139..86017681b6 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -2375,7 +2375,7 @@ static u32 _sceAtracGetContextAddress(int atracID) { if (!atrac->context_.IsValid()) { // allocate a new context_ u32 contextsize = 256; - atrac->context_ = kernelMemory.Alloc(contextsize, false, "Atrac Context"); + atrac->context_ = kernelMemory.Alloc(contextsize, false, StringFromFormat("AtracCtx/%d", atracID).c_str()); if (atrac->context_.IsValid()) Memory::Memset(atrac->context_.ptr, 0, 256, "AtracContextClear"); diff --git a/Core/HLE/sceHeap.cpp b/Core/HLE/sceHeap.cpp index e51f6b1d83..28cc63ee43 100644 --- a/Core/HLE/sceHeap.cpp +++ b/Core/HLE/sceHeap.cpp @@ -19,6 +19,7 @@ #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" #include "Common/Serialize/SerializeMap.h" +#include "Common/StringUtils.h" #include "Core/MemMap.h" #include "Core/Reporting.h" #include "Core/HLE/HLE.h" @@ -193,7 +194,7 @@ static int sceHeapCreateHeap(const char* name, u32 heapSize, int attr, u32 param Heap *heap = new Heap; heap->size = allocSize; heap->fromtop = (attr & PSP_HEAP_ATTR_HIGHMEM) != 0; - u32 addr = userMemory.Alloc(heap->size, heap->fromtop, "Heap"); + u32 addr = userMemory.Alloc(heap->size, heap->fromtop, StringFromFormat("Heap/%s", name).c_str()); if (addr == (u32)-1) { ERROR_LOG(HLE, "sceHeapCreateHeap(): Failed to allocate %i bytes memory", allocSize); delete heap; diff --git a/Core/HLE/sceKernelHeap.cpp b/Core/HLE/sceKernelHeap.cpp index d099fc3819..1663c81eec 100644 --- a/Core/HLE/sceKernelHeap.cpp +++ b/Core/HLE/sceKernelHeap.cpp @@ -2,6 +2,7 @@ #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" +#include "Common/StringUtils.h" #include "Core/HLE/HLE.h" #include "Core/HLE/FunctionWrappers.h" #include "Core/HLE/sceKernel.h" @@ -52,7 +53,7 @@ static int sceKernelCreateHeap(int partitionId, int size, int flags, const char return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "invalid partition"); // TODO: This should probably actually use flags? Name? - u32 addr = allocator->Alloc(allocSize, g_fromBottom, "SysMemForKernel-Heap"); + u32 addr = allocator->Alloc(allocSize, g_fromBottom, StringFromFormat("KernelHeap/%s", Name).c_str()); if (addr == (u32)-1) { // TODO: Validate error code. return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "fFailed to allocate %d bytes of memory", size); diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index d2ca493844..8c3c6fd3ae 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -678,7 +678,7 @@ int sceKernelCreateFpl(const char *name, u32 mpid, u32 attr, u32 blockSize, u32 int alignedSize = ((int)blockSize + alignment - 1) & ~(alignment - 1); u32 totalSize = alignedSize * numBlocks; bool atEnd = (attr & PSP_FPL_ATTR_HIGHMEM) != 0; - u32 address = allocator->Alloc(totalSize, atEnd, "FPL"); + u32 address = allocator->Alloc(totalSize, atEnd, StringFromFormat("FPL/%s", name).c_str()); if (address == (u32)-1) { DEBUG_LOG(SCEKERNEL, "sceKernelCreateFpl(\"%s\", partition=%i, attr=%08x, bsize=%i, nb=%i) FAILED - out of ram", name, mpid, attr, blockSize, numBlocks); @@ -1521,7 +1521,7 @@ SceUID sceKernelCreateVpl(const char *name, int partition, u32 attr, u32 vplSize // We ignore the upalign to 256 and do it ourselves by 8. u32 allocSize = vplSize; - u32 memBlockPtr = allocator->Alloc(allocSize, (attr & PSP_VPL_ATTR_HIGHMEM) != 0, "VPL"); + u32 memBlockPtr = allocator->Alloc(allocSize, (attr & PSP_VPL_ATTR_HIGHMEM) != 0, StringFromFormat("VPL/%s", name).c_str()); if (memBlockPtr == (u32)-1) return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "failed to allocate %i bytes of pool data", vplSize); @@ -2124,7 +2124,7 @@ SceUID sceKernelCreateTlspl(const char *name, u32 partition, u32 attr, u32 block u32 alignedSize = (blockSize + alignment - 1) & ~(alignment - 1); u32 totalSize = alignedSize * count; - u32 blockPtr = allocator->Alloc(totalSize, (attr & PSP_TLSPL_ATTR_HIGHMEM) != 0, name); + u32 blockPtr = allocator->Alloc(totalSize, (attr & PSP_TLSPL_ATTR_HIGHMEM) != 0, StringFromFormat("TLS/%s", name).c_str()); #ifdef _DEBUG allocator->ListBlocks(); #endif diff --git a/Core/HLE/sceKernelMsgPipe.cpp b/Core/HLE/sceKernelMsgPipe.cpp index 0ff34c6290..5b44e57bb4 100644 --- a/Core/HLE/sceKernelMsgPipe.cpp +++ b/Core/HLE/sceKernelMsgPipe.cpp @@ -687,7 +687,7 @@ int sceKernelCreateMsgPipe(const char *name, int partition, u32 attr, u32 size, if (size != 0) { // We ignore the upalign to 256. u32 allocSize = size; - memBlockPtr = allocator->Alloc(allocSize, (attr & SCE_KERNEL_MPA_HIGHMEM) != 0, "MsgPipe"); + memBlockPtr = allocator->Alloc(allocSize, (attr & SCE_KERNEL_MPA_HIGHMEM) != 0, StringFromFormat("MsgPipe/%s", name).c_str()); if (memBlockPtr == (u32)-1) return hleLogError(SCEKERNEL, SCE_KERNEL_ERROR_NO_MEMORY, "failed to allocate %i bytes for buffer", size); } diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index 995ead9667..40a575da74 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -401,15 +401,7 @@ public: FreeStack(); bool fromTop = (nt.attr & PSP_THREAD_ATTR_LOW_STACK) == 0; - if (nt.attr & PSP_THREAD_ATTR_KERNEL) - { - // Allocate stacks for kernel threads (idle) in kernel RAM - currentStack.start = kernelMemory.Alloc(stackSize, fromTop, (std::string("stack/") + nt.name).c_str()); - } - else - { - currentStack.start = userMemory.Alloc(stackSize, fromTop, (std::string("stack/") + nt.name).c_str()); - } + currentStack.start = StackAllocator().Alloc(stackSize, fromTop, StringFromFormat("stack/%s", nt.name).c_str()); if (currentStack.start == (u32)-1) { currentStack.start = 0; @@ -453,18 +445,14 @@ public: Memory::Memset(nt.initialStack, 0, nt.stackSize, "ThreadFreeStack"); } - if (nt.attr & PSP_THREAD_ATTR_KERNEL) { - kernelMemory.Free(currentStack.start); - } else { - userMemory.Free(currentStack.start); - } + StackAllocator().Free(currentStack.start); currentStack.start = 0; } } bool PushExtendedStack(u32 size) { - u32 stack = userMemory.Alloc(size, true, (std::string("extended/") + nt.name).c_str()); + u32 stack = userMemory.Alloc(size, true, StringFromFormat("extended/%s", nt.name).c_str()); if (stack == (u32)-1) return false; @@ -509,6 +497,13 @@ public: FreeStack(); } + BlockAllocator &StackAllocator() { + if (nt.attr & PSP_THREAD_ATTR_KERNEL) { + return kernelMemory; + } + return userMemory; + } + void setReturnValue(u32 retval); void setReturnValue(u64 retval); void resumeFromWait();