forked from bytecodealliance/wasm-micro-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return error when exception was raised after main thread finishes (by…
…tecodealliance#2169) Currently, if a thread is spawned and raises an exception after the main thread has finished, iwasm returns with success instead of returning 1 (i.e. error). Since wasm_runtime_get_wasi_exit_code waits for all threads to finish and only returns the wasi exit code, this PR performs the exception check again and returns error if an exception was raised.
- Loading branch information
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
*/ | ||
|
||
#ifndef __wasi__ | ||
#error This example only compiles to WASM/WASI target | ||
#endif | ||
|
||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <assert.h> | ||
|
||
#include "wasi_thread_start.h" | ||
|
||
enum CONSTANTS { | ||
SECOND = 1000 * 1000 * 1000, /* 1 second */ | ||
TIMEOUT = 1LL * SECOND | ||
}; | ||
|
||
typedef struct { | ||
start_args_t base; | ||
} shared_t; | ||
|
||
void | ||
__wasi_thread_start_C(int thread_id, int *start_arg) | ||
{ | ||
/* Wait so that the exception is raised after the main thread has finished | ||
* already */ | ||
__builtin_wasm_memory_atomic_wait32(NULL, 0, TIMEOUT); | ||
__builtin_trap(); | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
shared_t data = { 0 }; | ||
|
||
assert(start_args_init(&data.base)); | ||
int thread_id = __wasi_thread_spawn(&data); | ||
assert(thread_id > 0 && "Thread creation failed"); | ||
|
||
return EXIT_SUCCESS; | ||
} |
3 changes: 3 additions & 0 deletions
3
core/iwasm/libraries/lib-wasi-threads/test/trap_after_main_thread_finishes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"exit_code": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters