037d16b6e2cddc92a5ae86b101c84cffebca23a1
[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_struct {
9         int ctype_utf8;
10         char *messages_name;
11 };
12
13 struct __libc {
14         int has_thread_pointer;
15         int can_do_threads;
16         int threaded;
17         int secure;
18         size_t *auxv;
19         volatile int threads_minus_1;
20         FILE *ofl_head;
21         int ofl_lock[2];
22         size_t tls_size;
23         size_t page_size;
24         volatile int uselocale_cnt;
25         volatile int bytelocale_cnt_minus_1;
26         struct __locale_struct global_locale;
27 };
28
29 extern size_t __hwcap;
30
31 #ifndef PAGE_SIZE
32 #define PAGE_SIZE libc.page_size
33 #endif
34
35 #if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
36
37 #ifdef __PIC__
38 #if __GNUC__ < 4
39 #define BROKEN_VISIBILITY 1
40 #endif
41 #define ATTR_LIBC_VISIBILITY __attribute__((visibility("hidden")))
42 #else
43 #define ATTR_LIBC_VISIBILITY
44 #endif
45
46 extern struct __libc __libc ATTR_LIBC_VISIBILITY;
47 #define libc __libc
48
49 #else
50
51 #define USE_LIBC_ACCESSOR
52 #define ATTR_LIBC_VISIBILITY
53 extern struct __libc *__libc_loc(void) __attribute__((const));
54 #define libc (*__libc_loc())
55
56 #endif
57
58
59 /* Designed to avoid any overhead in non-threaded processes */
60 void __lock(volatile int *) ATTR_LIBC_VISIBILITY;
61 void __unlock(volatile int *) ATTR_LIBC_VISIBILITY;
62 int __lockfile(FILE *) ATTR_LIBC_VISIBILITY;
63 void __unlockfile(FILE *) ATTR_LIBC_VISIBILITY;
64 #define LOCK(x) __lock(x)
65 #define UNLOCK(x) __unlock(x)
66
67 void __synccall(void (*)(void *), void *);
68 int __setxid(int, int, int, int);
69
70 extern char **__environ;
71
72 #undef weak_alias
73 #define weak_alias(old, new) \
74         extern __typeof(old) new __attribute__((weak, alias(#old)))
75
76 #undef LFS64_2
77 #define LFS64_2(x, y) weak_alias(x, y)
78
79 #undef LFS64
80 #define LFS64(x) LFS64_2(x, x##64)
81
82 #endif