From 09dd11ddf800898c00ecb04a65fb5cd10fb481fa Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Wed, 8 May 2024 12:32:41 +0200 Subject: MHR-23: :boom: changes, reworked project tree. Signed-off-by: Amlal El Mahrouss --- NewKernel/KernelKit/ThreadLocalStorage.hxx | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 NewKernel/KernelKit/ThreadLocalStorage.hxx (limited to 'NewKernel/KernelKit/ThreadLocalStorage.hxx') diff --git a/NewKernel/KernelKit/ThreadLocalStorage.hxx b/NewKernel/KernelKit/ThreadLocalStorage.hxx new file mode 100644 index 00000000..8072b867 --- /dev/null +++ b/NewKernel/KernelKit/ThreadLocalStorage.hxx @@ -0,0 +1,53 @@ +/* ------------------------------------------- + + Copyright Mahrouss Logic + +------------------------------------------- */ + +#ifndef _KERNELKIT_TLS_HPP +#define _KERNELKIT_TLS_HPP + +#include + +//! @brief TLS implementation in C++ + +#define kCookieMag0 'H' +#define kCookieMag1 'C' +#define kCookieMag2 'R' + +template +T* tls_new_ptr(void); + +template +bool tls_delete_ptr(T* ptr); + +template +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 +{ + NewOS::Char Cookie[kTLSCookieLen]; + NewOS::UIntPtr StartCode; // Start Address + NewOS::UIntPtr StartData; // Allocation Heap + NewOS::UIntPtr StartStack; // Stack Pointer. + NewOS::Int32 ThreadID; // Thread execution ID. +}; + +/// @brief TLS install TIB and PIB. +EXTERN_C void rt_install_tib(ThreadInformationBlock* TIB, NewOS::VoidPtr PIB); + +///! @brief Cookie Sanity check. +NewOS::Boolean tls_check_tib(ThreadInformationBlock* Ptr); + +/// @brief TLS check system call +EXTERN_C NewOS::Void tls_check_syscall_impl(NewOS::HAL::StackFramePtr StackPtr) noexcept; + +#include + +// last rev 1/29/24 + +#endif /* ifndef _KERNELKIT_TLS_HPP */ -- cgit v1.2.3