X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Finternal%2Fpthread_impl.h;h=a89ef9ac7e1ec7b3a9606019a577d8e0b669a065;hb=49722a8ed4c8fd056ac8aebd6bec9d998b700f80;hp=a0226a6310ad2de069b730cd65d8083b7806a1df;hpb=fa80787698536ecd8b9028703a3bc2e3f59e3d65;p=musl diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index a0226a63..a89ef9ac 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "libc.h" #include "syscall.h" #include "atomic.h" @@ -13,41 +14,65 @@ #define pthread __pthread struct pthread { + /* Part 1 -- these fields may be external or + * internal (accessed via asm) ABI. Do not change. */ struct pthread *self; void **dtv, *unused1, *unused2; uintptr_t sysinfo; - uintptr_t canary; - pid_t tid, pid; - int tsd_used, errno_val; - volatile int cancel, canceldisable, cancelasync; - int detached; + uintptr_t canary, canary2; + + /* Part 2 -- implementation details, non-ABI. */ + int tid; + int errno_val; + volatile int detach_state; + volatile int cancel; + volatile unsigned char canceldisable, cancelasync; + unsigned char tsd_used:1; + unsigned char unblock_cancel:1; + unsigned char dlerror_flag:1; unsigned char *map_base; size_t map_size; void *stack; size_t stack_size; + size_t guard_size; void *start_arg; void *(*start)(void *); void *result; struct __ptcb *cancelbuf; void **tsd; - pthread_attr_t attr; - volatile int dead; struct { volatile void *volatile head; long off; volatile void *volatile pending; } robust_list; - int unblock_cancel; volatile int timer_id; locale_t locale; - volatile int killlock[2]; - volatile int exitlock[2]; - volatile int startlock[2]; - unsigned long sigmask[_NSIG/8/sizeof(long)]; + volatile int killlock[1]; + char *dlerror_buf; void *stdio_locks; + + /* Part 3 -- the positions of these fields relative to + * the end of the structure is external and internal ABI. */ + uintptr_t canary_at_end; void **dtv_copy; }; +struct start_sched_args { + void *start_arg; + void *(*start_fn)(void *); + sigset_t mask; + pthread_attr_t *attr; + volatile int futex; +}; + +enum { + DT_EXITED = 0, + DT_EXITING, + DT_JOINABLE, + DT_DETACHED, + DT_DYNAMIC, +}; + struct __timer { int timerid; pthread_t thread; @@ -87,6 +112,18 @@ struct __timer { #include "pthread_arch.h" +#ifndef CANARY +#define CANARY canary +#endif + +#ifndef DTP_OFFSET +#define DTP_OFFSET 0 +#endif + +#ifndef tls_mod_off_t +#define tls_mod_off_t size_t +#endif + #define SIGTIMER 32 #define SIGCANCEL 33 #define SIGSYNCCALL 34 @@ -99,40 +136,55 @@ struct __timer { ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ 0x80000000 }) -pthread_t __pthread_self_init(void); - -int __clone(int (*)(void *), void *, int, void *, ...); -int __set_thread_area(void *); -int __libc_sigaction(int, const struct sigaction *, struct sigaction *); -int __libc_sigprocmask(int, const sigset_t *, sigset_t *); -void __lock(volatile int *); -void __unmapself(void *, size_t); - -void __vm_wait(void); -void __vm_lock(void); -void __vm_unlock(void); - -int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); -int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); -void __wait(volatile int *, volatile int *, int, int); +void *__tls_get_addr(tls_mod_off_t *); +hidden void *__tls_get_new(tls_mod_off_t *); +hidden int __init_tp(void *); +hidden void *__copy_tls(unsigned char *); +hidden void __reset_tls(); + +hidden void __dl_thread_cleanup(void); +hidden void __fork_handler(int); +hidden void __testcancel(); +hidden void __do_cleanup_push(struct __ptcb *); +hidden void __do_cleanup_pop(struct __ptcb *); +hidden void __pthread_tsd_run_dtors(); + +extern hidden volatile int __block_new_threads; +extern hidden volatile size_t __pthread_tsd_size; +extern hidden void *__pthread_tsd_main[]; +extern hidden volatile int __aio_fut; + +hidden int __clone(int (*)(void *), void *, int, void *, ...); +hidden int __set_thread_area(void *); +hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); +hidden void __unmapself(void *, size_t); + +hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); +hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); +hidden void __wait(volatile int *, volatile int *, int, int); static inline void __wake(volatile void *addr, int cnt, int priv) { - if (priv) priv = 128; + if (priv) priv = FUTEX_PRIVATE; if (cnt<0) cnt = INT_MAX; __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || __syscall(SYS_futex, addr, FUTEX_WAKE, cnt); } +static inline void __futexwait(volatile void *addr, int val, int priv) +{ + if (priv) priv = FUTEX_PRIVATE; + __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS || + __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); +} -void __acquire_ptc(void); -void __release_ptc(void); -void __inhibit_ptc(void); +hidden void __acquire_ptc(void); +hidden void __release_ptc(void); +hidden void __inhibit_ptc(void); -void __block_all_sigs(void *); -void __block_app_sigs(void *); -void __restore_sigs(void *); +extern hidden size_t __default_stacksize; +extern hidden size_t __default_guardsize; #define DEFAULT_STACK_SIZE 81920 -#define DEFAULT_GUARD_SIZE PAGE_SIZE +#define DEFAULT_GUARD_SIZE 4096 #define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1)