always block signals for starting new threads, refactor start args
[musl] / src / thread / __unmapself.c
1 #include "pthread_impl.h"
2 #include "atomic.h"
3 #include "syscall.h"
4 /* cheat and reuse CRTJMP macro from dynlink code */
5 #include "dynlink.h"
6
7 static volatile int lock;
8 static void *unmap_base;
9 static size_t unmap_size;
10 static char shared_stack[256];
11
12 static void do_unmap()
13 {
14         __syscall(SYS_munmap, unmap_base, unmap_size);
15         __syscall(SYS_exit);
16 }
17
18 void __unmapself(void *base, size_t size)
19 {
20         int tid=__pthread_self()->tid;
21         char *stack = shared_stack + sizeof shared_stack;
22         stack -= (uintptr_t)stack % 16;
23         while (lock || a_cas(&lock, 0, tid))
24                 a_spin();
25         __syscall(SYS_set_tid_address, &lock);
26         unmap_base = base;
27         unmap_size = size;
28         CRTJMP(do_unmap, stack);
29 }