summaryrefslogtreecommitdiffhomepage
path: root/Kernel/Sources/PEFSharedObject.cxx
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-06-06 10:27:55 +0000
committerAmlal <amlalelmahrouss@icloud.com>2024-06-06 10:27:55 +0000
commit4e75e05a20ddd0dbca982e8f3bc2ea8043ed3a3f (patch)
tree95409c0e32b644578b94a5c230417da684d79dc9 /Kernel/Sources/PEFSharedObject.cxx
parentf5081a8f9a8537ad5be5d639955cd1d0e68a9e1d (diff)
parent9994b8f3f88131f41be1061fb0947177e66dc7b0 (diff)
Merged in MHR-23 (pull request #14)
Draft: MHR-23
Diffstat (limited to 'Kernel/Sources/PEFSharedObject.cxx')
-rw-r--r--Kernel/Sources/PEFSharedObject.cxx106
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";
+}