From 4efd7b8a6608a9299ef8cc750c264a3be0cb12e7 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 14:41:18 +0100 Subject: HCR-9 : Update EFIKit, working on Volume API. HCR-9 Related: - New EfiMountVolume, EfiUnmountVolume. Kernel Related: - Update Shared Object API, it was lacking a cleanup routine. - Add __mh_purecall as a C linked symbol for unknown symbols. Signed-off-by: Amlal El Mahrouss --- Private/Source/PEFSharedObjectRT.cxx | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Private/Source/PEFSharedObjectRT.cxx (limited to 'Private/Source/PEFSharedObjectRT.cxx') 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 +#include +#include +#include +#include +#include + +#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(); + + if (!library) { + kcout << "__LibInit: Out of Memory!\n"; + ProcessManager::Shared().Leak().GetCurrent().Leak().Crash(); + + return nullptr; + } + + library->Mount(hcore_tls_new_class()); + + 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(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; +} -- cgit v1.2.3 From 69d07f34fce76f89fe11beb7ced130e9aa72078b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 1 Feb 2024 15:14:39 +0100 Subject: Meta: update string. Signed-off-by: Amlal El Mahrouss --- Private/Source/PEFSharedObjectRT.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Private/Source/PEFSharedObjectRT.cxx') diff --git a/Private/Source/PEFSharedObjectRT.cxx b/Private/Source/PEFSharedObjectRT.cxx index 0b98834c..018b618e 100644 --- a/Private/Source/PEFSharedObjectRT.cxx +++ b/Private/Source/PEFSharedObjectRT.cxx @@ -68,7 +68,7 @@ extern "C" SharedObject *__LibInit() { library->Get()->fImageEntrypointOffset = library->Load(kPefStart, string_length(kPefStart, 0), kPefCode); - kcout << "__LibMain: Task was successful... Returning library...\n"; + kcout << "__LibInit: Task was successful... Returning library...\n"; return library; } -- cgit v1.2.3