diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5d256c210..50cd7b5356 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1590,6 +1590,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/HLE/sceKernelAlarm.h
Core/HLE/sceKernelEventFlag.cpp
Core/HLE/sceKernelEventFlag.h
+ Core/HLE/sceKernelHeap.cpp
+ Core/HLE/sceKernelHeap.h
Core/HLE/sceKernelInterrupt.cpp
Core/HLE/sceKernelInterrupt.h
Core/HLE/sceKernelMbx.cpp
diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj
index 1c422c1593..5b675bd729 100644
--- a/Core/Core.vcxproj
+++ b/Core/Core.vcxproj
@@ -371,6 +371,7 @@
+
@@ -899,6 +900,7 @@
+
diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters
index 19698164c2..c95b6aa41f 100644
--- a/Core/Core.vcxproj.filters
+++ b/Core/Core.vcxproj.filters
@@ -740,6 +740,9 @@
HW
+
+ HLE\Kernel
+
@@ -1373,10 +1376,13 @@
HW
+
+ HLE\Kernel
+
-
\ No newline at end of file
+
diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp
index 824c951492..ad571355ef 100644
--- a/Core/HLE/sceKernel.cpp
+++ b/Core/HLE/sceKernel.cpp
@@ -904,28 +904,6 @@ void Register_LoadExecForKernel()
RegisterModule("LoadExecForKernel", ARRAY_SIZE(LoadExecForKernel), LoadExecForKernel);
}
-static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name)
-{
- return hleLogError(SCEKERNEL, 0, "");
-}
-
-static int sceKernelAllocHeapMemory(int heapId, int size)
-{
- return hleLogError(SCEKERNEL, 0, "");
-}
-
-static int sceKernelDeleteHeap(int heapId)
-{
- return hleLogError(SCEKERNEL, 0, "");
-}
-
-const HLEFunction SysMemForKernel[] =
-{
- {0X636C953B, &WrapI_II, "sceKernelAllocHeapMemory", 'I', "ii" },
- {0XC9805775, &WrapI_I, "sceKernelDeleteHeap", 'I', "i" },
- {0X1C1FBFE7, &WrapI_IIIC, "sceKernelCreateHeap", 'I', "iiis" },
-};
-
const HLEFunction ExceptionManagerForKernel[] =
{
{0X3FB264FC, nullptr, "sceKernelRegisterExceptionHandler", '?', "" },
@@ -976,8 +954,3 @@ void Register_ThreadManForKernel()
{
RegisterModule("ThreadManForKernel", ARRAY_SIZE(ThreadManForKernel), ThreadManForKernel);
}
-
-void Register_LoadExecForKernel()
-{
- RegisterModule("LoadExecForKernel", ARRAY_SIZE(LoadExecForKernel), LoadExecForKernel);
-}
diff --git a/Core/HLE/sceKernel.h b/Core/HLE/sceKernel.h
index fa5928584b..96e94cb760 100644
--- a/Core/HLE/sceKernel.h
+++ b/Core/HLE/sceKernel.h
@@ -340,6 +340,7 @@ enum TMIDPurpose
PPSSPP_KERNEL_TMID_PMB = 0x100002,
PPSSPP_KERNEL_TMID_File = 0x100003,
PPSSPP_KERNEL_TMID_DirList = 0x100004,
+ PPSSPP_KERNEL_TMID_Heap = 0x100005,
};
typedef int SceUID;
diff --git a/Core/HLE/sceKernelHeap.cpp b/Core/HLE/sceKernelHeap.cpp
new file mode 100644
index 0000000000..fa146a93ee
--- /dev/null
+++ b/Core/HLE/sceKernelHeap.cpp
@@ -0,0 +1,115 @@
+#pragma once
+
+#include
+
+#include "Common/ChunkFile.h"
+#include "Core/HLE/HLE.h"
+#include "Core/HLE/FunctionWrappers.h"
+#include "Core/HLE/sceKernel.h"
+#include "Core/HLE/sceKernelHeap.h"
+#include "Core/HLE/sceKernelMemory.h"
+#include "Core/Util/BlockAllocator.h"
+
+struct HeapInformation : public KernelObject {
+ int uid = 0;
+ int partitionId = 0;
+ u32 size = 0;
+ int flags = 0;
+ u32 address = 0;
+ std::string name;
+ BlockAllocator alloc;
+
+ static u32 GetMissingErrorCode() { return SCE_KERNEL_ERROR_UNKNOWN_UID; }
+ static int GetStaticIDType() { return PPSSPP_KERNEL_TMID_Heap; }
+ int GetIDType() const override { return PPSSPP_KERNEL_TMID_Heap; }
+
+ void DoState(PointerWrap &p) {
+ p.Do(uid);
+ p.Do(partitionId);
+ p.Do(size);
+ p.Do(flags);
+ p.Do(address);
+ p.Do(name);
+ p.Do(alloc);
+ }
+};
+
+std::map heapInformationList;
+
+void __HeapInformationDoState(PointerWrap &p) {
+ auto s = p.Section("kernelHeap", 1);
+ if (!s)
+ return;
+
+ if (s >= 1) {
+ p.Do(heapInformationList);
+ }
+}
+
+static HeapInformation *getHeap(u32 heapId) {
+ auto found = heapInformationList.find(heapId);
+ if (found == heapInformationList.end()) {
+ return NULL;
+ }
+ return found->second;
+}
+
+const u32 HEAP_BLOCK_HEADER_SIZE = 8;
+const bool frombottom = false;
+
+static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name) {
+ HeapInformation *heap = new HeapInformation;
+ 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);
+ SceUID uid = kernelObjects.Create(heap);
+ heap->uid = uid;
+ heapInformationList[uid] = heap;
+ return hleLogSuccessInfoX(SCEKERNEL, uid, "");
+}
+
+static int sceKernelAllocHeapMemory(int heapId, int size) {
+ HeapInformation *heap = getHeap(heapId);
+ if (!heap) {
+ ERROR_LOG(HLE, "sceKernelAllocHeapMemory cannot find heapId", heapId);
+ return 0;
+ }
+
+ // There's 8 bytes at the end of every block, reserved.
+ u32 memSize = HEAP_BLOCK_HEADER_SIZE + size;
+ u32 addr = heap->alloc.Alloc(memSize, true);
+ return hleLogSuccessInfoX(SCEKERNEL, addr, "");
+}
+
+static int sceKernelDeleteHeap(int heapId) {
+ HeapInformation *heap = getHeap(heapId);
+ if (!heap) {
+ ERROR_LOG(HLE, "sceKernelDeleteHeap(%i): invalid heapId", heapId);
+ return -1;
+ }
+ userMemory.Free(heap->address);
+ kernelObjects.Destroy(heap->uid);
+ heapInformationList.erase(heapId);
+ return hleLogSuccessInfoX(SCEKERNEL, 0, "");
+}
+
+const HLEFunction SysMemForKernel[] =
+{
+ { 0X636C953B, &WrapI_II, "sceKernelAllocHeapMemory", 'I', "ii" },
+ { 0XC9805775, &WrapI_I, "sceKernelDeleteHeap", 'I', "i" },
+ { 0X1C1FBFE7, &WrapI_IIIC, "sceKernelCreateHeap", 'I', "iiis" },
+};
+
+void Register_SysMemForKernel() {
+ RegisterModule("SysMemForKernel", ARRAY_SIZE(SysMemForKernel), SysMemForKernel);
+}
diff --git a/Core/HLE/sceKernelHeap.h b/Core/HLE/sceKernelHeap.h
new file mode 100644
index 0000000000..a880601a44
--- /dev/null
+++ b/Core/HLE/sceKernelHeap.h
@@ -0,0 +1,5 @@
+#pragma once
+
+int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name);
+int sceKernelAllocHeapMemory(int heapId, int size);
+int sceKernelDeleteHeap(int heapId);
diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp
index 436e31c16a..40cccaa03d 100644
--- a/Core/HLE/sceKernelMemory.cpp
+++ b/Core/HLE/sceKernelMemory.cpp
@@ -2287,128 +2287,6 @@ const HLEFunction SysMemUserForUser[] = {
{0XD8DE5C1E, &WrapU_V, "SysMemUserForUser_D8DE5C1E", 'x', "" },
};
-const HLEFunction SysMemForKernel[] = {
- {0x636C953B, nullptr, "SysMemForKernel_636c953b", '?', "" },
- {0xC9805775, nullptr, "SysMemForKernel_c9805775", '?', "" },
- {0x1C1FBFE7, nullptr, "SysMemForKernel_1c1fbfe7", '?', "" },
-};
-
-void Register_SysMemForKernel() {
- RegisterModule("SysMemForKernel", ARRAY_SIZE(SysMemForKernel), SysMemForKernel);
-}
-
void Register_SysMemUserForUser() {
RegisterModule("SysMemUserForUser", ARRAY_SIZE(SysMemUserForUser), SysMemUserForUser);
}
-
-
-struct HeapInformation : public KernelObject {
- HeapInformation() {}
- int uid;
- int partitionId;
- u32 size;
- int flags;
- u32 address;
- std::string name;
- BlockAllocator alloc;
- static int GetStaticIDType() { return SCE_KERNEL_TMID_Fpl; }// wrong
- int GetIDType() const override { return SCE_KERNEL_TMID_Fpl; }// wrong
-
- void DoState(PointerWrap &p) {
- p.Do(uid);
- p.Do(partitionId);
- p.Do(size);
- p.Do(flags);
- p.Do(address);
- p.Do(name);
- p.Do(alloc);
- }
-};
-
-std::map heapInformationList;
-
-void __HeapInformationDoState(PointerWrap &p) {
- auto s = p.Section("kernelHeap", 1);
- if (!s)
- return;
-
- if (s >= 1) {
- p.Do(heapInformationList);
- }
-}
-
-static HeapInformation *getHeap(u32 heapId) {
- auto found = heapInformationList.find(heapId);
- if (found == heapInformationList.end()) {
- return NULL;
- }
- return found->second;
-}
-
-const u32 HEAP_BLOCK_HEADER_SIZE = 8;
-const bool frombottom = false;
-
-static int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name)
-{
- HeapInformation *heap = new HeapInformation;
- 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);
- SceUID uid = kernelObjects.Create(heap);
- heap->uid = uid;
- heapInformationList[uid] = heap;
-
-
- return hleLogSuccessInfoX(SCEKERNEL, uid, "");
-}
-
-
-static int sceKernelAllocHeapMemory(int heapId, int size)
-{
- HeapInformation *heap = getHeap(heapId);
- if (!heap) {
- ERROR_LOG(HLE, "sceKernelAllocHeapMemory cannot find heapId", heapId);
- return 0;
- }
-
- // There's 8 bytes at the end of every block, reserved.
- u32 memSize = HEAP_BLOCK_HEADER_SIZE + size;
- u32 addr = heap->alloc.Alloc(memSize, true);
- return hleLogSuccessInfoX(SCEKERNEL, addr, "");
-}
-
-static int sceKernelDeleteHeap(int heapId)
-{
- HeapInformation *heap = getHeap(heapId);
- if (!heap) {
- ERROR_LOG(HLE, "sceKernelDeleteHeap(%i): invalid heapId", heapId);
- return -1;
- }
- userMemory.Free(heap->address);
- kernelObjects.Destroy(heap->uid);
- heapInformationList.erase(heapId);
- return hleLogSuccessInfoX(SCEKERNEL, 0, "");
-}
-
-const HLEFunction SysMemForKernel[] =
-{
- { 0X636C953B, &WrapI_II, "sceKernelAllocHeapMemory", 'I', "ii" },
- { 0XC9805775, &WrapI_I, "sceKernelDeleteHeap", 'I', "i" },
- { 0X1C1FBFE7, &WrapI_IIIC, "sceKernelCreateHeap", 'I', "iiis" },
-};
-
-void Register_SysMemForKernel()
-{
- RegisterModule("SysMemForKernel", ARRAY_SIZE(SysMemForKernel), SysMemForKernel);
-}
-
diff --git a/Core/HLE/sceKernelMemory.h b/Core/HLE/sceKernelMemory.h
index 96de13e23e..2396792436 100644
--- a/Core/HLE/sceKernelMemory.h
+++ b/Core/HLE/sceKernelMemory.h
@@ -68,5 +68,3 @@ int sceKernelReferTlsplStatus(SceUID uid, u32 infoPtr);
void Register_SysMemForKernel();
void Register_SysMemUserForUser();
-void Register_SysMemForKernel();
-
diff --git a/Core/HLE/sceKernelThread.h b/Core/HLE/sceKernelThread.h
index 73ba3474ba..14cc1fde78 100644
--- a/Core/HLE/sceKernelThread.h
+++ b/Core/HLE/sceKernelThread.h
@@ -330,3 +330,7 @@ KernelObject *__KernelThreadEventHandlerObject();
SceUID sceKernelRegisterThreadEventHandler(const char *name, SceUID threadID, u32 mask, u32 handlerPtr, u32 commonArg);
int sceKernelReleaseThreadEventHandler(SceUID uid);
int sceKernelReferThreadEventHandlerStatus(SceUID uid, u32 infoPtr);
+
+int sceKernelCreateHeap(int partitionId, int size, int flags, const char *Name);
+int sceKernelAllocHeapMemory(int heapId, int size);
+int sceKernelDeleteHeap(int heapId);
diff --git a/UWP/CoreUWP/CoreUWP.vcxproj b/UWP/CoreUWP/CoreUWP.vcxproj
index 814930607b..0bbac0c46e 100644
--- a/UWP/CoreUWP/CoreUWP.vcxproj
+++ b/UWP/CoreUWP/CoreUWP.vcxproj
@@ -466,6 +466,7 @@
+
@@ -678,6 +679,7 @@
+
diff --git a/UWP/CoreUWP/CoreUWP.vcxproj.filters b/UWP/CoreUWP/CoreUWP.vcxproj.filters
index 07d1e09371..7afcc97e71 100644
--- a/UWP/CoreUWP/CoreUWP.vcxproj.filters
+++ b/UWP/CoreUWP/CoreUWP.vcxproj.filters
@@ -368,6 +368,9 @@
HLE
+
+ HLE
+
HLE
@@ -968,6 +971,9 @@
HLE
+
+ HLE
+
HLE
@@ -1298,4 +1304,4 @@
HW
-
\ No newline at end of file
+
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index d334324cf8..6f23ada75f 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -360,6 +360,7 @@ EXEC_AND_LIB_FILES := \
$(SRC)/Core/HLE/sceKernel.cpp \
$(SRC)/Core/HLE/sceKernelAlarm.cpp \
$(SRC)/Core/HLE/sceKernelEventFlag.cpp \
+ $(SRC)/Core/HLE/sceKernelHeap.cpp \
$(SRC)/Core/HLE/sceKernelInterrupt.cpp \
$(SRC)/Core/HLE/sceKernelMemory.cpp \
$(SRC)/Core/HLE/sceKernelModule.cpp \
diff --git a/libretro/Makefile.common b/libretro/Makefile.common
index d909df3ada..b1fd51bdb6 100644
--- a/libretro/Makefile.common
+++ b/libretro/Makefile.common
@@ -389,6 +389,7 @@ SOURCES_CXX += $(NATIVEDIR)/math/dataconv.cpp \
$(COREDIR)/HLE/sceKernel.cpp \
$(COREDIR)/HLE/sceKernelAlarm.cpp \
$(COREDIR)/HLE/sceKernelEventFlag.cpp \
+ $(COREDIR)/HLE/sceKernelHeap.cpp \
$(COREDIR)/HLE/sceKernelInterrupt.cpp \
$(COREDIR)/HLE/sceKernelMbx.cpp \
$(COREDIR)/HLE/sceKernelMemory.cpp \