1 /*
2  * Copyright 2019 The Emscripten Authors.  All rights reserved.
3  * Emscripten is available under two separate licenses, the MIT license and the
4  * University of Illinois/NCSA Open Source License.  Both these licenses can be
5  * found in the LICENSE file.
6  */
7 
8 #pragma once
9 
10 #include <stdint.h>
11 
12 #include <emscripten/emscripten.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 typedef struct asyncify_data_s {
19   void *stack_ptr;     /** Current position in the Asyncify stack (*not* the C stack) */
20   void *stack_limit;   /** Where the Asyncify stack ends. */
21   int rewind_id;       /** Interned ID of the rewind entry point; opaque to application. */
22 } asyncify_data_t;
23 
24 typedef struct emscripten_fiber_s {
25   void *stack_base;             /** Where the C stack starts (NOTE: grows down). */
26   void *stack_limit;            /** Where the C stack ends. */
27   void *stack_ptr;              /** Current position in the C stack. */
28   em_arg_callback_func entry;   /** Function to call when resuming this context. If NULL, asyncify_data is used to rewind the call stack. */
29   void *user_data;              /** Opaque pointer, passed as-is to the entry function. */
30   asyncify_data_t asyncify_data;
31 } emscripten_fiber_t;
32 
33 void emscripten_fiber_init(
34   emscripten_fiber_t *fiber,
35   em_arg_callback_func entry_func,
36   void *entry_func_arg,
37   void *c_stack,
38   size_t c_stack_size,
39   void *asyncify_stack,
40   size_t asyncify_stack_size
41 );
42 
43 void emscripten_fiber_init_from_current_context(
44   emscripten_fiber_t *fiber,
45   void *asyncify_stack,
46   size_t asyncify_stack_size
47 );
48 
49 void emscripten_fiber_swap(
50   emscripten_fiber_t *old_fiber,
51   emscripten_fiber_t *new_fiber
52 );
53 
54 #ifdef __cplusplus
55 }
56 #endif
57