From 3ce4b68fc3f1ad9ead503bb3f69bff11b4a3183a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 7 Jan 2025 08:33:01 +0100 Subject: FIX: KAN-12 (EPM GPF) ADD: Dylib object instead of DLL objects. ADD: Introduce CoreGfx instead of GfxMgr. Signed-off-by: Amlal El Mahrouss --- dev/Kernel/KernelKit/CodeMgr.h | 2 +- dev/Kernel/KernelKit/DriveMgr.h | 5 ++ dev/Kernel/KernelKit/IDLLObject.h | 48 ------------- dev/Kernel/KernelKit/IDylibObject.h | 48 +++++++++++++ dev/Kernel/KernelKit/IPEFDLLObject.h | 106 ---------------------------- dev/Kernel/KernelKit/IPEFDylibObject.h | 106 ++++++++++++++++++++++++++++ dev/Kernel/KernelKit/UserProcessScheduler.h | 4 +- 7 files changed, 162 insertions(+), 157 deletions(-) delete mode 100644 dev/Kernel/KernelKit/IDLLObject.h create mode 100644 dev/Kernel/KernelKit/IDylibObject.h delete mode 100644 dev/Kernel/KernelKit/IPEFDLLObject.h create mode 100644 dev/Kernel/KernelKit/IPEFDylibObject.h (limited to 'dev/Kernel/KernelKit') diff --git a/dev/Kernel/KernelKit/CodeMgr.h b/dev/Kernel/KernelKit/CodeMgr.h index d3b9f39a..12a63dc0 100644 --- a/dev/Kernel/KernelKit/CodeMgr.h +++ b/dev/Kernel/KernelKit/CodeMgr.h @@ -16,7 +16,7 @@ #include #include -#include +#include namespace Kernel { diff --git a/dev/Kernel/KernelKit/DriveMgr.h b/dev/Kernel/KernelKit/DriveMgr.h index e907acf8..4c879ab5 100644 --- a/dev/Kernel/KernelKit/DriveMgr.h +++ b/dev/Kernel/KernelKit/DriveMgr.h @@ -164,6 +164,11 @@ namespace Kernel /// @brief Fetches the main drive. /// @return the new drive as a trait. DriveTrait io_construct_main_drive(Void) noexcept; + + namespace Detect + { + Void io_detect_drive(DriveTrait& trait); + } } // namespace Kernel #endif /* ifndef INC_DRIVE_MANAGER_H */ diff --git a/dev/Kernel/KernelKit/IDLLObject.h b/dev/Kernel/KernelKit/IDLLObject.h deleted file mode 100644 index 035f0013..00000000 --- a/dev/Kernel/KernelKit/IDLLObject.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright (C) 2024, Theater Quality Corp, all rights reserved., all rights reserved. - * - * ======================================================== - */ - -#pragma once - -#include -#include - -#define ZKA_DLL_OBJECT : public IDLLObject - -namespace Kernel -{ - /// @brief DLL class object. A handle to a shared library. - class IDLLObject - { - public: - explicit IDLLObject() = default; - virtual ~IDLLObject() = default; - - struct DLL_TRAITS final - { - VoidPtr ImageObject{nullptr}; - VoidPtr ImageEntrypointOffset{nullptr}; - - Bool IsValid() - { - return ImageObject && ImageEntrypointOffset; - } - }; - - ZKA_COPY_DEFAULT(IDLLObject); - - virtual DLL_TRAITS** GetAddressOf() = 0; - virtual DLL_TRAITS* Get() = 0; - - virtual Void Mount(DLL_TRAITS* to_mount) = 0; - virtual Void Unmount() = 0; - }; - - /// @brief Pure implementation, missing method/function handler. - EXTERN_C void __zka_pure_call(void); -} // namespace Kernel diff --git a/dev/Kernel/KernelKit/IDylibObject.h b/dev/Kernel/KernelKit/IDylibObject.h new file mode 100644 index 00000000..d4c93034 --- /dev/null +++ b/dev/Kernel/KernelKit/IDylibObject.h @@ -0,0 +1,48 @@ +/* + * ======================================================== + * + * Kernel + * Copyright (C) 2024, Theater Quality Corp, all rights reserved., all rights reserved. + * + * ======================================================== + */ + +#pragma once + +#include +#include + +#define ZKA_DLL_OBJECT : public IDylibObject + +namespace Kernel +{ + /// @brief DLL class object. A handle to a shared library. + class IDylibObject + { + public: + explicit IDylibObject() = default; + virtual ~IDylibObject() = default; + + struct DLL_TRAITS final + { + VoidPtr ImageObject{nullptr}; + VoidPtr ImageEntrypointOffset{nullptr}; + + Bool IsValid() + { + return ImageObject && ImageEntrypointOffset; + } + }; + + ZKA_COPY_DEFAULT(IDylibObject); + + virtual DLL_TRAITS** GetAddressOf() = 0; + virtual DLL_TRAITS* Get() = 0; + + virtual Void Mount(DLL_TRAITS* to_mount) = 0; + virtual Void Unmount() = 0; + }; + + /// @brief Pure implementation, missing method/function handler. + EXTERN_C void __zka_pure_call(void); +} // namespace Kernel diff --git a/dev/Kernel/KernelKit/IPEFDLLObject.h b/dev/Kernel/KernelKit/IPEFDLLObject.h deleted file mode 100644 index 1781c589..00000000 --- a/dev/Kernel/KernelKit/IPEFDLLObject.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * ======================================================== - * - * Kernel - * Copyright (C) 2024, Theater Quality Corp, all rights reserved., all rights reserved. - * - * ======================================================== - */ - -#ifndef __KERNELKIT_SHARED_OBJECT_H__ -#define __KERNELKIT_SHARED_OBJECT_H__ - -#include -#include -#include -#include -#include - -namespace Kernel -{ - /** - * @brief Shared Library class - * Load library from this class - */ - class IPEFDLLObject final ZKA_DLL_OBJECT - { - public: - explicit IPEFDLLObject() = default; - ~IPEFDLLObject() = default; - - public: - ZKA_COPY_DEFAULT(IPEFDLLObject); - - private: - DLL_TRAITS* fMounted{nullptr}; - - public: - DLL_TRAITS** GetAddressOf() - { - return &fMounted; - } - - DLL_TRAITS* Get() - { - return fMounted; - } - - public: - void Mount(DLL_TRAITS* to_mount) - { - if (!to_mount || !to_mount->ImageObject) - return; - - fMounted = to_mount; - - if (fLoader && to_mount) - { - delete fLoader; - fLoader = nullptr; - } - - if (!fLoader) - { - fLoader = new PEFLoader(fMounted->ImageObject); - } - } - - void Unmount() - { - if (fMounted) - fMounted = nullptr; - }; - - template - SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) - { - if (symbol_name == nullptr || *symbol_name == 0) - return nullptr; - if (len > kPathLen || len < 1) - return nullptr; - - auto ret = - reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); - - if (!ret) - { - if (kind == kPefCode) - return (VoidPtr)&__zka_pure_call; - - return nullptr; - } - - return ret; - } - - private: - PEFLoader* fLoader{nullptr}; - }; - - typedef IPEFDLLObject* IDLL; - - EXTERN_C IDLL rtl_init_dylib(UserThread& header); - EXTERN_C Void rtl_fini_dylib(UserThread& header, IDLL lib, Bool* successful); -} // namespace Kernel - -#endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ diff --git a/dev/Kernel/KernelKit/IPEFDylibObject.h b/dev/Kernel/KernelKit/IPEFDylibObject.h new file mode 100644 index 00000000..c8a69690 --- /dev/null +++ b/dev/Kernel/KernelKit/IPEFDylibObject.h @@ -0,0 +1,106 @@ +/* + * ======================================================== + * + * Kernel + * Copyright (C) 2024, Theater Quality Corp, all rights reserved., all rights reserved. + * + * ======================================================== + */ + +#ifndef __KERNELKIT_SHARED_OBJECT_H__ +#define __KERNELKIT_SHARED_OBJECT_H__ + +#include +#include +#include +#include +#include + +namespace Kernel +{ + /** + * @brief Shared Library class + * Load library from this class + */ + class IPEFDylibObject final ZKA_DLL_OBJECT + { + public: + explicit IPEFDylibObject() = default; + ~IPEFDylibObject() = default; + + public: + ZKA_COPY_DEFAULT(IPEFDylibObject); + + private: + DLL_TRAITS* fMounted{nullptr}; + + public: + DLL_TRAITS** GetAddressOf() + { + return &fMounted; + } + + DLL_TRAITS* Get() + { + return fMounted; + } + + public: + void Mount(DLL_TRAITS* to_mount) + { + if (!to_mount || !to_mount->ImageObject) + return; + + fMounted = to_mount; + + if (fLoader && to_mount) + { + delete fLoader; + fLoader = nullptr; + } + + if (!fLoader) + { + fLoader = new PEFLoader(fMounted->ImageObject); + } + } + + void Unmount() + { + if (fMounted) + fMounted = nullptr; + }; + + template + SymbolType Load(const Char* symbol_name, SizeT len, Int32 kind) + { + if (symbol_name == nullptr || *symbol_name == 0) + return nullptr; + if (len > kPathLen || len < 1) + return nullptr; + + auto ret = + reinterpret_cast(fLoader->FindSymbol(symbol_name, kind)); + + if (!ret) + { + if (kind == kPefCode) + return (VoidPtr)&__zka_pure_call; + + return nullptr; + } + + return ret; + } + + private: + PEFLoader* fLoader{nullptr}; + }; + + typedef IPEFDylibObject* IDylib; + + EXTERN_C IDylib rtl_init_dylib(UserThread& header); + EXTERN_C Void rtl_fini_dylib(UserThread& header, IDylib lib, Bool* successful); +} // namespace Kernel + +#endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ diff --git a/dev/Kernel/KernelKit/UserProcessScheduler.h b/dev/Kernel/KernelKit/UserProcessScheduler.h index a08a5dc1..8212fdc2 100644 --- a/dev/Kernel/KernelKit/UserProcessScheduler.h +++ b/dev/Kernel/KernelKit/UserProcessScheduler.h @@ -30,7 +30,7 @@ namespace Kernel { //! @note Forward class declarations. - class IDLLObject; + class IDylibObject; class UserThread; class UserProcessTeam; class UserProcessScheduler; @@ -163,7 +163,7 @@ namespace Kernel UInt8* StackReserve{nullptr}; UserProcessImage Image{}; SizeT StackSize{kSchedMaxStackSz}; - IDLLObject* DylibDelegate{nullptr}; + IDylibObject* DylibDelegate{nullptr}; SizeT MemoryCursor{0UL}; SizeT MemoryLimit{kSchedMaxMemoryLimit}; SizeT UsedMemory{0UL}; -- cgit v1.2.3