summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/KernelKit/ThreadLocalStorage.hxx
diff options
context:
space:
mode:
authorAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
committerAmlal EL Mahrouss <amlalelmahrouss@icloud.com>2024-08-15 18:35:34 +0200
commitf3d931aa7cfaf96baef8383b59a8938779541ee7 (patch)
treefdb9fc51badb3dbd03e46ab0766a49d9522e13e2 /dev/Kernel/KernelKit/ThreadLocalStorage.hxx
parent86640816e8b1d3595365f1fcc8a2a9e61fb40ff1 (diff)
[IMP] Moved source code into dev/ folder.
Signed-off-by: Amlal EL Mahrouss <amlalelmahrouss@icloud.com>
Diffstat (limited to 'dev/Kernel/KernelKit/ThreadLocalStorage.hxx')
-rw-r--r--dev/Kernel/KernelKit/ThreadLocalStorage.hxx59
1 files changed, 59 insertions, 0 deletions
diff --git a/dev/Kernel/KernelKit/ThreadLocalStorage.hxx b/dev/Kernel/KernelKit/ThreadLocalStorage.hxx
new file mode 100644
index 00000000..afc4940f
--- /dev/null
+++ b/dev/Kernel/KernelKit/ThreadLocalStorage.hxx
@@ -0,0 +1,59 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef _KERNELKIT_TLS_HPP
+#define _KERNELKIT_TLS_HPP
+
+#include <NewKit/Defines.hxx>
+
+//! @brief TLS implementation in C++
+
+#define kCookieMag0 'H'
+#define kCookieMag1 'C'
+#define kCookieMag2 'R'
+
+#define kTLSCookieLen (3U)
+
+struct THREAD_INFORMATION_BLOCK;
+
+/// @brief Thread Information Block.
+/// Located in GS on AMD64, other architectures have their own stuff. (64x0, 32x0, ARM64)
+struct PACKED THREAD_INFORMATION_BLOCK final
+{
+ Kernel::Char f_Cookie[kTLSCookieLen]; // Process cookie.
+ Kernel::UIntPtr f_Code; // Start address (Instruction Pointer)
+ Kernel::UIntPtr f_Data; // Allocated Heap for process.
+ Kernel::UIntPtr f_Stack; // Application Stack pointer.
+ Kernel::Int32 f_ID; // Thread execution ID.
+ Kernel::Int64 f_UsedHeapPercent; // used heap in percent.
+ Kernel::Int64 f_FreeHeapPercent; // heap free in percent.
+};
+
+///! @brief Cookie Sanity check.
+Kernel::Boolean tls_check_tib(THREAD_INFORMATION_BLOCK* the_tib);
+
+///! @brief new ptr syscall.
+template <typename T>
+T* tls_new_ptr(void);
+
+///! @brief delete ptr syscall.
+template <typename T>
+Kernel::Boolean tls_delete_ptr(T* ptr);
+
+template <typename T, typename... Args>
+T* tls_new_class(Args&&... args);
+
+/// @brief TLS install TIB and PIB. (syscall)
+EXTERN_C void rt_install_tib(THREAD_INFORMATION_BLOCK* TIB, THREAD_INFORMATION_BLOCK* PIB);
+
+/// @brief TLS check (syscall)
+EXTERN_C Kernel::Bool tls_check_syscall_impl(Kernel::VoidPtr TIB) noexcept;
+
+#include <KernelKit/ThreadLocalStorage.inl>
+
+// last rev 7/7/24
+
+#endif /* ifndef _KERNELKIT_TLS_HPP */