diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-23 21:06:27 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-23 21:06:27 -0500 |
| commit | 23040fad647634c08697451fc22ee2ca999629c8 (patch) | |
| tree | 72888f88c7728c82f3f6df1f4f70591de15eab36 /src/kernel/KernelKit/IPEFDylibObject.h | |
| parent | e5cc7351f0577b54c528fb827a7c7e6306c3e843 (diff) | |
| parent | 83d870e58457a1d335a1d9b9966a6a1887cc297b (diff) | |
Merge pull request #81 from nekernel-org/dev
feat! breaking changes on kernel sources.
Diffstat (limited to 'src/kernel/KernelKit/IPEFDylibObject.h')
| -rw-r--r-- | src/kernel/KernelKit/IPEFDylibObject.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/kernel/KernelKit/IPEFDylibObject.h b/src/kernel/KernelKit/IPEFDylibObject.h new file mode 100644 index 00000000..17ef02d5 --- /dev/null +++ b/src/kernel/KernelKit/IPEFDylibObject.h @@ -0,0 +1,86 @@ +/* + * ======================================================== + * + * Kernel + * Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + * + * ======================================================== + */ + +#ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ +#define __KERNELKIT_PEF_SHARED_OBJECT_H__ + +#include <KernelKit/IDylibObject.h> +#include <KernelKit/PEF.h> +#include <KernelKit/PEFCodeMgr.h> +#include <KernelKit/ProcessScheduler.h> +#include <NeKit/Defines.h> + +namespace Kernel { +/** + * @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: + DylibTraits* fMounted{nullptr}; + + public: + DylibTraits** GetAddressOf() { return &fMounted; } + + DylibTraits* Get() { return fMounted; } + + public: + void Mount(DylibTraits* to_mount) noexcept { + 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() noexcept { + if (fMounted) fMounted = nullptr; + }; + + template <typename SymbolType> + SymbolType Load(const Char* symbol_name, const SizeT& len, const UInt32& 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).Leak().Leak()); + + if (!ret) { + if (kind == kPefCode) return (VoidPtr) &__ne_pure_call; + + return nullptr; + } + + return ret; + } + + private: + PEFLoader* fLoader{nullptr}; +}; + +typedef IPEFDylibObject* IDylibRef; + +EXTERN_C IDylibRef rtl_init_dylib_pef(USER_PROCESS& header); +EXTERN_C Void rtl_fini_dylib_pef(USER_PROCESS& header, IDylibRef lib, Bool* successful); +} // namespace Kernel + +#endif /* ifndef __KERNELKIT_PEF_SHARED_OBJECT_H__ */ |
