diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-18 21:39:29 +0200 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-08-18 21:39:29 +0200 |
| commit | da70596895d8135e08f8caac6978117697b4c021 (patch) | |
| tree | 2516785b5434df8453687f05dc8dd877438901ab /dev/ZKA/Sources/ThreadLocalStorage.cxx | |
| parent | 005de79004c9d30e64bdee6e14e06f9d47d1f2ab (diff) | |
[REFACTOR]
Improved project structure.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKA/Sources/ThreadLocalStorage.cxx')
| -rw-r--r-- | dev/ZKA/Sources/ThreadLocalStorage.cxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/dev/ZKA/Sources/ThreadLocalStorage.cxx b/dev/ZKA/Sources/ThreadLocalStorage.cxx new file mode 100644 index 00000000..f258fa11 --- /dev/null +++ b/dev/ZKA/Sources/ThreadLocalStorage.cxx @@ -0,0 +1,76 @@ +/* + * ======================================================== + * + * Kernel + * Copyright ZKA Technologies., all rights reserved. + * + * ======================================================== + */ + +#include <NewKit/String.hxx> +#include <CFKit/Property.hxx> +#include <KernelKit/ProcessScheduler.hxx> +#include <KernelKit/ThreadLocalStorage.hxx> + +///! BUGS: 0 + +/***********************************************************************************/ +/// @file ThreadLocalStorage.cxx +/// @brief TLS inside the kernel. +/***********************************************************************************/ + +using namespace Kernel; + +Kernel::Property cTLSEnforceCheck; + +/** + * @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) + return false; + + Encoder encoder; + const char* tibAsBytes = encoder.AsBytes(the_tib); + + kcout << "newoskrnl: 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 stackPtr The call frame. + * @return + */ +EXTERN_C Bool tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept +{ + if (!tib_ptr) + { + if (cTLSEnforceCheck.GetValue() == No) + { + return true; + } + else + { + kcout << "newoskrnl: 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 << "newoskrnl: crashing because of an invalid TIB...\r"; + return false; + } + + kcout << "newoskrnl: Verification succeeded! staying alive...\r"; + return true; +} |
