Skip to content

Commit 57817d3

Browse files
committed
Add a setjmp/longjmp runtime for a new sjlj translation proposed in LLVM
the new runtime code is basically a copy from: https://github.com/yamt/garbage/blob/wasm-sjlj-alt2/wasm/longjmp/rt.c. The corresponding LLVM change: llvm/llvm-project#84137 Discussion: https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit
1 parent 2ba2078 commit 57817d3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,4 @@ a license to everyone to use it as detailed in LICENSE.)
597597
* James Hu <[email protected]>
598598
* Jerry Zhuang <[email protected]>
599599
* Taisei Kon <[email protected]>
600+
* YAMAMOTO Takashi <[email protected]>

system/lib/compiler-rt/emscripten_setjmp.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* found in the LICENSE file.
66
*/
77

8+
#include <assert.h>
89
#include <stdint.h>
910
#include <stdlib.h>
1011
#include <setjmp.h>
@@ -102,4 +103,28 @@ void __wasm_longjmp(void *env, int val) {
102103
__builtin_wasm_throw(C_LONGJMP, &__wasm_longjmp_args);
103104
}
104105

106+
// jmp_buf should have large enough size and alignment to contain
107+
// this structure.
108+
struct jmp_buf_impl {
109+
void* func_invocation_id;
110+
uint32_t label;
111+
};
112+
113+
void __wasm_setjmp(void* env, uint32_t label, void* func_invocation_id) {
114+
struct jmp_buf_impl* jb = env;
115+
assert(label != 0); // ABI contract
116+
assert(func_invocation_id != NULL); // sanity check
117+
jb->func_invocation_id = func_invocation_id;
118+
jb->label = label;
119+
}
120+
121+
uint32_t __wasm_setjmp_test(void* env, void* func_invocation_id) {
122+
struct jmp_buf_impl* jb = env;
123+
assert(jb->label != 0); // ABI contract
124+
assert(func_invocation_id != NULL); // sanity check
125+
if (jb->func_invocation_id == func_invocation_id) {
126+
return jb->label;
127+
}
128+
return 0;
129+
}
105130
#endif

0 commit comments

Comments
 (0)