Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception-handling #134

Merged
merged 78 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
68dd59e
cmake: add TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING
yamt Mar 15, 2023
a446eea
toywasm_config.c.in: add TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING
yamt Mar 15, 2023
c6a2fc2
toywasm_config.h.in: add TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING
yamt Mar 15, 2023
37ac835
add a few FRAME_OP_ constants for exception-handling
yamt Mar 15, 2023
296a57e
implement tag section
yamt Mar 15, 2023
380ef7d
add a todo
yamt Mar 15, 2023
8d06d73
start implementing exception-handling opcodes
yamt Mar 15, 2023
200387d
implement taginst
yamt Mar 17, 2023
59559bb
module_tag
yamt Mar 17, 2023
43e31cb
implement tag import/export desc
yamt Mar 17, 2023
aca2a45
check_tagtype
yamt Mar 18, 2023
f619a26
fix build issues
yamt Mar 18, 2023
e296803
fix more build issues
yamt Mar 18, 2023
53ff8df
fix a copy-and-paste botch
yamt Mar 18, 2023
c90735f
comment
yamt Mar 18, 2023
ebe7af9
test/prepare-spec-test.sh: exception-handling
yamt Mar 21, 2023
a082c7e
start implementing throw
yamt Mar 21, 2023
12573dd
prepare-spec-test.sh: comment out old eh tests
yamt Jan 24, 2024
4769ac1
start implementing the new exception-handling proposal
yamt Jan 25, 2024
a0cb63f
fix build w/o TOYWASM_ENABLE_WRITER
yamt Jan 25, 2024
9b9773a
format
yamt Jan 25, 2024
bd0390d
implement execution of try_table opcode
yamt Jan 25, 2024
7e9c74a
start implementing execution of throw opcode
yamt Jan 25, 2024
29fc438
comment
yamt Jan 25, 2024
eafdf65
add TRAP_UNCAUGHT_EXCEPTION
yamt Jan 26, 2024
c65f186
add EXEC_EVENT_EXCEPTION
yamt Jan 26, 2024
873d256
comments
yamt Jan 26, 2024
14b8f9c
implement throw execution
yamt Jan 27, 2024
07c0e2e
prepare-spec-test.sh: comment
yamt Jan 27, 2024
92104d4
throw: use exnref on stack instead of ctx->event_u
yamt Jan 27, 2024
4e690d1
comment
yamt Jan 27, 2024
4b515b4
implement catch_ref
yamt Jan 27, 2024
2eaef7a
implement catch_all/catch_all_ref
yamt Jan 27, 2024
6c5c81f
implement throw_ref
yamt Jan 27, 2024
ed3eea3
fix the case where catch handler exits the function
yamt Jan 27, 2024
751c928
some test cases
yamt Jan 27, 2024
23ebe51
a script to run all wat in this directory
yamt Jan 27, 2024
6045dac
add a bit more cases
yamt Jan 27, 2024
6cdae76
fix a typo
yamt Jan 27, 2024
1abcbb4
avoid UBSAN misalignment complaints
yamt Jan 27, 2024
ec11cf0
fix an assertion
yamt Jan 27, 2024
54d6257
fix an assertion
yamt Jan 27, 2024
eba5caa
find_catch: don't go over a host frame
yamt Jan 27, 2024
ad5c898
add an assertion
yamt Jan 27, 2024
b0b0df0
comment
yamt Jan 27, 2024
d014c2c
fix build w/o TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING
yamt Jan 27, 2024
fe937a7
use #error instead of #warning
yamt Jan 27, 2024
6849bbf
another test wat
yamt Jan 27, 2024
e9822a8
fix operations with exnref
yamt Jan 27, 2024
cde62dc
test a bit more exnref operations
yamt Jan 27, 2024
f725860
README.md: exception-handling
yamt Jan 27, 2024
6d3a128
remove a trailing whitespace
yamt Jan 27, 2024
7df2d41
fix ref.is_null on extref
yamt Jan 28, 2024
9875cb8
fix a few opcode names
yamt Jan 28, 2024
be516ef
add another test wat
yamt Jan 28, 2024
13f06e4
implement eh module writer
yamt Jan 28, 2024
f379a76
test exnref global as well
yamt Jan 28, 2024
7e3fa98
ci: enable TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING for "full" assets
yamt Jan 28, 2024
b80e7a3
suppress a GCC maybe-uninitialized warning
yamt Jan 28, 2024
5f12772
comment
yamt Jan 28, 2024
b39383f
fix struct val size calculation for !TOYWASM_USE_SMALL_CELLS
yamt Jan 28, 2024
8929e05
fix armhf build
yamt Jan 28, 2024
e25d433
wat/eh/test.sh: separate the script into two parts
yamt Jan 28, 2024
5205385
wat/eh: add a prebuilt modules
yamt Jan 28, 2024
eae3b70
module_unload: don't forget to free tags
yamt Jan 28, 2024
03f178c
wat/eh/test.sh: look for TEST_RUNTIME_EXE as well for ci
yamt Jan 28, 2024
f2ef21b
ctest: run wat/eh/test.sh as well
yamt Jan 28, 2024
75421df
TRAP_THROW_REF_NULL
yamt Jan 28, 2024
86c6b4b
a test wat to throw null
yamt Jan 28, 2024
4835eb2
add a prebuilt module
yamt Jan 28, 2024
0954e41
wat/eh/test.sh: test trapping case as well
yamt Jan 28, 2024
50d66e5
another test wat
yamt Jan 28, 2024
6e309e0
add a prebuilt module
yamt Jan 28, 2024
58a48cc
do_exception: remove a wrong assertion and add a comment
yamt Jan 28, 2024
a93b7aa
comment
yamt Jan 28, 2024
eaf37b3
fix a current_locals corruption in push_exception
yamt Jan 28, 2024
aaa87fc
tweak a comment
yamt Jan 28, 2024
af296b8
comment
yamt Jan 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
MISC_FEATURES: [ON, OFF]
TOYWASM_ENABLE_WASM_THREADS: [ON, OFF]
TOYWASM_ENABLE_WASI_THREADS: [ON, OFF]
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: [ON, OFF]
exclude:
# I haven't used gcc for macos
- os: macos-latest
Expand All @@ -53,6 +54,10 @@ jobs:
TOYWASM_ENABLE_WASM_THREADS: ON
- TOYWASM_USE_SMALL_CELLS: OFF
TOYWASM_ENABLE_WASM_THREADS: ON
# TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING right now
# requires TOYWASM_USE_SMALL_CELLS
- TOYWASM_USE_SMALL_CELLS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
# exclude some more combinations to reduce the matrix
- TOYWASM_USE_SMALL_CELLS: ON
TOYWASM_USE_SEPARATE_LOCALS: ON
Expand All @@ -75,6 +80,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: ubuntu-20.04-amd64
os: ubuntu-20.04
compiler: clang
Expand All @@ -88,6 +94,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: full-ubuntu-20.04-amd64
os: ubuntu-20.04
compiler: clang
Expand All @@ -101,6 +108,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
- name: macos-11.0
os: macos-latest
compiler: clang
Expand All @@ -114,6 +122,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: full-macos-11.0
os: macos-latest
compiler: clang
Expand All @@ -127,6 +136,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON

