summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/src/ThreadLocalStorage.cc
diff options
context:
space:
mode:
authorAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:13 +0100
committerAmlal <amlalelmahrouss@icloud.com>2024-12-21 21:59:45 +0100
commit610f91d87152cbe48d3054fcf437d8239da6ef35 (patch)
treea386f7047ab73d088169ab2371ddc6ffe8020f1c /dev/Kernel/src/ThreadLocalStorage.cc
parent509fcca5986651c8ba712fb395f8498f2dea4109 (diff)
IMP: :boom: Breaking changes some checks are needed to be done.
Signed-off-by: Amlal <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/src/ThreadLocalStorage.cc')
-rw-r--r--dev/Kernel/src/ThreadLocalStorage.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/dev/Kernel/src/ThreadLocalStorage.cc b/dev/Kernel/src/ThreadLocalStorage.cc
new file mode 100644
index 00000000..e765f6a0
--- /dev/null
+++ b/dev/Kernel/src/ThreadLocalStorage.cc
@@ -0,0 +1,67 @@
+/*
+ * ========================================================
+ *
+ * minoskrnl
+ * Copyright (C) 2024, TQ B.V, all rights reserved., all rights reserved.
+ *
+ * ========================================================
+ */
+
+#include <NewKit/KString.h>
+#include <CFKit/Property.h>
+#include <KernelKit/UserProcessScheduler.h>
+#include <KernelKit/ThreadLocalStorage.h>
+
+/***********************************************************************************/
+/// @bugs: 0
+/// @file ThreadLocalStorage.cc
+/// @brief Process Thread Local Storage.
+/***********************************************************************************/
+
+using namespace Kernel;
+
+/**
+ * @brief Checks for cookie inside the TIB.
+ * @param tib_ptr the TIB to check.
+ * @return if the cookie is enabled, true; false otherwise
+ */
+
+Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* tib_ptr)
+{
+ if (!tib_ptr ||
+ !tib_ptr->Record)
+ return false;
+
+ ICodec encoder;
+ const Char* tib_as_bytes = encoder.AsBytes(tib_ptr);
+
+ kcout << "TLS: Validating the TIB...\r";
+
+ return tib_as_bytes[0] == kCookieMag0 && tib_as_bytes[1] == kCookieMag1 &&
+ tib_as_bytes[2] == kCookieMag2;
+}
+
+/**
+ * @brief System call implementation of the TLS check.
+ * @param tib_ptr The TIB record.
+ * @return
+ */
+EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept
+{
+ if (!tib_ptr)
+ {
+ kcout << "TLS: Failing because of an invalid TIB...\r";
+ return false;
+ }
+
+ THREAD_INFORMATION_BLOCK* tib = (THREAD_INFORMATION_BLOCK*)tib_ptr;
+
+ if (!tls_check_tib(tib))
+ {
+ kcout << "TLS: Failing because of an invalid TIB...\r";
+ return false;
+ }
+
+ kcout << "TLS Check pass.\r";
+ return true;
+}