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> |
Rich Felker | 11c531e | 2011-05-30 01:41:23 -0400 | [diff] [blame] | 15 | #include <locale.h> |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 16 | #include "libc.h" |
| 17 | #include "syscall.h" |
| 18 | #include "atomic.h" |
| 19 | #include "futex.h" |
| 20 | |
| 21 | #define pthread __pthread |
| 22 | |
| 23 | struct pthread { |
Rich Felker | 0b2006c | 2011-02-15 03:24:58 -0500 | [diff] [blame] | 24 | struct pthread *self; |
| 25 | unsigned long tlsdesc[4]; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 26 | pid_t tid, pid; |
Rich Felker | 0b2006c | 2011-02-15 03:24:58 -0500 | [diff] [blame] | 27 | int tsd_used, errno_val, *errno_ptr; |
Rich Felker | feee989 | 2011-04-17 11:43:03 -0400 | [diff] [blame] | 28 | volatile uintptr_t cp_sp, cp_ip; |
| 29 | volatile int cancel, canceldisable, cancelasync; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 30 | unsigned char *map_base; |
| 31 | size_t map_size; |
| 32 | void *start_arg; |
| 33 | void *(*start)(void *); |
| 34 | void *result; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 35 | int detached; |
| 36 | int exitlock; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 37 | struct __ptcb *cancelbuf; |
| 38 | void **tsd; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 39 | pthread_attr_t attr; |
Rich Felker | 5fcebcd | 2011-03-10 18:31:37 -0500 | [diff] [blame] | 40 | volatile int dead; |
Rich Felker | 047e434 | 2011-03-17 20:41:37 -0400 | [diff] [blame] | 41 | struct { |
| 42 | void **head; |
| 43 | long off; |
| 44 | void *pending; |
| 45 | } robust_list; |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 46 | int unblock_cancel; |
Rich Felker | 82171d6 | 2011-04-09 02:23:33 -0400 | [diff] [blame] | 47 | int delete_timer; |
Rich Felker | 11c531e | 2011-05-30 01:41:23 -0400 | [diff] [blame] | 48 | locale_t locale; |
Rich Felker | 7779dbd | 2011-06-14 01:35:51 -0400 | [diff] [blame] | 49 | int killlock; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 52 | struct __timer { |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 53 | int timerid; |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 54 | pthread_t thread; |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 57 | #define __SU (sizeof(size_t)/sizeof(int)) |
| 58 | |
| 59 | #define _a_stacksize __u.__s[0] |
| 60 | #define _a_guardsize __u.__s[1] |
| 61 | #define _a_detach __u.__i[2*__SU+0] |
| 62 | #define _m_type __u.__i[0] |
| 63 | #define _m_lock __u.__i[1] |
| 64 | #define _m_waiters __u.__i[2] |
Rich Felker | 93cc986 | 2011-03-17 13:17:15 -0400 | [diff] [blame] | 65 | #define _m_prev __u.__p[3] |
| 66 | #define _m_next __u.__p[4] |
| 67 | #define _m_count __u.__i[5] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 68 | #define _c_block __u.__i[0] |
Rich Felker | 5fd4a98 | 2011-03-07 17:39:13 -0500 | [diff] [blame] | 69 | #define _c_clock __u.__i[1] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 70 | #define _rw_wrlock __u.__i[0] |
| 71 | #define _rw_readers __u.__i[1] |
| 72 | #define _rw_waiters __u.__i[2] |
| 73 | #define _rw_owner __u.__i[3] |
Rich Felker | f16a308 | 2011-05-06 20:00:59 -0400 | [diff] [blame] | 74 | #define _b_inst __u.__p[0] |
| 75 | #define _b_limit __u.__i[2] |
| 76 | #define _b_lock __u.__i[3] |
| 77 | #define _b_waiters __u.__i[4] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 78 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 79 | #include "pthread_arch.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 80 | |
Rich Felker | 99b8a25 | 2011-05-07 23:23:58 -0400 | [diff] [blame] | 81 | #define SIGTIMER 32 |
| 82 | #define SIGCANCEL 33 |
Rich Felker | acb0480 | 2011-07-29 22:59:44 -0400 | [diff] [blame] | 83 | #define SIGSYNCCALL 34 |
Rich Felker | 99b8a25 | 2011-05-07 23:23:58 -0400 | [diff] [blame] | 84 | |
Rich Felker | 4c4e22d | 2011-05-07 23:37:10 -0400 | [diff] [blame] | 85 | #define SIGPT_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \ |
Rich Felker | f09e78d | 2011-06-13 20:37:52 -0400 | [diff] [blame] | 86 | [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) |
Rich Felker | 4c4e22d | 2011-05-07 23:37:10 -0400 | [diff] [blame] | 87 | #define SIGTIMER_SET ((sigset_t *)(unsigned long [1+(sizeof(long)==4)]){ \ |
| 88 | 0x80000000 }) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 89 | |
Rich Felker | dba68bf | 2011-07-30 08:02:14 -0400 | [diff] [blame^] | 90 | pthread_t __pthread_self_init(void); |
| 91 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 92 | int __set_thread_area(void *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 93 | int __libc_sigaction(int, const struct sigaction *, struct sigaction *); |
| 94 | int __libc_sigprocmask(int, const sigset_t *, sigset_t *); |
| 95 | void __lock(volatile int *); |
| 96 | void __unmapself(void *, size_t); |
| 97 | |
| 98 | int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); |
Rich Felker | feee989 | 2011-04-17 11:43:03 -0400 | [diff] [blame] | 99 | int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 100 | void __wait(volatile int *, volatile int *, int, int); |
| 101 | void __wake(volatile int *, int, int); |
| 102 | |
Rich Felker | acb0480 | 2011-07-29 22:59:44 -0400 | [diff] [blame] | 103 | void __synccall_lock(); |
| 104 | void __synccall_unlock(); |
Rich Felker | b2486a8 | 2011-04-06 20:27:07 -0400 | [diff] [blame] | 105 | |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 106 | #define DEFAULT_STACK_SIZE (16384-PAGE_SIZE) |
| 107 | #define DEFAULT_GUARD_SIZE PAGE_SIZE |
| 108 | |
| 109 | #endif |