From de413aa50bac1342e4ac8c7a66697ea3b551c2e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 19 Mar 2024 21:01:12 +0100 Subject: Kernel(Secret): Major commit. - Extensive cleanup of the code, and kernel improvements. - The System API has been reworked to be better designed. What is needed now: - AHCI disk driver. - HCFS/NewFS driver. - EPM layout implementation. - Separate bootloader and kernel. --- Public/Kits/System.Core/Defs.hxx | 19 +++++++++++- Public/Kits/System.Core/File.hxx | 4 +-- Public/Kits/System.Core/HCoreBase.hxx | 7 ----- Public/Kits/System.Core/HCoreHeap+Impl.cxx | 44 ---------------------------- Public/Kits/System.Core/HCoreHeap.hxx | 20 ------------- Public/Kits/System.Core/Heap+Impl.cxx | 37 ----------------------- Public/Kits/System.Core/Heap.hxx | 23 ++++++++++++--- Public/Kits/System.Core/HeapCoreImpl.cxx | 47 ++++++++++++++++++++++++++++++ Public/Kits/System.Core/HeapImpl.cxx | 41 ++++++++++++++++++++++++++ Public/Kits/System.Core/Hint.hxx | 18 ++++++++++++ Public/Kits/System.Core/HintBase.hxx | 18 ------------ Public/Kits/System.Core/InitRuntime.cxx | 12 ++++++++ Public/Kits/System.Core/New+Delete.cxx | 2 +- Public/Kits/System.Core/RuntimeInit.cxx | 12 -------- Public/Kits/System.Core/System.Core.hxx | 9 +++--- 15 files changed, 162 insertions(+), 151 deletions(-) delete mode 100644 Public/Kits/System.Core/HCoreBase.hxx delete mode 100644 Public/Kits/System.Core/HCoreHeap+Impl.cxx delete mode 100644 Public/Kits/System.Core/HCoreHeap.hxx delete mode 100644 Public/Kits/System.Core/Heap+Impl.cxx create mode 100644 Public/Kits/System.Core/HeapCoreImpl.cxx create mode 100644 Public/Kits/System.Core/HeapImpl.cxx create mode 100644 Public/Kits/System.Core/Hint.hxx delete mode 100644 Public/Kits/System.Core/HintBase.hxx create mode 100644 Public/Kits/System.Core/InitRuntime.cxx delete mode 100644 Public/Kits/System.Core/RuntimeInit.cxx (limited to 'Public/Kits/System.Core') diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx index bcb3585c..9a17d571 100644 --- a/Public/Kits/System.Core/Defs.hxx +++ b/Public/Kits/System.Core/Defs.hxx @@ -108,4 +108,21 @@ enum HcProcessCall { kProcessCallsCount = 7, }; -#include +#include + +class Exception { + public: + explicit Exception() = default; + virtual ~Exception() = default; + + public: + HCORE_COPY_DEFAULT(Exception); + + public: + const char *Name(); + const char *Reason(); + + private: + const char *mReason{ + "System.Core: System Exception: Catastrophic failure!"}; +}; diff --git a/Public/Kits/System.Core/File.hxx b/Public/Kits/System.Core/File.hxx index 2f799330..97377800 100644 --- a/Public/Kits/System.Core/File.hxx +++ b/Public/Kits/System.Core/File.hxx @@ -25,10 +25,10 @@ class File final { public: voidPtr Read(SizeT off, SizeT sz); - void Write(voidPtr buf, SizeT off, SizeT sz); + void Write(VoidPtr buf, SizeT off, SizeT sz); void Seek(SizeT off); voidPtr Read(SizeT sz); - void Write(voidPtr buf, SizeT sz); + void Write(VoidPtr buf, SizeT sz); void Rewind(); public: diff --git a/Public/Kits/System.Core/HCoreBase.hxx b/Public/Kits/System.Core/HCoreBase.hxx deleted file mode 100644 index 774f9883..00000000 --- a/Public/Kits/System.Core/HCoreBase.hxx +++ /dev/null @@ -1,7 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#pragma once - -#include diff --git a/Public/Kits/System.Core/HCoreHeap+Impl.cxx b/Public/Kits/System.Core/HCoreHeap+Impl.cxx deleted file mode 100644 index 0e1b1732..00000000 --- a/Public/Kits/System.Core/HCoreHeap+Impl.cxx +++ /dev/null @@ -1,44 +0,0 @@ -/** =========================================== - (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.hxx b/Public/Kits/System.Core/HCoreHeap.hxx deleted file mode 100644 index 41143495..00000000 --- a/Public/Kits/System.Core/HCoreHeap.hxx +++ /dev/null @@ -1,20 +0,0 @@ -/** =========================================== - (C) Mahrouss Logic - ===========================================*/ - -#pragma once - -#include - -CA_EXTERN_C ObjectPtr HcGetProcessObject(void); -CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags); -CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr); -CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr); -CA_EXTERN_C QWORD HcProcessHeapExists(ObjectPtr refObj, PVOID ptr); - -enum HcAllocationKind { - kStandardAllocation = 0xC, - kArrayAllocation = 0xD, -}; - -#define kAllocationTypes 2 diff --git a/Public/Kits/System.Core/Heap+Impl.cxx b/Public/Kits/System.Core/Heap+Impl.cxx deleted file mode 100644 index e3dcb11c..00000000 --- a/Public/Kits/System.Core/Heap+Impl.cxx +++ /dev/null @@ -1,37 +0,0 @@ -/* ------------------------------------------- - - 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.hxx b/Public/Kits/System.Core/Heap.hxx index dfcb4587..31e44c7e 100644 --- a/Public/Kits/System.Core/Heap.hxx +++ b/Public/Kits/System.Core/Heap.hxx @@ -6,8 +6,22 @@ #pragma once -#include #include +#include + +#define kAllocationTypes 2 + +CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, + DWORD flags); +CA_EXTERN_C BOOL HcProcessHeapExists(ObjectPtr refObj, PVOID ptr); +CA_EXTERN_C QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID ptr); +CA_EXTERN_C VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID ptr); +CA_EXTERN_C ObjectPtr HcGetProcessObject(void); + +enum HcAllocationKind { + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, +}; namespace System { using namespace HCore; @@ -29,7 +43,7 @@ class Heap final { explicit Heap() = default; public: - ~Heap() = default; + ~Heap(); public: HCORE_COPY_DEFAULT(Heap); @@ -56,9 +70,10 @@ class MemoryException final { const char *Reason(); private: - const char *mReason{"System.Core: Process Heap Exception: Catastrophic failure!"}; + const char *mReason{ + "System.Core: Process Heap Exception: Catastrophic failure!"}; private: friend Heap; }; -} // namespace System \ No newline at end of file +} // namespace System \ No newline at end of file diff --git a/Public/Kits/System.Core/HeapCoreImpl.cxx b/Public/Kits/System.Core/HeapCoreImpl.cxx new file mode 100644 index 00000000..2980a3de --- /dev/null +++ b/Public/Kits/System.Core/HeapCoreImpl.cxx @@ -0,0 +1,47 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include + +/// @brief Allocate from the user's heap. +/// @param refObj Process object. +/// @param sz size of object. +/// @param flags flags. +/// @return +CA_EXTERN_C PVOID HcAllocateProcessHeap(ObjectPtr refObj, QWORD sz, DWORD flags) +{ + CA_MUST_PASS(sz); + CA_MUST_PASS(flags); + + return (PVOID)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 VOID HcFreeProcessHeap(ObjectPtr refObj, PVOID 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 QWORD HcProcessHeapSize(ObjectPtr refObj, PVOID 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 BOOL HcProcessHeapExists(ObjectPtr refObj, PVOID ptr) +{ + CA_MUST_PASS(ptr); + return refObj->Invoke(refObj, kProcessCallCheckPtr, ptr); +} diff --git a/Public/Kits/System.Core/HeapImpl.cxx b/Public/Kits/System.Core/HeapImpl.cxx new file mode 100644 index 00000000..f41c868f --- /dev/null +++ b/Public/Kits/System.Core/HeapImpl.cxx @@ -0,0 +1,41 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include +#include + +using namespace System; + +/// @brief Shared instance of the heap. +/// @return +Heap* Heap::Shared() noexcept { + static Heap* heap = nullptr; + + if (!heap) { + heap = new Heap(); + } + + return heap; +} + +Heap::~Heap() { delete this; } + +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/Hint.hxx b/Public/Kits/System.Core/Hint.hxx new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/Kits/System.Core/Hint.hxx @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#define _Input +#define _Output + +#define _Optional + +#define _StrictCheckInput +#define _StrictCheckOutput + +#define _InOut +#define _StrictInOut diff --git a/Public/Kits/System.Core/HintBase.hxx b/Public/Kits/System.Core/HintBase.hxx deleted file mode 100644 index 86faf455..00000000 --- a/Public/Kits/System.Core/HintBase.hxx +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#pragma once - -#define _Input -#define _Output - -#define _Optional - -#define _StrictCheckInput -#define _StrictCheckOutput - -#define _InOut -#define _StrictInOut diff --git a/Public/Kits/System.Core/InitRuntime.cxx b/Public/Kits/System.Core/InitRuntime.cxx new file mode 100644 index 00000000..01eb2c1f --- /dev/null +++ b/Public/Kits/System.Core/InitRuntime.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/New+Delete.cxx b/Public/Kits/System.Core/New+Delete.cxx index cac883f4..507cb7a3 100644 --- a/Public/Kits/System.Core/New+Delete.cxx +++ b/Public/Kits/System.Core/New+Delete.cxx @@ -4,7 +4,7 @@ ------------------------------------------- */ -#include +#include void* operator new[](size_t sz) { diff --git a/Public/Kits/System.Core/RuntimeInit.cxx b/Public/Kits/System.Core/RuntimeInit.cxx deleted file mode 100644 index b6022bef..00000000 --- a/Public/Kits/System.Core/RuntimeInit.cxx +++ /dev/null @@ -1,12 +0,0 @@ -/** =========================================== - (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/System.Core.hxx b/Public/Kits/System.Core/System.Core.hxx index b368b997..07b7199c 100644 --- a/Public/Kits/System.Core/System.Core.hxx +++ b/Public/Kits/System.Core/System.Core.hxx @@ -4,12 +4,11 @@ #pragma once -/// Core API -#include - /// Process Heap API -#include +#include /// File API & Device API. +#include -/// Process & Threading API \ No newline at end of file +/// Process & Threading API +#include \ No newline at end of file -- cgit v1.2.3