Skip to content

Commit 3195086

Browse files
committed
C_LONGJMP definition, comments
1 parent 18e2fb2 commit 3195086

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

system/lib/compiler-rt/emscripten_setjmp.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ struct __WasmLongjmpArgs {
7878
void *env;
7979
int val;
8080
};
81+
82+
// llvm uses `1` for the __c_longjmp tag.
83+
// See https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
84+
#define C_LONGJMP 1
8185
#endif
8286

8387
// jmp_buf should have large enough size and alignment to contain
@@ -109,19 +113,20 @@ uint32_t __wasm_setjmp_test(void* env, void* func_invocation_id) {
109113
}
110114

111115
#ifdef __USING_WASM_SJLJ__
116+
// Wasm EH allows us to throw and catch multiple values, but that requires
117+
// multivalue support in the toolchain, whch is not reliable at the time.
118+
// TODO Consider switching to throwing two values at the same time later.
112119
void __wasm_longjmp(void* env, int val) {
113120
struct jmp_buf_impl* jb = env;
114121
struct __WasmLongjmpArgs* arg = &jb->arg;
115-
/*
116-
* C standard says:
117-
* The longjmp function cannot cause the setjmp macro to return
118-
* the value 0; if val is 0, the setjmp macro returns the value 1.
119-
*/
122+
// C standard says:
123+
// The longjmp function cannot cause the setjmp macro to return
124+
// the value 0; if val is 0, the setjmp macro returns the value 1.
120125
if (val == 0) {
121126
val = 1;
122127
}
123128
arg->env = env;
124129
arg->val = val;
125-
__builtin_wasm_throw(1, arg); /* 1 == C_LONGJMP */
130+
__builtin_wasm_throw(C_LONGJMP, arg);
126131
}
127132
#endif

0 commit comments

Comments
 (0)