summaryrefslogtreecommitdiff
path: root/lib/libc/internal/include/__thread.h
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-22 23:27:56 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-22 23:30:32 +0100
commit0f30d227497418c6d3bef7d52244407e30454504 (patch)
tree0e1ac19623d3268380cf74328cdf643648a2f43c /lib/libc/internal/include/__thread.h
parent90dad97fc07f049383903a166631e2c257f9b8c1 (diff)
Added c11 threads, fixed some locks and add *_unlocked functions
Diffstat (limited to 'lib/libc/internal/include/__thread.h')
-rw-r--r--lib/libc/internal/include/__thread.h44
1 files changed, 43 insertions, 1 deletions
diff --git a/lib/libc/internal/include/__thread.h b/lib/libc/internal/include/__thread.h
index 7639707a..3c68f8dd 100644
--- a/lib/libc/internal/include/__thread.h
+++ b/lib/libc/internal/include/__thread.h
@@ -1,8 +1,50 @@
#ifndef __LIBC_THREAD_H
#define __LIBC_THREAD_H
+#include <stdatomic.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#define THREAD_STACK_SIZE (1024 * 1024)
+#define THREAD_GUARD_SIZE 8192
+
+enum __thread_state { THREAD_STATE_EXITED, THREAD_STATE_JOINABLE, THREAD_STATE_DETACHED };
+
+struct tls {
+ void *data;
+ size_t length;
+ size_t size;
+ size_t align;
+};
+
struct __thread_self {
- int tid;
+ struct __thread_self *self;
+
+ /* Backing mapping for this thread (used by thrd_join/thrd_detach to munmap safely) */
+ void *map_base;
+ size_t map_size;
+
+#ifdef __aarch64__
+ uintptr_t *dtv;
+ uintptr_t canary;
+#endif
+
+ long tid;
+ int res;
+ int errno_v;
+ volatile int state;
+
+#ifdef __x86_64__
+ uintptr_t canary;
+ uintptr_t *dtv;
+#endif
};
+void __libc_tls_copy(void *);
+
+#if defined(__x86_64__)
+long __clone(long (*fn)(void *), void *arg, unsigned long flags, void *child_stack, long *ptid, void *newtls,
+ long *ctid);
+#endif
+
#endif