diff options
Diffstat (limited to 'Private/Source')
| -rw-r--r-- | Private/Source/PEFCodeManager.cxx | 2 | ||||
| -rw-r--r-- | Private/Source/PEFSharedObjectMain.cxx | 58 | ||||
| -rw-r--r-- | Private/Source/PEFSharedObjectRT.cxx | 107 |
3 files changed, 108 insertions, 59 deletions
diff --git a/Private/Source/PEFCodeManager.cxx b/Private/Source/PEFCodeManager.cxx index 8804d1ca..63e8659f 100644 --- a/Private/Source/PEFCodeManager.cxx +++ b/Private/Source/PEFCodeManager.cxx @@ -7,9 +7,9 @@ * ======================================================== */ -#include <KernelKit/CodeManager.hpp> #include <KernelKit/DebugOutput.hpp> #include <KernelKit/FileManager.hpp> +#include <KernelKit/PEFCodeManager.hxx> #include <KernelKit/ProcessManager.hpp> #include <NewKit/Defines.hpp> #include <NewKit/ErrorID.hpp> diff --git a/Private/Source/PEFSharedObjectMain.cxx b/Private/Source/PEFSharedObjectMain.cxx deleted file mode 100644 index c1803312..00000000 --- a/Private/Source/PEFSharedObjectMain.cxx +++ /dev/null @@ -1,58 +0,0 @@ -/* - * ======================================================== - * - * HCore - * Copyright Mahrouss Logic, all rights reserved. - * - * ======================================================== - */ - -#include <KernelKit/DebugOutput.hpp> -#include <KernelKit/PEF.hpp> -#include <KernelKit/ProcessManager.hpp> -#include <KernelKit/PEFSharedObject.hxx> -#include <KernelKit/ThreadLocalStorage.hxx> -#include <NewKit/Defines.hpp> - -using namespace HCore; - -/***********************************************************************************/ -/// @file SharedObjectEntry.cxx -/// @brief Shared Object Init code. -/***********************************************************************************/ - -/***********************************************************************************/ -/* @brief Allocate new library to be added to the lookup table. - */ -/***********************************************************************************/ - -extern "C" SharedObject *__LibMain(VoidPtr image) { - SharedObject *library = hcore_tls_new_class<SharedObject>(); - - if (!library) { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>()); - - if (!library->Get()) { - kcout << "__LibMain: Out of Memory!\n"; - ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); - - return nullptr; - } - - library->Get()->fImageObject = - ProcessManager::Shared().Leak().GetCurrent().Leak().Image; - - library->Get()->fImageEntrypointOffset = library->Load<VoidPtr>(kPefStart); - - kcout << "__LibMain: Done jumping to library...\n"; - - return library; -} - -/***********************************************************************************/ diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx new file mode 100644 index 00000000..0b98834c --- /dev/null +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -0,0 +1,107 @@ +/* + * ======================================================== + * + * HCore + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +#include <KernelKit/DebugOutput.hpp> +#include <KernelKit/PEF.hpp> +#include <KernelKit/PEFSharedObject.hxx> +#include <KernelKit/ProcessManager.hpp> +#include <KernelKit/ThreadLocalStorage.hxx> +#include <NewKit/Defines.hpp> + +#include "NewKit/RuntimeCheck.hpp" + +/* ------------------------------------------- + + Revision History: + + 01/02/24: Rework shared library ABI, except a __LibInit and __LibFini + (amlel) + + ------------------------------------------- */ + +using namespace HCore; + +/***********************************************************************************/ +/// @file SharedObjectRT.cxx +/// @brief Shared Object runtime. +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Allocates a new library. */ +/***********************************************************************************/ + +extern "C" SharedObject *__LibInit() { + SharedObject *library = hcore_tls_new_class<SharedObject>(); + + if (!library) { + kcout << "__LibInit: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(hcore_tls_new_class<SharedObject::SharedObjectTraits>()); + + if (!library->Get()) { + kcout << "__LibInit: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageObject = + ProcessManager::Shared().Leak().GetCurrent().Leak().Image; + + if (!library->Get()->fImageObject) { + kcout << "__LibInit: Invalid image!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Get()->fImageEntrypointOffset = + library->Load<VoidPtr>(kPefStart, string_length(kPefStart, 0), kPefCode); + + kcout << "__LibMain: Task was successful... Returning library...\n"; + + return library; +} + +/***********************************************************************************/ + +/***********************************************************************************/ +/* @brief Frees the library. */ +/* @note Please check if the lib got freed! */ +/* @param SharedObjectPtr the library to free. */ +/***********************************************************************************/ + +extern "C" Void __LibFini(SharedObjectPtr lib, bool *successful) { + MUST_PASS(successful); + + // sanity check (will also trigger a bug check) + if (lib == nullptr) { + kcout << "__LibFini: Invalid image!\n"; + *successful = false; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + } + + delete lib->Get(); + delete lib; + + lib = nullptr; + + *successful = true; +} + +/***********************************************************************************/ + +extern "C" void __mh_purecall(void) { + // virtual placeholder. + return; +} |
