summaryrefslogtreecommitdiffhomepage
path: root/Private/KernelKit/ThreadLocalStorage.hxx
blob: 910daf31382fb9f424781f994d0ca170cdfe1d55 (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
/*
 *	========================================================
 *
 *	HCore
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#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 *hcore_tls_new_ptr(void);

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

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

typedef char rt_cookie_type[3];

/// @brief Thread Information Block for Local Storage.
/// Located in GS on AMD64, Virtual Address 0x10000 (64x0, 32x0, ARM64)
struct ThreadInformationBlock final
{
    HCore::Char Name[255];     // Module Name
    HCore::UIntPtr StartCode;  // Start Address
    HCore::UIntPtr StartData;  // Allocation Heap
    HCore::UIntPtr StartStack; // Stack Pointer.
    HCore::Int32 Arch;         // Architecture and/or platform.
    rt_cookie_type Cookie;     // Not shown in public header, this is the way we tell something went wrong.
};

/// @brief TLS install TIB
extern void rt_install_tib(ThreadInformationBlock *pTib);

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

#include "ThreadLocalStorage.inl"

// last rev 1/29/24

#endif /* ifndef _KERNELKIT_TLS_HPP */