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