8000 Fill correct stack info in pthread_getattr_np stub (#23887) · emscripten-core/emscripten@d6ebc74 · GitHub
[go: up one dir, main page]

Skip to content

Commit d6ebc74

Browse files
authored
Fill correct stack info in pthread_getattr_np stub (#23887)
See use case here: https://github.com/python/cpython/pull/130398/files#diff-c22186367cbe20233e843261998dc027ae5f1f8c0d2e778abfa454ae74cc59deR365-R380 I guess for stack protection, this only enables introspecting whether we run out of the spill stack. I'm not sure whether to expect running out of spill stack or running out of true stack to be more common. But at least this unbreaks the code.
1 parent f4fb3cd commit d6ebc74

21 files changed

+55
-29
lines changed

system/lib/pthread/library_pthread_stub.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,6 @@ int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) {
276276
return 0;
277277
}
278278

279-
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
280-
return 0;
281-
}
282-
283279
int pthread_setcancelstate(int state, int* oldstate) {
284280
return 0;
285281
}

system/lib/pthread/pthread_self_stub.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "pthread_impl.h"
99
#include <unistd.h>
10+
#include <emscripten/stack.h>
1011

1112
static struct pthread __main_pthread;
1213

@@ -24,8 +25,14 @@ pthread_t emscripten_main_runtime_thread_id() {
2425
return &__main_pthread;
2526
}
2627

28+
extern int __stack_high;
29+
extern int __stack_low;
30+
2731
__attribute__((constructor))
2832
static void init_pthread_self(void) {
2933
__main_pthread.locale = &libc.global_locale;
3034
__main_pthread.tid = getpid();
35+
__main_pthread.stack = &__stack_high;
36+
__main_pthread.stack_size = ((size_t)&__stack_high) - ((size_t)&__stack_low);
37+
__main_pthread.guard_size = __default_guardsize;
3138
}

test/code_size/embind_val_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"a.html.gz": 380,
44
"a.js": 7030,
55
"a.js.gz": 3022,
6-
"a.wasm": 9119,
7-
"a.wasm.gz": 4701,
8-
"total": 16701,
9-
"total_gz": 8103
6+
"a.wasm": 9155,
7+
"a.wasm.gz": 4724,
8+
"total": 16737,
9+
"total_gz": 8126
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 12442,
3-
"a.html.gz": 6793,
4-
"total": 12442,
5-
"total_gz": 6793
2+
"a.html": 12494,
3+
"a.html.gz": 6812,
4+
"total": 12494,
5+
"total_gz": 6812
66
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"a.html": 17205,
3-
"a.html.gz": 7516,
4-
"total": 17205,
5-
"total_gz": 7516
2+
"a.html": 17262,
3+
"a.html.gz": 7542,
4+
"total": 17262,
5+
"total_gz": 7542
66
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
129166
1+
129206
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
128578
1+
128599
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
170787
1+
170827
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
144542
1+
144582
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
142117
1+
142157

0 commit comments

Comments
 (0)
0