1 #ifndef _PTHREAD_IMPL_H 2 #define _PTHREAD_IMPL_H 3 4 #include <pthread.h> 5 #include <errno.h> 6 #include <limits.h> 7 #include <sys/mman.h> 8 #include "libc.h" 9 // #include "atomic.h" 10 #include "../include/features.h" 11 12 enum { 13 DT_EXITING = 0, 14 DT_JOINABLE, 15 DT_DETACHED, 16 }; 17 18 struct __timer { 19 int timerid; 20 pthread_t thread; 21 }; 22 23 #define __SU (sizeof(size_t)/sizeof(int)) 24 25 #define _a_stacksize __u.__s[0] 26 #define _a_guardsize __u.__s[1] 27 #define _a_stackaddr __u.__s[2] 28 #define _a_detach __u.__i[3*__SU+0] 29 #define _a_sched __u.__i[3*__SU+1] 30 #define _a_policy __u.__i[3*__SU+2] 31 #define _a_prio __u.__i[3*__SU+3] 32 #define _m_type __u.__i[0] 33 #define _m_lock __u.__vi[1] 34 #define _m_waiters __u.__vi[2] 35 #define _m_prev __u.__p[3] 36 #define _m_next __u.__p[4] 37 #define _m_count __u.__i[5] 38 #define _c_shared __u.__p[0] 39 #define _c_seq __u.__vi[2] 40 #define _c_waiters __u.__vi[3] 41 #define _c_clock __u.__i[4] 42 #define _c_lock __u.__vi[8] 43 #define _c_head __u.__p[1] 44 #define _c_tail __u.__p[5] 45 #define _rw_lock __u.__vi[0] 46 #define _rw_waiters __u.__vi[1] 47 #define _rw_shared __u.__i[2] 48 #define _b_lock __u.__vi[0] 49 #define _b_waiters __u.__vi[1] 50 #define _b_limit __u.__i[2] 51 #define _b_count __u.__vi[3] 52 #define _b_waiters2 __u.__vi[4] 53 #define _b_inst __u.__p[3] 54 55 #ifndef CANARY 56 #define CANARY canary 57 #endif 58 59 #ifndef DTP_OFFSET 60 #define DTP_OFFSET 0 61 #endif 62 63 #ifndef tls_mod_off_t 64 #define tls_mod_off_t size_t 65 #endif 66 67 #define SIGTIMER 32 68 #define SIGCANCEL 33 69 #define SIGSYNCCALL 34 70 71 #define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) 72 #define SIGPT_SET \ 73 ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ 74 [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) 75 #define SIGTIMER_SET \ 76 ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ 77 0x80000000 }) 78 79 void *__tls_get_addr(tls_mod_off_t *); 80 hidden int __init_tp(void *); 81 hidden void *__copy_tls(unsigned char *); 82 hidden void __reset_tls(void); 83 84 hidden void __membarrier_init(void); 85 hidden void __dl_thread_cleanup(void); 86 hidden void __testcancel(void); 87 hidden void __do_cleanup_push(struct pthread_cleanup_buffer *); 88 hidden void __do_cleanup_pop(struct pthread_cleanup_buffer *); 89 hidden void __pthread_tsd_run_dtors(void); 90 91 hidden void __pthread_key_delete_synccall(void (*)(void *), void *); 92 hidden int __pthread_key_delete_impl(pthread_key_t); 93 94 extern hidden volatile size_t __pthread_tsd_size; 95 extern hidden void *__pthread_tsd_main[]; 96 extern hidden volatile int __aio_fut; 97 extern hidden volatile int __eintr_valid_flag; 98 99 hidden int __clone(int (*)(void *), void *, int, void *, ...); 100 hidden int __thread_clone(int (*func)(void *), int flags, pthread_t *thread, unsigned char *sp); 101 hidden int __set_thread_area(void *); 102 hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); 103 hidden void __unmapself(void *, size_t); 104 105 hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); 106 hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); 107 hidden void __wait(volatile int *, volatile int *, int, int); 108 109 hidden void __acquire_ptc(void); 110 hidden void __release_ptc(void); 111 hidden void __inhibit_ptc(void); 112 113 hidden void __tl_lock(void); 114 hidden void __tl_unlock(void); 115 hidden void __tl_sync(pthread_t); 116 117 extern hidden volatile int __thread_list_lock; 118 119 extern hidden unsigned __default_stacksize; 120 extern hidden unsigned __default_guardsize; 121 122 #define DEFAULT_STACK_SIZE 131072 123 #define DEFAULT_GUARD_SIZE 8192 124 125 #define DEFAULT_STACK_MAX (8<<20) 126 #define DEFAULT_GUARD_MAX (1<<20) 127 128 #define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) 129 130 #define MUSL_TYPE_THREAD (-1) 131 #define MUSL_TYPE_PROCESS (0) 132 133 #define PTHREAD_MUTEX_TYPE_MASK 3 134 #define PTHREAD_PRIORITY_LOWEST 31 135 136 #endif 137