diff options
| author | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-26 13:44:38 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@el-mahrouss-logic.com> | 2024-03-26 13:47:32 +0100 |
| commit | 66e4f909bd1a495d3f1c34d2e1b5cd71099ab1ae (patch) | |
| tree | d64cc867d352d190dfd5693262a42b31e28b9239 | |
| parent | dbe4573f61ae059c9dafb8e7623370121d443451 (diff) | |
Kernel and System.Core: kernel related fixes and :boom: on User API.
- UserHeap.cxx: Document code and fix issue in ke_free_heap_internal.
- Scheduler: Rename ProcessManager to ProcessScheduler.
- The System API has been reworked to improve it's design, such as no
more C++ to improve it's portability.
- Moved containers into it's own API.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
25 files changed, 146 insertions, 372 deletions
diff --git a/Private/Builtins/AHCI/Interface.hxx b/Private/Builtins/AHCI/Interface.hxx index 72be3d6a..0fef6992 100644 --- a/Private/Builtins/AHCI/Interface.hxx +++ b/Private/Builtins/AHCI/Interface.hxx @@ -24,5 +24,5 @@ namespace HCore::Builtins { /// @brief Returns an AHCI handle. /// @param pointerAhciObject the handle to pass. /// @return -inline Boolean HcGetHandleAHCI(_InOut ObjectPtr* pointerAhciObject); +inline Boolean HcGetHandleAHCI(_InOut ObjectRef* pointerAhciObject); } // namespace HCore::Builtins
\ No newline at end of file diff --git a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp index 8039ce8a..c55b9857 100644 --- a/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp +++ b/Private/HALKit/AMD64/HalCoreInterruptHandlerAMD64.cpp @@ -9,16 +9,16 @@ #include <NewKit/String.hpp> EXTERN_C void idt_handle_gpf(HCore::UIntPtr rsp) { - MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(HCore::ProcessScheduler::Shared().Leak().GetCurrent()); HCore::kcout << "NewKernel.exe: Stack Pointer: " << HCore::StringBuilder::FromInt("rsp{%}", rsp); HCore::kcout << "NewKernel.exe: General Protection Fault, caused by " - << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + << HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().GetName(); - HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } EXTERN_C void idt_handle_scheduler(HCore::UIntPtr rsp) { @@ -26,7 +26,7 @@ EXTERN_C void idt_handle_scheduler(HCore::UIntPtr rsp) { HCore::kcout << "NewKernel.exe: Will be scheduled back later " - << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName() + << HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().GetName() << HCore::end_line(); /// schedule another process. @@ -38,35 +38,35 @@ EXTERN_C void idt_handle_scheduler(HCore::UIntPtr rsp) { EXTERN_C void idt_handle_pf(HCore::UIntPtr rsp) { HCore::kcout << HCore::StringBuilder::FromInt("rsp{%}", rsp); - MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(HCore::ProcessScheduler::Shared().Leak().GetCurrent()); HCore::kcout << "NewKernel.exe: Segmentation Fault, caused by " - << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + << HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().GetName(); - HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } EXTERN_C void idt_handle_math(HCore::UIntPtr rsp) { HCore::kcout << HCore::StringBuilder::FromInt("rsp{%}", rsp); - MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(HCore::ProcessScheduler::Shared().Leak().GetCurrent()); HCore::kcout << "NewKernel.exe: Math error, caused by " - << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + << HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().GetName(); - HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } EXTERN_C void idt_handle_generic(HCore::UIntPtr rsp) { HCore::kcout << HCore::StringBuilder::FromInt("sp{%}", rsp); - MUST_PASS(HCore::ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(HCore::ProcessScheduler::Shared().Leak().GetCurrent()); HCore::kcout << "NewKernel.exe: Execution error, caused by " - << HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().GetName(); + << HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().GetName(); - HCore::ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + HCore::ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } diff --git a/Private/KernelKit/ProcessScheduler.hpp b/Private/KernelKit/ProcessScheduler.hpp index bc974a9b..4f499033 100644 --- a/Private/KernelKit/ProcessScheduler.hpp +++ b/Private/KernelKit/ProcessScheduler.hpp @@ -26,7 +26,7 @@ namespace HCore { class ProcessHeader; class ProcessTeam; -class ProcessManager; +class ProcessScheduler; //! @brief ProcessHeader identifier. typedef Int64 ProcessID; @@ -36,7 +36,7 @@ inline constexpr SizeT kProcessLen = 256U; //! @brief Forward declaration. class ProcessHeader; -class ProcessManager; +class ProcessScheduler; class ProcessHelper; //! @brief ProcessHeader status enum. @@ -181,7 +181,7 @@ class ProcessHeader final { const AffinityKind &GetAffinity(); private: - friend ProcessManager; + friend ProcessScheduler; friend ProcessHelper; }; @@ -206,14 +206,14 @@ using ProcessPtr = ProcessHeader *; /// @brief ProcessHeader manager class. /// The main class which you call to schedule an app. -class ProcessManager final { +class ProcessScheduler final { private: - explicit ProcessManager() = default; + explicit ProcessScheduler() = default; public: - ~ProcessManager() = default; + ~ProcessScheduler() = default; - HCORE_COPY_DEFAULT(ProcessManager) + HCORE_COPY_DEFAULT(ProcessScheduler) operator bool() { return mTeam.AsArray().Count() > 0; } bool operator!() { return mTeam.AsArray().Count() == 0; } @@ -226,7 +226,7 @@ class ProcessManager final { Ref<ProcessHeader> &GetCurrent(); SizeT Run() noexcept; - static Ref<ProcessManager> Shared(); + static Ref<ProcessScheduler> Shared(); private: ProcessTeam mTeam; diff --git a/Private/KernelKit/ThreadLocalStorage.inl b/Private/KernelKit/ThreadLocalStorage.inl index 4a8a816a..fe2d02d0 100644 --- a/Private/KernelKit/ThreadLocalStorage.inl +++ b/Private/KernelKit/ThreadLocalStorage.inl @@ -14,9 +14,9 @@ template <typename T> inline T* tls_new_ptr(void) { using namespace HCore; - MUST_PASS(ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); - auto ref_process = ProcessManager::Shared().Leak().GetCurrent(); + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); T* pointer = (T*)ref_process.Leak().New(sizeof(T)); return pointer; @@ -29,11 +29,11 @@ inline bool tls_delete_ptr(T* ptr) { using namespace HCore; - MUST_PASS(ProcessManager::Shared().Leak().GetCurrent()); + MUST_PASS(ProcessScheduler::Shared().Leak().GetCurrent()); ptr->~T(); - auto ref_process = ProcessManager::Shared().Leak().GetCurrent(); + auto ref_process = ProcessScheduler::Shared().Leak().GetCurrent(); return ref_process.Leak().Delete(ptr, sizeof(T)); } diff --git a/Private/NewBoot/Source/makefile b/Private/NewBoot/Source/makefile index 0bded801..35c473ec 100644 --- a/Private/NewBoot/Source/makefile +++ b/Private/NewBoot/Source/makefile @@ -1,5 +1,5 @@ ################################################## -# (C) Mahrouss Logic, 2024, all rights reserved. +# (C) Mahrouss Logic, all rights reserved. # This is the bootloader makefile. ################################################## diff --git a/Private/ObjectKit/ObjectKit.hxx b/Private/ObjectKit/ObjectKit.hxx index 744f8a61..0a388156 100644 --- a/Private/ObjectKit/ObjectKit.hxx +++ b/Private/ObjectKit/ObjectKit.hxx @@ -31,6 +31,6 @@ typedef struct Object final { HCore::Void(*Release)(struct Object* Self); HCore::IntPtr(*Invoke)(struct Object* Self, HCore::Int32 Sel, ...); HCore::Void(*Query)(struct Object* Self, HCore::VoidPtr* Dst, HCore::SizeT SzDst, HCore::XRN::GUIDSequence GuidOf); -} Object, *ObjectPtr; +} *ObjectRef; -#define object_cast reinterpret_cast<ObjectPtr> +#define object_cast reinterpret_cast<ObjectRef> diff --git a/Private/Source/IndexableProperty.cxx b/Private/Source/IndexableProperty.cxx index 4341038c..3d5152bf 100644 --- a/Private/Source/IndexableProperty.cxx +++ b/Private/Source/IndexableProperty.cxx @@ -11,6 +11,7 @@ #include <NewKit/MutableArray.hpp> #include <NewKit/Utils.hpp> +/// @brief File Indexer. /// BUGS: 0 #define kMaxLenIndexer 256 diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index ec8756d1..fc12d7a4 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -144,7 +144,7 @@ bool execute_from_image(PEFLoader &exec) noexcept { ProcessHeader proc(errOrStart.Leak().Leak()); Ref<ProcessHeader> refProc = proc; - return ProcessManager::Shared().Leak().Add(refProc); + return ProcessScheduler::Shared().Leak().Add(refProc); } } // namespace Utils diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx index 06c5813c..dc75e8b6 100644 --- a/Private/Source/PEFSharedObjectRT.cxx +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -39,7 +39,7 @@ EXTERN_C SharedObjectPtr rt_library_init(void) { SharedObjectPtr library = tls_new_class<SharedObject>(); if (!library) { - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); return nullptr; } @@ -47,16 +47,16 @@ EXTERN_C SharedObjectPtr rt_library_init(void) { library->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); if (!library->Get()) { - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); return nullptr; } library->Get()->fImageObject = - ProcessManager::Shared().Leak().GetCurrent().Leak().Image; + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Image; if (!library->Get()->fImageObject) { - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); return nullptr; } @@ -79,7 +79,7 @@ EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool *successful) { // sanity check (will also trigger a bug check) if (lib == nullptr) { *successful = false; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } delete lib->Get(); diff --git a/Private/Source/ProcessScheduler.cxx b/Private/Source/ProcessScheduler.cxx index a2c47225..ebcf82c0 100644 --- a/Private/Source/ProcessScheduler.cxx +++ b/Private/Source/ProcessScheduler.cxx @@ -5,7 +5,7 @@ ------------------------------------------- */ /***********************************************************************************/ -/// @file ProcessManager.cxx +/// @file ProcessScheduler.cxx /// @brief ProcessHeader Scheduler API. /***********************************************************************************/ @@ -32,7 +32,7 @@ const Int32 &rt_get_exit_code() noexcept { return kExitCode; } /***********************************************************************************/ void ProcessHeader::Crash() { - kcout << "ProcessManager: Crashed, ExitCode: -1.\r\n"; + kcout << "ProcessScheduler: Crashed, ExitCode: -1.\r\n"; MUST_PASS(!ke_bug_check()); this->Exit(-1); @@ -115,11 +115,11 @@ const AffinityKind &ProcessHeader::GetAffinity() { return this->Affinity; } */ void ProcessHeader::Exit(Int32 exit_code) { if (this->ProcessId != - ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId) + ProcessScheduler::Shared().Leak().GetCurrent().Leak().ProcessId) ke_stop(RUNTIME_CHECK_PROCESS); if (this->Ring == (Int32)ProcessSelector::kRingKernel && - ProcessManager::Shared().Leak().GetCurrent().Leak().Ring > 0) + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Ring > 0) ke_stop(RUNTIME_CHECK_PROCESS); kExitCode = exit_code; @@ -141,15 +141,15 @@ void ProcessHeader::Exit(Int32 exit_code) { this->Image = nullptr; this->StackFrame = nullptr; - ProcessManager::Shared().Leak().Remove(this->ProcessId); + ProcessScheduler::Shared().Leak().Remove(this->ProcessId); } -SizeT ProcessManager::Add(Ref<ProcessHeader> &process) { +SizeT ProcessScheduler::Add(Ref<ProcessHeader> &process) { if (!process) return -1; if (process.Leak().Ring != (Int32)ProcessSelector::kRingKernel) return -1; - kcout << "ProcessManager::Add(Ref<ProcessHeader>& process)\r\n"; + kcout << "ProcessScheduler::Add(Ref<ProcessHeader>& process)\r\n"; process.Leak().HeapPtr = rt_new_heap(kUserHeapUser | kUserHeapRw); process.Leak().ProcessId = mTeam.AsArray().Count(); @@ -180,15 +180,15 @@ SizeT ProcessManager::Add(Ref<ProcessHeader> &process) { return mTeam.AsArray().Count() - 1; } -bool ProcessManager::Remove(SizeT process) { +bool ProcessScheduler::Remove(SizeT process) { if (process > mTeam.AsArray().Count()) return false; - kcout << "ProcessManager::Remove(SizeT process)\r\n"; + kcout << "ProcessScheduler::Remove(SizeT process)\r\n"; return mTeam.AsArray().Remove(process); } -SizeT ProcessManager::Run() noexcept { +SizeT ProcessScheduler::Run() noexcept { SizeT processIndex = 0; //! we store this guy to tell the scheduler how many //! things we have scheduled. @@ -219,16 +219,16 @@ SizeT ProcessManager::Run() noexcept { return processIndex; } -Ref<ProcessManager> ProcessManager::Shared() { - static ProcessManager ref; +Ref<ProcessScheduler> ProcessScheduler::Shared() { + static ProcessScheduler ref; return {ref}; } -Ref<ProcessHeader> &ProcessManager::GetCurrent() { return mTeam.AsRef(); } +Ref<ProcessHeader> &ProcessScheduler::GetCurrent() { return mTeam.AsRef(); } PID &ProcessHelper::GetCurrentPID() { kcout << "ProcessHelper::GetCurrentPID: Leaking ProcessId...\r\n"; - return ProcessManager::Shared().Leak().GetCurrent().Leak().ProcessId; + return ProcessScheduler::Shared().Leak().GetCurrent().Leak().ProcessId; } bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader> &process) { @@ -255,12 +255,12 @@ bool ProcessHelper::CanBeScheduled(Ref<ProcessHeader> &process) { */ bool ProcessHelper::StartScheduling() { if (ProcessHelper::CanBeScheduled( - ProcessManager::Shared().Leak().GetCurrent())) { - --ProcessManager::Shared().Leak().GetCurrent().Leak().PTime; + ProcessScheduler::Shared().Leak().GetCurrent())) { + --ProcessScheduler::Shared().Leak().GetCurrent().Leak().PTime; return false; } - auto processRef = ProcessManager::Shared().Leak(); + auto processRef = ProcessScheduler::Shared().Leak(); if (!processRef) return false; // we have nothing to schedule. simply return. diff --git a/Private/Source/ThreadLocalStorage.cxx b/Private/Source/ThreadLocalStorage.cxx index 45a52e46..c75c1c5a 100644 --- a/Private/Source/ThreadLocalStorage.cxx +++ b/Private/Source/ThreadLocalStorage.cxx @@ -47,7 +47,7 @@ EXTERN_C Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcep if (!tls_check_tib(tib)) { kcout << "NewKernel.exe: Verification failed, Crashing...\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); } kcout << "NewKernel.exe: Verification succeeded! Keeping on...\n"; diff --git a/Private/Source/Timer.cxx b/Private/Source/Timer.cxx index ecca679a..af9aea25 100644 --- a/Private/Source/Timer.cxx +++ b/Private/Source/Timer.cxx @@ -10,8 +10,11 @@ using namespace HCore; +/// @brief Unimplemented as it is an interface. Int32 HardwareTimerInterface::Wait() noexcept { return H_UNIMPLEMENTED; } +/// @brief HardwareTimer class, meant to be generic. + HardwareTimer::HardwareTimer(Int64 seconds) : fWaitFor(seconds) {} HardwareTimer::~HardwareTimer() { fWaitFor = 0; } diff --git a/Private/Source/UserHeap.cxx b/Private/Source/UserHeap.cxx index 45b29d51..4b172d11 100644 --- a/Private/Source/UserHeap.cxx +++ b/Private/Source/UserHeap.cxx @@ -6,6 +6,7 @@ #include <NewKit/PageManager.hpp> #include <KernelKit/UserHeap.hpp> +#include <KernelKit/ProcessScheduler.hpp> #define kHeapHeaderPaddingSz 16 @@ -60,6 +61,9 @@ STATIC Void ke_free_heap_internal(VoidPtr vaddr); STATIC VoidPtr ke_make_heap(VoidPtr vaddr, Int flags); STATIC Boolean ke_check_and_free_heap(const SizeT& index, VoidPtr ptr); +/// @brief Find an unused heap header to allocate on. +/// @param flags the flags to use. +/// @return STATIC VoidPtr ke_find_unused_heap(Int flags) { for (SizeT index = 0; index < kUserHeapMaxSz; ++index) { if (HeapManager::The()[index] && @@ -80,6 +84,10 @@ STATIC VoidPtr ke_find_unused_heap(Int flags) { return nullptr; } +/// @brief Makes a new heap for the process to use. +/// @param virtualAddress the virtual address of the process. +/// @param flags the flags. +/// @return STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) { if (virtualAddress) { UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>(virtualAddress); @@ -102,14 +110,21 @@ STATIC VoidPtr ke_make_heap(VoidPtr virtualAddress, Int flags) { return nullptr; } +/// @brief Internally makrs the heap as free. +/// This is done by setting the fFree bit to true +/// @param virtualAddress +/// @return STATIC Void ke_free_heap_internal(VoidPtr virtualAddress) { UserHeapHeader* poolHdr = reinterpret_cast<UserHeapHeader*>( reinterpret_cast<UIntPtr>(virtualAddress) - sizeof(UserHeapHeader)); if (poolHdr->fMagic == kUserHeapMag) { - MUST_PASS(poolHdr->fFree); + if (!poolHdr->fFree) { + ProcessScheduler::Shared().Leak().GetCurrent().Leak().Crash(); + return; + } - poolHdr->fFree = false; + poolHdr->fFree = true; poolHdr->fFlags = 0; kcout << "[ke_free_heap_internal] Successfully marked header as free!\r\n"; diff --git a/Private/makefile b/Private/makefile index b7e99049..bf068f14 100644 --- a/Private/makefile +++ b/Private/makefile @@ -1,5 +1,5 @@ ################################################## -# (C) Mahrouss Logic, 2024, all rights reserved. +# (C) Mahrouss Logic, all rights reserved. # This is the microkernel makefile. ################################################## @@ -25,10 +25,9 @@ error: MOVEALL=./MoveAll.sh -.PHONY: h-core-amd64-pc -h-core-amd64-pc: clean - $(CC) $(CCFLAGS) $(DEBUG) Source/*.cxx HALKit/AMD64/Storage/*.cxx HALKit/AMD64/PCI/*.cxx Source/Network/*.cxx\ - Source/Storage/*.cxx HALKit/AMD64/*.cxx HALKit/AMD64/*.cpp HALKit/AMD64/*.s +.PHONY: h-core-amd64-epm +h-core-amd64-epm: clean + $(CC) $(CCFLAGS) $(DEBUG) $(wildcard Source/*.cxx HALKit/AMD64/Storage/*.cxx) $(wildcard HALKit/AMD64/PCI/*.cxx) $(wildcard Source/Network/*.cxx) $(wildcard Source/Storage/*.cxx) $(wildcard HALKit/AMD64/*.cxx) $(wildcard HALKit/AMD64/*.cpp) $(wildcard HALKit/AMD64/*.s) $(ASM) $(ASMFLAGS) HALKit/AMD64/HalInterruptAPI.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalSMPCoreManager.asm $(ASM) $(ASMFLAGS) HALKit/AMD64/HalNewBoot.asm @@ -37,13 +36,13 @@ h-core-amd64-pc: clean OBJCOPY=x86_64-w64-mingw32-objcopy -.PHONY: link-amd64-pc -link-amd64-pc: +.PHONY: link-amd64-epm +link-amd64-epm: $(LD) $(LDFLAGS) $(LDOBJ) -o $(KERNEL) cp $(KERNEL) Root/Boot .PHONY: all -all: h-core-amd64-pc link-amd64-pc +all: h-core-amd64-epm link-amd64-epm @echo "Fully built." diff --git a/Public/Developer/System.Core/Headers/Containers/ODF.hxx b/Public/Developer/System.Containers/Headers/ODF.hxx index 266726bf..266726bf 100644 --- a/Public/Developer/System.Core/Headers/Containers/ODF.hxx +++ b/Public/Developer/System.Containers/Headers/ODF.hxx diff --git a/Public/Developer/System.Core/Headers/Containers/XIFF.hxx b/Public/Developer/System.Containers/Headers/XIFF.hxx index 4c97e2a3..4c97e2a3 100644 --- a/Public/Developer/System.Core/Headers/Containers/XIFF.hxx +++ b/Public/Developer/System.Containers/Headers/XIFF.hxx diff --git a/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s b/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s index a61d6d1f..3876175b 100644 --- a/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s +++ b/Public/Developer/System.Core/AMD64/HCoreAssemblyRoutines.s @@ -4,12 +4,12 @@ .section .text -.globl HcGetInstanceObject +.globl HcGetAppObject .globl __assert_chk_fail /* @brief Process object getter */ /* @throws: ApptError: appartement error. */ -HcGetInstanceObject: +HcGetAppObject: mov $0x10, %rcx /* sysGetProcessObject */ int $0x21 diff --git a/Public/Developer/System.Core/Headers/Defines.hxx b/Public/Developer/System.Core/Headers/Defines.hxx index 867dac76..9d6d84ee 100644 --- a/Public/Developer/System.Core/Headers/Defines.hxx +++ b/Public/Developer/System.Core/Headers/Defines.hxx @@ -136,77 +136,6 @@ enum HcProcessCall { #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\\" @@ -241,10 +170,15 @@ typedef struct Object final { 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; +} *ObjectRef; + +#define object_cast reinterpret_cast<ObjectRef> + +CA_EXTERN_C ObjectRef HcGetAppObject(VoidType); -#define object_cast reinterpret_cast<ObjectPtr> +CA_INLINE ObjectRef kApplicationObject; -CA_EXTERN_C ObjectPtr HcGetInstanceObject(void); +typedef CharacterTypeUTF8 Str255Type[255]; -CA_INLINE ObjectPtr kApplicationObject; +template <SizeType N> +using StrType = CharacterTypeUTF8[N]; diff --git a/Public/Developer/System.Core/Headers/File.hxx b/Public/Developer/System.Core/Headers/File.hxx deleted file mode 100644 index 3d3abf13..00000000 --- a/Public/Developer/System.Core/Headers/File.hxx +++ /dev/null @@ -1,120 +0,0 @@ -/* ------------------------------------------- - - Copyright Mahrouss Logic - -------------------------------------------- */ - -#ifndef __FILE_API__ -#define __FILE_API__ - -#include <System.Core/Headers/Defines.hxx> - -#define kFileOpenInterface 10 -#define kFileAliasInterface 11 - -namespace System { -class FileInterface; -class DirectoryInterface; - -typedef IntPtrType FSRef; - -enum { - kErrorNoSuchPath = -44, - kErrorNotAFile = -45, - kErrorNotADirectory = -46, - kErrorDirectory = -47, - kErrorBrokenSymlink = -48, -}; - -/// @brief System file interface - -class FileInterface final { - public: - explicit FileInterface(const char *path) { - CA_MUST_PASS(path); - - mHandle = kApplicationObject->Invoke( - kApplicationObject, kProcessCallOpenHandle, kFileOpenInterface, path); - } - - ~FileInterface() { - CA_MUST_PASS(kApplicationObject); - - kApplicationObject->Invoke(kApplicationObject, kProcessCallCloseHandle, - kFileOpenInterface, mHandle); - } - - public: - CA_COPY_DEFAULT(FileInterface); - - public: - PtrVoidType ReadFork(const CharacterTypeUTF8* name, UIntPtrType off, SizeType sz) { - return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, - 2, name, off, sz); - } - - PtrVoidType ReadFork(const CharacterTypeUTF8* name, SizeType sz) { - return (PtrVoidType)kApplicationObject->Invoke(kApplicationObject, mHandle, - name, 3, sz); - } - - void WriteFork(const CharacterTypeUTF8* name, PtrVoidType buf, UIntPtrType off, SizeType sz) { - kApplicationObject->Invoke(kApplicationObject, mHandle, 4, name, buf, off, sz); - } - - void WriteFork(const CharacterTypeUTF8* name, PtrVoidType buf, SizeType sz) { - kApplicationObject->Invoke(kApplicationObject, mHandle, 5, name, buf, sz); - } - - void SeekFork(const CharacterTypeUTF8* name) { - kApplicationObject->Invoke(kApplicationObject, mHandle, 6, name); - } - - void RewindFork() { kApplicationObject->Invoke(kApplicationObject, mHandle, 7); } - - public: - const CharacterTypeUTF8 *MIME() { - return (const char *)kApplicationObject->Invoke(kApplicationObject, mHandle, - 8); - } - - void MIME(const CharacterTypeUTF8 *mime) { - CA_MUST_PASS(mime); - - kApplicationObject->Invoke(kApplicationObject, mHandle, 9, mime); - } - - private: - FSRef 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!"}; -}; - -inline IntPtrType FSMakeAlias(const char *from, const char *outputWhere) { - CA_MUST_PASS(from); - CA_MUST_PASS(outputWhere); - - return kApplicationObject->Invoke(kApplicationObject, kProcessCallOpenHandle, - kFileAliasInterface, from); -} -} // namespace System - -#endif // ifndef __FILE_API__ diff --git a/Public/Developer/System.Core/Headers/Heap.hxx b/Public/Developer/System.Core/Headers/Heap.hxx index 8fea34d4..98ee5bd2 100644 --- a/Public/Developer/System.Core/Headers/Heap.hxx +++ b/Public/Developer/System.Core/Headers/Heap.hxx @@ -8,57 +8,25 @@ #include <System.Core/Headers/Defines.hxx> -namespace System { -class HeapException; -class HeapInterface; +#define kAllocationTypes 2 -typedef PtrVoidType HeapRef; - -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(HeapRef me) noexcept; - SizeType Size(HeapRef me) noexcept; - HeapRef 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!"}; +enum HcAllocationKind { + kStandardAllocation = 0xC, + kArrayAllocation = 0xD, }; -} // namespace System +/// @brief Allocates a new heap from process pool. +/// @param refObj +/// @param sz +/// @param flags +/// @return +CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectRef refObj, QWordType sz, + DWordType flags); + +/// @brief Check if pointer exists. +/// @param refObj +/// @param ptr +/// @return +CA_EXTERN_C BooleanType HcProcessHeapExists(ObjectRef refObj, PtrVoidType ptr); +CA_EXTERN_C QWordType HcProcessHeapSize(ObjectRef refObj, PtrVoidType ptr); +CA_EXTERN_C VoidType HcFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr); diff --git a/Public/Developer/System.Core/Headers/Window/Window.hxx b/Public/Developer/System.Core/Headers/Window/Window.hxx index 5eb1b3ce..4c79d50b 100644 --- a/Public/Developer/System.Core/Headers/Window/Window.hxx +++ b/Public/Developer/System.Core/Headers/Window/Window.hxx @@ -77,11 +77,23 @@ CA_EXTERN_C ControlRef CreateControl(const DWordType id); /// @return CA_EXTERN_C VoidType ReleaseControl(const ControlRef id); -CA_EXTERN_C BooleanType MoveControl(const ControlRef id, GraphicsPoint where); +/// @brief Moves a control inside a GraphicsPort. +/// @param id the control ref. +/// @param where where to move at. +/// @return +CA_EXTERN_C Int32Type SetControlPosition(const ControlRef id, GraphicsPoint where); -CA_EXTERN_C BooleanType EnableControl(const ControlRef id, BooleanType visible); +/// @brief Enable control. +/// @param id +/// @param enabled +/// @return +CA_EXTERN_C Int32Type SetControlEnabled(const ControlRef id, BooleanType enabled); -CA_EXTERN_C BooleanType VisibleControl(const ControlRef id, BooleanType visible); +/// @brief Make control visible. +/// @param id +/// @param visible +/// @return +CA_EXTERN_C Int32Type MakeControlVisible(const ControlRef id, BooleanType visible); /// @brief Creates a new window. /// @param name the window name @@ -104,3 +116,16 @@ CA_EXTERN_C VoidType ReleaseWindow(GraphicsPort* port); /// @param port the menu port. /// @return void CA_EXTERN_C VoidType ReleaseMenu(GraphicsPort* port); + +/// @brief Moves a window on the desktop. (menu arent movable, will return kErrIncompatible is menu is provided.) +/// @param id the gfx port. +/// @param where to move. +/// @return error code. +CA_EXTERN_C Int32Type MoveWindow(const GraphicsPort* id, GraphicsPoint where); + +enum { + kWinErrIncompatible = 0x74, + kWinErrOutOfMemory, + kWinErrInvalidArg, + kWinErrNotImplemented, +}; diff --git a/Public/Developer/System.Core/Makefile b/Public/Developer/System.Core/Makefile index 28ce0bea..c4a97c30 100644 --- a/Public/Developer/System.Core/Makefile +++ b/Public/Developer/System.Core/Makefile @@ -1,5 +1,5 @@ ################################################## -# (C) Mahrouss Logic, 2024, all rights reserved. +# (C) Mahrouss Logic, all rights reserved. # This is the System.Graphics Makefile. ################################################## diff --git a/Public/Developer/System.Core/Sources/LibEntrypoint.cxx b/Public/Developer/System.Core/Sources/CRT0.cxx index b874ef55..a0235e68 100644 --- a/Public/Developer/System.Core/Sources/LibEntrypoint.cxx +++ b/Public/Developer/System.Core/Sources/CRT0.cxx @@ -6,8 +6,8 @@ /// @brief Inits the DLL. /// @return if it was succesful or not. -DWordType __DllMain(VoidType) { - kApplicationObject = HcGetInstanceObject(); +CA_EXTERN_C DWordType __DllMain(VoidType) { + kApplicationObject = HcGetAppObject(); CA_MUST_PASS(kApplicationObject); return 0; diff --git a/Public/Developer/System.Core/Sources/Heap.cxx b/Public/Developer/System.Core/Sources/Heap.cxx index 370693cc..fcd80a7f 100644 --- a/Public/Developer/System.Core/Sources/Heap.cxx +++ b/Public/Developer/System.Core/Sources/Heap.cxx @@ -11,7 +11,7 @@ /// @param sz size of object. /// @param flags flags. /// @return -CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectPtr refObj, QWordType sz, +CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectRef refObj, QWordType sz, DWordType flags) { CA_MUST_PASS(sz); CA_MUST_PASS(flags); @@ -22,7 +22,7 @@ CA_EXTERN_C PtrVoidType HcAllocateProcessHeap(ObjectPtr refObj, QWordType sz, /// @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_EXTERN_C VoidType HcFreeProcessHeap(ObjectRef refObj, PtrVoidType ptr) { CA_MUST_PASS(ptr); CA_UNREFERENCED_PARAMETER(refObj->Invoke(refObj, kProcessCallFreePtr, ptr)); } @@ -31,7 +31,7 @@ CA_EXTERN_C VoidType HcFreeProcessHeap(ObjectPtr refObj, PtrVoidType ptr) { /// @param refObj Process object. /// @param ptr the pointer to find. /// @return the size. -CA_EXTERN_C QWordType HcProcessHeapSize(ObjectPtr refObj, PtrVoidType ptr) { +CA_EXTERN_C QWordType HcProcessHeapSize(ObjectRef refObj, PtrVoidType ptr) { CA_MUST_PASS(ptr); return refObj->Invoke(refObj, kProcessCallSizePtr, ptr); } @@ -40,44 +40,7 @@ CA_EXTERN_C QWordType HcProcessHeapSize(ObjectPtr refObj, PtrVoidType ptr) { /// @param refObj Process object. /// @param ptr the pointer to check. /// @return if it exists -CA_EXTERN_C BooleanType HcProcessHeapExists(ObjectPtr refObj, PtrVoidType ptr) { +CA_EXTERN_C BooleanType HcProcessHeapExists(ObjectRef 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(kApplicationObject, (PtrVoidType)this)); -} - -HeapInterface::~HeapInterface() { delete this; } - -void HeapInterface::Delete(HeapRef me) noexcept { - CA_MUST_PASS(me); - HcFreeProcessHeap(kApplicationObject, me); -} - -SizeType HeapInterface::Size(HeapRef me) noexcept { - CA_MUST_PASS(me); - return HcProcessHeapSize(kApplicationObject, me); -} - -HeapRef HeapInterface::New(const SizeType& sz, const DWordType flags) { - SizeType _sz = sz; - if (!_sz) ++_sz; - - return HcAllocateProcessHeap(kApplicationObject, _sz, flags); -} diff --git a/Public/Developer/System.Core/Sources/New+Delete.cxx b/Public/Developer/System.Core/Sources/New+Delete.cxx index 98674a73..6e40aa06 100644 --- a/Public/Developer/System.Core/Sources/New+Delete.cxx +++ b/Public/Developer/System.Core/Sources/New+Delete.cxx @@ -5,20 +5,6 @@ ------------------------------------------- */ #include <System.Core/Headers/Heap.hxx> -#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; |
