Ruby  3.4.0dev (2024-11-06 revision 4120f2babd7924a31c6d685be2429492af5c19b9)
machine.c
1 #include <stdlib.h>
2 #include "wasm/machine.h"
3 #include "wasm/asyncify.h"
4 
5 #ifndef WASM_SCAN_STACK_BUFFER_SIZE
6 # define WASM_SCAN_STACK_BUFFER_SIZE 6144
7 #endif
8 
9 struct asyncify_buf {
10  void *top;
11  void *end;
12  uint8_t buffer[WASM_SCAN_STACK_BUFFER_SIZE];
13 };
14 
15 static void
16 init_asyncify_buf(struct asyncify_buf* buf)
17 {
18  buf->top = &buf->buffer[0];
19  buf->end = &buf->buffer[WASM_SCAN_STACK_BUFFER_SIZE];
20 }
21 
22 static void *_rb_wasm_active_scan_buf = NULL;
23 
24 void
25 rb_wasm_scan_locals(rb_wasm_scan_func scan)
26 {
27  static struct asyncify_buf buf;
28  static int spilling = 0;
29  if (!spilling) {
30  spilling = 1;
31  init_asyncify_buf(&buf);
32  _rb_wasm_active_scan_buf = &buf;
33  asyncify_start_unwind(&buf);
34  } else {
35  asyncify_stop_rewind();
36  spilling = 0;
37  _rb_wasm_active_scan_buf = NULL;
38  scan(buf.top, buf.end);
39  }
40 }
41 
42 static void *rb_wasm_stack_base = NULL;
43 
44 __attribute__((constructor))
45 int
46 rb_wasm_record_stack_base(void)
47 {
48  rb_wasm_stack_base = rb_wasm_get_stack_pointer();
49  return 0;
50 }
51 
52 void *
53 rb_wasm_stack_get_base(void)
54 {
55  return rb_wasm_stack_base;
56 }
57 
58 void *
59 rb_wasm_handle_scan_unwind(void)
60 {
61  return _rb_wasm_active_scan_buf;
62 }