diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 00:57:17 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-22 00:57:17 +0100 |
| commit | 7b16a971891e12550569aa67d4185c2e51c3b8a9 (patch) | |
| tree | 41a2916a5225139cca013181af6a7faf53036305 /Public/SDK/System.Core/Sources | |
| parent | 80b76666074aa94f165e3db7b3dda2145ca6efc0 (diff) | |
unstable: /Public/: Rename Kits/ to SDK/
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public/SDK/System.Core/Sources')
| -rw-r--r-- | Public/SDK/System.Core/Sources/DllMain.cxx | 14 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Sources/Heap.cxx | 83 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Sources/New+Delete.cxx | 65 |
3 files changed, 162 insertions, 0 deletions
diff --git a/Public/SDK/System.Core/Sources/DllMain.cxx b/Public/SDK/System.Core/Sources/DllMain.cxx new file mode 100644 index 00000000..9412cbbb --- /dev/null +++ b/Public/SDK/System.Core/Sources/DllMain.cxx @@ -0,0 +1,14 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include <System.Core/Headers/Heap.hxx> + +/// @brief Inits the DLL. +/// @return if it was succesful or not. +DWordType __DllMain(VoidType) { + kInstanceObject = HcGetInstanceObject(); + CA_MUST_PASS(kInstanceObject); + + return 0; +}
\ No newline at end of file diff --git a/Public/SDK/System.Core/Sources/Heap.cxx b/Public/SDK/System.Core/Sources/Heap.cxx new file mode 100644 index 00000000..b3f43ad3 --- /dev/null +++ b/Public/SDK/System.Core/Sources/Heap.cxx @@ -0,0 +1,83 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <System.Core/Headers/Heap.hxx> + +/// @brief Allocate from the user's heap. +/// @param refObj Process object. +/// @param sz size of object. +/// @param flags flags. +/// @return +CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectPtr refObj, QWordType sz, + DWordType flags) { + CA_MUST_PASS(sz); + CA_MUST_PASS(flags); + + return (PtrVoidType)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param refObj Process object. +/// @param ptr the pointer to free. +CA_EXTERN_C VoidType HcFreeProcessHeap(ObjectPtr refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param refObj Process object. +/// @param ptr the pointer to find. +/// @return the size. +CA_EXTERN_C QWordType HcProcessHeapSize(ObjectPtr refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param refObj Process object. +/// @param ptr the pointer to check. +/// @return if it exists +CA_EXTERN_C BooleanType HcProcessHeapExists(ObjectPtr refObj, PtrVoidType ptr) { + CA_MUST_PASS(ptr); + return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); +} + +using namespace System; + +/// @brief Shared instance of the heap. +/// @return +HeapInterface* HeapInterface::Shared() noexcept { + static HeapInterface* heap = nullptr; + + if (!heap) { + heap = new HeapInterface(); + } + + return heap; +} + +HeapInterface::HeapInterface() { + CA_MUST_PASS(HcProcessHeapExists(kInstanceObject, (PtrVoidType)this)); +} + +HeapInterface::~HeapInterface() { delete this; } + +void HeapInterface::Delete(HeapPtr me) noexcept { + CA_MUST_PASS(me); + HcFreeProcessHeap(kInstanceObject, me); +} + +SizeType HeapInterface::Size(HeapPtr me) noexcept { + CA_MUST_PASS(me); + return HcProcessHeapSize(kInstanceObject, me); +} + +HeapPtr HeapInterface::New(const SizeType& sz, const DWordType flags) { + SizeType _sz = sz; + if (!_sz) ++_sz; + + return HcAllocateProcessHeap(kInstanceObject, _sz, flags); +} diff --git a/Public/SDK/System.Core/Sources/New+Delete.cxx b/Public/SDK/System.Core/Sources/New+Delete.cxx new file mode 100644 index 00000000..019db66c --- /dev/null +++ b/Public/SDK/System.Core/Sources/New+Delete.cxx @@ -0,0 +1,65 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include <System.Core/Headers/Heap.hxx> + +#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(kInstanceObject, sz, kStandardAllocation); +} + +void* operator new(size_t sz) +{ + if (sz == 0) + ++sz; + + return HcAllocateProcessHeap(kInstanceObject, sz, kArrayAllocation); +} + +void operator delete[](void* ptr) +{ + if (ptr == nullptr) + return; + + HcFreeProcessHeap(kInstanceObject, ptr); +} + +void operator delete(void* ptr) +{ + if (ptr == nullptr) + return; + + HcFreeProcessHeap(kInstanceObject, ptr); +} + +void operator delete(void* ptr, size_t sz) +{ + if (ptr == nullptr) + return; + + (void)sz; + + HcFreeProcessHeap(kInstanceObject, ptr); +} + |
