| 1 |
#define _GNU_SOURCE |
| 2 |
#include "pthread_impl.h" |
| 3 |
#include "libc.h" |
| 4 |
#ifdef __wasilibc_unmodified_upstream |
| 5 |
#include <sys/mman.h> |
| 6 |
#endif |
| 7 |
|
| 8 |
int pthread_getattr_np(pthread_t t, pthread_attr_t *a) |
| 9 |
{ |
| 10 |
*a = (pthread_attr_t){0}; |
| 11 |
a->_a_detach = t->detach_state>=DT_DETACHED; |
| 12 |
a->_a_guardsize = t->guard_size; |
| 13 |
if (t->stack) { |
| 14 |
a->_a_stackaddr = (uintptr_t)t->stack; |
| 15 |
a->_a_stacksize = t->stack_size; |
| 16 |
} else { |
| 17 |
#ifdef __wasilibc_unmodified_upstream |
| 18 |
char *p = (void *)libc.auxv; |
| 19 |
size_t l = PAGE_SIZE; |
| 20 |
p += -(uintptr_t)p & PAGE_SIZE-1; |
| 21 |
a->_a_stackaddr = (uintptr_t)p; |
| 22 |
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM) |
| 23 |
l += PAGE_SIZE; |
| 24 |
a->_a_stacksize = l; |
| 25 |
#else |
| 26 |
return ENOSYS; |
| 27 |
#endif |
| 28 |
} |
| 29 |
return 0; |
| 30 |
} |