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