blob: f5fc2d3ebc9fd5f8d4bac4d8cc4ca0e4322fd577 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* ========================================================
*
* Kernel
* Copyright ZKA Technologies, all rights reserved.
*
* ========================================================
*/
#include <KernelKit/ProcessScheduler.hxx>
#include <KernelKit/ThreadLocalStorage.hxx>
///! BUGS: 0
/***********************************************************************************/
/// @file ThreadLocalStorage.cxx
/// @brief TLS implementation in kernel.
/***********************************************************************************/
using namespace Kernel;
/**
* @brief Check for cookie inside TIB.
* @param tib the TIB to check.
* @return if the cookie is enabled.
*/
Boolean tls_check_tib(ThreadInformationBlock* tib)
{
if (!tib)
return false;
Encoder encoder;
const char* tibAsBytes = encoder.AsBytes(tib);
kcout << "newoskrnl: Checking for a valid cookie...\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 Void tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept
{
if (!TIB)
return;
ThreadInformationBlock* tib = (ThreadInformationBlock*)TIB;
if (!tls_check_tib(tib))
{
kcout << "newoskrnl: crashing because of an invalid TIB...\r";
ProcessScheduler::The().Leak().TheCurrent().Leak().Crash();
}
kcout << "newoskrnl: Verification succeeded! Keeping on...\r";
}
|