From bc7870aea4c437e1a80b779eb7a968d55733d24c Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 13 Jul 2024 00:20:21 +0200 Subject: [IMP] Kernel properties (such as \KernelVersion) [REFACTOR] Rename KernelHeap to just Heap. [FIX] Scheduler's way of checking boundaries was not correct. Signed-off-by: Amlal El Mahrouss --- Kernel/Sources/ThreadLocalStorage.cxx | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'Kernel/Sources/ThreadLocalStorage.cxx') diff --git a/Kernel/Sources/ThreadLocalStorage.cxx b/Kernel/Sources/ThreadLocalStorage.cxx index f5fc2d3e..245ffa1c 100644 --- a/Kernel/Sources/ThreadLocalStorage.cxx +++ b/Kernel/Sources/ThreadLocalStorage.cxx @@ -7,6 +7,8 @@ * ======================================================== */ +#include +#include #include #include @@ -14,11 +16,13 @@ /***********************************************************************************/ /// @file ThreadLocalStorage.cxx -/// @brief TLS implementation in kernel. +/// @brief TLS inside the kernel. /***********************************************************************************/ using namespace Kernel; +Kernel::Property cTLSEnforceCheck; + /** * @brief Check for cookie inside TIB. * @param tib the TIB to check. @@ -33,7 +37,7 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) Encoder encoder; const char* tibAsBytes = encoder.AsBytes(tib); - kcout << "newoskrnl: Checking for a valid cookie...\r"; + kcout << "newoskrnl: checking for a valid cookie...\r"; return tibAsBytes[0] == kCookieMag0 && tibAsBytes[1] == kCookieMag1 && tibAsBytes[2] == kCookieMag2; @@ -44,18 +48,28 @@ Boolean tls_check_tib(ThreadInformationBlock* tib) * @param stackPtr The call frame. * @return */ -EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept +EXTERN_C Void tls_check_syscall_impl(Kernel::VoidPtr tib_ptr) noexcept { - if (!TIB) - return; + if (!tib_ptr) + { + if (cTLSEnforceCheck.GetValue() == No) + { + return; + } + else + { + kcout << "newoskrnl: crashing because of an invalid TIB...\r"; + ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); + } + } - ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB; + ThreadInformationBlock* tib_struct = (ThreadInformationBlock*)tib_ptr; - if (!tls_check_tib(tib)) + if (!tls_check_tib(tib_struct)) { kcout << "newoskrnl: crashing because of an invalid TIB...\r"; ProcessScheduler::The().Leak().TheCurrent().Leak().Crash(); } - kcout << "newoskrnl: Verification succeeded! Keeping on...\r"; + kcout << "newoskrnl: Verification succeeded! staying alive...\r"; } -- cgit v1.2.3