diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-02 09:25:18 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-06-02 09:25:18 +0200 |
| commit | 39415bb759f7eb67fb393385c28c3d2e5d7f6857 (patch) | |
| tree | c818db537a0f722e7d3dee0a7770df2ef1ebe3f6 /Kernel/Sources/PEFSharedObject.cxx | |
| parent | c34c46598c12b04b2877aa7290dd401cc40a29e3 (diff) | |
MHR-23: Porting to ARM64 now.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/Sources/PEFSharedObject.cxx')
| -rw-r--r-- | Kernel/Sources/PEFSharedObject.cxx | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Kernel/Sources/PEFSharedObject.cxx b/Kernel/Sources/PEFSharedObject.cxx new file mode 100644 index 00000000..06825a3c --- /dev/null +++ b/Kernel/Sources/PEFSharedObject.cxx @@ -0,0 +1,106 @@ +/* + * ======================================================== + * + * NewOS + * Copyright SoftwareLabs, all rights reserved. + * + * ======================================================== + */ + +#include <KernelKit/DebugOutput.hpp> +#include <KernelKit/PEF.hpp> +#include <KernelKit/PEFSharedObject.hxx> +#include <KernelKit/ProcessScheduler.hxx> +#include <KernelKit/ThreadLocalStorage.hxx> +#include <NewKit/Defines.hpp> + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared library ABI, except a rt_library_init and + rt_library_free (amlel) 15/02/24: Breaking changes, changed the name of the + routines. (amlel) + + ------------------------------------------- */ + +using namespace NewOS; + +/***********************************************************************************/ +/// @file SharedObjectRT.cxx +/// @brief Shared Object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Library runtime initializer. */ +/***********************************************************************************/ + +EXTERN_C SharedObjectPtr rt_library_init(void) +{ + SharedObjectPtr library = tls_new_class<SharedObject>(); + + if (!library) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(tls_new_class<SharedObject::SharedObjectTrait>()); + + if (!library->Get()) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageObject = + ProcessScheduler::The().Leak().GetCurrent().Leak().Image; + + if (!library->Get()->fImageObject) + { + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageEntrypointOffset = + library->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode); + + return library; +} + +/***********************************************************************************/ +/* @brief Ends the library. */ +/* @note Please check if the lib got freed! */ +/* @param SharedObjectPtr the library to free. */ +/***********************************************************************************/ + +EXTERN_C Void rt_library_free(SharedObjectPtr lib, bool* successful) +{ + MUST_PASS(successful); + + // sanity check (will also trigger a bug check if this fails) + if (lib == nullptr) + { + *successful = false; + ProcessScheduler::The().Leak().GetCurrent().Leak().Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} + +/***********************************************************************************/ + +/// @brief Unimplemented function (crashes by default) +/// @param +EXTERN_C void __mh_purecall(void) +{ + kcout << "newoskrnl: unimplemented symbol!\r"; +} |
