From 98347089c7e4e2b306d25a0db77e00aa2ea50882 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 18 Mar 2024 20:01:38 +0100 Subject: unstable, secret: Very important changes done to the system API, add threading functions. Signed-off-by: Amlal El Mahrouss --- Public/Kits/System.Core/Defs.hxx | 19 +++++++++++++ Public/Kits/System.Core/HCoreHeap.hxx | 7 +++++ Public/Kits/System.Core/Heap.cxx | 5 +++- Public/Kits/System.Core/HintBase.hxx | 18 ++++++++++++ Public/Kits/System.Core/Makefile | 2 +- Public/Kits/System.Core/New+Delete.cxx | 50 ++++++++++++++++++++++++++++++++++ Public/Kits/System.Core/System.hxx | 2 +- Public/Kits/System.Core/ThreadAPI.hxx | 36 ------------------------ Public/Kits/System.Core/Threading.hxx | 35 ++++++++++++++++++++++++ 9 files changed, 135 insertions(+), 39 deletions(-) create mode 100644 Public/Kits/System.Core/HintBase.hxx create mode 100644 Public/Kits/System.Core/New+Delete.cxx delete mode 100644 Public/Kits/System.Core/ThreadAPI.hxx create mode 100644 Public/Kits/System.Core/Threading.hxx (limited to 'Public/Kits/System.Core') diff --git a/Public/Kits/System.Core/Defs.hxx b/Public/Kits/System.Core/Defs.hxx index ad615ef9..d1e5d483 100644 --- a/Public/Kits/System.Core/Defs.hxx +++ b/Public/Kits/System.Core/Defs.hxx @@ -45,12 +45,29 @@ typedef __UINT16_TYPE__ WORD; typedef __UINT32_TYPE__ DWORD; typedef __UINT64_TYPE__ QWORD; +typedef char CHAR; +typedef CHAR* PCHAR; + typedef void* PVOID; typedef void VOID; +typedef __UINTPTR_TYPE__ UINT_PTR; +typedef __INTPTR_TYPE__ INT_PTR; +typedef __UINT64_TYPE__ UINT64; +typedef __INT64_TYPE__ INT64; +typedef __UINT32_TYPE__ UINT32; +typedef __INT32_TYPE__ INT32; + typedef __WCHAR_TYPE__ WCHAR; typedef WCHAR* PWCHAR; +typedef bool BOOL; + +#define TRUE true +#define FALSE false + +#define PTR * + #define CA_UNREFERENCED_PARAMETER(e) ((VOID)e) #ifdef __x86_64__ @@ -90,3 +107,5 @@ enum { kProcessHeapCallCloseHandle, kProcessHeapCallsCnt, }; + +#include diff --git a/Public/Kits/System.Core/HCoreHeap.hxx b/Public/Kits/System.Core/HCoreHeap.hxx index 0c6eb1dc..41143495 100644 --- a/Public/Kits/System.Core/HCoreHeap.hxx +++ b/Public/Kits/System.Core/HCoreHeap.hxx @@ -11,3 +11,10 @@ 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.cxx b/Public/Kits/System.Core/Heap.cxx index 56188e95..aaac37a8 100644 --- a/Public/Kits/System.Core/Heap.cxx +++ b/Public/Kits/System.Core/Heap.cxx @@ -20,7 +20,10 @@ Heap* Heap::Shared() noexcept { return heap; } -void Heap::Delete(HeapPtr me) noexcept { HcFreeProcessHeap(kInstanceObject, me); } +void Heap::Delete(HeapPtr me) noexcept { + CA_MUST_PASS(me); + HcFreeProcessHeap(kInstanceObject, me); +} SizeT Heap::Size(HeapPtr me) noexcept { CA_MUST_PASS(me); diff --git a/Public/Kits/System.Core/HintBase.hxx b/Public/Kits/System.Core/HintBase.hxx new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/Kits/System.Core/HintBase.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/Makefile b/Public/Kits/System.Core/Makefile index f358dfa5..286c1120 100644 --- a/Public/Kits/System.Core/Makefile +++ b/Public/Kits/System.Core/Makefile @@ -4,7 +4,7 @@ ################################################## CC=x86_64-w64-mingw32-g++ -CCFLAGS=-shared -ffreestanding -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17 +CCFLAGS=-shared -ffreestanding -nostdlib -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17 OUTPUT=System.Core.dll .PHONY: build-core diff --git a/Public/Kits/System.Core/New+Delete.cxx b/Public/Kits/System.Core/New+Delete.cxx new file mode 100644 index 00000000..cac883f4 --- /dev/null +++ b/Public/Kits/System.Core/New+Delete.cxx @@ -0,0 +1,50 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#include + +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); +} + diff --git a/Public/Kits/System.Core/System.hxx b/Public/Kits/System.Core/System.hxx index 37cab4a4..05028d87 100644 --- a/Public/Kits/System.Core/System.hxx +++ b/Public/Kits/System.Core/System.hxx @@ -13,6 +13,6 @@ #include #include #include -#include +#include using namespace HCore; diff --git a/Public/Kits/System.Core/ThreadAPI.hxx b/Public/Kits/System.Core/ThreadAPI.hxx deleted file mode 100644 index ec15a64c..00000000 --- a/Public/Kits/System.Core/ThreadAPI.hxx +++ /dev/null @@ -1,36 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -// -// Created by Amlal on 1/27/24. -// - -#ifndef __THREAD_API__ -#define __THREAD_API__ - -#include - -namespace HCore { -/// @brief Thread Information Block for Local Storage. -/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64) -struct ThreadInformationBlock final { - const Char Name[255]; // Module Name - const UIntPtr StartAddress; // Start Address - const UIntPtr StartHeap; // Allocation Heap - const UIntPtr StartStack; // Stack Pointer. - const Int32 Arch; // Architecture and/or platform. -}; - -enum { - kPC_IA64, - kPC_AMD64 = kPC_IA64, - kPC_ARM, - kMACS_64x0, - kMACS_32x0, -}; -} // namespace HCore - -#endif // __THREAD_API__ diff --git a/Public/Kits/System.Core/Threading.hxx b/Public/Kits/System.Core/Threading.hxx new file mode 100644 index 00000000..5d5ed0a6 --- /dev/null +++ b/Public/Kits/System.Core/Threading.hxx @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD_API__ +#define __THREAD_API__ + +#include + +/// @brief Thread Information Block variant for scheduling. +struct ThreadInformationBlock final { + const CHAR Name[255]; // Module Name + 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. +}; + +ThreadInformationBlock* HcCreateThread(_Input PVOID Start, + _Optional _InOut PVOID HeapOpt, _Optional _InOut PVOID StackOpt); + +BOOL HcDestroyThread(_Input ThreadInformationBlock* TIB); + +BOOL HcStopThread(_Input ThreadInformationBlock* TIB); + +BOOL HcResumeThread(_Input ThreadInformationBlock* TIB); + +#endif // __THREAD_API__ -- cgit v1.2.3