Commit 8992b99
authored
trap on blocking call in sync task before return (#12043)
* trap on blocking call in sync task before return
This implements a spec change (PR pending) such that tasks created for calls to
synchronous exports may not call potentially-blocking imports or return `wait`
or `poll` callback codes prior to returning a value. Specifically, the
following are prohibited in that scenario:
- returning callback-code.{wait,poll}
- sync calling an async import
- sync calling subtask.cancel
- sync calling {stream,future}.{read,write}
- sync calling {stream,future}.cancel-{read,write}
- calling waitable-set.{wait,poll}
- calling thread.suspend
This breaks a number of tests, which will be addressed in follow-up commits:
- The `{tcp,udp}-socket.bind` implementation in `wasmtime-wasi` is implemented
using `Linker::func_wrap_concurrent` and thus assumed to be async, whereas the
WIT interface says they're sync, leading to a type mismatch error at runtime.
Alex and I have discussed this and have a general plan to address it.
- A number of tests in the tests/component-model submodule that points to the
spec repo are failing. Those will presumably be fixed as part of the upcoming
spec PR (although some could be due to bugs in this implementation, in which
case I'll fix them).
- A number of tests in tests/misc_testsuite are failing. I'll address those in
a follow-up commit.
Signed-off-by: Joel Dice <[email protected]>
* call `check_may_leave` before `check_blocking`
`check_blocking` needs access to the current task, but that's not set for
post-return functions since those should not be calling _any_ imports at all, so
first check for that.
Signed-off-by: Joel Dice <[email protected]>
* fix `misc_testsuite` test regressions
This amounts to adding `async` to any exported component functions that might
need to block.
Signed-off-by: Joel Dice <[email protected]>
* simplify code in `ConcurrentState::check_blocking`
Signed-off-by: Joel Dice <[email protected]>
* make `thread.yield` a no-op in non-blocking contexts
Per the proposed spec changes, `thread.yield` should return control to the guest
immediately without allowing any other thread to run. Similarly, when an
async-lifted export or callback returns `CALLBACK_CODE_YIELD`, we should call
the callback again immediately without allowing another thread to run.
Signed-off-by: Joel Dice <[email protected]>
* fix build when `component-model-async` feature disabled
Signed-off-by: Joel Dice <[email protected]>
* fix more test regressions
Signed-off-by: Joel Dice <[email protected]>
* fix more test regressions
Note that this temporarily updates the `tests/component-model` submodule to the
branch for WebAssembly/component-model#577 until that PR
is merged.
Signed-off-by: Joel Dice <[email protected]>
* tweak `Trap::CannotBlockSyncTask` message
This clarifies that such a task cannot block prior to returning.
Signed-off-by: Joel Dice <[email protected]>
* fix cancel_host_future test
Signed-off-by: Joel Dice <[email protected]>
* trap sync-lowered, guest->guest async calls in sync tasks
I somehow forgot to address this earlier. Thanks to Luke for catching this.
Note that this commit doesn't include test coverage, but Luke's forthecoming
tests in the `component-model` repo will cover it, and we'll pull that in with
the next submodule update.
Signed-off-by: Joel Dice <[email protected]>
* switch back to `main` branch of `component-model` repo
...and skip or `should_fail` the tests that won't pass until
WebAssembly/component-model#578 is merged.
Signed-off-by: Joel Dice <[email protected]>
* add `trap-if-block-and-sync.wast`
We'll remove this again in favor of the upstream version once
WebAssembly/component-model#578 has been merged.
Signed-off-by: Joel Dice <[email protected]>
* address review feedback
- Assert that `StoreOpaque::suspend` is not called in a non-blocking context except in specific circumstances
- Typecheck async-ness for dynamic host functions
- Use type parameter instead of value parameter in `call_host[_dynamic]`
Signed-off-by: Joel Dice <[email protected]>
* add explanation comments to `check_blocking` calls
Signed-off-by: Joel Dice <[email protected]>
* fix fuzz test oracle for async functions
Signed-off-by: Joel Dice <[email protected]>
---------
Signed-off-by: Joel Dice <[email protected]>1 parent 9fd594a commit 8992b99
File tree
36 files changed
+876
-156
lines changed- crates
- cranelift/src/compiler
- environ/src
- component
- translate
- fact
- misc/component-async-tests/wit
- test-programs/src/bin
- test-util/src
- wasmtime/src/runtime
- component
- concurrent
- func
- vm/component
- tests
- all
- component_model
- misc_testsuite
- component-model-threading
- component-model/async
36 files changed
+876
-156
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
745 | 753 | | |
746 | 754 | | |
747 | 755 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
| 191 | + | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
| 481 | + | |
481 | 482 | | |
482 | 483 | | |
483 | 484 | | |
| |||
1160 | 1161 | | |
1161 | 1162 | | |
1162 | 1163 | | |
| 1164 | + | |
1163 | 1165 | | |
1164 | 1166 | | |
1165 | 1167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1112 | 1112 | | |
1113 | 1113 | | |
1114 | 1114 | | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
1115 | 1119 | | |
1116 | 1120 | | |
1117 | 1121 | | |
| |||
1242 | 1246 | | |
1243 | 1247 | | |
1244 | 1248 | | |
| 1249 | + | |
1245 | 1250 | | |
1246 | 1251 | | |
1247 | 1252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
348 | 349 | | |
349 | 350 | | |
350 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| 93 | + | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
259 | 262 | | |
260 | 263 | | |
261 | 264 | | |
| 265 | + | |
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
| |||
712 | 716 | | |
713 | 717 | | |
714 | 718 | | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
715 | 730 | | |
716 | 731 | | |
717 | 732 | | |
| |||
870 | 885 | | |
871 | 886 | | |
872 | 887 | | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
873 | 891 | | |
874 | 892 | | |
875 | 893 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
544 | 544 | | |
545 | 545 | | |
546 | 546 | | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
547 | 552 | | |
548 | 553 | | |
549 | 554 | | |
| |||
748 | 753 | | |
749 | 754 | | |
750 | 755 | | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
751 | 761 | | |
752 | 762 | | |
753 | 763 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
| |||
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
190 | 194 | | |
191 | 195 | | |
192 | 196 | | |
| 197 | + | |
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
0 commit comments