-
Notifications
You must be signed in to change notification settings - Fork 199
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
Add support for pthread_getattr_np #470
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
#define _GNU_SOURCE | ||
#include "pthread_impl.h" | ||
#include "libc.h" | ||
#ifdef __wasilibc_unmodified_upstream | ||
#include <sys/mman.h> | ||
#endif | ||
|
||
int pthread_getattr_np(pthread_t t, pthread_attr_t *a) | ||
{ | ||
|
@@ -12,13 +14,17 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) | |
a->_a_stackaddr = (uintptr_t)t->stack; | ||
a->_a_stacksize = t->stack_size; | ||
} else { | ||
#ifdef __wasilibc_unmodified_upstream | ||
char *p = (void *)libc.auxv; | ||
size_t l = PAGE_SIZE; | ||
p += -(uintptr_t)p & PAGE_SIZE-1; | ||
a->_a_stackaddr = (uintptr_t)p; | ||
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM) | ||
l += PAGE_SIZE; | ||
a->_a_stacksize = l; | ||
#else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we can leave the It looks like that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea was to fill these fields in main thread struct and handle everything the same way. Otherwise this would need to duplicate the logic for getting stack bounds, fallback to __heap_base, etc... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced only |
||
return ENOSYS; | ||
#endif | ||
} | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code only calculates the stack found of the main thread (i.e. the singular stack that the linker produces). Is that intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fills data for main thread, spawned threads have these fields filled in pthread_create.