summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/KernelKit/IPEFDylibObject.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-01-07 08:33:01 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-01-07 08:33:01 +0100
commit3ce4b68fc3f1ad9ead503bb3f69bff11b4a3183a (patch)
tree9d679d2092e71a35305ae6c6c9554bfc6528b6ca /dev/Kernel/KernelKit/IPEFDylibObject.h
parentecf2a09a48ef029d09075af744c04e643661ec27 (diff)
FIX: KAN-12 (EPM GPF)
ADD: Dylib object instead of DLL objects. ADD: Introduce CoreGfx instead of GfxMgr. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/KernelKit/IPEFDylibObject.h')
-rw-r--r--dev/Kernel/KernelKit/IPEFDylibObject.h106
1 files changed, 106 insertions, 0 deletions
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 <KernelKit/PEF.h>
+#include <NewKit/Defines.h>
+#include <KernelKit/PEFCodeMgr.h>
+#include <KernelKit/UserProcessScheduler.h>
+#include <KernelKit/IDylibObject.h>
+
+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 <typename SymbolType>
+ 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<SymbolType>(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__ */