summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/env/__init_tls.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/env/__init_tls.c')
-rw-r--r--libc-top-half/musl/src/env/__init_tls.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c
index c3e407c..4f4c221 100644
--- a/libc-top-half/musl/src/env/__init_tls.c
+++ b/libc-top-half/musl/src/env/__init_tls.c
@@ -31,25 +31,35 @@ extern unsigned char __global_base;
extern weak unsigned char __stack_high;
extern weak unsigned char __stack_low;
-static inline void setup_default_stack_size()
+struct stack_bounds {
+ void *base;
+ size_t size;
+};
+
+static inline struct stack_bounds get_stack_bounds()
{
- ptrdiff_t stack_size;
+ struct stack_bounds bounds;
- if (&__stack_high)
- stack_size = &__stack_high - &__stack_low;
- else {
+ if (&__stack_high) {
+ bounds.base = &__stack_high;
+ bounds.size = &__stack_high - &__stack_low;
+ } else {
unsigned char *sp;
__asm__(
".globaltype __stack_pointer, i32\n"
"global.get __stack_pointer\n"
"local.set %0\n"
: "=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 =
- stack_size < DEFAULT_STACK_MAX ?
- stack_size : DEFAULT_STACK_MAX;
+ return bounds;
}
void __wasi_init_tp() {
@@ -68,8 +78,14 @@ int __init_tp(void *p)
td->detach_state = DT_JOINABLE;
td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
#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->stack = bounds.base;
+ td->stack_size = bounds.size;
+ td->guard_size = 0;
/*
* Initialize the TID to a value which doesn't conflict with
* host-allocated TIDs, so that TID-based locks can work.