From 3b3b36dcc6542e203475fe1d50ed89799e3f3fc6 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 25 Mar 2024 20:17:53 +0100 Subject: Kernel: implement some tickets, improved stuff. Signed-off-by: Amlal El Mahrouss --- .../Developer/System.Core/Sources/New+Delete.cxx | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Public/Developer/System.Core/Sources/New+Delete.cxx (limited to 'Public/Developer/System.Core/Sources/New+Delete.cxx') diff --git a/Public/Developer/System.Core/Sources/New+Delete.cxx b/Public/Developer/System.Core/Sources/New+Delete.cxx new file mode 100644 index 00000000..98674a73 --- /dev/null +++ b/Public/Developer/System.Core/Sources/New+Delete.cxx @@ -0,0 +1,55 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +#define kAllocationTypes 2 + +enum HcAllocationKind { + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; + +CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectPtr refObj, QWordType sz, + DWordType flags); +CA_EXTERN_C BooleanType HcProcessHeapExists(ObjectPtr refObj, PtrVoidType ptr); +CA_EXTERN_C QWordType HcProcessHeapSize(ObjectPtr refObj, PtrVoidType ptr); +CA_EXTERN_C VoidType HcFreeProcessHeap(ObjectPtr refObj, PtrVoidType ptr); + +typedef SizeType size_t; + +void* operator new[](size_t sz) { + if (sz == 0) ++sz; + + return HcAllocateProcessHeap(kApplicationObject, sz, kStandardAllocation); +} + +void* operator new(size_t sz) { + if (sz == 0) ++sz; + + return HcAllocateProcessHeap(kApplicationObject, sz, kArrayAllocation); +} + +void operator delete[](void* ptr) { + if (ptr == nullptr) return; + + HcFreeProcessHeap(kApplicationObject, ptr); +} + +void operator delete(void* ptr) { + if (ptr == nullptr) return; + + HcFreeProcessHeap(kApplicationObject, ptr); +} + +void operator delete(void* ptr, size_t sz) { + if (ptr == nullptr) return; + + (void)sz; + + HcFreeProcessHeap(kApplicationObject, ptr); +} -- cgit v1.2.3