diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:13:48 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-03-23 19:15:17 +0100 |
| commit | a13e1c0911c0627184bc38f18c7fdda64447b3ad (patch) | |
| tree | 073a62c09bf216e85a3f310376640fa1805147f9 /dev/kernel/KernelKit/IPEFDylibObject.h | |
| parent | 149fa096eb306d03686b3b67e813cf1a78e08cd0 (diff) | |
meta(kernel): Reworked repository's filesystem structure.
Removing useless parts of the project too.
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.h | 106 |
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..20f87410 --- /dev/null +++ b/dev/kernel/KernelKit/IPEFDylibObject.h @@ -0,0 +1,106 @@ +/* + * ======================================================== + * + * Kernel + * Copyright (C) 2024-2025, Amlal EL Mahrouss, 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 NeOS +{ + /** + * @brief Shared Library class + * Load library from this class + */ + class IPEFDylibObject final NE_DYLIB_OBJECT + { + public: + explicit IPEFDylibObject() = default; + ~IPEFDylibObject() = default; + + public: + NE_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* IDylibRef; + + EXTERN_C IDylibRef rtl_init_dylib(UserProcess& header); + EXTERN_C Void rtl_fini_dylib(UserProcess& header, IDylibRef lib, Bool* successful); +} // namespace NeOS + +#endif /* ifndef __KERNELKIT_SHARED_OBJECT_H__ */ |
