Commit d6aa879
committed
finding 2: use JS-provided throw_or_abort_impl for WASM error recovery
In WASM builds, BB_NO_EXCEPTIONS is defined which routes throw_or_abort
to std::abort(), killing the WASM process on any error with no recovery.
Two changes fix this:
C++ side: throw_or_abort_impl now stores the error message in an
exported buffer (get_last_error_ptr/get_last_error_length) before
aborting. The abort produces a WebAssembly.RuntimeError trap that is
catchable in JS.
JS side: cbindCall() catches the WASM trap, reads the stored error
message via the exported functions, and re-throws as a proper
Error with the original message. The WASM instance stays alive.
Before: any throw_or_abort in WASM kills the process, PXE crashes.
After: the JS caller gets a catchable Error("actual error message").1 parent e882aec commit d6aa879
File tree
2 files changed
+71
-2
lines changed- barretenberg
- cpp/src/barretenberg/env
- ts/src/barretenberg_wasm/barretenberg_wasm_main
2 files changed
+71
-2
lines changedLines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
8 | 31 | | |
9 | 32 | | |
10 | 33 | | |
| |||
24 | 47 | | |
25 | 48 | | |
26 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
27 | 59 | | |
28 | 60 | | |
29 | 61 | | |
Lines changed: 39 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
226 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
227 | 246 | | |
228 | 247 | | |
229 | 248 | | |
| |||
251 | 270 | | |
252 | 271 | | |
253 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
254 | 291 | | |
255 | 292 | | |
256 | 293 | | |
| |||
0 commit comments