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; |
Rich Felker | 58aa5f4 | 2012-05-03 20:42:45 -0400 | [diff] [blame] | 25 | void *dtv, *unused1, *unused2; |
| 26 | uintptr_t sysinfo; |
| 27 | uintptr_t canary; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 28 | pid_t tid, pid; |
Rich Felker | 0b2006c | 2011-02-15 03:24:58 -0500 | [diff] [blame] | 29 | int tsd_used, errno_val, *errno_ptr; |
Rich Felker | feee989 | 2011-04-17 11:43:03 -0400 | [diff] [blame] | 30 | volatile int cancel, canceldisable, cancelasync; |
Rich Felker | bbbe87e | 2012-07-12 11:23:43 -0400 | [diff] [blame] | 31 | int detached; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 32 | unsigned char *map_base; |
| 33 | size_t map_size; |
| 34 | void *start_arg; |
| 35 | void *(*start)(void *); |
| 36 | void *result; |
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 | bbbe87e | 2012-07-12 11:23:43 -0400 | [diff] [blame] | 49 | int killlock[2]; |
| 50 | int exitlock[2]; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 51 | }; |
| 52 | |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 53 | struct __timer { |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 54 | int timerid; |
Rich Felker | bf619d8 | 2011-03-29 12:58:22 -0400 | [diff] [blame] | 55 | pthread_t thread; |
Rich Felker | 70c31c7 | 2011-03-29 10:05:57 -0400 | [diff] [blame] | 56 | }; |
| 57 | |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 58 | #define __SU (sizeof(size_t)/sizeof(int)) |
| 59 | |
| 60 | #define _a_stacksize __u.__s[0] |
| 61 | #define _a_guardsize __u.__s[1] |
Rich Felker | 819006a | 2012-06-09 19:53:29 -0400 | [diff] [blame] | 62 | #define _a_stackaddr __u.__s[2] |
| 63 | #define _a_detach __u.__i[3*__SU+0] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 64 | #define _m_type __u.__i[0] |
| 65 | #define _m_lock __u.__i[1] |
| 66 | #define _m_waiters __u.__i[2] |
Rich Felker | 93cc986 | 2011-03-17 13:17:15 -0400 | [diff] [blame] | 67 | #define _m_prev __u.__p[3] |
| 68 | #define _m_next __u.__p[4] |
| 69 | #define _m_count __u.__i[5] |
Rich Felker | cba4e1c | 2011-09-25 02:38:03 -0400 | [diff] [blame] | 70 | #define _c_mutex __u.__p[0] |
Rich Felker | 729d636 | 2011-09-26 00:25:13 -0400 | [diff] [blame] | 71 | #define _c_seq __u.__i[2] |
Rich Felker | cba4e1c | 2011-09-25 02:38:03 -0400 | [diff] [blame] | 72 | #define _c_waiters __u.__i[3] |
| 73 | #define _c_clock __u.__i[4] |
Rich Felker | 729d636 | 2011-09-26 00:25:13 -0400 | [diff] [blame] | 74 | #define _c_lock __u.__i[5] |
| 75 | #define _c_lockwait __u.__i[6] |
Rich Felker | 1fa0521 | 2011-09-26 12:54:28 -0400 | [diff] [blame] | 76 | #define _c_waiters2 __u.__i[7] |
Rich Felker | 5a2e180 | 2011-10-02 22:58:28 -0400 | [diff] [blame] | 77 | #define _c_destroy __u.__i[8] |
Rich Felker | 50304f2 | 2011-08-03 10:21:32 -0400 | [diff] [blame] | 78 | #define _rw_lock __u.__i[0] |
| 79 | #define _rw_waiters __u.__i[1] |
Rich Felker | 6016457 | 2011-09-27 13:50:29 -0400 | [diff] [blame] | 80 | #define _b_lock __u.__i[0] |
| 81 | #define _b_waiters __u.__i[1] |
Rich Felker | f16a308 | 2011-05-06 20:00:59 -0400 | [diff] [blame] | 82 | #define _b_limit __u.__i[2] |
Rich Felker | 6016457 | 2011-09-27 13:50:29 -0400 | [diff] [blame] | 83 | #define _b_count __u.__i[3] |
Rich Felker | 9cee930 | 2011-09-28 18:57:18 -0400 | [diff] [blame] | 84 | #define _b_waiters2 __u.__i[4] |
Rich Felker | 9ae1cf6 | 2012-05-21 22:51:30 -0400 | [diff] [blame] | 85 | #define _b_inst __u.__p[3] |
Rich Felker | e882756 | 2011-02-17 17:16:20 -0500 | [diff] [blame] | 86 | |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 87 | #include "pthread_arch.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 88 | |
Rich Felker | 99b8a25 | 2011-05-07 23:23:58 -0400 | [diff] [blame] | 89 | #define SIGTIMER 32 |
| 90 | #define SIGCANCEL 33 |
Rich Felker | acb0480 | 2011-07-29 22:59:44 -0400 | [diff] [blame] | 91 | #define SIGSYNCCALL 34 |
Rich Felker | 99b8a25 | 2011-05-07 23:23:58 -0400 | [diff] [blame] | 92 | |
Rich Felker | 2f43704 | 2012-08-09 22:52:13 -0400 | [diff] [blame] | 93 | #define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) |
| 94 | #define SIGPT_SET \ |
| 95 | ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \ |
Rich Felker | f09e78d | 2011-06-13 20:37:52 -0400 | [diff] [blame] | 96 | [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) |
Rich Felker | 2f43704 | 2012-08-09 22:52:13 -0400 | [diff] [blame] | 97 | #define SIGTIMER_SET \ |
| 98 | ((sigset_t *)(const unsigned long [__SYSCALL_SSLEN/sizeof(long)]){ \ |
Rich Felker | 4c4e22d | 2011-05-07 23:37:10 -0400 | [diff] [blame] | 99 | 0x80000000 }) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 100 | |
Rich Felker | dba68bf | 2011-07-30 08:02:14 -0400 | [diff] [blame] | 101 | pthread_t __pthread_self_init(void); |
| 102 | |
Rich Felker | 3f72cda | 2011-09-18 10:14:37 -0400 | [diff] [blame] | 103 | int __clone(int (*)(void *), void *, int, void *, ...); |
Rich Felker | 7b2dd22 | 2011-02-15 03:56:52 -0500 | [diff] [blame] | 104 | int __set_thread_area(void *); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 105 | int __libc_sigaction(int, const struct sigaction *, struct sigaction *); |
| 106 | int __libc_sigprocmask(int, const sigset_t *, sigset_t *); |
| 107 | void __lock(volatile int *); |
| 108 | void __unmapself(void *, size_t); |
| 109 | |
Rich Felker | ec381af | 2011-08-02 21:11:36 -0400 | [diff] [blame] | 110 | int __timedwait(volatile int *, int, clockid_t, const struct timespec *, void (*)(void *), void *, int); |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 111 | void __wait(volatile int *, volatile int *, int, int); |
| 112 | void __wake(volatile int *, int, int); |
| 113 | |
Rich Felker | acb0480 | 2011-07-29 22:59:44 -0400 | [diff] [blame] | 114 | void __synccall_lock(); |
| 115 | void __synccall_unlock(); |
Rich Felker | b2486a8 | 2011-04-06 20:27:07 -0400 | [diff] [blame] | 116 | |
Rich Felker | 13b3645 | 2012-06-02 20:15:37 -0400 | [diff] [blame] | 117 | #define DEFAULT_STACK_SIZE 81920 |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 118 | #define DEFAULT_GUARD_SIZE PAGE_SIZE |
| 119 | |
| 120 | #endif |