summaryrefslogtreecommitdiff
path: root/wasm/fiber.h
diff options
context:
space:
mode:
authorYuta Saito <kateinoigakukun@gmail.com>2022-01-15 23:10:48 +0900
committerYuta Saito <kateinoigakukun@gmail.com>2022-01-19 11:19:06 +0900
commit65f95f26ff0e7b4be4704fedc52344a26d22a4e2 (patch)
treee4bd17869d8dd479855592f3a571aacae19e964c /wasm/fiber.h
parente41b121e94ccce9877824e55f865885bbabe40c3 (diff)
downloadruby-65f95f26ff0e7b4be4704fedc52344a26d22a4e2.tar.gz
[wasm] add asyncify based setjmp, fiber, register scan emulation
configure.ac: setup build tools and register objects main.c: wrap main with rb_wasm_rt_start to handle asyncify unwinds tool/m4/ruby_wasm_tools.m4: setup default command based on WASI_SDK_PATH environment variable. checks wasm-opt which is used for asyncify. tool/wasm-clangw wasm/wasm-opt: a clang wrapper which replaces real wasm-opt with do-nothing wasm-opt to avoid misoptimization before asyncify. asyncify is performed at POSTLINK, but clang linker driver tries to run optimization by wasm-opt unconditionally. inlining pass at wasm level breaks asyncify's assumption, so should not optimize before POSTLIK. wasm/GNUmakefile.in: wasm specific rules to compile objects
Diffstat (limited to 'wasm/fiber.h')
-rw-r--r--wasm/fiber.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/wasm/fiber.h b/wasm/fiber.h
new file mode 100644
index 0000000000..0f3a336332
--- /dev/null
+++ b/wasm/fiber.h
@@ -0,0 +1,43 @@
+#ifndef RB_WASM_SUPPORT_FIBER_H
+#define RB_WASM_SUPPORT_FIBER_H
+
+#include <stdbool.h>
+
+#ifndef WASM_FIBER_STACK_BUFFER_SIZE
+# define WASM_FIBER_STACK_BUFFER_SIZE 6144
+#endif
+
+struct __rb_wasm_asyncify_fiber_ctx {
+ void* top;
+ void* end;
+ char buffer[WASM_FIBER_STACK_BUFFER_SIZE];
+};
+
+// Fiber execution context needed to perform context switch
+typedef struct {
+ // Fiber entry point called when the fiber started for the first time.
+ // NULL if the entry point is main
+ void (*entry_point)(void *, void *);
+ // Opaque argument pointers passed to the entry point function
+ void *arg0, *arg1;
+
+ // Internal asyncify buffer space
+ struct __rb_wasm_asyncify_fiber_ctx asyncify_buf;
+
+ bool is_rewinding;
+ bool is_started;
+} rb_wasm_fiber_context;
+
+// Initialize a given fiber context to be ready to pass to `rb_wasm_swapcontext`
+void rb_wasm_init_context(rb_wasm_fiber_context *fcp, void (*func)(void *, void *), void *arg0, void *arg1);
+
+// Swap the execution control with `target_fiber` and save the current context in `old_fiber`
+// NOTE: `old_fiber` must be the current executing fiber context
+void rb_wasm_swapcontext(rb_wasm_fiber_context *old_fiber, rb_wasm_fiber_context *target_fiber);
+
+// Returns the Asyncify buffer of next fiber if unwound for fiber context switch.
+// Used by the top level Asyncify handling in wasm/runtime.c
+void *rb_wasm_handle_fiber_unwind(void (**new_fiber_entry)(void *, void *),
+ void **arg0, void **arg1, bool *is_new_fiber_started);
+
+#endif