@@ -74,40 +74,20 @@ void emscripten_longjmp(uintptr_t env, int val) {
74
74
#endif
75
75
76
76
#ifdef __USING_WASM_SJLJ__
77
-
78
77
struct __WasmLongjmpArgs {
79
78
void * env ;
80
79
int val ;
81
80
};
82
-
83
- thread_local struct __WasmLongjmpArgs __wasm_longjmp_args ;
84
-
85
- // llvm uses `1` for the __c_longjmp tag.
86
- // See https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
87
- #define C_LONGJMP 1
88
-
89
- // Wasm EH allows us to throw and catch multiple values, but that requires
90
- // multivalue support in the toolchain, whch is not reliable at the time.
91
- // TODO Consider switching to throwing two values at the same time later.
92
- void __wasm_longjmp (void * env , int val ) {
93
- __wasm_longjmp_args .env = env ;
94
- /*
95
-  * C standard:
96
-  * The longjmp function cannot cause the setjmp macro to return
97
-  * the value 0; if val is 0, the setjmp macro returns the value 1.
98
-  */
99
- if (val == 0 ) {
100
- val = 1 ;
101
- }
102
- __wasm_longjmp_args .val = val ;
103
- __builtin_wasm_throw (C_LONGJMP , & __wasm_longjmp_args );
104
- }
81
+ #endif
105
82
106
83
// jmp_buf should have large enough size and alignment to contain
107
84
// this structure.
108
85
struct jmp_buf_impl {
109
86
void * func_invocation_id ;
110
87
uint32_t label ;
88
+ #ifdef __USING_WASM_SJLJ__
89
+ struct __WasmLongjmpArgs arg ;
90
+ #endif
111
91
};
112
92
113
93
void __wasm_setjmp (void * env , uint32_t label , void * func_invocation_id ) {
@@ -127,4 +107,23 @@ uint32_t __wasm_setjmp_test(void* env, void* func_invocation_id) {
127
107
}
128
108
return 0 ;
129
109
}
110
+
111
+ #ifdef __USING_WASM_SJLJ__
112
+ void
113
+ __wasm_longjmp (void * env , int val )
114
+ {
115
+ struct jmp_buf_impl * jb = env ;
116
+ struct __WasmLongjmpArgs * arg = & jb -> arg ;
117
+ /*
118
+ * C standard says:
119
+ * The longjmp function cannot cause the setjmp macro to return
120
+ * the value 0; if val is 0, the setjmp macro returns the value 1.
121
+ */
122
+ if (val == 0 ) {
123
+ val = 1 ;
124
+ }
125
+ arg -> env = env ;
126
+ arg -> val = val ;
127
+ __builtin_wasm_throw (1 , arg ); /* 1 == C_LONGJMP */
128
+ }
130
129
#endif
0 commit comments