mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 07:02:41 +00:00
PAGE_SIZE was hardcoded to 4096, which is historically what most systems use, but on several archs it is a kernel config parameter, user space can only know it at execution time from the aux vector. PAGE_SIZE and PAGESIZE are not defined on archs where page size is a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE) to query it. Internally libc code defines PAGE_SIZE to libc.page_size, which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink as well. (Note that libc.page_size can be accessed without GOT, ie. before relocations are done) Some fpathconf settings are hardcoded to 4096, these should be actually queried from the filesystem using statfs.
24 lines
618 B
C
24 lines
618 B
C
#define _GNU_SOURCE
|
|
#include "pthread_impl.h"
|
|
#include "libc.h"
|
|
#include <sys/mman.h>
|
|
|
|
int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
|
|
{
|
|
*a = (pthread_attr_t){0};
|
|
a->_a_detach = !!t->detached;
|
|
if (t->stack) {
|
|
a->_a_stackaddr = (uintptr_t)t->stack;
|
|
a->_a_stacksize = t->stack_size - DEFAULT_STACK_SIZE;
|
|
} else {
|
|
char *p = (void *)libc.auxv;
|
|
size_t l = PAGE_SIZE;
|
|
p += -(uintptr_t)p & PAGE_SIZE-1;
|
|
a->_a_stackaddr = (uintptr_t)p;
|
|
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
|
|
l += PAGE_SIZE;
|
|
a->_a_stacksize = l - DEFAULT_STACK_SIZE;
|
|
}
|
|
return 0;
|
|
}
|