- name: ubuntu-20.04-i386
os: ubuntu-20.04
Expand All @@ -141,6 +151,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: ubuntu-20.04-arm64
os: ubuntu-20.04
compiler: clang
Expand All @@ -154,6 +165,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: ubuntu-20.04-armhf
os: ubuntu-20.04
compiler: clang
Expand All @@ -167,6 +179,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: ubuntu-20.04-s390x
os: ubuntu-20.04
compiler: clang
Expand All @@ -180,6 +193,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF
- name: ubuntu-20.04-riscv64
os: ubuntu-20.04
compiler: clang
Expand All @@ -193,6 +207,7 @@ jobs:
MISC_FEATURES: OFF
TOYWASM_ENABLE_WASM_THREADS: OFF
TOYWASM_ENABLE_WASI_THREADS: OFF
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: OFF

- name: full-ubuntu-20.04-i386
os: ubuntu-20.04
Expand All @@ -207,6 +222,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
- name: full-ubuntu-20.04-arm64
os: ubuntu-20.04
compiler: clang
Expand All @@ -220,6 +236,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
- name: full-ubuntu-20.04-armhf
os: ubuntu-20.04
compiler: clang
Expand All @@ -233,6 +250,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
- name: full-ubuntu-20.04-s390x
os: ubuntu-20.04
compiler: clang
Expand All @@ -246,6 +264,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON
- name: full-ubuntu-20.04-riscv64
os: ubuntu-20.04
compiler: clang
Expand All @@ -259,6 +278,7 @@ jobs:
MISC_FEATURES: ON
TOYWASM_ENABLE_WASM_THREADS: ON
TOYWASM_ENABLE_WASI_THREADS: ON
TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING: ON

