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 | feee989 | 2011-04-17 11:43:03 -0400 | [diff] [blame^] | 27 | volatile uintptr_t cp_sp, cp_ip; |
| 28 | volatile int cancel, canceldisable, cancelasync; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 29 | unsigned char *map_base; |
| 30 | size_t map_size; |
| 31 | void *start_arg; |
| 32 | void *(*start)(void *); |
| 33 | void *result; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 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 | 047e434 | 2011-03-17 20:41:37 -0400 | [diff] [blame] | 40 | struct { |
| 41 | void **head; |
| 42 | long off; |
| 43 | void *pending; |
| 44 | } robust_list; |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 45 | int unblock_cancel; |
Rich Felker | 82171d6 | 2011-04-09 02:23:33 -0400 | [diff] [blame] | 46 | int delete_timer; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 47 | }; |
| 48 | |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 49 | struct __timer { |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 50 | int timerid; |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 51 | pthread_t thread; |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 52 | }; |
| 53 | |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 54 | #define __SU (sizeof(size_t)/sizeof(int)) |
| 55 | |
| 56 | #define _a_stacksize __u.__s[0] |
| 57 | #define _a_guardsize __u.__s[1] |
| 58 | #define _a_detach __u.__i[2*__SU+0] |
| 59 | #define _m_type __u.__i[0] |
| 60 | #define _m_lock __u.__i[1] |
| 61 | #define _m_waiters __u.__i[2] |
Rich Felker | 93cc986 | 2011-03-17 13:17:15 -0400 | [diff] [blame] | 62 | #define _m_prev __u.__p[3] |
| 63 | #define _m_next __u.__p[4] |
| 64 | #define _m_count __u.__i[5] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 65 | #define _c_block __u.__i[0] |
Rich Felker | 5fd4a98 | 2011-03-07 17:39:13 -0500 | [diff] [blame] | 66 | #define _c_clock __u.__i[1] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 67 | #define _rw_wrlock __u.__i[0] |
| 68 | #define _rw_readers __u.__i[1] |
| 69 | #define _rw_waiters __u.__i[2] |
| 70 | #define _rw_owner __u.__i[3] |
| 71 | #define _b_count __u.__i[0] |
| 72 | #define _b_limit __u.__i[1] |
| 73 | #define _b_left __u.__i[2] |
| 74 | #define _b_waiters __u.__i[3] |
| 75 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 76 | #include "pthread_arch.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 77 | |
| 78 | #define SIGCANCEL 32 |
| 79 | #define SIGSYSCALL 33 |
Rich Felker | 016a5dc | 2011-04-14 12:51:00 -0400 | [diff] [blame] | 80 | #define SIGTIMER 34 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 81 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 82 | int __set_thread_area(void *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 83 | int __libc_sigaction(int, const struct sigaction *, struct sigaction *); |
| 84 | int __libc_sigprocmask(int, const sigset_t *, sigset_t *); |
| 85 | void __lock(volatile int *); |
| 86 | void __unmapself(void *, size_t); |
| 87 | |
| 88 | int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); |
Rich Felker | feee989 | 2011-04-17 11:43:03 -0400 | [diff] [blame^] | 89 | int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 90 | void __wait(volatile int *, volatile int *, int, int); |
| 91 | void __wake(volatile int *, int, int); |
| 92 | |
Rich Felker | b2486a8 | 2011-04-06 20:27:07 -0400 | [diff] [blame] | 93 | void __rsyscall_lock(); |
| 94 | void __rsyscall_unlock(); |
| 95 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 96 | #define DEFAULT_STACK_SIZE (16384-PAGE_SIZE) |
| 97 | #define DEFAULT_GUARD_SIZE PAGE_SIZE |
| 98 | |
| 99 | #endif |