1 #include "wasm/machine.h"
2 #include "wasm/setjmp.h"
3 #include "wasm/fiber.h"
4 #include "wasm/asyncify.h"
7 int rb_wasm_rt_start(int (main
)(int argc
, char **argv
), int argc
, char **argv
) {
11 bool new_fiber_started
= false;
12 void *arg0
= NULL
, *arg1
= NULL
;
13 void (*fiber_entry_point
)(void *, void *) = NULL
;
16 if (fiber_entry_point
) {
17 fiber_entry_point(arg0
, arg1
);
19 result
= main(argc
, argv
);
22 extern void *rb_asyncify_unwind_buf
;
23 // Exit Asyncify loop if there is no unwound buffer, which
24 // means that main function has returned normally.
25 if (rb_asyncify_unwind_buf
== NULL
) {
29 // NOTE: it's important to call 'asyncify_stop_unwind' here instead in rb_wasm_handle_jmp_unwind
30 // because unless that, Asyncify inserts another unwind check here and it unwinds to the root frame.
31 asyncify_stop_unwind();
33 if ((asyncify_buf
= rb_wasm_handle_jmp_unwind()) != NULL
) {
34 asyncify_start_rewind(asyncify_buf
);
37 if ((asyncify_buf
= rb_wasm_handle_scan_unwind()) != NULL
) {
38 asyncify_start_rewind(asyncify_buf
);
42 asyncify_buf
= rb_wasm_handle_fiber_unwind(&fiber_entry_point
, &arg0
, &arg1
, &new_fiber_started
);
43 // Newly starting fiber doesn't have asyncify buffer yet, so don't rewind it for the first time entry
45 asyncify_start_rewind(asyncify_buf
);
47 } else if (new_fiber_started
) {