From baf2afd8cd672dcb9c13d956dfdd73b61dfee558 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 19 Mar 2024 10:05:31 +0100 Subject: unstable, secret: See below. System.Core: - Add RunTime init function. - Add ReadMe.md Kernel: - Improve TLS code, use Encoder class instead of casting directly. - Refactor process team to include processscheduler.hpp instead. ObjectKit: - Rename Object.hxx to ObjectKit.hxx Builtins/AHCI: - Rename API.hxx to Interface.hxx Signed-off-by: Amlal El Mahrouss --- Public/Kits/System.Core/Defs.hxx | 20 +++++------ Public/Kits/System.Core/HCoreHeap+Impl.cxx | 44 +++++++++++++++++++++++++ Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx | 27 --------------- Public/Kits/System.Core/Heap+Impl.cxx | 37 +++++++++++++++++++++ Public/Kits/System.Core/Heap.cxx | 38 --------------------- Public/Kits/System.Core/ReadMe.md | 10 ++++++ Public/Kits/System.Core/RuntimeInit.cxx | 12 +++++++ Public/Kits/System.Core/Threading.hxx | 9 +++-- 8 files changed, 117 insertions(+), 80 deletions(-) create mode 100644 Public/Kits/System.Core/HCoreHeap+Impl.cxx delete mode 100644 Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx create mode 100644 Public/Kits/System.Core/Heap+Impl.cxx delete mode 100644 Public/Kits/System.Core/Heap.cxx create mode 100644 Public/Kits/System.Core/ReadMe.md create mode 100644 Public/Kits/System.Core/RuntimeInit.cxx (limited to 'Public') diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx index d1e5d483..bcb3585c 100644 --- a/Public/Kits/System.Core/Defs.hxx +++ b/Public/Kits/System.Core/Defs.hxx @@ -14,7 +14,7 @@ #undef CA_MUST_PASS #endif -#include +#include #ifdef _DEBUG #define CA_MUST_PASS(e) { if (!e) { __assert_chk_fail() } } @@ -97,15 +97,15 @@ typedef bool BOOL; CA_INLINE ObjectPtr kInstanceObject; -enum { - kProcessHeapCallAlloc = 1, - kProcessHeapCallFree, - kProcessHeapCallSize, - kProcessHeapCallCheck, - kProcessHeapCallAllocStack, - kProcessHeapCallOpenHandle, - kProcessHeapCallCloseHandle, - kProcessHeapCallsCnt, +enum HcProcessCall { + kProcessCallAllocPtr = 1, + kProcessCallFreePtr, + kProcessCallSizePtr, + kProcessCallCheckPtr, + kProcessCallAllocStack, + kProcessCallOpenHandle, + kProcessCallCloseHandle, + kProcessCallsCount = 7, }; #include diff --git a/Public/Kits/System.Core/HCoreHeap+Impl.cxx b/Public/Kits/System.Core/HCoreHeap+Impl.cxx new file mode 100644 index 00000000..0e1b1732 --- /dev/null +++ b/Public/Kits/System.Core/HCoreHeap+Impl.cxx @@ -0,0 +1,44 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include + +/// @brief Allocate from the user's heap. +/// @param refObj +/// @param sz +/// @param flags +/// @return +CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags) +{ + return (PVOID)refObj->Invoke(refObj, kProcessCallAllocPtr, sz, flags); +} + +/// @brief Free pointer from the user's heap. +/// @param refObj +/// @param ptr +/// @return +CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr) +{ + CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); +} + +/// @brief Get pointer size. +/// @param refObj +/// @param ptr +/// @return +CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr) +{ + return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); +} + +/// @brief Check if the pointer exists. +/// @param refObj Process object. +/// @param ptr +/// @return +CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr) +{ + return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); +} + +// EOF. diff --git a/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx b/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx deleted file mode 100644 index 86b2bf47..00000000 --- a/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx +++ /dev/null @@ -1,27 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#include - -CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags) -{ - return (PVOID)refObj->Invoke(refObj, kProcessHeapCallAlloc, sz, flags); -} - -CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr) -{ - CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessHeapCallFree, ptr)); -} - -CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr) -{ - return refObj->Invoke(refObj, kProcessHeapCallSize, ptr); -} - -CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr) -{ - return refObj->Invoke(refObj, kProcessHeapCallCheck, ptr); -} - -// eof. diff --git a/Public/Kits/System.Core/Heap+Impl.cxx b/Public/Kits/System.Core/Heap+Impl.cxx new file mode 100644 index 00000000..e3dcb11c --- /dev/null +++ b/Public/Kits/System.Core/Heap+Impl.cxx @@ -0,0 +1,37 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +using namespace System; + +Heap* Heap::Shared() noexcept { + static Heap* heap = nullptr; + + if (!heap) { + heap = new Heap(); + } + + return heap; +} + +void Heap::Delete(HeapPtr me) noexcept { + CA_MUST_PASS(me); + HcFreeProcessHeap(kInstanceObject, me); +} + +SizeT Heap::Size(HeapPtr me) noexcept { + CA_MUST_PASS(me); + return HcProcessHeapSize(kInstanceObject, me); +} + +HeapPtr Heap::New(const SizeT &sz, const Int32 flags) { + SizeT _sz = sz; + if (!_sz) ++_sz; + + return HcAllocateProcessHeap(kInstanceObject, _sz, flags); +} \ No newline at end of file diff --git a/Public/Kits/System.Core/Heap.cxx b/Public/Kits/System.Core/Heap.cxx deleted file mode 100644 index aaac37a8..00000000 --- a/Public/Kits/System.Core/Heap.cxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#include -#include - -using namespace System; - -Heap* Heap::Shared() noexcept { - static Heap* heap = nullptr; - - if (!heap) { - heap = new Heap(); - kInstanceObject = HcGetProcessObject(); - } - - return heap; -} - -void Heap::Delete(HeapPtr me) noexcept { - CA_MUST_PASS(me); - HcFreeProcessHeap(kInstanceObject, me); -} - -SizeT Heap::Size(HeapPtr me) noexcept { - CA_MUST_PASS(me); - return HcProcessHeapSize(kInstanceObject, me); -} - -HeapPtr Heap::New(const SizeT &sz, const Int32 flags) { - SizeT _sz = sz; - if (!_sz) ++_sz; - - return HcAllocateProcessHeap(kInstanceObject, _sz, flags); -} \ No newline at end of file diff --git a/Public/Kits/System.Core/ReadMe.md b/Public/Kits/System.Core/ReadMe.md new file mode 100644 index 00000000..92bfca25 --- /dev/null +++ b/Public/Kits/System.Core/ReadMe.md @@ -0,0 +1,10 @@ +# System.Core +## Core System API. + +Currently contains: +- System Call Interface. +- Heap API. +- System Heap API. +- File API. +- Core functions and data types. +- System Threading API. \ No newline at end of file diff --git a/Public/Kits/System.Core/RuntimeInit.cxx b/Public/Kits/System.Core/RuntimeInit.cxx new file mode 100644 index 00000000..b6022bef --- /dev/null +++ b/Public/Kits/System.Core/RuntimeInit.cxx @@ -0,0 +1,12 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include + +/// @brief Inits the C runtime +/// @return if it was succesful or not. +DWORD HcInitRuntime(VOID) { + kInstanceObject = HcGetProcessObject(); + return 0; +} \ No newline at end of file diff --git a/Public/Kits/System.Core/Threading.hxx b/Public/Kits/System.Core/Threading.hxx index 5d5ed0a6..bddbbf3f 100644 --- a/Public/Kits/System.Core/Threading.hxx +++ b/Public/Kits/System.Core/Threading.hxx @@ -14,17 +14,16 @@ #include /// @brief Thread Information Block variant for scheduling. -struct ThreadInformationBlock final { - const CHAR Name[255]; // Module Name +struct PACKED ThreadInformationBlock final { const UINT_PTR StartAddress; // Start Address const UINT_PTR StartHeap; // Allocation Heap const UINT_PTR StartStack; // Stack Pointer. - const DWORD Arch; // Architecture and/or platform. - const WORD TID; // Execution Thread ID. + const WORD ThreadID; // Execution Thread ID. }; ThreadInformationBlock* HcCreateThread(_Input PVOID Start, - _Optional _InOut PVOID HeapOpt, _Optional _InOut PVOID StackOpt); + _Optional _InOut PVOID HeapOpt, + _Optional _InOut PVOID StackOpt); BOOL HcDestroyThread(_Input ThreadInformationBlock* TIB); -- cgit v1.2.3