79d53fc8f550457008a0dbaba18a6c616b9e4e2b
[oweals/musl.git] / 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         volatile int uselocale_cnt;
27         volatile int bytelocale_cnt_minus_1;
28         struct __locale_struct global_locale;
29 };
30
31 extern size_t __hwcap;
32
33 #ifndef PAGE_SIZE
34 #define PAGE_SIZE libc.page_size
35 #endif
36
37 #if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
38
39 #ifdef __PIC__
40 #if __GNUC__ < 4
41 #define BROKEN_VISIBILITY 1
42 #endif
43 #define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
44 #else
45 #define ATTR_LIBC_VISIBILITY
46 #endif
47
48 extern struct __libc __libc ATTR_LIBC_VISIBILITY;
49 #define libc __libc
50
51 #else
52
53 #define USE_LIBC_ACCESSOR
54 #define ATTR_LIBC_VISIBILITY
55 extern struct __libc *__libc_loc(void) __attribute__((const));
56 #define libc (*__libc_loc())
57
58 #endif
59
60
61 /* Designed to avoid any overhead in non-threaded processes */
62 void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
63 void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
64 int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
65 void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
66 #define LOCK(x) __lock(x)
67 #define UNLOCK(x) __unlock(x)
68
69 void __synccall(void (*)(void *), void *);
70 int __setxid(int, int, int, int);
71
72 extern char **__environ;
73
74 #undef weak_alias
75 #define weak_alias(old, new) \
76         extern __typeof(old) new __attribute__((weak, alias(#old)))
77
78 #undef LFS64_2
79 #define LFS64_2(x, y) weak_alias(x, y)
80
81 #undef LFS64
82 #define LFS64(x) LFS64_2(x, x##64)
83
84 #endif