summaryrefslogtreecommitdiffhomepage
path: root/Private/Source/ThreadLocalStorage.cxx
blob: 8aeb0431e5ad651b2935afc2b94e95ca56d8931b (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
/*
 * ========================================================
 *
 * HCore
 * Copyright Mahrouss Logic, all rights reserved.
 *
 *  ========================================================
 */

#include <KernelKit/ProcessManager.hpp>
#include <KernelKit/ThreadLocalStorage.hxx>

/// bugs 0

/***********************************************************************************/
/// @file ThreadLocalStorage.cxx
/// @brief TLS implementation in kernel.
/***********************************************************************************/

using namespace HCore;

/**
 * Check for cookie inside TIB.
 * @param ptr
 * @return if the cookie is enabled.
 */
Boolean hcore_tls_check(VoidPtr ptr) {
  if (!ptr) return false;

  const char* _ptr = (const char*)ptr;

  kcout << "TLS: Checking for cookie...\n";

  return _ptr[0] == kCookieMag0 && _ptr[1] == kCookieMag1 &&
         _ptr[2] == kCookieMag2;
}

/**
 * System call implementation in HCore
 * @param ptr
 * @return
 */
Void hcore_tls_check_syscall_impl(ThreadInformationBlock ptr) noexcept {
  if (!hcore_tls_check(ptr.Cookie)) {
    kcout << "TLS: Verification failure, Crashing...\n";
    ProcessManager::Shared().Leak().GetCurrent().Leak().Crash();
  }

  kcout << "TLS: Verification succeeded! Keeping on...\n";
}