runs-on: ${{matrix.os}}

Expand All @@ -278,6 +298,7 @@ jobs:
echo "-DTOYWASM_ENABLE_TRACING_INSN=${{matrix.TOYWASM_ENABLE_TRACING}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_USE_SMALL_CELLS=${{matrix.TOYWASM_USE_SMALL_CELLS}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_USE_SEPARATE_LOCALS=${{matrix.TOYWASM_USE_SEPARATE_LOCALS}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_ENABLE_WASM_EXCEPTION_HANDLING=${{matrix.TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_ENABLE_WASM_EXTENDED_CONST=${{matrix.MISC_FEATURES}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_ENABLE_WASM_MULTI_MEMORY=${{matrix.MISC_FEATURES}}" >> ${GITHUB_ENV}
echo "-DTOYWASM_ENABLE_WASM_TAILCALL=${{matrix.MISC_FEATURES}}" >> ${GITHUB_ENV}
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ set_tests_properties(toywasm-cli-wasm3-spec-test-threads PROPERTIES ENVIRONMENT
set_tests_properties(toywasm-cli-wasm3-spec-test-threads PROPERTIES LABELS "spec:wasm-threads")
endif()

if(TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING)
add_test(NAME toywasm-cli-exception-handling-test
COMMAND ./test.sh
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wat/eh
)
set_tests_properties(toywasm-cli-exception-handling-test PROPERTIES ENVIRONMENT "${TEST_ENV}")
set_tests_properties(toywasm-cli-exception-handling-test PROPERTIES LABELS "exception-handling")
endif()

if(TOYWASM_ENABLE_WASI)
add_test(NAME toywasm-cli-wasi-testsuite
COMMAND ./test/run-wasi-testsuite.sh
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ is built with an ancient wasi-sdk to workaround

## What are implemented?

|Feature |Status |
| ---------------------- | ------------------------------------------------ |
|[WebAssembly] |Complete `2.0 (Draft 2022-06-27)` |
|[extended-const] |Complete (`TOYWASM_ENABLE_WASM_EXTENDED_CONST`) |
|[multi-memory] |Complete (`TOYWASM_ENABLE_WASM_MULTI_MEMORY`) |
|[tail-call] |Complete (`TOYWASM_ENABLE_WASM_TAILCALL`) |
|[threads] |Complete (`TOYWASM_ENABLE_WASM_THREADS`) |
|[wasi_snapshot_preview1]|See [the top comment in wasi.c] |
|[wasi-threads] |Complete (`TOYWASM_ENABLE_WASI_THREADS`) |
|[dynamic-linking] |Complete (`TOYWASM_ENABLE_DYLD`) |
|Feature |Status |
| ---------------------- | -------------------------------------------------- |
|[WebAssembly] |Complete `2.0 (Draft 2022-06-27)` |
|[extended-const] |Complete (`TOYWASM_ENABLE_WASM_EXTENDED_CONST`) |
|[exception-handling] |Complete (`TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING`) |
|[multi-memory] |Complete (`TOYWASM_ENABLE_WASM_MULTI_MEMORY`) |
|[tail-call] |Complete (`TOYWASM_ENABLE_WASM_TAILCALL`) |
|[threads] |Complete (`TOYWASM_ENABLE_WASM_THREADS`) |
|[wasi_snapshot_preview1]|See [the top comment in wasi.c] |
|[wasi-threads] |Complete (`TOYWASM_ENABLE_WASI_THREADS`) |
|[dynamic-linking] |Complete (`TOYWASM_ENABLE_DYLD`) |

Note: As this runtime is relatively new, all proposals which had finished
when I started this implementation are just included in the `WebAssembly`
Expand All @@ -69,6 +70,7 @@ It includes

[WebAssembly]: https://github.com/WebAssembly/spec
[extended-const]: https://github.com/WebAssembly/extended-const
[exception-handling]: https://github.com/WebAssembly/exception-handling
[multi-memory]: https://github.com/WebAssembly/multi-memory
[tail-call]: https://github.com/WebAssembly/tail-call
[threads]: https://github.com/WebAssembly/threads
Expand Down
1 change: 1 addition & 0 deletions cmake/ToywasmConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ option(TOYWASM_ENABLE_WRITER "Enable module writer" ON)
option(TOYWASM_ENABLE_WASM_SIMD "Enable SIMD" ON)

# enable each wasm proposals.
option(TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING "Enable exception-handling proposal" OFF)
option(TOYWASM_ENABLE_WASM_EXTENDED_CONST "Enable extended-const proposal" OFF)
option(TOYWASM_ENABLE_WASM_MULTI_MEMORY "Enable multi-memory proposal" OFF)
option(TOYWASM_ENABLE_WASM_TAILCALL "Enable WASM tail-call proposal" OFF)
Expand Down
10 changes: 7 additions & 3 deletions lib/cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ valtype_cellsize(enum valtype t)
#endif
case TYPE_FUNCREF:
case TYPE_EXTERNREF:
sz = sizeof(void *) / sizeof(struct cell);
sz = EXTERNREF_NCELLS;
assert(sizeof(void *) == sz * sizeof(struct cell));
break;
#if defined(TOYWASM_ENABLE_WASM_EXCEPTION_HANDLING)
case TYPE_EXNREF:
sz = EXNREF_NCELLS;
assert(sizeof(struct exception) <= sz * sizeof(struct cell));
break;
#endif
default:
xassert(false);
sz = 0;
Expand Down Expand Up @@ -225,15 +231,13 @@ void
val_to_cells(const struct val *val, struct cell *cells, uint32_t ncells)
{
assert(ncells <= ARRAYCOUNT(val->u.cells));
assert(ncells == 1 || ncells == 2 || ncells == 4);
cells_copy(cells, val->u.cells, ncells);
}

void
val_from_cells(struct val *val, const struct cell *cells, uint32_t ncells)
{
assert(ncells <= ARRAYCOUNT(val->u.cells));
assert(ncells == 1 || ncells == 2 || ncells == 4);
cells_copy(val->u.cells, cells, ncells);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ enum ctrlframe_op {

FRAME_OP_END = 0x0b,

FRAME_OP_TRY_TABLE = 0x1f,

/* pseudo op */
FRAME_OP_EMPTY_ELSE = 0xfe,
FRAME_OP_INVOKE = 0xff,
};

enum try_handler_tag {
CATCH = 0x00,
CATCH_REF = 0x01,
CATCH_ALL = 0x02,
CATCH_ALL_REF = 0x03,
};

struct context {
struct exec_context *exec;
struct validation_context *validation;
Expand Down
Loading
Loading