Implement strict validation of thread IDs according to the specification (#2521)

This commit is contained in:
Marcin Kolny
2023-08-31 13:23:54 +01:00
committed by GitHub
parent 411b903cee
commit 53d7027de0
7 changed files with 11 additions and 13 deletions

View File

@ -50,16 +50,11 @@ main(int argc, char **argv)
}
thread_id = __wasi_thread_spawn(&data);
if (thread_id < 0) {
printf("Failed to create thread: %d\n", thread_id);
ret = EXIT_FAILURE;
goto final;
}
ASSERT_VALID_TID(thread_id);
if (__builtin_wasm_memory_atomic_wait32(&data.th_ready, 0, SECOND) == 2) {
printf("Timeout\n");
ret = EXIT_FAILURE;
goto final;
return EXIT_FAILURE;
}
printf("Thread completed, new value: %d, thread id: %d\n", data.value,
@ -67,7 +62,6 @@ main(int argc, char **argv)
assert(thread_id == data.thread_id);
final:
start_args_deinit(&data.base);
return ret;

View File

@ -7,6 +7,10 @@
#define STACK_SIZE 32 * 1024 // same as the main stack
/* See https://github.com/WebAssembly/wasi-threads#design-choice-thread-ids */
#define ASSERT_VALID_TID(TID) \
assert(TID >= 1 && TID <= 0x1FFFFFFF && "Invalid thread ID")
typedef struct {
void *stack;
} start_args_t;