summaryrefslogtreecommitdiffhomepage
path: root/Private/Source
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-01 17:08:13 +0000
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-01 17:08:13 +0000
commit5c59cd35a2fa3e620542b73e8c3f66f0dccd241c (patch)
tree985e7e39fd9657ceb45ab292f6a934e0e6d4571b /Private/Source
parent6c4cc0dba681fef1cef3c31877653a1d6413fc90 (diff)
parent6ce7dffe92775f262384a028af233999a7d18048 (diff)
Merge branch 'HCR-9-add-support-for-file-load-hel-amd64' into 'trunk'
See below. See merge request mahrouss-logic/micro-kernel!2
Diffstat (limited to 'Private/Source')
-rw-r--r--Private/Source/Framebuffer.cxx48
-rw-r--r--Private/Source/KernelHeap.cxx29
-rw-r--r--Private/Source/PEFCodeManager.cxx2
-rw-r--r--Private/Source/PEFSharedObjectMain.cxx58
-rw-r--r--Private/Source/PEFSharedObjectRT.cxx107
-rw-r--r--Private/Source/PageManager.cxx21
-rw-r--r--Private/Source/Pmm.cxx9
7 files changed, 177 insertions, 97 deletions
diff --git a/Private/Source/Framebuffer.cxx b/Private/Source/Framebuffer.cxx
index 251cdb93..3b8fa229 100644
--- a/Private/Source/Framebuffer.cxx
+++ b/Private/Source/Framebuffer.cxx
@@ -1,36 +1,34 @@
-/*
- * ========================================================
- *
- * HCore
- * Copyright Mahrouss Logic, all rights reserved.
- *
- * ========================================================
- */
+/* -------------------------------------------
-#include <KernelKit/Framebuffer.hpp>
+ Copyright Mahrouss Logic
-namespace HCore {
-Framebuffer::Framebuffer(HCore::Ref<FramebufferContext*>& addr)
- : m_FrameBufferAddr(addr), m_Colour(FramebufferColorKind::RGB32) {}
+ File: Framebuffer.cxx
+ Purpose: EFI C++ library
-Framebuffer::~Framebuffer() = default;
+ Revision History:
-volatile UIntPtr* Framebuffer::operator[](const UIntPtr& width_and_height) {
- if (m_FrameBufferAddr)
- return reinterpret_cast<volatile HCore::UIntPtr*>(
- m_FrameBufferAddr->m_Base + width_and_height);
+ 01/02/24: Added file (amlel)
- return nullptr;
-}
+------------------------------------------- */
-Ref<FramebufferContext*>& Framebuffer::Leak() { return m_FrameBufferAddr; }
+#include <KernelKit/Framebuffer.hpp>
-Framebuffer::operator bool() { return m_FrameBufferAddr; }
+using namespace HCore;
-const FramebufferColorKind& Framebuffer::Color(
- const FramebufferColorKind& colour) {
- if (colour != FramebufferColorKind::INVALID) m_Colour = colour;
+volatile UIntPtr *Framebuffer::operator[](const UIntPtr &width_and_height) {
+ return (UIntPtr *)(m_FrameBufferAddr->m_Base * width_and_height);
+}
+
+const FramebufferColorKind &Framebuffer::Color(
+ const FramebufferColorKind &colour) {
+ if (m_Colour != FramebufferColorKind::INVALID &&
+ colour != FramebufferColorKind::INVALID) {
+ m_Colour = colour;
+ }
return m_Colour;
}
-} // namespace HCore
+
+Ref<FramebufferContext *> &Framebuffer::Leak() {
+ return this->m_FrameBufferAddr;
+}
diff --git a/Private/Source/KernelHeap.cxx b/Private/Source/KernelHeap.cxx
index 42ea0187..603b91b3 100644
--- a/Private/Source/KernelHeap.cxx
+++ b/Private/Source/KernelHeap.cxx
@@ -9,6 +9,8 @@
#include <NewKit/KernelHeap.hpp>
+#include "NewKit/PageManager.hpp"
+
//! @file KernelHeap.cpp
//! @brief Kernel allocator.
@@ -48,6 +50,8 @@ VoidPtr ke_new_ke_heap(const SizeT &sz, const bool rw, const bool user) {
Ref<PTEWrapper *> wrapper = kPmm.RequestPage(user, rw);
if (wrapper) {
+ wrapper->NoExecute(true);
+
kLastWrapper = wrapper;
kWrapperList[kWrapperCount] = wrapper;
@@ -67,15 +71,27 @@ Int32 ke_delete_ke_heap(voidPtr ptr) {
const UIntPtr virtualAddress = reinterpret_cast<UIntPtr>(ptr);
if (kLastWrapper && virtualAddress == kLastWrapper->VirtualAddress()) {
- return kPmm.FreePage(kLastWrapper);
+ if (kPmm.FreePage(kLastWrapper)) {
+ kLastWrapper->NoExecute(false);
+ return true;
+ }
+
+ return false;
}
- Ref<PTEWrapper *> wrapper;
+ Ref<PTEWrapper *> wrapper{nullptr};
for (SizeT indexWrapper = 0; indexWrapper < kWrapperCount; ++indexWrapper) {
if (kWrapperList[indexWrapper]->VirtualAddress() == virtualAddress) {
wrapper = kWrapperList[indexWrapper];
- return kPmm.FreePage(wrapper);
+
+ // if page is no more, then mark it also as non executable.
+ if (kPmm.FreePage(wrapper)) {
+ wrapper->NoExecute(false);
+ return true;
+ }
+
+ return false;
}
}
}
@@ -108,11 +124,10 @@ Boolean kernel_valid_ptr(voidPtr ptr) {
}
/// @brief The Kernel heap initializer function.
-/// @return
-Void ke_init_ke_heap() noexcept
-{
+/// @return
+Void ke_init_ke_heap() noexcept {
kWrapperCount = 0UL;
- Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper*>(nullptr);
+ Ref<PTEWrapper *> kLastWrapper = Ref<PTEWrapper *>(nullptr);
Pmm kPmm = Pmm();
}
} // namespace HCore
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..018b618e
--- /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 << "__LibInit: 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;
+}
diff --git a/Private/Source/PageManager.cxx b/Private/Source/PageManager.cxx
index 95097f99..d6455a18 100644
--- a/Private/Source/PageManager.cxx
+++ b/Private/Source/PageManager.cxx
@@ -85,8 +85,20 @@ bool PageManager::Free(Ref<PTEWrapper *> &wrapper) {
return false;
}
+////////////////////////////
+
+// VIRTUAL ADDRESS
+
+////////////////////////////
+
const UIntPtr &PTEWrapper::VirtualAddress() { return m_VirtAddr; }
+////////////////////////////
+
+// PAGE GETTERS
+
+////////////////////////////
+
bool PTEWrapper::Shareable() {
auto raw = reinterpret_cast<PTE *>(m_VirtAddr);
@@ -120,4 +132,13 @@ bool PTEWrapper::Access() {
return m_Accessed;
}
+
+////////////////////////////
+
+// NO EXECUTE PROTECTION
+
+////////////////////////////
+
+void PTEWrapper::NoExecute(const bool enable) { this->m_ExecDisable = enable; }
+const bool &PTEWrapper::NoExecute() { return this->m_ExecDisable; }
} // namespace HCore
diff --git a/Private/Source/Pmm.cxx b/Private/Source/Pmm.cxx
index aa5a3c89..76191fdd 100644
--- a/Private/Source/Pmm.cxx
+++ b/Private/Source/Pmm.cxx
@@ -11,11 +11,8 @@
#include <NewKit/Pmm.hpp>
namespace HCore {
-Pmm::Pmm() = default;
-
-Pmm::Pmm(Ref<PageManager *> &pm) : m_PageManager(pm) {
- MUST_PASS(pm.Leak());
- kcout << "[PMM] New PhysicalMemoryManager\r\n";
+Pmm::Pmm() : m_PageManager() {
+ kcout << "[PMM] Allocate PageMemoryManager\r\n";
}
Pmm::~Pmm() = default;
@@ -23,7 +20,7 @@ Pmm::~Pmm() = default;
/* If this returns Null pointer, enter emergency mode */
Ref<PTEWrapper *> Pmm::RequestPage(Boolean user, Boolean readWrite) {
if (m_PageManager) {
- PTEWrapper *pt = m_PageManager.Leak()->Request(user, readWrite, true);
+ PTEWrapper *pt = m_PageManager.Leak().Request(user, readWrite, true);
if (pt) return Ref<PTEWrapper *>(pt);