Ruby: wasm/machine.c Source File

Ruby 3.2.5p208 (2024-07-26 revision 31d0f1a2e7dbfb60731d1f05b868e1d578cda493)

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
15static void
16init_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
22static void *_rb_wasm_active_scan_buf = NULL;
23
24void
25rb_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
42static void *rb_wasm_stack_base = NULL;
43
44 __attribute__((constructor))
45int
46rb_wasm_record_stack_base(void)
47{
48 rb_wasm_stack_base = rb_wasm_get_stack_pointer();
49 return 0;
50}
51
52void *
53rb_wasm_stack_get_base(void)
54{
55 return rb_wasm_stack_base;
56}
57
58void *
59rb_wasm_handle_scan_unwind(void)
60{
61 return _rb_wasm_active_scan_buf;
62}
asyncify_buf
Definition machine.c:9
__attribute__
Definition vm_insnhelper.c:2198