From 5d3c5e918c38a4432d5efbfc0f70de76c4779eed Mon Sep 17 00:00:00 2001 From: R Date: Fri, 2 Aug 2024 17:56:28 +0100 Subject: [PATCH] Improve some pthreads stub functions, batch 0 (#519) This is one part of breaking up #518 into smaller PRs. This should be (IMO) the least-controversial batch of commits --- Makefile | 6 +++++- expected/wasm32-wasip1-threads/defined-symbols.txt | 4 ++++ libc-top-half/musl/src/thread/pthread_attr_setguardsize.c | 5 +++++ libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 542b43eba..174115e23 100644 --- a/Makefile +++ b/Makefile @@ -288,12 +288,16 @@ LIBC_TOP_HALF_MUSL_SOURCES += \ thread/pthread_attr_destroy.c \ thread/pthread_attr_get.c \ thread/pthread_attr_init.c \ - thread/pthread_attr_setstack.c \ thread/pthread_attr_setdetachstate.c \ + thread/pthread_attr_setguardsize.c \ + thread/pthread_attr_setstack.c \ thread/pthread_attr_setstacksize.c \ thread/pthread_barrier_destroy.c \ thread/pthread_barrier_init.c \ thread/pthread_barrier_wait.c \ + thread/pthread_barrierattr_destroy.c \ + thread/pthread_barrierattr_init.c \ + thread/pthread_barrierattr_setpshared.c \ thread/pthread_cleanup_push.c \ thread/pthread_cond_broadcast.c \ thread/pthread_cond_destroy.c \ diff --git a/expected/wasm32-wasip1-threads/defined-symbols.txt b/expected/wasm32-wasip1-threads/defined-symbols.txt index 730648fe3..822a559cb 100644 --- a/expected/wasm32-wasip1-threads/defined-symbols.txt +++ b/expected/wasm32-wasip1-threads/defined-symbols.txt @@ -992,12 +992,16 @@ pthread_attr_getstack pthread_attr_getstacksize pthread_attr_init pthread_attr_setdetachstate +pthread_attr_setguardsize pthread_attr_setstack pthread_attr_setstacksize pthread_barrier_destroy pthread_barrier_init pthread_barrier_wait +pthread_barrierattr_destroy pthread_barrierattr_getpshared +pthread_barrierattr_init +pthread_barrierattr_setpshared pthread_cond_broadcast pthread_cond_destroy pthread_cond_init diff --git a/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c b/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c index 1c5c60acb..589ff676e 100644 --- a/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c +++ b/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c @@ -2,7 +2,12 @@ int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) { +#ifdef __wasilibc_unmodified_upstream if (size > SIZE_MAX/8) return EINVAL; +#else + /* WASI doesn't have memory protection required for stack guards. */ + if (size > 0) return EINVAL; +#endif a->_a_guardsize = size; return 0; } diff --git a/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c b/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c index 649a89130..68c7d65d8 100644 --- a/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c +++ b/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c @@ -22,6 +22,7 @@ int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust) a->__attr &= ~4; return 0; #else - return EINVAL; + if (robust) return EINVAL; + return 0; #endif }