summaryrefslogtreecommitdiff
path: root/wasm2c
diff options
context:
space:
mode:
Diffstat (limited to 'wasm2c')
-rw-r--r--wasm2c/wasm-rt-impl.c2
-rw-r--r--wasm2c/wasm-rt-impl.h6
2 files changed, 7 insertions, 1 deletions
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 2404d7d1..81804a39 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -32,6 +32,7 @@ typedef struct FuncType {
} FuncType;
uint32_t wasm_rt_call_stack_depth;
+uint32_t g_saved_call_stack_depth;
jmp_buf g_jmp_buf;
FuncType* g_func_types;
@@ -39,6 +40,7 @@ uint32_t g_func_type_count;
void wasm_rt_trap(wasm_rt_trap_t code) {
assert(code != WASM_RT_TRAP_NONE);
+ wasm_rt_call_stack_depth = g_saved_call_stack_depth;
longjmp(g_jmp_buf, code);
}
diff --git a/wasm2c/wasm-rt-impl.h b/wasm2c/wasm-rt-impl.h
index f4bfa09d..bdc4502f 100644
--- a/wasm2c/wasm-rt-impl.h
+++ b/wasm2c/wasm-rt-impl.h
@@ -28,6 +28,9 @@ extern "C" {
/** A setjmp buffer used for handling traps. */
extern jmp_buf g_jmp_buf;
+/** Saved call stack depth that will be restored in case a trap occurs. */
+extern uint32_t g_saved_call_stack_depth;
+
/** Convenience macro to use before calling a wasm function. On first execution
* it will return `WASM_RT_TRAP_NONE` (i.e. 0). If the function traps, it will
* jump back and return the trap that occurred.
@@ -43,7 +46,8 @@ extern jmp_buf g_jmp_buf;
* my_wasm_func();
* ```
*/
-#define wasm_rt_impl_try() setjmp(g_jmp_buf)
+#define wasm_rt_impl_try() \
+ (g_saved_call_stack_depth = wasm_rt_call_stack_depth, setjmp(g_jmp_buf))
#ifdef __cplusplus
}