summaryrefslogtreecommitdiffhomepage
path: root/Private/NewKit
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/NewKit
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/NewKit')
-rw-r--r--Private/NewKit/Macros.hpp12
-rw-r--r--Private/NewKit/PageManager.hpp103
-rw-r--r--Private/NewKit/Pmm.hpp58
-rw-r--r--Private/NewKit/Ref.hpp124
4 files changed, 139 insertions, 158 deletions
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/NewKit/PageManager.hpp b/Private/NewKit/PageManager.hpp
index b5337268..fdde95f8 100644
--- a/Private/NewKit/PageManager.hpp
+++ b/Private/NewKit/PageManager.hpp
@@ -18,64 +18,65 @@
#ifndef kBadAddress
#define kBadAddress (0)
-#endif // #ifndef kBadAddress
+#endif // #ifndef kBadAddress
-namespace HCore
-{
+namespace HCore {
class PageManager;
-class PTEWrapper final
-{
- public:
- explicit PTEWrapper(Boolean Rw = false, Boolean User = false, Boolean ExecDisable = false, UIntPtr Address = 0);
- ~PTEWrapper();
-
- PTEWrapper &operator=(const PTEWrapper &) = default;
- PTEWrapper(const PTEWrapper &) = default;
-
- public:
- void FlushTLB(Ref<PageManager> &pm);
- const UIntPtr &VirtualAddress();
-
- bool Reclaim();
- bool Shareable();
- bool Present();
- bool Access();
-
- private:
- Boolean m_Rw;
- Boolean m_User;
- Boolean m_ExecDisable;
- UIntPtr m_VirtAddr;
- Boolean m_Cache;
- Boolean m_Shareable;
- Boolean m_Wt;
- Boolean m_Present;
- Boolean m_Accessed;
-
- private:
- friend class PageManager;
- friend class Pmm;
+class PTEWrapper final {
+ public:
+ explicit PTEWrapper(Boolean Rw = false, Boolean User = false,
+ Boolean ExecDisable = false, UIntPtr Address = 0);
+ ~PTEWrapper();
+
+ PTEWrapper &operator=(const PTEWrapper &) = default;
+ PTEWrapper(const PTEWrapper &) = default;
+
+ public:
+ void FlushTLB(Ref<PageManager> &pm);
+ const UIntPtr &VirtualAddress();
+
+ void NoExecute(const bool enable = false);
+ const bool &NoExecute();
+
+ bool Reclaim();
+ bool Shareable();
+ bool Present();
+ bool Access();
+
+ private:
+ Boolean m_Rw;
+ Boolean m_User;
+ Boolean m_ExecDisable;
+ UIntPtr m_VirtAddr;
+ Boolean m_Cache;
+ Boolean m_Shareable;
+ Boolean m_Wt;
+ Boolean m_Present;
+ Boolean m_Accessed;
+
+ private:
+ friend class PageManager;
+ friend class Pmm;
};
-struct PageManager final
-{
- public:
- PageManager() = default;
- ~PageManager() = default;
+struct PageManager final {
+ public:
+ PageManager() = default;
+ ~PageManager() = default;
- PageManager &operator=(const PageManager &) = default;
- PageManager(const PageManager &) = default;
+ PageManager &operator=(const PageManager &) = default;
+ PageManager(const PageManager &) = default;
- public:
- PTEWrapper *Request(Boolean Rw, Boolean User, Boolean ExecDisable);
- bool Free(Ref<PTEWrapper*> &wrapper);
+ public:
+ PTEWrapper *Request(Boolean Rw, Boolean User, Boolean ExecDisable);
+ bool Free(Ref<PTEWrapper *> &wrapper);
- private:
- void FlushTLB(UIntPtr VirtAddr);
+ private:
+ void FlushTLB(UIntPtr VirtAddr);
- private:
- friend PTEWrapper;
- friend class Pmm;
+ private:
+ friend PTEWrapper;
+ friend class Pmm;
};
-} // namespace HCore
+} // namespace HCore
diff --git a/Private/NewKit/Pmm.hpp b/Private/NewKit/Pmm.hpp
index 58bf7609..eb7f75ab 100644
--- a/Private/NewKit/Pmm.hpp
+++ b/Private/NewKit/Pmm.hpp
@@ -13,33 +13,31 @@
#include <NewKit/PageManager.hpp>
#include <NewKit/Ref.hpp>
-namespace HCore
-{
- class Pmm;
- class PTEWrapper;
-
- class Pmm final
- {
- public:
- Pmm();
- ~Pmm();
-
- public:
- explicit Pmm(Ref<PageManager*> &pm);
-
- Pmm &operator=(const Pmm &) = delete;
- Pmm(const Pmm &) = delete;
-
- Ref<PTEWrapper*> RequestPage(Boolean user = false, Boolean readWrite = false);
- Boolean FreePage(Ref<PTEWrapper*> refPage);
-
- Boolean ToggleRw(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean TogglePresent(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean ToggleUser(Ref<PTEWrapper*> refPage, Boolean enable = true);
- Boolean ToggleShare(Ref<PTEWrapper*> refPage, Boolean enable = true);
-
- private:
- Ref<PageManager*> m_PageManager;
-
- };
-} // namespace HCore
+namespace HCore {
+class Pmm;
+class PTEWrapper;
+
+class Pmm final {
+ public:
+ explicit Pmm();
+ ~Pmm();
+
+ Pmm &operator=(const Pmm &) = delete;
+ Pmm(const Pmm &) = default;
+
+ Ref<PTEWrapper *> RequestPage(Boolean user = false,
+ Boolean readWrite = false);
+ Boolean FreePage(Ref<PTEWrapper *> refPage);
+
+ Boolean ToggleRw(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean TogglePresent(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean ToggleUser(Ref<PTEWrapper *> refPage, Boolean enable = true);
+ Boolean ToggleShare(Ref<PTEWrapper *> refPage, Boolean enable = true);
+
+ /// @brief Get the page manager of this.
+ Ref<PageManager> &Leak() { return m_PageManager; }
+
+ private:
+ Ref<PageManager> m_PageManager;
+};
+} // namespace HCore
diff --git a/Private/NewKit/Ref.hpp b/Private/NewKit/Ref.hpp
index d11f3f75..9988c213 100644
--- a/Private/NewKit/Ref.hpp
+++ b/Private/NewKit/Ref.hpp
@@ -13,76 +13,54 @@
#include <NewKit/Defines.hpp>
#include <NewKit/RuntimeCheck.hpp>
-namespace HCore
-{
- template <typename T>
- class Ref final
- {
- public:
- Ref() = default;
- ~Ref() = default;
-
- public:
- Ref(T cls, const bool &strong = false) : m_Class(cls), m_Strong(strong) {}
-
- Ref &operator=(T ref)
- {
- m_Class = ref;
- return *this;
- }
-
- public:
- T operator->() const
- {
- return m_Class;
- }
-
- T &Leak()
- {
- return m_Class;
- }
-
- T operator*()
- {
- return m_Class;
- }
-
- bool IsStrong() const
- {
- return m_Strong;
- }
-
- operator bool()
- {
- return m_Class;
- }
-
- private:
- T m_Class;
- bool m_Strong{ false };
-
- };
-
- template <typename T>
- class NonNullRef final
- {
- public:
- NonNullRef() = delete;
- NonNullRef(nullPtr) = delete;
-
- NonNullRef(T *ref) : m_Ref(ref, true) {}
-
- Ref<T> &operator->()
- {
- MUST_PASS(m_Ref);
- return m_Ref;
- }
-
- NonNullRef &operator=(const NonNullRef<T> &ref) = delete;
- NonNullRef(const NonNullRef<T> &ref) = default;
-
- private:
- Ref<T> m_Ref{nullptr};
-
- };
-} // namespace HCore
+namespace HCore {
+template <typename T>
+class Ref final {
+ public:
+ Ref() = default;
+ ~Ref() = default;
+
+ public:
+ Ref(T cls, const bool &strong = false) : m_Class(cls), m_Strong(strong) {}
+
+ Ref &operator=(T ref) {
+ m_Class = ref;
+ return *this;
+ }
+
+ public:
+ T operator->() const { return m_Class; }
+
+ T &Leak() { return m_Class; }
+
+ T operator*() { return m_Class; }
+
+ bool IsStrong() const { return m_Strong; }
+
+ operator bool() { return m_Strong; }
+
+ private:
+ T m_Class;
+ bool m_Strong{false};
+};
+
+template <typename T>
+class NonNullRef final {
+ public:
+ NonNullRef() = delete;
+ NonNullRef(nullPtr) = delete;
+
+ NonNullRef(T *ref) : m_Ref(ref, true) {}
+
+ Ref<T> &operator->() {
+ MUST_PASS(m_Ref);
+ return m_Ref;
+ }
+
+ NonNullRef &operator=(const NonNullRef<T> &ref) = delete;
+ NonNullRef(const NonNullRef<T> &ref) = default;
+
+ private:
+ Ref<T> m_Ref{nullptr};
+};
+} // namespace HCore