summaryrefslogtreecommitdiffhomepage
path: root/Kernel/KernelKit/ThreadLocalStorage.hxx
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/KernelKit/ThreadLocalStorage.hxx
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/KernelKit/ThreadLocalStorage.hxx')
-rw-r--r--Kernel/KernelKit/ThreadLocalStorage.hxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/Kernel/KernelKit/ThreadLocalStorage.hxx b/Kernel/KernelKit/ThreadLocalStorage.hxx
new file mode 100644
index 00000000..eece3cbc
--- /dev/null
+++ b/Kernel/KernelKit/ThreadLocalStorage.hxx
@@ -0,0 +1,53 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#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 'R'
+
+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
+{
+ 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 <KernelKit/ThreadLocalStorage.inl>
+
+// last rev 1/29/24
+
+#endif /* ifndef _KERNELKIT_TLS_HPP */