From 0f531ca74f6d3efe73557f8ff6c2c0613bfaaccb Mon Sep 17 00:00:00 2001 From: krispy <125815038+kr1spy2115@users.noreply.github.com> Date: Sun, 10 Mar 2024 19:05:43 +0100 Subject: [PATCH] sceNpHeap main functions (#201) * sceNpHeap main functions sceNpHeapMalloc sceNpHeapGetStat sceNpHeapDestroy * + --------- Co-authored-by: red-prig --- src/np/ps4_libscenpcommon.pas | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/np/ps4_libscenpcommon.pas b/src/np/ps4_libscenpcommon.pas index 698c012d..b48f5e87 100644 --- a/src/np/ps4_libscenpcommon.pas +++ b/src/np/ps4_libscenpcommon.pas @@ -79,6 +79,13 @@ type entry:Pointer; // 24 end; + pSceNpHeapStat=^SceNpHeapStat; + SceNpHeapStat=packed record + maxSystemSize :QWORD; + maxInuseSize :QWORD; + currentInuseSize:QWORD; + end; + implementation uses @@ -222,6 +229,42 @@ begin end; end; +function ps4__sceNpHeapMalloc(heap:pSceNpHeap;size:size_t):Pointer; SysV_ABI_CDecl; +begin + Result:=nil; + if (heap^.mspace<>nil) then + begin + Result:=ps4_sceLibcMspaceMalloc(heap^.mspace,size); + end; +end; + +function ps4_sceNpHeapGetStat(heap:pSceNpHeap;stat:pSceNpHeapStat):Integer; SysV_ABI_CDecl; +var + data:SceLibcMallocManagedSize; +begin + data:=Default(SceLibcMallocManagedSize); + data.size :=40; + data.version:=1; + + Result:=ps4_sceLibcMspaceMallocStats(heap^.mspace,@data); + + if (Result=0) then + begin + stat^.maxSystemSize :=data.maxSystemSize; + stat^.maxInuseSize :=data.maxInuseSize; + stat^.currentInuseSize:=data.currentInuseSize; + end; +end; + +procedure ps4_sceNpHeapDestroy(heap:pSceNpHeap); SysV_ABI_CDecl; +begin + if (heap^.mspace<>nil) then + begin + ps4_sceLibcMspaceDestroy(heap^.mspace); + heap^.mspace:=nil; + end; +end; + function ps4_sceNpCreateEventFlag(ef:pSceKernelEventFlag; pName:PChar; attr:DWORD; @@ -271,6 +314,9 @@ begin lib^.set_proc($E33C5EBE082D62B4,@ps4_sceNpMutexDestroy); // sceNpLwMutexDestroy // lib^.set_proc($07EC86217D7E0532,@ps4_sceNpHeapInit); + lib^.set_proc($9305B9A9D75FF8BA,@ps4__sceNpHeapMalloc); + lib^.set_proc($DA3747A0FA52F96D,@ps4_sceNpHeapGetStat); + lib^.set_proc($C15767EFC1CA737D,@ps4_sceNpHeapDestroy); lib^.set_proc($EA3156A407EA01C7,@ps4_sceNpCreateEventFlag); lib^.set_proc($D2CC8D921240355C,@ps4__ZN3sce2np6ObjectnwEmR14SceNpAllocator); end;