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