mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-08-15 06:09:41 +00:00
Add support for pthread_getattr_np (#470)
This commit is contained in:
parent
a1b4def387
commit
c8ef60ad9b
1
Makefile
1
Makefile
@ -258,6 +258,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
|
|||||||
thread/pthread_create.c \
|
thread/pthread_create.c \
|
||||||
thread/pthread_detach.c \
|
thread/pthread_detach.c \
|
||||||
thread/pthread_equal.c \
|
thread/pthread_equal.c \
|
||||||
|
thread/pthread_getattr_np.c \
|
||||||
thread/pthread_getspecific.c \
|
thread/pthread_getspecific.c \
|
||||||
thread/pthread_join.c \
|
thread/pthread_join.c \
|
||||||
thread/pthread_key_create.c \
|
thread/pthread_key_create.c \
|
||||||
|
@ -1010,6 +1010,7 @@ pthread_condattr_setpshared
|
|||||||
pthread_create
|
pthread_create
|
||||||
pthread_detach
|
pthread_detach
|
||||||
pthread_equal
|
pthread_equal
|
||||||
|
pthread_getattr_np
|
||||||
pthread_getspecific
|
pthread_getspecific
|
||||||
pthread_join
|
pthread_join
|
||||||
pthread_key_create
|
pthread_key_create
|
||||||
|
38
libc-top-half/musl/src/env/__init_tls.c
vendored
38
libc-top-half/musl/src/env/__init_tls.c
vendored
@ -31,25 +31,35 @@ extern unsigned char __global_base;
|
|||||||
extern weak unsigned char __stack_high;
|
extern weak unsigned char __stack_high;
|
||||||
extern weak unsigned char __stack_low;
|
extern weak unsigned char __stack_low;
|
||||||
|
|
||||||
static inline void setup_default_stack_size()
|
struct stack_bounds {
|
||||||
{
|
void *base;
|
||||||
ptrdiff_t stack_size;
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
if (&__stack_high)
|
static inline struct stack_bounds get_stack_bounds()
|
||||||
stack_size = &__stack_high - &__stack_low;
|
{
|
||||||
else {
|
struct stack_bounds bounds;
|
||||||
|
|
||||||
|
if (&__stack_high) {
|
||||||
|
bounds.base = &__stack_high;
|
||||||
|
bounds.size = &__stack_high - &__stack_low;
|
||||||
|
} else {
|
||||||
unsigned char *sp;
|
unsigned char *sp;
|
||||||
__asm__(
|
__asm__(
|
||||||
".globaltype __stack_pointer, i32\n"
|
".globaltype __stack_pointer, i32\n"
|
||||||
"global.get __stack_pointer\n"
|
"global.get __stack_pointer\n"
|
||||||
"local.set %0\n"
|
"local.set %0\n"
|
||||||
: "=r"(sp));
|
: "=r"(sp));
|
||||||
stack_size = sp > &__global_base ? &__heap_base - &__data_end : (ptrdiff_t)&__global_base;
|
if (sp > &__global_base) {
|
||||||
|
bounds.base = &__heap_base;
|
||||||
|
bounds.size = &__heap_base - &__data_end;
|
||||||
|
} else {
|
||||||
|
bounds.base = &__global_base;
|
||||||
|
bounds.size = (size_t)&__global_base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__default_stacksize =
|
return bounds;
|
||||||
stack_size < DEFAULT_STACK_MAX ?
|
|
||||||
stack_size : DEFAULT_STACK_MAX;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __wasi_init_tp() {
|
void __wasi_init_tp() {
|
||||||
@ -68,8 +78,14 @@ int __init_tp(void *p)
|
|||||||
td->detach_state = DT_JOINABLE;
|
td->detach_state = DT_JOINABLE;
|
||||||
td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
|
td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
|
||||||
#else
|
#else
|
||||||
setup_default_stack_size();
|
struct stack_bounds bounds = get_stack_bounds();
|
||||||
|
__default_stacksize =
|
||||||
|
bounds.size < DEFAULT_STACK_MAX ?
|
||||||
|
bounds.size : DEFAULT_STACK_MAX;
|
||||||
td->detach_state = DT_JOINABLE;
|
td->detach_state = DT_JOINABLE;
|
||||||
|
td->stack = bounds.base;
|
||||||
|
td->stack_size = bounds.size;
|
||||||
|
td->guard_size = 0;
|
||||||
/*
|
/*
|
||||||
* Initialize the TID to a value which doesn't conflict with
|
* Initialize the TID to a value which doesn't conflict with
|
||||||
* host-allocated TIDs, so that TID-based locks can work.
|
* host-allocated TIDs, so that TID-based locks can work.
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "pthread_impl.h"
|
#include "pthread_impl.h"
|
||||||
#include "libc.h"
|
#include "libc.h"
|
||||||
|
#ifdef __wasilibc_unmodified_upstream
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
|
int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
|
||||||
{
|
{
|
||||||
@ -12,6 +14,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
|
|||||||
a->_a_stackaddr = (uintptr_t)t->stack;
|
a->_a_stackaddr = (uintptr_t)t->stack;
|
||||||
a->_a_stacksize = t->stack_size;
|
a->_a_stacksize = t->stack_size;
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef __wasilibc_unmodified_upstream
|
||||||
char *p = (void *)libc.auxv;
|
char *p = (void *)libc.auxv;
|
||||||
size_t l = PAGE_SIZE;
|
size_t l = PAGE_SIZE;
|
||||||
p += -(uintptr_t)p & PAGE_SIZE-1;
|
p += -(uintptr_t)p & PAGE_SIZE-1;
|
||||||
@ -19,6 +22,9 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
|
|||||||
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
|
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
|
||||||
l += PAGE_SIZE;
|
l += PAGE_SIZE;
|
||||||
a->_a_stacksize = l;
|
a->_a_stacksize = l;
|
||||||
|
#else
|
||||||
|
return ENOSYS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user