Skip to content

Fill correct stack info in pthread_getattr_np stub #23887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions system/lib/pthread/library_pthread_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) {
return 0;
}

int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
return 0;
}

int pthread_setcancelstate(int state, int* oldstate) {
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions system/lib/pthread/pthread_self_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "pthread_impl.h"
#include <unistd.h>
#include <emscripten/stack.h>

static struct pthread __main_pthread;

Expand All @@ -28,4 +29,7 @@ __attribute__((constructor))
static void init_pthread_self(void) {
__main_pthread.locale = &libc.global_locale;
__main_pthread.tid = getpid();
__main_pthread.stack = (void*)emscripten_stack_get_base();
__main_pthread.stack_size = emscripten_stack_get_base();
__main_pthread.guard_size = __default_guardsize;
}
8 changes: 4 additions & 4 deletions test/code_size/embind_val_wasm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"a.html.gz": 380,
"a.js": 7030,
"a.js.gz": 3022,
"a.wasm": 9119,
"a.wasm.gz": 4701,
"total": 16701,
"total_gz": 8103
"a.wasm": 9162,
"a.wasm.gz": 4729,
"total": 16744,
"total_gz": 8131
}
4 changes: 2 additions & 2 deletions test/code_size/random_printf_wasm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"a.html": 12442,
"a.html": 12494,
"a.html.gz": 6793,
"total": 12442,
"total": 12494,
"total_gz": 6793
}
4 changes: 2 additions & 2 deletions test/code_size/random_printf_wasm2js.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"a.html": 17205,
"a.html": 17262,
"a.html.gz": 7516,
"total": 17205,
"total": 17262,
"total_gz": 7516
}
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129166
129209
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128578
128599
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170787
170834
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144542
144589
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142117
142164
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_lto.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
122011
122051
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232560
232607
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131729
131776
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
169089
169136
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15105
15157
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4141
4182
18 changes: 18 additions & 0 deletions test/other/test_pthread_stub.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _GNU_SOURCE
#include <assert.h>
#include <errno.h>
#include <stdint.h>
Expand Down Expand Up @@ -29,6 +30,7 @@ void* start_pthread(void* arg) {
#define CHECK_C11_FAIL(X) CHECK_C11(X, thrd_nomem)

void test_c11_threads() {
printf("test_c11_threads\n");
int rtn;
int res;

Expand All @@ -45,6 +47,7 @@ void test_c11_threads() {
}

void test_pthreads() {
printf("test_pthreads\n");
int rtn;
int res;

Expand All @@ -59,8 +62,23 @@ void test_pthreads() {
pthread_cleanup_pop(1);
}

void test_pthread_getattr_np() {
printf("test_pthread_getattr_np\n");
int rtn;
pthread_attr_t attr;
size_t stack_size, guard_size;
void *stack_addr;

CHECK_SUCCESS(pthread_getattr_np(pthread_self(), &attr));
CHECK_SUCCESS(pthread_attr_getguardsize(&attr, &guard_size));
CHECK_SUCCESS(pthread_attr_getstack(&attr, &stack_addr, &stack_size));
CHECK_SUCCESS(pthread_attr_destroy(&attr));
printf("stack_addr: %p, stack_size: %zu, guard_size: %zu\n", stack_addr, stack_size, guard_size);
}

int main() {
test_c11_threads();
test_pthreads();
test_pthread_getattr_np();
return 0;
}
4 changes: 4 additions & 0 deletions test/other/test_pthread_stub.out
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
test_c11_threads
test_pthreads
cleanup: 42
test_pthread_getattr_np
stack_addr: 0xffff0000, stack_size: 65536, guard_size: 8192
1 change: 1 addition & 0 deletions test/other/test_stub_pthread_getattr_np.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stack_addr: 0, stack_size: 65536, guard_size: 8192
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15105
15157
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12186
12294
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15105
15157
1 change: 1 addition & 0 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ def get_files(self):
'pthread_attr_setscope.c',
'pthread_attr_setstack.c',
'pthread_attr_setstacksize.c',
'pthread_getattr_np.c',
'pthread_getconcurrency.c',
'pthread_getcpuclockid.c',
'pthread_getschedparam.c',
Expand Down
Loading