summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/src/IPEFDLLObject.cc
diff options
context:
space:
mode:
Diffstat (limited to 'dev/Kernel/src/IPEFDLLObject.cc')
-rw-r--r--dev/Kernel/src/IPEFDLLObject.cc103
1 files changed, 103 insertions, 0 deletions
diff --git a/dev/Kernel/src/IPEFDLLObject.cc b/dev/Kernel/src/IPEFDLLObject.cc
new file mode 100644
index 00000000..0089b877
--- /dev/null
+++ b/dev/Kernel/src/IPEFDLLObject.cc
@@ -0,0 +1,103 @@
+/*
+ * ========================================================
+ *
+ * minoskrnl
+ * Copyright (C) 2024, TQ B.V, all rights reserved., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <KernelKit/DebugOutput.h>
+#include <KernelKit/PEF.h>
+#include <KernelKit/IPEFDLLObject.h>
+#include <KernelKit/UserProcessScheduler.h>
+#include <KernelKit/ThreadLocalStorage.h>
+#include <NewKit/Defines.h>
+
+/* -------------------------------------------
+
+ Revision History:
+
+ 01/02/24: Reworked dll ABI, expect a rtl_init_dylib and
+ rtl_fini_dylib (amlel) 15/02/24: Breaking changes, changed the name of the
+ routines. (amlel)
+
+ 07/28/24: Replace rt_library_free with rtl_fini_dylib
+
+ 10/8/24: FIX: Fix log comment.
+
+ ------------------------------------------- */
+
+using namespace Kernel;
+
+/***********************************************************************************/
+/// @file IPEFDLLObject.cc
+/// @brief PEF's DLL runtime.
+/***********************************************************************************/
+
+/***********************************************************************************/
+/** @brief Library initializer. */
+/***********************************************************************************/
+
+EXTERN_C IDLL rtl_init_dylib(UserProcess* header)
+{
+ IDLL dll_obj = tls_new_class<IPEFDLLObject>();
+
+ if (!dll_obj)
+ {
+ header->Crash();
+ return nullptr;
+ }
+
+ dll_obj->Mount(tls_new_class<IPEFDLLObject::DLL_TRAITS>());
+
+ if (!dll_obj->Get())
+ {
+ tls_delete_class(dll_obj);
+ header->Crash();
+
+ return nullptr;
+ }
+
+ dll_obj->Get()->ImageObject =
+ header->Image.fBlob;
+
+ if (!dll_obj->Get()->ImageObject)
+ {
+ tls_delete_class(dll_obj);
+ header->Crash();
+
+ return nullptr;
+ }
+
+ dll_obj->Get()->ImageEntrypointOffset =
+ dll_obj->Load<VoidPtr>(kPefStart, rt_string_len(kPefStart, 0), kPefCode);
+
+ return dll_obj;
+}
+
+/***********************************************************************************/
+/** @brief Frees the dll_obj. */
+/** @note Please check if the dll_obj got freed! */
+/** @param dll_obj The dll_obj to free. */
+/** @param successful Reports if successful or not. */
+/***********************************************************************************/
+
+EXTERN_C Void rtl_fini_dylib(UserProcess* header, IDLL dll_obj, Bool* successful)
+{
+ MUST_PASS(successful);
+
+ // sanity check (will also trigger a bug check if this fails)
+ if (dll_obj == nullptr)
+ {
+ *successful = false;
+ header->Crash();
+ }
+
+ delete dll_obj->Get();
+ delete dll_obj;
+
+ dll_obj = nullptr;
+
+ *successful = true;
+}