diff options
| author | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
|---|---|---|
| committer | Amlal <amlal@el-mahrouss-logic.com> | 2024-09-22 17:46:11 +0200 |
| commit | 8719b4570a2d10dd49a0d3a47e24f5c55bdda85e (patch) | |
| tree | ba095740888f3768e08b2ea058b0ea6da2d0403d /dev/zka/src/ThreadLocalStorage.cxx | |
| parent | 45944b3d2dab04b763fcc6d10164fe8069e60b08 (diff) | |
:boom: A big refactor on the filesystem structure.
Signed-off-by: Amlal <amlal@el-mahrouss-logic.com>
Diffstat (limited to 'dev/zka/src/ThreadLocalStorage.cxx')
| -rw-r--r-- | dev/zka/src/ThreadLocalStorage.cxx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/dev/zka/src/ThreadLocalStorage.cxx b/dev/zka/src/ThreadLocalStorage.cxx new file mode 100644 index 00000000..587edafd --- /dev/null +++ b/dev/zka/src/ThreadLocalStorage.cxx @@ -0,0 +1,68 @@ +/* + * ======================================================== + * + * newoskrnl + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include <NewKit/String.hxx> +#include <CFKit/Property.hxx> +#include <KernelKit/UserProcessScheduler.hxx> +#include <KernelKit/ThreadLocalStorage.hxx> + +///! BUGS: 0 + +/***********************************************************************************/ +/// @file ThreadLocalStorage.cxx +/// @brief TLS inside the Kernel. +/***********************************************************************************/ + +using namespace Kernel; + +/** + * @brief Checks for cookie inside the TIB. + * @param tib the TIB to check. + * @return if the cookie is enabled. + */ + +Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib) +{ + if (!the_tib || + !the_tib->f_ThreadRecord) + return false; + + IEncoderObject encoder; + const char* tibAsBytes = encoder.AsBytes(the_tib); + + kcout << "checking for a valid cookie inside the TIB...\r"; + + return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && + tibAsBytes[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 << "failing because of an invalid TIB...\r"; + return false; + } + + THREAD_INFORMATION_BLOCK* tib_struct = (THREAD_INFORMATION_BLOCK*)tib_ptr; + + if (!tls_check_tib(tib_struct)) + { + kcout << "crashing because of an invalid TIB...\r"; + return false; + } + + kcout << "Verification succeeded! staying alive...\r"; + return true; +} |
