Implement strict validation of thread IDs according to the specification (#2521)
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user