Skip to content

Commit 7c2c401

Browse files
committed
Fill correct stack info in pthread_getattr_np stub
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 e7612e1 commit 7c2c401

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

system/lib/pthread/library_pthread_stub.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) {
277277
}
278278

279279
int pthread_getattr_np(pthread_t thread, pthread_attr_t *attr) {
280+
attr->_a_stackaddr = emscripten_stack_get_base();
281+
attr->_a_stacksize = emscripten_stack_get_base() - emscripten_stack_get_end();
282+
attr->_a_guardsize = __default_guardsize;
280283
return 0;
281284
}
282285

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#define _GNU_SOURCE
2+
#include "pthread.h"
3+
#include "stdio.h"
4+
#include "assert.h"
5+
6+
int main() {
7+
pthread_attr_t attr;
8+
size_t stack_size, guard_size;
9+
void *stack_addr;
10+
11+
assert(pthread_getattr_np(pthread_self(), &attr) == 0);
12+
assert(pthread_attr_getguardsize(&attr, &guard_size) == 0);
13+
assert(pthread_attr_getstack(&attr, &stack_addr, &stack_size) == 0);
14+
assert(pthread_attr_destroy(&attr) == 0);
15+
printf("stack_addr: %p, stack_size: %zu, guard_size: %zu\n", stack_addr, stack_size, guard_size);
16+
return 0;
17+
}

test/test_other.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15777,3 +15777,6 @@ def test_rollup(self):
1577715777

1577815778
def test_rlimit(self):
1577915779
self.do_other_test('test_rlimit.c', emcc_args=['-O1'])
15780+
15781+
def test_stub_pthread_getattr_np(self):
15782+
self.do_runf(test_file('other/test_stub_pthread_getattr_np.c'), 'stack_addr: 0, stack_size: 65536, guard_size: 8192')

0 commit comments

Comments
 (0)