Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 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 { |
Rich Felker | 0b2006c | 2011-02-15 03:24:58 -0500 | [diff] [blame] | 23 | struct pthread *self; |
| 24 | unsigned long tlsdesc[4]; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 25 | pid_t tid, pid; |
Rich Felker | 0b2006c | 2011-02-15 03:24:58 -0500 | [diff] [blame] | 26 | int tsd_used, errno_val, *errno_ptr; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 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; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 36 | struct __ptcb *cancelbuf; |
| 37 | void **tsd; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 38 | pthread_attr_t attr; |
Rich Felker | 5fcebcd | 2011-03-10 18:31:37 -0500 | [diff] [blame] | 39 | volatile int dead; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 40 | }; |
| 41 | |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 42 | #define __SU (sizeof(size_t)/sizeof(int)) |
| 43 | |
| 44 | #define _a_stacksize __u.__s[0] |
| 45 | #define _a_guardsize __u.__s[1] |
| 46 | #define _a_detach __u.__i[2*__SU+0] |
| 47 | #define _m_type __u.__i[0] |
| 48 | #define _m_lock __u.__i[1] |
| 49 | #define _m_waiters __u.__i[2] |
Rich Felker | 93cc986 | 2011-03-17 13:17:15 -0400 | [diff] [blame^] | 50 | #define _m_prev __u.__p[3] |
| 51 | #define _m_next __u.__p[4] |
| 52 | #define _m_count __u.__i[5] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 53 | #define _c_block __u.__i[0] |
Rich Felker | 5fd4a98 | 2011-03-07 17:39:13 -0500 | [diff] [blame] | 54 | #define _c_clock __u.__i[1] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 55 | #define _rw_wrlock __u.__i[0] |
| 56 | #define _rw_readers __u.__i[1] |
| 57 | #define _rw_waiters __u.__i[2] |
| 58 | #define _rw_owner __u.__i[3] |
| 59 | #define _b_count __u.__i[0] |
| 60 | #define _b_limit __u.__i[1] |
| 61 | #define _b_left __u.__i[2] |
| 62 | #define _b_waiters __u.__i[3] |
| 63 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 64 | #include "pthread_arch.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 65 | |
| 66 | #define SIGCANCEL 32 |
| 67 | #define SIGSYSCALL 33 |
| 68 | #define SIGTIMER 32 /* ?? */ |
| 69 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 70 | int __set_thread_area(void *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 71 | int __libc_sigaction(int, const struct sigaction *, struct sigaction *); |
| 72 | int __libc_sigprocmask(int, const sigset_t *, sigset_t *); |
| 73 | void __lock(volatile int *); |
| 74 | void __unmapself(void *, size_t); |
| 75 | |
| 76 | int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); |
| 77 | void __wait(volatile int *, volatile int *, int, int); |
| 78 | void __wake(volatile int *, int, int); |
| 79 | |
| 80 | #define DEFAULT_STACK_SIZE (16384-PAGE_SIZE) |
| 81 | #define DEFAULT_GUARD_SIZE PAGE_SIZE |
| 82 | |
| 83 | #endif |