mips: add vdso support
[musl.git] / src / internal / pthread_impl.h
blob3890bb56fb4d122db323e513460a4c045666d741
1 #ifndef _PTHREAD_IMPL_H
2 #define _PTHREAD_IMPL_H
4 #include <pthread.h>
5 #include <signal.h>
6 #include <errno.h>
7 #include <limits.h>
8 #include "libc.h"
9 #include "syscall.h"
10 #include "atomic.h"
11 #include "futex.h"
13 #define pthread __pthread
15 struct pthread {
16 struct pthread *self;
17 void **dtv, *unused1, *unused2;
18 uintptr_t sysinfo;
19 uintptr_t canary, canary2;
20 pid_t tid, pid;
21 int tsd_used, errno_val;
22 volatile int cancel, canceldisable, cancelasync;
23 int detached;
24 unsigned char *map_base;
25 size_t map_size;
26 void *stack;
27 size_t stack_size;
28 void *start_arg;
29 void *(*start)(void *);
30 void *result;
31 struct __ptcb *cancelbuf;
32 void **tsd;
33 pthread_attr_t attr;
34 volatile int dead;
35 struct {
36 volatile void *volatile head;
37 long off;
38 volatile void *volatile pending;
39 } robust_list;
40 int unblock_cancel;
41 volatile int timer_id;
42 locale_t locale;
43 volatile int killlock[2];
44 volatile int exitlock[2];
45 volatile int startlock[2];
46 unsigned long sigmask[_NSIG/8/sizeof(long)];
47 char *dlerror_buf;
48 int dlerror_flag;
49 void *stdio_locks;
50 uintptr_t canary_at_end;
51 void **dtv_copy;
54 struct __timer {
55 int timerid;
56 pthread_t thread;
59 #define __SU (sizeof(size_t)/sizeof(int))
61 #define _a_stacksize __u.__s[0]
62 #define _a_guardsize __u.__s[1]
63 #define _a_stackaddr __u.__s[2]
64 #define _a_detach __u.__i[3*__SU+0]
65 #define _a_sched __u.__i[3*__SU+1]
66 #define _a_policy __u.__i[3*__SU+2]
67 #define _a_prio __u.__i[3*__SU+3]
68 #define _m_type __u.__i[0]
69 #define _m_lock __u.__vi[1]
70 #define _m_waiters __u.__vi[2]
71 #define _m_prev __u.__p[3]
72 #define _m_next __u.__p[4]
73 #define _m_count __u.__i[5]
74 #define _c_shared __u.__p[0]
75 #define _c_seq __u.__vi[2]
76 #define _c_waiters __u.__vi[3]
77 #define _c_clock __u.__i[4]
78 #define _c_lock __u.__vi[8]
79 #define _c_head __u.__p[1]
80 #define _c_tail __u.__p[5]
81 #define _rw_lock __u.__vi[0]
82 #define _rw_waiters __u.__vi[1]
83 #define _rw_shared __u.__i[2]
84 #define _b_lock __u.__vi[0]
85 #define _b_waiters __u.__vi[1]
86 #define _b_limit __u.__i[2]
87 #define _b_count __u.__vi[3]
88 #define _b_waiters2 __u.__vi[4]
89 #define _b_inst __u.__p[3]
91 #include "pthread_arch.h"
93 #ifndef CANARY
94 #define CANARY canary
95 #endif
97 #ifndef DTP_OFFSET
98 #define DTP_OFFSET 0
99 #endif
101 #define SIGTIMER 32
102 #define SIGCANCEL 33
103 #define SIGSYNCCALL 34
105 #define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 })
106 #define SIGPT_SET \
107 ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
108 [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) })
109 #define SIGTIMER_SET \
110 ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \
111 0x80000000 })
113 pthread_t __pthread_self_init(void);
115 int __clone(int (*)(void *), void *, int, void *, ...);
116 int __set_thread_area(void *);
117 int __libc_sigaction(int, const struct sigaction *, struct sigaction *);
118 int __libc_sigprocmask(int, const sigset_t *, sigset_t *);
119 void __lock(volatile int *);
120 void __unmapself(void *, size_t);
122 void __vm_wait(void);
123 void __vm_lock(void);
124 void __vm_unlock(void);
126 int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int);
127 int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int);
128 void __wait(volatile int *, volatile int *, int, int);
129 static inline void __wake(volatile void *addr, int cnt, int priv)
131 if (priv) priv = 128;
132 if (cnt<0) cnt = INT_MAX;
133 __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS ||
134 __syscall(SYS_futex, addr, FUTEX_WAKE, cnt);
137 void __acquire_ptc(void);
138 void __release_ptc(void);
139 void __inhibit_ptc(void);
141 void __block_all_sigs(void *);
142 void __block_app_sigs(void *);
143 void __restore_sigs(void *);
145 #define DEFAULT_STACK_SIZE 81920
146 #define DEFAULT_GUARD_SIZE PAGE_SIZE
148 #define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1)
150 #endif