summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/thread
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:03 +0000
commitf1db79e6e5c383cf76f3bf0dd42115d19591a72b (patch)
tree3f9509008e8a130c45b7e31b1520d66d720493ec /libc-top-half/musl/src/thread
parentAdding upstream version 0.0~git20230821.ec4566b. (diff)
downloadwasi-libc-f1db79e6e5c383cf76f3bf0dd42115d19591a72b.tar.xz
wasi-libc-f1db79e6e5c383cf76f3bf0dd42115d19591a72b.zip
Adding upstream version 0.0~git20240411.9e8c542.upstream/0.0_git20240411.9e8c542upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/thread')
-rw-r--r--libc-top-half/musl/src/thread/pthread_create.c17
-rw-r--r--libc-top-half/musl/src/thread/pthread_getattr_np.c6
2 files changed, 17 insertions, 6 deletions
diff --git a/libc-top-half/musl/src/thread/pthread_create.c b/libc-top-half/musl/src/thread/pthread_create.c
index 5de9f5a..450fe15 100644
--- a/libc-top-half/musl/src/thread/pthread_create.c
+++ b/libc-top-half/musl/src/thread/pthread_create.c
@@ -13,6 +13,7 @@
#endif
#include <stdalign.h>
+#include <assert.h>
static void dummy_0()
{
@@ -558,13 +559,17 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
__wait(&args->control, 0, 3, 0);
}
#else
+#define WASI_THREADS_MAX_TID 0x1FFFFFFF
/* `wasi_thread_spawn` will either return a host-provided thread ID (TID)
- * (`>= 0`) or an error code (`< 0`). As in the unmodified version, all
- * spawn failures translate to EAGAIN; unlike the modified version, there is
- * no need to "start up" the child thread--the host does this. If the spawn
- * did succeed, then we store the TID atomically, since this parent thread
- * is racing with the child thread to set this field; this way, whichever
- * thread reaches this point first can continue without waiting. */
+ * (`<1, 0x1FFFFFFF>`) or an error code (`< 0`). Please note that `0` is
+ * reserved for compatibility reasons and must not be returned by the runtime.
+ * As in the unmodified version, all spawn failures translate to EAGAIN;
+ * unlike the modified version, there is no need to "start up" the child
+ * thread--the host does this. If the spawn did succeed, then we store the
+ * TID atomically, since this parent thread is racing with the child thread
+ * to set this field; this way, whichever thread reaches this point first
+ * can continue without waiting. */
+ assert(ret != 0 && ret <= WASI_THREADS_MAX_TID);
if (ret < 0) {
ret = -EAGAIN;
} else {
diff --git a/libc-top-half/musl/src/thread/pthread_getattr_np.c b/libc-top-half/musl/src/thread/pthread_getattr_np.c
index 2881831..c23e5d7 100644
--- a/libc-top-half/musl/src/thread/pthread_getattr_np.c
+++ b/libc-top-half/musl/src/thread/pthread_getattr_np.c
@@ -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,6 +14,7 @@ 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;
@@ -19,6 +22,9 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a)
while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM)
l += PAGE_SIZE;
a->_a_stacksize = l;
+#else
+ return ENOSYS;
+#endif
}
return 0;
}