summaryrefslogtreecommitdiffhomepage
path: root/Private/KernelKit/ThreadLocalStorage.hxx
blob: c6be2c2b0db5573c9226fc5be4092d6801f17133 (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
/* -------------------------------------------

    Copyright Mahrouss Logic

------------------------------------------- */

#ifndef _KERNELKIT_TLS_HPP
#define _KERNELKIT_TLS_HPP

#include <NewKit/Defines.hpp>

//! @brief TLS implementation in C++

#define kCookieMag0 'h'
#define kCookieMag1 'C'
#define kCookieMag2 'o'

template <typename T>
T *tls_new_ptr(void);

template <typename T>
bool tls_delete_ptr(T *ptr);

template <typename T, typename... Args>
T *tls_new_class(Args &&...args);

#define kTLSCookieLen 3

/// @brief Thread Information Block for Local Storage.
/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64)
struct PACKED ThreadInformationBlock final {
  HCore::Char    Cookie[kTLSCookieLen];
  HCore::UIntPtr StartCode;       // Start Address
  HCore::UIntPtr StartData;       // Allocation Heap
  HCore::UIntPtr StartStack;      // Stack Pointer.
  HCore::Int32   ThreadID;                // Thread execution ID.
};

/// @brief TLS install TIB
EXTERN_C void rt_install_tib(ThreadInformationBlock *pTib, HCore::VoidPtr pPib);

///! @brief Cookie Sanity check.
HCore::Boolean tls_check_tib(ThreadInformationBlock* ptr);

/// @brief TLS check system call
EXTERN_C HCore::Void tls_check_syscall_impl(HCore::HAL::StackFramePtr stackPtr) noexcept;

#include <KernelKit/ThreadLocalStorage.inl>

// last rev 1/29/24

#endif /* ifndef _KERNELKIT_TLS_HPP */