eliminate costly tricks to avoid TLS access for current locale state
[musl] / src / internal / libc.h
1 #ifndef LIBC_H
2 #define LIBC_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <limits.h>
7
8 struct __locale_map;
9
10 struct __locale_struct {
11         volatile int ctype_utf8;
12         char *messages_name;
13         struct __locale_map *volatile cat[4];
14 };
15
16 struct __libc {
17         int can_do_threads;
18         int threaded;
19         int secure;
20         volatile int threads_minus_1;
21         size_t *auxv;
22         FILE *ofl_head;
23         volatile int ofl_lock[2];
24         size_t tls_size;
25         size_t page_size;
26         struct __locale_struct global_locale;
27 };
28
29 #ifndef PAGE_SIZE
30 #define PAGE_SIZE libc.page_size
31 #endif
32
33 #ifdef __PIC__
34 #define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
35 #else
36 #define ATTR_LIBC_VISIBILITY
37 #endif
38
39 extern struct __libc __libc ATTR_LIBC_VISIBILITY;
40 #define libc __libc
41
42 extern size_t __hwcap ATTR_LIBC_VISIBILITY;
43 extern size_t __sysinfo ATTR_LIBC_VISIBILITY;
44 extern char *__progname, *__progname_full;
45
46 /* Designed to avoid any overhead in non-threaded processes */
47 void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
48 void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
49 int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
50 void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
51 #define LOCK(x) __lock(x)
52 #define UNLOCK(x) __unlock(x)
53
54 void __synccall(void (*)(void *), void *);
55 int __setxid(int, int, int, int);
56
57 extern char **__environ;
58
59 #undef weak_alias
60 #define weak_alias(old, new) \
61         extern __typeof(old) new __attribute__((weak, alias(#old)))
62
63 #undef LFS64_2
64 #define LFS64_2(x, y) weak_alias(x, y)
65
66 #undef LFS64
67 #define LFS64(x) LFS64_2(x, x##64)
68
69 #endif