d751f197fde08a22e323bb5a52ddbee1ec6ed1fd
[musl] / src / internal / pthread_impl.h
1 #ifndef _PTHREAD_IMPL_H
2 #define _PTHREAD_IMPL_H
3
4 #include <pthread.h>
5 #include <sched.h>
6 #include <signal.h>
7 #include <unistd.h>
8 #include <sys/mman.h>
9 #include <errno.h>
10 #include <limits.h>
11 #include <inttypes.h>
12 #include <setjmp.h>
13 #include <string.h>
14 #include <time.h>
15 #include "libc.h"
16 #include "syscall.h"
17 #include "atomic.h"
18 #include "futex.h"
19
20 #define pthread __pthread
21
22 struct pthread {
23         struct pthread *self;
24         unsigned long tlsdesc[4];
25         pid_t tid, pid;
26         int tsd_used, errno_val, *errno_ptr;
27         volatile int canceldisable, cancelasync, cancelpoint, cancel;
28         unsigned char *map_base;
29         size_t map_size;
30         void *start_arg;
31         void *(*start)(void *);
32         void *result;
33         jmp_buf exit_jmp_buf;
34         int detached;
35         int exitlock;
36         struct __ptcb *cancelbuf;
37         void **tsd;
38         pthread_attr_t attr;
39 };
40
41 static inline struct pthread *__pthread_self()
42 {
43         struct pthread *self;
44         __asm__ ("movl %%gs:0,%0" : "=r" (self) );
45         return self;
46 }
47
48 #define SIGCANCEL 32
49 #define SIGSYSCALL 33
50 #define SIGTIMER  32 /* ?? */
51
52 int __set_thread_area(unsigned long *);
53 int __set_pthread_self(void *);
54 int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
55 int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
56 void __lock(volatile int *);
57 void __unmapself(void *, size_t);
58
59 int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int);
60 void __wait(volatile int *, volatile int *, int, int);
61 void __wake(volatile int *, int, int);
62
63 #define DEFAULT_STACK_SIZE (16384-PAGE_SIZE)
64 #define DEFAULT_GUARD_SIZE PAGE_SIZE
65
66 #endif