diff options
Diffstat (limited to 'wasm/setjmp.h')
-rw-r--r-- | wasm/setjmp.h | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/wasm/setjmp.h b/wasm/setjmp.h index 30ea23ca12..cc14df33be 100644 --- a/wasm/setjmp.h +++ b/wasm/setjmp.h @@ -19,7 +19,7 @@ typedef struct { struct __rb_wasm_asyncify_jmp_buf setjmp_buf; // Internal Asyncify buffer space used while unwinding from longjmp // but never used for rewinding. - struct __rb_wasm_asyncify_jmp_buf longjmp_buf; + struct __rb_wasm_asyncify_jmp_buf *longjmp_buf_ptr; // Used to save top address of Asyncify stack `setjmp_buf`, which is // overwritten during first rewind. void *dst_buf_top; @@ -58,4 +58,38 @@ typedef rb_wasm_jmp_buf jmp_buf; #define setjmp(env) rb_wasm_setjmp(env) #define longjmp(env, payload) rb_wasm_longjmp(env, payload) + +typedef void (*rb_wasm_try_catch_func_t)(void *ctx); + +struct rb_wasm_try_catch { + rb_wasm_try_catch_func_t try_f; + rb_wasm_try_catch_func_t catch_f; + void *context; + int state; +}; + +// +// Lightweight try-catch API without unwinding to root frame. +// + +void +rb_wasm_try_catch_init(struct rb_wasm_try_catch *try_catch, + rb_wasm_try_catch_func_t try_f, + rb_wasm_try_catch_func_t catch_f, + void *context); + +// Run, catch longjmp thrown by run, and re-catch longjmp thrown by catch, ... +// +// 1. run try_f of try_catch struct +// 2. catch longjmps with the given target jmp_buf or exit +// 3. run catch_f if not NULL, otherwise exit +// 4. catch longjmps with the given target jmp_buf or exit +// 5. repeat from step 3 +// +// NOTICE: This API assumes that all longjmp targeting the given jmp_buf are NOT called +// after the function that called this function has exited. +// +void +rb_wasm_try_catch_loop_run(struct rb_wasm_try_catch *try_catch, rb_wasm_jmp_buf *target); + #endif |