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 | |
| 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')
| -rw-r--r-- | Public/SDK/System.Core/.gitkeep | 0 | ||||
| -rw-r--r-- | Public/SDK/System.Core/AMD64/HCoreAssemblyRoutines.s | 24 | ||||
| -rw-r--r-- | Public/SDK/System.Core/ARM64/.gitkeep | 0 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Containers/ODF.hxx | 43 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Containers/XIFF.hxx | 42 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Defs.hxx | 248 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/File.hxx | 70 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Heap.hxx | 63 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Hint.hxx | 18 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Headers/Thread.hxx | 49 | ||||
| -rw-r--r-- | Public/SDK/System.Core/Makefile | 20 | ||||
| -rw-r--r-- | Public/SDK/System.Core/RISCV/.gitkeep | 0 | ||||
| -rw-r--r-- | Public/SDK/System.Core/ReadMe.md | 10 | ||||
| -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 | ||||
| -rw-r--r-- | Public/SDK/System.Core/compile_flags.txt | 4 |
17 files changed, 753 insertions, 0 deletions
diff --git a/Public/SDK/System.Core/.gitkeep b/Public/SDK/System.Core/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Public/SDK/System.Core/.gitkeep diff --git a/Public/SDK/System.Core/AMD64/HCoreAssemblyRoutines.s b/Public/SDK/System.Core/AMD64/HCoreAssemblyRoutines.s new file mode 100644 index 00000000..a61d6d1f --- /dev/null +++ b/Public/SDK/System.Core/AMD64/HCoreAssemblyRoutines.s @@ -0,0 +1,24 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +.section .text + +.globl HcGetInstanceObject +.globl __assert_chk_fail + +/* @brief Process object getter */ +/* @throws: ApptError: appartement error. */ +HcGetInstanceObject: + mov $0x10, %rcx /* sysGetProcessObject */ + int $0x21 + + /* rax gets saved and returned. */ + ret + +__assert_chk_fail: + mov $0x11, %rcx /* sysTerminateCurrentProcess */ + int $0x21 + + ret + diff --git a/Public/SDK/System.Core/ARM64/.gitkeep b/Public/SDK/System.Core/ARM64/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Public/SDK/System.Core/ARM64/.gitkeep diff --git a/Public/SDK/System.Core/Headers/Containers/ODF.hxx b/Public/SDK/System.Core/Headers/Containers/ODF.hxx new file mode 100644 index 00000000..53098c3f --- /dev/null +++ b/Public/SDK/System.Core/Headers/Containers/ODF.hxx @@ -0,0 +1,43 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#ifndef __ODF__ +#define __ODF__ + +#include <System.Core/Headers/Defs.hxx> + +/** + * @brief Open Document Format + * @file ODF.hxx +*/ + +/// @brief four-character code for ODF. +#define kFourCCLength_ODF 4 + +/// @brief Document file header. +typedef struct ODFFileHeader +{ + CharacterType f_Ident[kFourCCLength_ODF]; + + Int32Type f_DocumentKind; + Int32Type f_DocumentSize; + + Int64Type f_MetaForkOffset; + Int64Type f_DocumentForkOffset; + + CharacterType f_Padding[4]; +} PACKED ODFFileHeader; + +/// @brief ODF Fork header +typedef struct ODFForkHeader +{ + CharacterType f_MetadataName[255]; + + Int32Type f_MetadataKind; + Int32Type f_MetadataSize; + + CharacterType f_Padding; +} PACKED ODFForkHeader; + +#endif // !__ODF__
\ No newline at end of file diff --git a/Public/SDK/System.Core/Headers/Containers/XIFF.hxx b/Public/SDK/System.Core/Headers/Containers/XIFF.hxx new file mode 100644 index 00000000..e14868a6 --- /dev/null +++ b/Public/SDK/System.Core/Headers/Containers/XIFF.hxx @@ -0,0 +1,42 @@ +/** =========================================== + (C) Mahrouss Logic + ===========================================*/ + +#ifndef __XIFF__ +#define __XIFF__ + +/** --------------------------------------------------- + + * THIS FILE CONTAINS CODE FOR THE eXtended Information File Format. + * XIFF is used to make setup programs/audio/video files. + +------------------------------------------------------- */ + +#include <System.Core/Headers/Defs.hxx> + +/// @brief four-character code for XIFF. +#define kFourCCLength_XIFF 4 + +#define kXIFFContainerVideo "XVFF" +#define kXIFFContainerAudio "XAFF" +#define kXIFFContainerInstaller "XNFF" +#define kXIFFContainerGeneric "XIFF" +#define kXIFFContainerBinary "XBFF" + +/*** + * @brief Generic XIFF header + * Used by XIFF based containers. + */ + +struct PACKED XiffHeader final { + ByteType f_Magic[kFourCCLength_XIFF]; // XIFF string (includes \0) + DWordType f_Size; // overall size of header (XiffHeader) in bytes + DWordType f_FormatType; // format type. generic + ByteType f_SpecificMag[kFourCCLength_XIFF]; // The sub header magic + DWordType f_SpecificSize; // length of the format data + DWordType f_SpecificFormatType; // format type. generic +}; + +typedef struct XiffHeader XiffHeader; + +#endif // ifndef __XIFF__ diff --git a/Public/SDK/System.Core/Headers/Defs.hxx b/Public/SDK/System.Core/Headers/Defs.hxx new file mode 100644 index 00000000..367849da --- /dev/null +++ b/Public/SDK/System.Core/Headers/Defs.hxx @@ -0,0 +1,248 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#ifndef __cplusplus +#error This API is meant to be used with C++. +#endif + +#ifdef CA_MUST_PASS +#undef CA_MUST_PASS +#endif + +#ifdef _DEBUG +#define CA_MUST_PASS(e) { if (!e) { __assert_chk_fail() } } +#else +#define CA_MUST_PASS(e) CA_UNREFERENCED_PARAMETER(e) +#endif + +#ifdef __cplusplus + +#define CA_EXTERN_C extern "C" + +#else + +#define CA_EXTERN_C extern + +#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)) + +#define CA_PASCAL CA_STDCALL + +typedef __UINT8_TYPE__ ByteType; +typedef __UINT16_TYPE__ WordType; +typedef __UINT32_TYPE__ DWordType; +typedef __UINT64_TYPE__ QWordType; +typedef __SIZE_TYPE__ SizeType; + +typedef char CharacterType; +typedef CharacterType* PtrCharacterType; + +typedef void* PtrVoidType; +typedef void VoidType; + +typedef __UINTPTR_TYPE__ UIntPtrType; +typedef __INTPTR_TYPE__ IntPtrType; +typedef __UINT64_TYPE__ UInt64Type; +typedef __INT64_TYPE__ Int64Type; +typedef __UINT32_TYPE__ UInt32Type; +typedef __INT32_TYPE__ Int32Type; + +typedef CharacterType BooleanType; + +#define CA_COPY_DELETE(KLASS) \ + KLASS &operator=(const KLASS &) = delete; \ + KLASS(const KLASS &) = delete; + + +#define CA_COPY_DEFAULT(KLASS) \ + KLASS &operator=(const KLASS &) = default; \ + KLASS(const KLASS &) = default; + + +#define CA_MOVE_DELETE(KLASS) \ + KLASS &operator=(KLASS &&) = delete; \ + KLASS(KLASS &&) = delete; + + +#define CA_MOVE_DEFAULT(KLASS) \ + KLASS &operator=(KLASS &&) = default; \ + KLASS(KLASS &&) = default; + + +#define Yes 1 +#define No 0 + +#define CA_PTR * + +#define CA_FAR __far +#define CA_NEAR __near + +#define CA_UNREFERENCED_PARAMETER(e) ((VoidType)e) + +#ifdef __x86_64__ +# define _M_AMD64 2 +#endif + +#ifdef __aarch64__ +# define _M_AARCH64 3 +#endif + +#ifdef __powerpc64__ +# define _M_PPC64 4 +#endif + +#ifdef __64x0__ +# define _M_64000 5 +#endif + +#ifdef __riscv__ +# define _M_RISCV 6 +#endif + +#define CA_STATIC static +#define CA_INLINE inline +#define CA_CONST const + +#ifdef __cplusplus +#define CA_CONSTEXPR constexpr +#else +#define CA_CONSTEXPR +#endif // __cplusplus + +enum HcProcessCall { + kProcessCallAllocPtr = 1, + kProcessCallFreePtr, + kProcessCallSizePtr, + kProcessCallCheckPtr, + kProcessCallAllocStack, + /// @brief Open a specific handle (can be used as sel to call methods related to it.) + kProcessCallOpenHandle, + kProcessCallCloseHandle, + /// @brief Number of process calls. + kProcessCallsCount = 7, +}; + +#include <System.Core/Headers/Hint.hxx> + +class SystemException { + public: + explicit SystemException() = default; + virtual ~SystemException() = default; + + public: + CA_COPY_DEFAULT(SystemException); + + public: + virtual const char *Name() = 0; + virtual const char *Reason() = 0; + +}; + +/// @brief Object exception +/// Throws when the object isn't found. +class ObjectNotFoundException : public SystemException { + public: + explicit ObjectNotFoundException() = default; + virtual ~ObjectNotFoundException() = default; + + public: + CA_COPY_DEFAULT(ObjectNotFoundException); + + public: + const char *Name() override { return "ObjectNotFoundException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{ + "System.Core: ObjectNotFoundException: Catastrophic failure!"}; +}; + +/// @brief pointer exception +/// Throws when the object isn't found. +class PointerException : public SystemException { + public: + explicit PointerException() = default; + virtual ~PointerException() = default; + + public: + CA_COPY_DEFAULT(PointerException); + + public: + const char *Name() override { return "PointerException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{ + "System.Core: PointerException: Catastrophic failure!"}; +}; + +/// @brief pointer exception +/// Throws when the object isn't found. +class NullPointerException : public SystemException { + public: + explicit NullPointerException() = default; + virtual ~NullPointerException() = default; + + public: + CA_COPY_DEFAULT(NullPointerException); + + public: + const char *Name() override { return "NullPointerException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{ + "System.Core: NullPointerException: Catastrophic failure!"}; +}; + +#define kObjectGlobalNamespaceSystem "HCORE_ROOT\\" +#define kObjectGlobalNamespaceUser "HCORE_USER_ROOT\\" + +enum { + kObjectTypeProcess, + kObjectTypeFile, + kObjectTypeDevice, + kObjectTypeNetwork, + kObjectTypeInvalid, + KObjectTypeUserDefined = 0xCF, + kObjectTypeCount = 5, +}; + +/** + * @brief GUID type, something you can also find in CFKit. + * @author AMlal El Mahrouss + */ +typedef struct GUID final { + DWordType Data1; + WordType Data2; + WordType Data3; + ByteType Data4[8]; +} GUIDType, *PtrGUIDType; + +/// \brief Object handle. +/// \author Amlal El Mahrouss +typedef struct Object final { + CharacterType ObjectName[255]; + DWordType ObjectType; + CharacterType ObjectNamespace[255]; + + VoidType(*Release)(struct Object* Self); + IntPtrType(*Invoke)(struct Object* Self, DWordType Sel, ...); + VoidType(*Query)(struct Object* Self, PtrVoidType* Dst, SizeType SzDst, struct GUID* GuidOf); +} Object, *ObjectPtr; + +#define object_cast reinterpret_cast<ObjectPtr> + +CA_EXTERN_C ObjectPtr HcGetInstanceObject(void); + +CA_INLINE ObjectPtr kInstanceObject; diff --git a/Public/SDK/System.Core/Headers/File.hxx b/Public/SDK/System.Core/Headers/File.hxx new file mode 100644 index 00000000..48331c15 --- /dev/null +++ b/Public/SDK/System.Core/Headers/File.hxx @@ -0,0 +1,70 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef __FILE_API__ +#define __FILE_API__ + +#include <System.Core/Headers/Defs.hxx> + +/// @brief SOM class, translated to C++ + +namespace System { +class FileInterface final { + public: + explicit FileInterface(const char *path) { + mHandle = kInstanceObject->Invoke(kInstanceObject, kProcessCallOpenHandle, + 0, path); + } + + ~FileInterface() { + kInstanceObject->Invoke(kInstanceObject, kProcessCallCloseHandle, 0, + mHandle); + } + + public: + CA_COPY_DEFAULT(FileInterface); + + public: + PtrVoidType Read(UIntPtrType off, SizeType sz) { return (PtrVoidType)kInstanceObject->Invoke(kInstanceObject, mHandle, 2, off, sz); } + PtrVoidType Read(SizeType sz) { return (PtrVoidType)kInstanceObject->Invoke(kInstanceObject, mHandle, 3, sz); } + + void Write(PtrVoidType buf, UIntPtrType off, SizeType sz) { kInstanceObject->Invoke(kInstanceObject, mHandle, 4, buf, off, sz); } + void Write(PtrVoidType buf, SizeType sz) { kInstanceObject->Invoke(kInstanceObject, mHandle, 5, buf, sz); } + + void Seek(UIntPtrType off) { kInstanceObject->Invoke(kInstanceObject, mHandle, 5); } + void Rewind() { kInstanceObject->Invoke(kInstanceObject, mHandle, 6); } + + public: + const char *MIME(); + void MIME(const char *mime); + + private: + IntPtrType mHandle; +}; + +typedef FileInterface *FilePtr; + +/// @brief file exception +/// Throws when the file isn't found or invalid. +class FileException : public SystemException { + public: + explicit FileException() = default; + virtual ~FileException() = default; + + public: + CA_COPY_DEFAULT(FileException); + + public: + const char *Name() override { return "FileException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{"System.Core: FileException: Catastrophic failure!"}; +}; + +} // namespace System + +#endif // ifndef __FILE_API__ diff --git a/Public/SDK/System.Core/Headers/Heap.hxx b/Public/SDK/System.Core/Headers/Heap.hxx new file mode 100644 index 00000000..43eaacab --- /dev/null +++ b/Public/SDK/System.Core/Headers/Heap.hxx @@ -0,0 +1,63 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#pragma once + +#include <System.Core/Headers/Defs.hxx> + +namespace System { +class MemoryException; + +typedef PtrVoidType HeapPtr; + +enum { + kHeapExpandable = 2, + kHeapNoExecute = 4, + kHeapShared = 6, + kHeapReadOnly = 8, + kHeapNoFlags = 0 +}; + +class HeapInterface final { + private: + explicit HeapInterface(); + + public: + ~HeapInterface(); + + public: + CA_COPY_DEFAULT(HeapInterface); + + public: + static HeapInterface *Shared() noexcept; + + public: + void Delete(HeapPtr me) noexcept; + SizeType Size(HeapPtr me) noexcept; + HeapPtr New(const SizeType &sz, + const DWordType flags = kHeapNoFlags); +}; + + +/// @brief heap exception +/// Throws when the heap pointer isn't found or invalid. +class HeapException : public SystemException { + public: + explicit HeapException() = default; + virtual ~HeapException() = default; + + public: + CA_COPY_DEFAULT(HeapException); + + public: + const char *Name() override { return "HeapException"; } + const char *Reason() override { return mReason; } + + private: + const char *mReason{"System.Core: HeapException: Catastrophic failure!"}; +}; + +} // namespace System
\ No newline at end of file diff --git a/Public/SDK/System.Core/Headers/Hint.hxx b/Public/SDK/System.Core/Headers/Hint.hxx new file mode 100644 index 00000000..86faf455 --- /dev/null +++ b/Public/SDK/System.Core/Headers/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/SDK/System.Core/Headers/Thread.hxx b/Public/SDK/System.Core/Headers/Thread.hxx new file mode 100644 index 00000000..306419b3 --- /dev/null +++ b/Public/SDK/System.Core/Headers/Thread.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +// +// Created by Amlal on 3/18/24 +// + +#ifndef __THREAD_API__ +#define __THREAD_API__ + +#include <System.Core/Headers/Defs.hxx> + +/// @brief Thread Information Block, which holds information about the running thread. +typedef PtrVoidType PtrThread; + +/// @brief Creates a new thread. +/// @param StartProc +/// @param OptionalHeap +/// @param OptionalStack +/// @param Detach +/// @param Join +/// @return +PtrThread HcCreateThread(_Input PtrVoidType StartProc, + _Optional _InOut PtrVoidType OptionalHeap, + _Optional _InOut PtrVoidType OptionalStack, + _Optional _Input BooleanType Detach, + _Optional _Input BooleanType Join); + +/// @brief Destroys the thread object. +/// @param ThreadPtr +/// @return +BooleanType HcDestroyThread(_Input PtrThread ThreadPtr); + +/// @brief Stops the thread. +/// @param ThreadPtr +/// @return +BooleanType HcStopThread(_Input PtrThread ThreadPtr); + +/// @brief Resumes it. +/// @param ThreadPtr +/// @return +BooleanType HcResumeThread(_Input PtrThread ThreadPtr); + +QWordType HcProcessIdThread(_Input PtrThread ThreadPtr); + +#endif // __THREAD_API__ diff --git a/Public/SDK/System.Core/Makefile b/Public/SDK/System.Core/Makefile new file mode 100644 index 00000000..13fdf960 --- /dev/null +++ b/Public/SDK/System.Core/Makefile @@ -0,0 +1,20 @@ +################################################## +# (C) Mahrouss Logic, 2024, all rights reserved. +# This is the System.Graphics Makefile. +################################################## + +CC=x86_64-w64-mingw32-g++ +CCFLAGS=-shared -ffreestanding -nostdlib -fno-rtti -fno-exceptions -std=c++20 -Xlinker --subsystem=17 +OUTPUT=System.Core.dll + +.PHONY: build-core-amd64 +build-core-amd64: + $(CC) -I../ -I$(HOME) -I../../../Private/ $(CCFLAGS) $(wildcard Sources/*.cxx) $(wildcard AMD64/*.s) -o $(OUTPUT) + +.PHONY: all +all: build-core + @echo "[System.Core.dll] Build done." + +.PHONY: clean +clean: + rm -f *.o diff --git a/Public/SDK/System.Core/RISCV/.gitkeep b/Public/SDK/System.Core/RISCV/.gitkeep new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/Public/SDK/System.Core/RISCV/.gitkeep diff --git a/Public/SDK/System.Core/ReadMe.md b/Public/SDK/System.Core/ReadMe.md new file mode 100644 index 00000000..92bfca25 --- /dev/null +++ b/Public/SDK/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/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); +} + diff --git a/Public/SDK/System.Core/compile_flags.txt b/Public/SDK/System.Core/compile_flags.txt new file mode 100644 index 00000000..6e721e73 --- /dev/null +++ b/Public/SDK/System.Core/compile_flags.txt @@ -0,0 +1,4 @@ +-I./ +-I../ +-I../../../Private +-std=c++20 |
