diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-16 17:02:05 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-16 17:02:05 +0100 |
| commit | 90dad97fc07f049383903a166631e2c257f9b8c1 (patch) | |
| tree | 096cd247ecfda9e46598215a4f32aecedeedda90 /lib/libc/internal/include/libc.h | |
| parent | 0e832a9329cc4d4647e1ce529846073f21e66991 (diff) | |
Add support for TLS in the libc
Diffstat (limited to 'lib/libc/internal/include/libc.h')
| -rw-r--r-- | lib/libc/internal/include/libc.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/libc/internal/include/libc.h b/lib/libc/internal/include/libc.h new file mode 100644 index 00000000..f06fa6d8 --- /dev/null +++ b/lib/libc/internal/include/libc.h @@ -0,0 +1,48 @@ +#ifndef __LIBC_LIBC_H +#define __LIBC_LIBC_H + +#include <stdatomic.h> +#include <stddef.h> +#include <sys/cdefs.h> + +#define weak_reference(old, new) extern __typeof(old)((new)) __attribute__((__weak__, __alias__(#old))) + +struct tls { + struct tls *next; + void *data; + size_t size; + size_t align; + size_t length; + size_t offset; +}; + +struct libc { + size_t auxv[32]; + struct { + void *base; + size_t size; + } tls; + + enum { + LIBC_ENVP_TOUCHED = 1 << 0, + } flags; + + struct { + volatile atomic_flag abort; + volatile atomic_flag malloc; + volatile atomic_flag environ; + } lock; +}; + +extern struct libc __libc; + +#define panic(__errmsg) __libc_panic(__FILE__ ":" __STRING(__LINE__) ": ", __PRETTY_FUNCTION__, ": " __STRING(__errmsg)) + +#define panic_if(__cond, __errmsg) \ + do { \ + if (__predict_false(__cond)) \ + panic(__errmsg); \ + } while (0) + +__dead void __libc_panic(const char *, const char *, const char *); +#endif |
