summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-01 14:41:18 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-01 14:45:34 +0100
commit4efd7b8a6608a9299ef8cc750c264a3be0cb12e7 (patch)
treed146ac34c2587274beecd602ca8f6064cd11e125
parent1bb395c7ceae7d06448e2ac6f60e91ffffe6b091 (diff)
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 <amlalelmahrouss@icloud.com>
-rw-r--r--Private/EFIKit/EFILib.hxx6
-rw-r--r--Private/HALKit/AMD64/DebugManager.asm2
-rw-r--r--Private/KernelKit/PEFSharedObject.hxx39
-rw-r--r--Private/NewKit/Macros.hpp12
-rw-r--r--Private/Source/PEFCodeManager.cxx2
-rw-r--r--Private/Source/PEFSharedObjectMain.cxx58
-rw-r--r--Private/Source/PEFSharedObjectRT.cxx107
7 files changed, 140 insertions, 86 deletions
diff --git a/Private/EFIKit/EFILib.hxx b/Private/EFIKit/EFILib.hxx
index 3f041e37..fcd5df7d 100644
--- a/Private/EFIKit/EFILib.hxx
+++ b/Private/EFIKit/EFILib.hxx
@@ -68,7 +68,11 @@ enum {
kPartCnt,
};
-class EFIPartitionManager final {};
+typedef EfiHandlePtr* EfiFilesystemHandlePtr;
+
+EfiFilesystemHandlePtr EfiMountVolume(const EfiCharType* MountPath,
+ Int32 PartitionType);
+Boolean EfiUnmountVolume(EfiFilesystemHandlePtr Handle);
#ifdef __BOOTLOADER__
#include <BootKit/Platform.hxx>
diff --git a/Private/HALKit/AMD64/DebugManager.asm b/Private/HALKit/AMD64/DebugManager.asm
index cf3a4539..5cc0cd10 100644
--- a/Private/HALKit/AMD64/DebugManager.asm
+++ b/Private/HALKit/AMD64/DebugManager.asm
@@ -14,8 +14,6 @@
__rt_debug_record_table:
db "DebugMgr/HCore", 0xa, 0xd, 0
- ;; User Data goes there
- resb 64
__rt_debug_int_3:
push 0x6677 ;; Debug check error
;; then halt and goes back to L0, thens halts...
diff --git a/Private/KernelKit/PEFSharedObject.hxx b/Private/KernelKit/PEFSharedObject.hxx
index af90858e..263f08f4 100644
--- a/Private/KernelKit/PEFSharedObject.hxx
+++ b/Private/KernelKit/PEFSharedObject.hxx
@@ -16,10 +16,13 @@
#include <NewKit/Defines.hpp>
namespace HCore {
- /**
- * @brief Shared Library class
- * Load library from this class
- */
+/// @brief Pure implementation, missing method/function handler.
+extern "C" void __mh_purecall(void);
+
+/**
+ * @brief Shared Library class
+ * Load library from this class
+ */
class SharedObject final {
public:
struct SharedObjectTraits final {
@@ -44,9 +47,7 @@ class SharedObject final {
public:
void Mount(SharedObjectTraits *to_mount) {
- if (!to_mount ||
- !to_mount->fImageObject)
- return;
+ if (!to_mount || !to_mount->fImageObject) return;
fMounted = to_mount;
@@ -65,17 +66,18 @@ class SharedObject final {
};
template <typename SymbolType>
- SymbolType Load(const char *symbol_name) {
- auto ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefCode));
+ SymbolType Load(const char *symbol_name, SizeT len, Int32 kind) {
+ if (symbol_name == nullptr || *symbol_name == 0) return nullptr;
+ if (len > kPathLen || len < 1) return nullptr;
- if (!ret)
- ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefData));
+ auto ret =
+ reinterpret_cast<SymbolType>(fLoader->FindSymbol(symbol_name, kind));
- if (!ret)
- ret = reinterpret_cast<SymbolType>(
- fLoader->FindSymbol(symbol_name, kPefZero));
+ if (!ret) {
+ if (kind == kPefCode) return (VoidPtr)__mh_purecall;
+
+ return nullptr;
+ }
return ret;
}
@@ -84,10 +86,7 @@ class SharedObject final {
PEFLoader *fLoader{nullptr};
};
-inline void hcore_pure_call(void) {
- // virtual placeholder.
- return;
-}
+typedef SharedObject *SharedObjectPtr;
} // namespace HCore
#endif /* ifndef __KERNELKIT_SHARED_OBJECT_HXX__ */
diff --git a/Private/NewKit/Macros.hpp b/Private/NewKit/Macros.hpp
index 02be7180..94fd8fe8 100644
--- a/Private/NewKit/Macros.hpp
+++ b/Private/NewKit/Macros.hpp
@@ -65,7 +65,7 @@
#endif
#ifndef ENUM_STRING
-#define ENUM_STRING(NAME, VAL) constexpr const char *NAME = VAL
+#define ENUM_STRING(NAME, VAL) inline constexpr const char *NAME = VAL
#endif
#ifndef END_STRING_ENUM
@@ -76,9 +76,13 @@
#define Alloca(Sz) __builtin_alloca(Sz)
#endif // #ifndef Alloca
-#ifndef CantReach
-#define CantReach() __builtin_unreachable()
+#ifndef CANT_REACH
+#define CANT_REACH() __builtin_unreachable()
#endif
#define kBadPtr 0xFBFBFBFBFBFBFBFB
-#define kmaxAddr 0xFFFFFFFFFFFFFFFF
+#define kMaxAddr 0xFFFFFFFFFFFFFFFF
+#define kPathLen 255
+
+#define PACKED ATTRIBUTE(packed)
+#define NO_EXEC ATTRIBUTE(noexec)
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;
+}