1#include "wasm/setjmp.h"
2#include "wasm/asyncify.h"
3#include "wasm/machine.h"
7void check_direct(
void) {
10 printf(
"[%s] start\n", __func__);
11 printf(
"[%s] call rb_wasm_setjmp\n", __func__);
12 if ((val = rb_wasm_setjmp(buf)) == 0) {
13 printf(
"[%s] rb_wasm_setjmp(buf) == 0\n", __func__);
14 printf(
"[%s] call rb_wasm_longjmp(buf, 2)\n", __func__);
15 rb_wasm_longjmp(buf, 2);
16 assert(0 &&
"unreachable after longjmp");
18 printf(
"[%s] rb_wasm_setjmp(buf) == %d\n", __func__, val);
19 printf(
"[%s] sp = %p\n", __func__, rb_wasm_get_stack_pointer());
20 assert(val == 2 &&
"unexpected returned value");
22 printf(
"[%s] end\n", __func__);
27 printf(
"[%s] start sp = %p\n", __func__, rb_wasm_get_stack_pointer());
28 printf(
"[%s] call rb_wasm_setjmp\n", __func__);
29 if (rb_wasm_setjmp(buf) == 0) {
30 printf(
"[%s] rb_wasm_setjmp(buf) == 0\n", __func__);
31 printf(
"[%s] call rb_wasm_longjmp(dst, 4)\n", __func__);
32 rb_wasm_longjmp(*dst, 4);
33 assert(0 &&
"unreachable after longjmp");
35 assert(0 &&
"unreachable");
37 printf(
"[%s] end\n", __func__);
40void check_jump_two_level(
void) {
43 printf(
"[%s] start\n", __func__);
44 printf(
"[%s] call rb_wasm_setjmp\n", __func__);
45 if ((val = rb_wasm_setjmp(buf)) == 0) {
46 printf(
"[%s] rb_wasm_setjmp(buf) == 0\n", __func__);
47 printf(
"[%s] call jump_to_dst(&buf)\n", __func__);
49 assert(0 &&
"unreachable after longjmp");
51 printf(
"[%s] rb_wasm_setjmp(buf) == %d\n", __func__, val);
52 assert(val == 4 &&
"unexpected returned value");
54 printf(
"[%s] end\n", __func__);
57void check_reuse(
void) {
60 printf(
"[%s] start\n", __func__);
61 printf(
"[%s] call rb_wasm_setjmp\n", __func__);
62 if ((val = rb_wasm_setjmp(buf)) == 0) {
63 printf(
"[%s] rb_wasm_setjmp(buf) == 0\n", __func__);
64 printf(
"[%s] call rb_wasm_longjmp(buf, 2)\n", __func__);
65 rb_wasm_longjmp(buf, 2);
66 assert(0 &&
"unreachable after longjmp");
68 printf(
"[%s] rb_wasm_setjmp(buf) == %d\n", __func__, val);
70 printf(
"[%s] re-call rb_wasm_longjmp(buf, %d)\n", __func__, val + 1);
71 rb_wasm_longjmp(buf, val + 1);
74 printf(
"[%s] end\n", __func__);
77void check_stack_ptr(
void) {
78 static void *normal_sp;
80 normal_sp = rb_wasm_get_stack_pointer();
82 printf(
"[%s] start sp = %p\n", __func__, normal_sp);
83 printf(
"[%s] call rb_wasm_setjmp\n", __func__);
84 if (rb_wasm_setjmp(buf) == 0) {
85 printf(
"[%s] call jump_to_dst(&buf)\n", __func__);
87 assert(0 &&
"unreachable after longjmp");
89 printf(
"[%s] sp = %p\n", __func__, rb_wasm_get_stack_pointer());
90 assert(rb_wasm_get_stack_pointer() == normal_sp);
92 printf(
"[%s] end\n", __func__);
97int start(
int argc,
char **argv) {
99 check_jump_two_level();
105int main(
int argc,
char **argv) {
106 extern int rb_wasm_rt_start(
int (main)(
int argc,
char **argv),
int argc,
char **argv);
107 return rb_wasm_rt_start(start, argc, argv);