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