diff options
| author | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
|---|---|---|
| committer | Amlal <amlal.elmahrouss@icloud.com> | 2024-10-28 07:01:58 +0100 |
| commit | e0024d9ea688ee91a77abc0e28c5ea24b13ca67d (patch) | |
| tree | a4e29bd919cbeccf2689e81a5d52bfc02f2a8b77 /dev/ZKAKit/src/ThreadLocalStorage.cc | |
| parent | 36a3600ff7fc65a63b7386b7a680dbe8e647bd8f (diff) | |
IMP: Refactor whole source code to make it even.
- That is because previously the source was both in lowercase and lettercase.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/ZKAKit/src/ThreadLocalStorage.cc')
| -rw-r--r-- | dev/ZKAKit/src/ThreadLocalStorage.cc | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/dev/ZKAKit/src/ThreadLocalStorage.cc b/dev/ZKAKit/src/ThreadLocalStorage.cc new file mode 100644 index 00000000..8c75d522 --- /dev/null +++ b/dev/ZKAKit/src/ThreadLocalStorage.cc @@ -0,0 +1,67 @@ +/* + * ======================================================== + * + * minoskrnl + * Copyright ZKA Web Services Co., all rights reserved. + * + * ======================================================== + */ + +#include <NewKit/String.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->f_ThreadRecord) + return false; + + IEncoderObject encoder; + const char* tib_as_bytes = encoder.AsBytes(tib_ptr); + + kcout << "Checking for a valid cookie inside 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 << "Failing because of an invalid TIB...\r"; + return false; + } + + THREAD_INFORMATION_BLOCK* tib = (THREAD_INFORMATION_BLOCK*)tib_ptr; + + if (!tls_check_tib(tib)) + { + kcout << "Crashing because of an invalid TIB...\r"; + return false; + } + + kcout << "Verification succeeded! staying alive...\r"; + return true; +} |
