move rsyscall out of pthread_create module
[musl] / src / internal / libc.h
1 #ifndef LIBC_H
2 #define LIBC_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 struct __libc {
8         int *(*errno_location)(void);
9         void (*cancelpt)(int);
10         void (*lock)(volatile int *);
11         void (*lockfile)(FILE *);
12         void (*fork_handler)(int);
13         int (*atexit)(void (*)(void));
14         void (*fini)(void);
15         void (*ldso_fini)(void);
16         volatile int threads_minus_1;
17         int ofl_lock;
18         FILE *ofl_head;
19 };
20
21
22 #if 100*__GNUC__+__GNUC_MINOR__ >= 303 || defined(__PCC__) || defined(__TINYC__)
23 extern struct __libc __libc __attribute__((visibility("hidden")));
24 #define libc __libc
25
26 #elif !defined(__PIC__)
27 extern struct __libc __libc;
28 #define libc __libc
29
30 #else
31 #define USE_LIBC_ACCESSOR
32 extern struct __libc *__libc_loc(void) __attribute__((const));
33 #define libc (*__libc_loc())
34
35 #endif
36
37
38 /* Designed to avoid any overhead in non-threaded processes */
39 void __lock(volatile int *);
40 void __lockfile(FILE *);
41 #define LOCK(x) (libc.threads_minus_1 ? (__lock(x),1) : ((void)(x),1))
42 #define UNLOCK(x) (*(x)=0)
43 #define CANCELPT(x) (libc.cancelpt ? libc.cancelpt((x)),0 : (void)(x),0)
44 #define CANCELPT_BEGIN CANCELPT(1)
45 #define CANCELPT_TRY CANCELPT(0)
46 #define CANCELPT_END CANCELPT(-1)
47 #define CANCELPT_INHIBIT CANCELPT(2)
48 #define CANCELPT_RESUME CANCELPT(-2)
49
50 int __rsyscall(int, long, long, long, long, long, long);
51
52 extern char **__environ;
53 #define environ __environ
54
55 #undef weak_alias
56 #define weak_alias(old, new) \
57         extern __typeof(old) new __attribute__((weak, alias(#old)))
58
59 #undef LFS64_2
60 //#define LFS64_2(x, y) weak_alias(x, y)
61 #define LFS64_2(x, y) extern __typeof(x) y
62
63 #undef LFS64
64 #define LFS64(x) LFS64_2(x, x##64)
65
66 #endif