diff --git a/Core/HLE/HLETables.cpp b/Core/HLE/HLETables.cpp index 0f4c440c4bf3..d65547664b41 100644 --- a/Core/HLE/HLETables.cpp +++ b/Core/HLE/HLETables.cpp @@ -40,6 +40,7 @@ #include "sceJpeg.h" #include "sceKernel.h" #include "sceKernelEventFlag.h" +#include "sceKernelHeap.h" #include "sceKernelMemory.h" #include "sceKernelInterrupt.h" #include "sceKernelModule.h" diff --git a/Core/HLE/sceKernelHeap.cpp b/Core/HLE/sceKernelHeap.cpp index 8baa81a0ab10..5aec59e8730f 100644 --- a/Core/HLE/sceKernelHeap.cpp +++ b/Core/HLE/sceKernelHeap.cpp @@ -1,5 +1,3 @@ -#pragma once - #include #include "Common/ChunkFile.h" @@ -26,7 +24,7 @@ struct Heap : public KernelObject { static int GetStaticIDType() { return PPSSPP_KERNEL_TMID_Heap; } int GetIDType() const override { return PPSSPP_KERNEL_TMID_Heap; } - void DoState(PointerWrap &p) { + void DoState(PointerWrap &p) override { p.Do(uid); p.Do(partitionId); p.Do(size); @@ -38,19 +36,22 @@ struct Heap : public KernelObject { }; static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name) { + u32 allocSize = (size + 3) & ~3; + + // TODO: partitionId should probably decide if we allocate from userMemory or kernel or whatever... + u32 addr = userMemory.Alloc(allocSize, frombottom, "SysMemForKernel-Heap"); + if (addr == (u32)-1) { + ERROR_LOG(HLE, "sceKernelCreateHeap(partitionId=%d): Failed to allocate %d bytes memory", partitionId, size); + return SCE_KERNEL_ERROR_NO_MEMORY; // Blind guess + } + Heap *heap = new Heap(); SceUID uid = kernelObjects.Create(heap); + heap->partitionId = partitionId; heap->flags = flags; heap->name = *Name; - int allocSize = (size + 3) & ~3; heap->size = allocSize; - u32 addr = userMemory.Alloc(heap->size, frombottom, "SysMemForKernel-Heap"); - if (addr == (u32)-1) { - ERROR_LOG(HLE, "sceKernelCreateHeap(): Failed to allocate %i bytes memory", size); - heap->uid = -1; - delete heap; - } heap->address = addr; heap->alloc.Init(heap->address + 128, heap->size - 128); heap->uid = uid; @@ -66,7 +67,7 @@ static int sceKernelAllocHeapMemory(int heapId, int size) { u32 addr = heap->alloc.Alloc(memSize, true); return hleLogSuccessInfoX(SCEKERNEL, addr, ""); } else { - ERROR_LOG(HLE, "sceKernelAllocHeapMemory cannot find heapId", heapId); + ERROR_LOG(HLE, "sceKernelAllocHeapMemory(%d): cannot find heapId", heapId); return error; } } @@ -79,7 +80,7 @@ static int sceKernelDeleteHeap(int heapId) { kernelObjects.Destroy(heap->uid); return hleLogSuccessInfoX(SCEKERNEL, 0, ""); } else { - ERROR_LOG(HLE, "sceKernelDeleteHeap(%i): invalid heapId", heapId); + ERROR_LOG(HLE, "sceKernelDeleteHeap(%d): invalid heapId", heapId); return error; } } diff --git a/Core/HLE/sceKernelHeap.h b/Core/HLE/sceKernelHeap.h index 7b43021ac678..1279c7496232 100644 --- a/Core/HLE/sceKernelHeap.h +++ b/Core/HLE/sceKernelHeap.h @@ -1,7 +1,3 @@ #pragma once -#include "Common/ChunkFile.h" - -int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name); -int sceKernelAllocHeapMemory(int heapId, int size); -int sceKernelDeleteHeap(int heapId); +void Register_SysMemForKernel(); diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h index 2396792436e9..dce6df77e04a 100644 --- a/Core/HLE/sceKernelMemory.h +++ b/Core/HLE/sceKernelMemory.h @@ -66,5 +66,4 @@ int sceKernelGetTlsAddr(SceUID uid); int sceKernelFreeTlspl(SceUID uid); int sceKernelReferTlsplStatus(SceUID uid, u32 infoPtr); -void Register_SysMemForKernel(); void Register_SysMemUserForUser();