diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-17 21:38:54 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-17 21:39:15 +0100 |
| commit | a4bfc396a78ddd553de519ab927d8479d0c3c45d (patch) | |
| tree | 6ff41607784ee4db226843c1aec6b06d4be5a779 /Public/Kits/System.Core | |
| parent | a8366afaf39321ae2bbae70740f5ca65bee06769 (diff) | |
unrelated: See below.
Public: Kits: Implemented System API and the concept of object handles.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'Public/Kits/System.Core')
| -rw-r--r-- | Public/Kits/System.Core/Containers/XIFF.hxx | 4 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Defs.hxx | 23 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HCoreBase.hxx | 6 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HCoreHeap.hxx | 10 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HCoreHeap.s | 23 | ||||
| -rw-r--r-- | Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx | 27 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Heap.cxx | 11 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Heap.hxx | 6 | ||||
| -rw-r--r-- | Public/Kits/System.Core/Makefile | 12 |
9 files changed, 90 insertions, 32 deletions
diff --git a/Public/Kits/System.Core/Containers/XIFF.hxx b/Public/Kits/System.Core/Containers/XIFF.hxx index 002d05f4..b9fa741e 100644 --- a/Public/Kits/System.Core/Containers/XIFF.hxx +++ b/Public/Kits/System.Core/Containers/XIFF.hxx @@ -35,8 +35,8 @@ typedef struct XiffHeader XiffHeader; #define kXIFFContainerVideo "XVFF" #define kXIFFContainerAudio "XAFF" -#define kXIFFContainerInstaller "XnFF" +#define kXIFFContainerInstaller "XNFF" #define kXIFFContainerGeneric "XIFF" -#define kXIFFContainerBinary "XEFF" +#define kXIFFContainerBinary "XBFF" #endif // ifndef __XIFF__ diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx index 3ebe5c2c..ad615ef9 100644 --- a/Public/Kits/System.Core/Defs.hxx +++ b/Public/Kits/System.Core/Defs.hxx @@ -14,12 +14,10 @@ #undef CA_MUST_PASS #endif -#define CA_UNREFERENCED_PARAMETER(e) ((void)e) - -/// Assertion macros. +#include <ObjectKit/Object.hxx> #ifdef _DEBUG -#define CA_MUST_PASS(e) __assert(e) +#define CA_MUST_PASS(e) { if (!e) { __assert_chk_fail() } } #else #define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) #endif @@ -34,6 +32,8 @@ #endif +CA_EXTERN_C void __assert_chk_fail(void); + #define CA_STDCALL __attribute__((stdcall)) #define CA_CDECL __attribute__((cdecl)) #define CA_MSCALL __attribute__((ms_abi)) @@ -51,6 +51,8 @@ typedef void VOID; typedef __WCHAR_TYPE__ WCHAR; typedef WCHAR* PWCHAR; +#define CA_UNREFERENCED_PARAMETER(e) ((VOID)e) + #ifdef __x86_64__ # define _M_AMD64 2 #endif @@ -75,3 +77,16 @@ typedef WCHAR* PWCHAR; #else #define CA_CONSTEXPR #endif // __cplusplus + +CA_INLINE ObjectPtr kInstanceObject; + +enum { + kProcessHeapCallAlloc = 1, + kProcessHeapCallFree, + kProcessHeapCallSize, + kProcessHeapCallCheck, + kProcessHeapCallAllocStack, + kProcessHeapCallOpenHandle, + kProcessHeapCallCloseHandle, + kProcessHeapCallsCnt, +}; diff --git a/Public/Kits/System.Core/HCoreBase.hxx b/Public/Kits/System.Core/HCoreBase.hxx index 5bb6f9af..774f9883 100644 --- a/Public/Kits/System.Core/HCoreBase.hxx +++ b/Public/Kits/System.Core/HCoreBase.hxx @@ -5,9 +5,3 @@ #pragma once #include <System.Core/Defs.hxx> - -typedef struct HcObject { - void(*Release)(void); - void(*Invoke)(void); - void(*QueryInterface)(void); -} *HcObjectPtr; diff --git a/Public/Kits/System.Core/HCoreHeap.hxx b/Public/Kits/System.Core/HCoreHeap.hxx index 88cbbeb7..0c6eb1dc 100644 --- a/Public/Kits/System.Core/HCoreHeap.hxx +++ b/Public/Kits/System.Core/HCoreHeap.hxx @@ -6,8 +6,8 @@ #include <System.Core/HCoreBase.hxx> -CA_EXTERN_C HcObjectPtr HcGetProcessHeap(void); -CA_EXTERN_C void* HcAllocateProcessHeap(HcObjectPtr refObj, long long int sz, int flags); -CA_EXTERN_C void HcFreeProcessHeap(HcObjectPtr refObj, void* ptr); -CA_EXTERN_C long long int HcProcessHeapSize(HcObjectPtr refObj, void* ptr); -CA_EXTERN_C long long int HcProcessHeapExists(HcObjectPtr refObj, void* ptr); +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); diff --git a/Public/Kits/System.Core/HCoreHeap.s b/Public/Kits/System.Core/HCoreHeap.s new file mode 100644 index 00000000..108c6fcf --- /dev/null +++ b/Public/Kits/System.Core/HCoreHeap.s @@ -0,0 +1,23 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +.section .text + +.globl HcGetProcessObject +.globl __assert_chk_fail + +/* Process Heap getter */ +HcGetProcessObject: + mov $0x1, %rcx /* sysGetProcessObject */ + int $0x21 + + /* rax gets saved and returned. */ + ret + +__assert_chk_fail: + mov $0x2, %rcx /* sysTerminateCurrentProcess */ + int $0x21 + + ret + diff --git a/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx b/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx new file mode 100644 index 00000000..86b2bf47 --- /dev/null +++ b/Public/Kits/System.Core/HCoreHeap_ObjectAPI.cxx @@ -0,0 +1,27 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#include <System.Core/HCoreHeap.hxx> + +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.cxx b/Public/Kits/System.Core/Heap.cxx index c7401aad..56188e95 100644 --- a/Public/Kits/System.Core/Heap.cxx +++ b/Public/Kits/System.Core/Heap.cxx @@ -7,32 +7,29 @@ #include <System.Core/Heap.hxx> #include <System.Core/System.Core.hxx> -using namespace HCore; using namespace System; -STATIC HcObjectPtr kObjectHeap; - Heap* Heap::Shared() noexcept { static Heap* heap = nullptr; if (!heap) { heap = new Heap(); - kObjectHeap = HcGetProcessHeap(); + kInstanceObject = HcGetProcessObject(); } return heap; } -void Heap::Delete(HeapPtr me) noexcept { HcFreeProcessHeap(kObjectHeap, me); } +void Heap::Delete(HeapPtr me) noexcept { HcFreeProcessHeap(kInstanceObject, me); } SizeT Heap::Size(HeapPtr me) noexcept { CA_MUST_PASS(me); - return HcProcessHeapSize(kObjectHeap, me); + return HcProcessHeapSize(kInstanceObject, me); } HeapPtr Heap::New(const SizeT &sz, const Int32 flags) { SizeT _sz = sz; if (!_sz) ++_sz; - return HcAllocateProcessHeap(kObjectHeap, _sz, flags); + 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 292a1227..dfcb4587 100644 --- a/Public/Kits/System.Core/Heap.hxx +++ b/Public/Kits/System.Core/Heap.hxx @@ -10,6 +10,8 @@ #include <CompilerKit/CompilerKit.hxx> namespace System { +using namespace HCore; + class MemoryException; typedef PVOID HeapPtr; @@ -24,10 +26,10 @@ enum { class Heap final { private: - explicit Heap(); + explicit Heap() = default; public: - ~Heap(); + ~Heap() = default; public: HCORE_COPY_DEFAULT(Heap); diff --git a/Public/Kits/System.Core/Makefile b/Public/Kits/System.Core/Makefile index d710b2e8..f358dfa5 100644 --- a/Public/Kits/System.Core/Makefile +++ b/Public/Kits/System.Core/Makefile @@ -1,18 +1,18 @@ ################################################## -# ; (C) Mahrouss Logic, 2024, all rights reserved. +# (C) Mahrouss Logic, 2024, all rights reserved. # This is the System.Graphics Makefile. ################################################## CC=x86_64-w64-mingw32-g++ -CCFLAGS=-shared -ffreestanding -fno-rtti -fno-exceptions -std=c++20 +CCFLAGS=-shared -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17 OUTPUT=System.Core.dll -.PHONY: build-gkit -build-gkit: - $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) *.cxx -o $(OUTPUT) +.PHONY: build-core +build-core: + $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) $(wildcard *.cxx) $(wildcard *.s) -o $(OUTPUT) .PHONY: all -all: build-gkit +all: build-core @echo "[System.Core.dll] Build done." .PHONY: clean |
