debase-ruby_core_source 0.10.12 → 0.10.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/addr2line.h +20 -0
  3. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/builtin.h +83 -0
  4. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/check_type/check_type.h +63 -0
  6. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/container_of/container_of.h +142 -0
  7. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/list/list.h +788 -0
  8. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/str/str.h +16 -0
  9. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/constant.h +55 -0
  10. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/darray.h +198 -0
  11. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/debug_counter.h +467 -0
  12. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/dln.h +31 -0
  13. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/encindex.h +70 -0
  14. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/eval_intern.h +304 -0
  15. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/gc.h +142 -0
  16. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/hrtime.h +168 -0
  17. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/id.h +293 -0
  18. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/id_table.h +36 -0
  19. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/insns.inc +247 -0
  20. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/insns_info.inc +8978 -0
  21. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/array.h +113 -0
  22. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/bignum.h +246 -0
  23. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/bits.h +565 -0
  24. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/class.h +188 -0
  25. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compar.h +49 -0
  26. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compile.h +35 -0
  27. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compilers.h +107 -0
  28. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/complex.h +29 -0
  29. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/cont.h +24 -0
  30. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/dir.h +16 -0
  31. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enc.h +19 -0
  32. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/encoding.h +30 -0
  33. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enum.h +18 -0
  34. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enumerator.h +21 -0
  35. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/error.h +191 -0
  36. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/eval.h +32 -0
  37. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/file.h +38 -0
  38. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/fixnum.h +184 -0
  39. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/gc.h +175 -0
  40. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/hash.h +243 -0
  41. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/imemo.h +243 -0
  42. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/inits.h +50 -0
  43. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/io.h +38 -0
  44. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/load.h +18 -0
  45. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/loadpath.h +16 -0
  46. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/math.h +23 -0
  47. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/missing.h +18 -0
  48. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/numeric.h +271 -0
  49. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/object.h +83 -0
  50. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/parse.h +23 -0
  51. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/proc.h +32 -0
  52. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/process.h +137 -0
  53. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/random.h +16 -0
  54. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/range.h +40 -0
  55. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/rational.h +72 -0
  56. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/re.h +30 -0
  57. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/sanitizers.h +190 -0
  58. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/serial.h +23 -0
  59. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/signal.h +21 -0
  60. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/static_assert.h +16 -0
  61. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/string.h +141 -0
  62. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/struct.h +153 -0
  63. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/symbol.h +40 -0
  64. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/thread.h +53 -0
  65. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/time.h +34 -0
  66. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/transcode.h +20 -0
  67. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/util.h +27 -0
  68. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/variable.h +83 -0
  69. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/vm.h +132 -0
  70. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/warnings.h +16 -0
  71. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal.h +109 -0
  72. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/iseq.h +320 -0
  73. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/known_errors.inc +791 -0
  74. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/method.h +245 -0
  75. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/mjit.h +231 -0
  76. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/mjit_compile.inc +8265 -0
  77. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/node.h +499 -0
  78. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/node_name.inc +210 -0
  79. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/opt_sc.inc +107 -0
  80. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/optinsn.inc +128 -0
  81. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/optunifs.inc +43 -0
  82. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/parse.h +214 -0
  83. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/probes_helper.h +44 -0
  84. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ractor_core.h +346 -0
  85. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regenc.h +254 -0
  86. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regint.h +942 -0
  87. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regparse.h +370 -0
  88. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/revision.h +2 -0
  89. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ruby_assert.h +14 -0
  90. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ruby_atomic.h +23 -0
  91. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/siphash.h +48 -0
  92. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/symbol.h +119 -0
  93. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/thread_pthread.h +115 -0
  94. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/thread_win32.h +61 -0
  95. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/timev.h +57 -0
  96. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/transcode_data.h +138 -0
  97. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/transient_heap.h +65 -0
  98. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/variable.h +21 -0
  99. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/version.h +88 -0
  100. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm.inc +5415 -0
  101. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_call_iseq_optimized.inc +244 -0
  102. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_callinfo.h +454 -0
  103. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_core.h +2103 -0
  104. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_debug.h +119 -0
  105. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_exec.h +197 -0
  106. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_insnhelper.h +265 -0
  107. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_opts.h +73 -0
  108. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_sync.h +137 -0
  109. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vmtc.inc +241 -0
  110. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit.h +63 -0
  111. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_asm.h +392 -0
  112. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_codegen.h +19 -0
  113. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_core.h +302 -0
  114. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_iface.h +38 -0
  115. data/lib/debase/ruby_core_source/version.rb +1 -1
  116. metadata +116 -3
@@ -0,0 +1,2103 @@
1
+ #ifndef RUBY_VM_CORE_H
2
+ #define RUBY_VM_CORE_H
3
+ /**********************************************************************
4
+
5
+ vm_core.h -
6
+
7
+ $Author$
8
+ created at: 04/01/01 19:41:38 JST
9
+
10
+ Copyright (C) 2004-2007 Koichi Sasada
11
+
12
+ **********************************************************************/
13
+
14
+ /*
15
+ * Enable check mode.
16
+ * 1: enable local assertions.
17
+ */
18
+ #ifndef VM_CHECK_MODE
19
+
20
+ // respect RUBY_DUBUG: if given n is 0, then use RUBY_DEBUG
21
+ #define N_OR_RUBY_DEBUG(n) (((n) > 0) ? (n) : RUBY_DEBUG)
22
+
23
+ #define VM_CHECK_MODE N_OR_RUBY_DEBUG(0)
24
+ #endif
25
+
26
+ /**
27
+ * VM Debug Level
28
+ *
29
+ * debug level:
30
+ * 0: no debug output
31
+ * 1: show instruction name
32
+ * 2: show stack frame when control stack frame is changed
33
+ * 3: show stack status
34
+ * 4: show register
35
+ * 5:
36
+ * 10: gc check
37
+ */
38
+
39
+ #ifndef VMDEBUG
40
+ #define VMDEBUG 0
41
+ #endif
42
+
43
+ #if 0
44
+ #undef VMDEBUG
45
+ #define VMDEBUG 3
46
+ #endif
47
+
48
+ #include "ruby/internal/config.h"
49
+
50
+ #include <stddef.h>
51
+ #include <signal.h>
52
+ #include <stdarg.h>
53
+
54
+ #include "ruby_assert.h"
55
+
56
+ #if VM_CHECK_MODE > 0
57
+ #define VM_ASSERT(expr) RUBY_ASSERT_MESG_WHEN(VM_CHECK_MODE > 0, expr, #expr)
58
+ #define VM_UNREACHABLE(func) rb_bug(#func ": unreachable")
59
+
60
+ #else
61
+ #define VM_ASSERT(expr) ((void)0)
62
+ #define VM_UNREACHABLE(func) UNREACHABLE
63
+ #endif
64
+
65
+ #include <setjmp.h>
66
+
67
+ #include "ruby/internal/stdbool.h"
68
+ #include "ccan/list/list.h"
69
+ #include "id.h"
70
+ #include "internal.h"
71
+ #include "internal/array.h"
72
+ #include "internal/serial.h"
73
+ #include "internal/vm.h"
74
+ #include "method.h"
75
+ #include "node.h"
76
+ #include "ruby/ruby.h"
77
+ #include "ruby/st.h"
78
+ #include "ruby_atomic.h"
79
+ #include "vm_opts.h"
80
+ #include "darray.h"
81
+
82
+ #include "ruby/thread_native.h"
83
+ #include THREAD_IMPL_H
84
+
85
+ #define RUBY_VM_THREAD_MODEL 2
86
+
87
+ /*
88
+ * implementation selector of get_insn_info algorithm
89
+ * 0: linear search
90
+ * 1: binary search
91
+ * 2: succinct bitvector
92
+ */
93
+ #ifndef VM_INSN_INFO_TABLE_IMPL
94
+ # define VM_INSN_INFO_TABLE_IMPL 2
95
+ #endif
96
+
97
+ #if defined(NSIG_MAX) /* POSIX issue 8 */
98
+ # undef NSIG
99
+ # define NSIG NSIG_MAX
100
+ #elif defined(_SIG_MAXSIG) /* FreeBSD */
101
+ # undef NSIG
102
+ # define NSIG _SIG_MAXSIG
103
+ #elif defined(_SIGMAX) /* QNX */
104
+ # define NSIG (_SIGMAX + 1)
105
+ #elif defined(NSIG) /* 99% of everything else */
106
+ # /* take it */
107
+ #else /* Last resort */
108
+ # define NSIG (sizeof(sigset_t) * CHAR_BIT + 1)
109
+ #endif
110
+
111
+ #define RUBY_NSIG NSIG
112
+
113
+ #if defined(SIGCLD)
114
+ # define RUBY_SIGCHLD (SIGCLD)
115
+ #elif defined(SIGCHLD)
116
+ # define RUBY_SIGCHLD (SIGCHLD)
117
+ #else
118
+ # define RUBY_SIGCHLD (0)
119
+ #endif
120
+
121
+ /* platforms with broken or non-existent SIGCHLD work by polling */
122
+ #if defined(__APPLE__)
123
+ # define SIGCHLD_LOSSY (1)
124
+ #else
125
+ # define SIGCHLD_LOSSY (0)
126
+ #endif
127
+
128
+ /* define to 0 to test old code path */
129
+ #define WAITPID_USE_SIGCHLD (RUBY_SIGCHLD || SIGCHLD_LOSSY)
130
+
131
+ #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
132
+ # define USE_SIGALTSTACK
133
+ void *rb_allocate_sigaltstack(void);
134
+ void *rb_register_sigaltstack(void *);
135
+ # define RB_ALTSTACK_INIT(var, altstack) var = rb_register_sigaltstack(altstack)
136
+ # define RB_ALTSTACK_FREE(var) free(var)
137
+ # define RB_ALTSTACK(var) var
138
+ #else /* noop */
139
+ # define RB_ALTSTACK_INIT(var, altstack)
140
+ # define RB_ALTSTACK_FREE(var)
141
+ # define RB_ALTSTACK(var) (0)
142
+ #endif
143
+
144
+ /*****************/
145
+ /* configuration */
146
+ /*****************/
147
+
148
+ /* gcc ver. check */
149
+ #if defined(__GNUC__) && __GNUC__ >= 2
150
+
151
+ #if OPT_TOKEN_THREADED_CODE
152
+ #if OPT_DIRECT_THREADED_CODE
153
+ #undef OPT_DIRECT_THREADED_CODE
154
+ #endif
155
+ #endif
156
+
157
+ #else /* defined(__GNUC__) && __GNUC__ >= 2 */
158
+
159
+ /* disable threaded code options */
160
+ #if OPT_DIRECT_THREADED_CODE
161
+ #undef OPT_DIRECT_THREADED_CODE
162
+ #endif
163
+ #if OPT_TOKEN_THREADED_CODE
164
+ #undef OPT_TOKEN_THREADED_CODE
165
+ #endif
166
+ #endif
167
+
168
+ /* call threaded code */
169
+ #if OPT_CALL_THREADED_CODE
170
+ #if OPT_DIRECT_THREADED_CODE
171
+ #undef OPT_DIRECT_THREADED_CODE
172
+ #endif /* OPT_DIRECT_THREADED_CODE */
173
+ #if OPT_STACK_CACHING
174
+ #undef OPT_STACK_CACHING
175
+ #endif /* OPT_STACK_CACHING */
176
+ #endif /* OPT_CALL_THREADED_CODE */
177
+
178
+ void rb_vm_encoded_insn_data_table_init(void);
179
+ typedef unsigned long rb_num_t;
180
+ typedef signed long rb_snum_t;
181
+
182
+ enum ruby_tag_type {
183
+ RUBY_TAG_NONE = 0x0,
184
+ RUBY_TAG_RETURN = 0x1,
185
+ RUBY_TAG_BREAK = 0x2,
186
+ RUBY_TAG_NEXT = 0x3,
187
+ RUBY_TAG_RETRY = 0x4,
188
+ RUBY_TAG_REDO = 0x5,
189
+ RUBY_TAG_RAISE = 0x6,
190
+ RUBY_TAG_THROW = 0x7,
191
+ RUBY_TAG_FATAL = 0x8,
192
+ RUBY_TAG_MASK = 0xf
193
+ };
194
+
195
+ #define TAG_NONE RUBY_TAG_NONE
196
+ #define TAG_RETURN RUBY_TAG_RETURN
197
+ #define TAG_BREAK RUBY_TAG_BREAK
198
+ #define TAG_NEXT RUBY_TAG_NEXT
199
+ #define TAG_RETRY RUBY_TAG_RETRY
200
+ #define TAG_REDO RUBY_TAG_REDO
201
+ #define TAG_RAISE RUBY_TAG_RAISE
202
+ #define TAG_THROW RUBY_TAG_THROW
203
+ #define TAG_FATAL RUBY_TAG_FATAL
204
+ #define TAG_MASK RUBY_TAG_MASK
205
+
206
+ enum ruby_vm_throw_flags {
207
+ VM_THROW_NO_ESCAPE_FLAG = 0x8000,
208
+ VM_THROW_STATE_MASK = 0xff
209
+ };
210
+
211
+ /* forward declarations */
212
+ struct rb_thread_struct;
213
+ struct rb_control_frame_struct;
214
+
215
+ /* iseq data type */
216
+ typedef struct rb_compile_option_struct rb_compile_option_t;
217
+
218
+ union ic_serial_entry {
219
+ rb_serial_t raw;
220
+ VALUE data[2];
221
+ };
222
+
223
+ // imemo_constcache
224
+ struct iseq_inline_constant_cache_entry {
225
+ VALUE flags;
226
+
227
+ VALUE value; // v0
228
+ union ic_serial_entry ic_serial; // v1, v2
229
+ const rb_cref_t *ic_cref; // v3
230
+ };
231
+ STATIC_ASSERT(sizeof_iseq_inline_constant_cache_entry,
232
+ (offsetof(struct iseq_inline_constant_cache_entry, ic_cref) +
233
+ sizeof(const rb_cref_t *)) <= sizeof(struct RObject));
234
+
235
+ #if SIZEOF_SERIAL_T <= SIZEOF_VALUE
236
+
237
+ #define GET_IC_SERIAL(ice) (ice)->ic_serial.raw
238
+ #define SET_IC_SERIAL(ice, v) (ice)->ic_serial.raw = (v)
239
+
240
+ #else
241
+
242
+ static inline rb_serial_t
243
+ get_ic_serial(const struct iseq_inline_constant_cache_entry *ice)
244
+ {
245
+ union ic_serial_entry tmp;
246
+ tmp.data[0] = ice->ic_serial.data[0];
247
+ tmp.data[1] = ice->ic_serial.data[1];
248
+ return tmp.raw;
249
+ }
250
+
251
+ #define GET_IC_SERIAL(ice) get_ic_serial(ice)
252
+
253
+ static inline void
254
+ set_ic_serial(struct iseq_inline_constant_cache_entry *ice, rb_serial_t v)
255
+ {
256
+ union ic_serial_entry tmp;
257
+ tmp.raw = v;
258
+ ice->ic_serial.data[0] = tmp.data[0];
259
+ ice->ic_serial.data[1] = tmp.data[1];
260
+ }
261
+
262
+ #define SET_IC_SERIAL(ice, v) set_ic_serial((ice), (v))
263
+
264
+ #endif
265
+
266
+ struct iseq_inline_constant_cache {
267
+ struct iseq_inline_constant_cache_entry *entry;
268
+ // For YJIT: the index to the opt_getinlinecache instruction in the same iseq.
269
+ // It's set during compile time and constant once set.
270
+ unsigned get_insn_idx;
271
+ };
272
+
273
+ struct iseq_inline_iv_cache_entry {
274
+ struct rb_iv_index_tbl_entry *entry;
275
+ };
276
+
277
+ struct iseq_inline_cvar_cache_entry {
278
+ struct rb_cvar_class_tbl_entry *entry;
279
+ };
280
+
281
+ union iseq_inline_storage_entry {
282
+ struct {
283
+ struct rb_thread_struct *running_thread;
284
+ VALUE value;
285
+ } once;
286
+ struct iseq_inline_constant_cache ic_cache;
287
+ struct iseq_inline_iv_cache_entry iv_cache;
288
+ };
289
+
290
+ struct rb_calling_info {
291
+ const struct rb_callinfo *ci;
292
+ const struct rb_callcache *cc;
293
+ VALUE block_handler;
294
+ VALUE recv;
295
+ int argc;
296
+ int kw_splat;
297
+ };
298
+
299
+ struct rb_execution_context_struct;
300
+
301
+ #if 1
302
+ #define CoreDataFromValue(obj, type) (type*)DATA_PTR(obj)
303
+ #else
304
+ #define CoreDataFromValue(obj, type) (type*)rb_data_object_get(obj)
305
+ #endif
306
+ #define GetCoreDataFromValue(obj, type, ptr) ((ptr) = CoreDataFromValue((obj), type))
307
+
308
+ typedef struct rb_iseq_location_struct {
309
+ VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
310
+ VALUE base_label; /* String */
311
+ VALUE label; /* String */
312
+ VALUE first_lineno; /* TODO: may be unsigned short */
313
+ int node_id;
314
+ rb_code_location_t code_location;
315
+ } rb_iseq_location_t;
316
+
317
+ #define PATHOBJ_PATH 0
318
+ #define PATHOBJ_REALPATH 1
319
+
320
+ static inline VALUE
321
+ pathobj_path(VALUE pathobj)
322
+ {
323
+ if (RB_TYPE_P(pathobj, T_STRING)) {
324
+ return pathobj;
325
+ }
326
+ else {
327
+ VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
328
+ return RARRAY_AREF(pathobj, PATHOBJ_PATH);
329
+ }
330
+ }
331
+
332
+ static inline VALUE
333
+ pathobj_realpath(VALUE pathobj)
334
+ {
335
+ if (RB_TYPE_P(pathobj, T_STRING)) {
336
+ return pathobj;
337
+ }
338
+ else {
339
+ VM_ASSERT(RB_TYPE_P(pathobj, T_ARRAY));
340
+ return RARRAY_AREF(pathobj, PATHOBJ_REALPATH);
341
+ }
342
+ }
343
+
344
+ /* Forward declarations */
345
+ struct rb_mjit_unit;
346
+
347
+ // List of YJIT block versions
348
+ typedef rb_darray(struct yjit_block_version *) rb_yjit_block_array_t;
349
+ typedef rb_darray(rb_yjit_block_array_t) rb_yjit_block_array_array_t;
350
+
351
+ struct rb_iseq_constant_body {
352
+ enum iseq_type {
353
+ ISEQ_TYPE_TOP,
354
+ ISEQ_TYPE_METHOD,
355
+ ISEQ_TYPE_BLOCK,
356
+ ISEQ_TYPE_CLASS,
357
+ ISEQ_TYPE_RESCUE,
358
+ ISEQ_TYPE_ENSURE,
359
+ ISEQ_TYPE_EVAL,
360
+ ISEQ_TYPE_MAIN,
361
+ ISEQ_TYPE_PLAIN
362
+ } type; /* instruction sequence type */
363
+
364
+ unsigned int iseq_size;
365
+ VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
366
+
367
+ /**
368
+ * parameter information
369
+ *
370
+ * def m(a1, a2, ..., aM, # mandatory
371
+ * b1=(...), b2=(...), ..., bN=(...), # optional
372
+ * *c, # rest
373
+ * d1, d2, ..., dO, # post
374
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
375
+ * **f, # keyword_rest
376
+ * &g) # block
377
+ * =>
378
+ *
379
+ * lead_num = M
380
+ * opt_num = N
381
+ * rest_start = M+N
382
+ * post_start = M+N+(*1)
383
+ * post_num = O
384
+ * keyword_num = K
385
+ * block_start = M+N+(*1)+O+K
386
+ * keyword_bits = M+N+(*1)+O+K+(&1)
387
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
388
+ */
389
+
390
+ struct {
391
+ struct {
392
+ unsigned int has_lead : 1;
393
+ unsigned int has_opt : 1;
394
+ unsigned int has_rest : 1;
395
+ unsigned int has_post : 1;
396
+ unsigned int has_kw : 1;
397
+ unsigned int has_kwrest : 1;
398
+ unsigned int has_block : 1;
399
+
400
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
401
+ unsigned int accepts_no_kwarg : 1;
402
+ unsigned int ruby2_keywords: 1;
403
+ } flags;
404
+
405
+ unsigned int size;
406
+
407
+ int lead_num;
408
+ int opt_num;
409
+ int rest_start;
410
+ int post_start;
411
+ int post_num;
412
+ int block_start;
413
+
414
+ const VALUE *opt_table; /* (opt_num + 1) entries. */
415
+ /* opt_num and opt_table:
416
+ *
417
+ * def foo o1=e1, o2=e2, ..., oN=eN
418
+ * #=>
419
+ * # prologue code
420
+ * A1: e1
421
+ * A2: e2
422
+ * ...
423
+ * AN: eN
424
+ * AL: body
425
+ * opt_num = N
426
+ * opt_table = [A1, A2, ..., AN, AL]
427
+ */
428
+
429
+ const struct rb_iseq_param_keyword {
430
+ int num;
431
+ int required_num;
432
+ int bits_start;
433
+ int rest_start;
434
+ const ID *table;
435
+ VALUE *default_values;
436
+ } *keyword;
437
+ } param;
438
+
439
+ rb_iseq_location_t location;
440
+
441
+ /* insn info, must be freed */
442
+ struct iseq_insn_info {
443
+ const struct iseq_insn_info_entry *body;
444
+ unsigned int *positions;
445
+ unsigned int size;
446
+ #if VM_INSN_INFO_TABLE_IMPL == 2
447
+ struct succ_index_table *succ_index_table;
448
+ #endif
449
+ } insns_info;
450
+
451
+ const ID *local_table; /* must free */
452
+
453
+ /* catch table */
454
+ struct iseq_catch_table *catch_table;
455
+
456
+ /* for child iseq */
457
+ const struct rb_iseq_struct *parent_iseq;
458
+ struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
459
+
460
+ union iseq_inline_storage_entry *is_entries;
461
+ struct rb_call_data *call_data; //struct rb_call_data calls[ci_size];
462
+
463
+ struct {
464
+ rb_snum_t flip_count;
465
+ VALUE script_lines;
466
+ VALUE coverage;
467
+ VALUE pc2branchindex;
468
+ VALUE *original_iseq;
469
+ } variable;
470
+
471
+ unsigned int local_table_size;
472
+ unsigned int is_size;
473
+ unsigned int ci_size;
474
+ unsigned int stack_max; /* for stack overflow check */
475
+
476
+ char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */
477
+ // If true, this ISeq is leaf *and* backtraces are not used, for example,
478
+ // by rb_profile_frames. We verify only leafness on VM_CHECK_MODE though.
479
+ // Note that GC allocations might use backtraces due to
480
+ // ObjectSpace#trace_object_allocations.
481
+ // For more details, see: https://bugs.ruby-lang.org/issues/16956
482
+ bool builtin_inline_p;
483
+ struct rb_id_table *outer_variables;
484
+
485
+ #if USE_MJIT
486
+ /* The following fields are MJIT related info. */
487
+ VALUE (*jit_func)(struct rb_execution_context_struct *,
488
+ struct rb_control_frame_struct *); /* function pointer for loaded native code */
489
+ long unsigned total_calls; /* number of total calls with `mjit_exec()` */
490
+ struct rb_mjit_unit *jit_unit;
491
+ #endif
492
+
493
+ rb_yjit_block_array_array_t yjit_blocks; // empty, or has a size equal to iseq_size
494
+ };
495
+
496
+ /* T_IMEMO/iseq */
497
+ /* typedef rb_iseq_t is in method.h */
498
+ struct rb_iseq_struct {
499
+ VALUE flags; /* 1 */
500
+ VALUE wrapper; /* 2 */
501
+
502
+ struct rb_iseq_constant_body *body; /* 3 */
503
+
504
+ union { /* 4, 5 words */
505
+ struct iseq_compile_data *compile_data; /* used at compile time */
506
+
507
+ struct {
508
+ VALUE obj;
509
+ int index;
510
+ } loader;
511
+
512
+ struct {
513
+ struct rb_hook_list_struct *local_hooks;
514
+ rb_event_flag_t global_trace_events;
515
+ } exec;
516
+ } aux;
517
+ };
518
+
519
+ #ifndef USE_LAZY_LOAD
520
+ #define USE_LAZY_LOAD 0
521
+ #endif
522
+
523
+ #if USE_LAZY_LOAD
524
+ const rb_iseq_t *rb_iseq_complete(const rb_iseq_t *iseq);
525
+ #endif
526
+
527
+ static inline const rb_iseq_t *
528
+ rb_iseq_check(const rb_iseq_t *iseq)
529
+ {
530
+ #if USE_LAZY_LOAD
531
+ if (iseq->body == NULL) {
532
+ rb_iseq_complete((rb_iseq_t *)iseq);
533
+ }
534
+ #endif
535
+ return iseq;
536
+ }
537
+
538
+ static inline const rb_iseq_t *
539
+ def_iseq_ptr(rb_method_definition_t *def)
540
+ {
541
+ //TODO: re-visit. to check the bug, enable this assertion.
542
+ #if VM_CHECK_MODE > 0
543
+ if (def->type != VM_METHOD_TYPE_ISEQ) rb_bug("def_iseq_ptr: not iseq (%d)", def->type);
544
+ #endif
545
+ return rb_iseq_check(def->body.iseq.iseqptr);
546
+ }
547
+
548
+ enum ruby_special_exceptions {
549
+ ruby_error_reenter,
550
+ ruby_error_nomemory,
551
+ ruby_error_sysstack,
552
+ ruby_error_stackfatal,
553
+ ruby_error_stream_closed,
554
+ ruby_special_error_count
555
+ };
556
+
557
+ enum ruby_basic_operators {
558
+ BOP_PLUS,
559
+ BOP_MINUS,
560
+ BOP_MULT,
561
+ BOP_DIV,
562
+ BOP_MOD,
563
+ BOP_EQ,
564
+ BOP_EQQ,
565
+ BOP_LT,
566
+ BOP_LE,
567
+ BOP_LTLT,
568
+ BOP_AREF,
569
+ BOP_ASET,
570
+ BOP_LENGTH,
571
+ BOP_SIZE,
572
+ BOP_EMPTY_P,
573
+ BOP_NIL_P,
574
+ BOP_SUCC,
575
+ BOP_GT,
576
+ BOP_GE,
577
+ BOP_NOT,
578
+ BOP_NEQ,
579
+ BOP_MATCH,
580
+ BOP_FREEZE,
581
+ BOP_UMINUS,
582
+ BOP_MAX,
583
+ BOP_MIN,
584
+ BOP_CALL,
585
+ BOP_AND,
586
+ BOP_OR,
587
+
588
+ BOP_LAST_
589
+ };
590
+
591
+ #define GetVMPtr(obj, ptr) \
592
+ GetCoreDataFromValue((obj), rb_vm_t, (ptr))
593
+
594
+ struct rb_vm_struct;
595
+ typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
596
+
597
+ typedef struct rb_at_exit_list {
598
+ rb_vm_at_exit_func *func;
599
+ struct rb_at_exit_list *next;
600
+ } rb_at_exit_list;
601
+
602
+ struct rb_objspace;
603
+ struct rb_objspace *rb_objspace_alloc(void);
604
+ void rb_objspace_free(struct rb_objspace *);
605
+ void rb_objspace_call_finalizer(struct rb_objspace *);
606
+
607
+ typedef struct rb_hook_list_struct {
608
+ struct rb_event_hook_struct *hooks;
609
+ rb_event_flag_t events;
610
+ unsigned int need_clean;
611
+ unsigned int running;
612
+ } rb_hook_list_t;
613
+
614
+
615
+ // see builtin.h for definition
616
+ typedef const struct rb_builtin_function *RB_BUILTIN;
617
+
618
+ typedef struct rb_vm_struct {
619
+ VALUE self;
620
+
621
+ struct {
622
+ struct list_head set;
623
+ unsigned int cnt;
624
+ unsigned int blocking_cnt;
625
+
626
+ struct rb_ractor_struct *main_ractor;
627
+ struct rb_thread_struct *main_thread; // == vm->ractor.main_ractor->threads.main
628
+
629
+ struct {
630
+ // monitor
631
+ rb_nativethread_lock_t lock;
632
+ struct rb_ractor_struct *lock_owner;
633
+ unsigned int lock_rec;
634
+
635
+ // barrier
636
+ bool barrier_waiting;
637
+ unsigned int barrier_cnt;
638
+ rb_nativethread_cond_t barrier_cond;
639
+
640
+ // join at exit
641
+ rb_nativethread_cond_t terminate_cond;
642
+ bool terminate_waiting;
643
+ } sync;
644
+ } ractor;
645
+
646
+ #ifdef USE_SIGALTSTACK
647
+ void *main_altstack;
648
+ #endif
649
+
650
+ rb_serial_t fork_gen;
651
+ rb_nativethread_lock_t waitpid_lock;
652
+ struct list_head waiting_pids; /* PID > 0: <=> struct waitpid_state */
653
+ struct list_head waiting_grps; /* PID <= 0: <=> struct waitpid_state */
654
+ struct list_head waiting_fds; /* <=> struct waiting_fd */
655
+
656
+ /* set in single-threaded processes only: */
657
+ volatile int ubf_async_safe;
658
+
659
+ unsigned int running: 1;
660
+ unsigned int thread_abort_on_exception: 1;
661
+ unsigned int thread_report_on_exception: 1;
662
+ unsigned int thread_ignore_deadlock: 1;
663
+
664
+ /* object management */
665
+ VALUE mark_object_ary;
666
+ const VALUE special_exceptions[ruby_special_error_count];
667
+
668
+ /* load */
669
+ VALUE top_self;
670
+ VALUE load_path;
671
+ VALUE load_path_snapshot;
672
+ VALUE load_path_check_cache;
673
+ VALUE expanded_load_path;
674
+ VALUE loaded_features;
675
+ VALUE loaded_features_snapshot;
676
+ VALUE loaded_features_realpaths;
677
+ struct st_table *loaded_features_index;
678
+ struct st_table *loading_table;
679
+
680
+ /* signal */
681
+ struct {
682
+ VALUE cmd[RUBY_NSIG];
683
+ } trap_list;
684
+
685
+ /* relation table of ensure - rollback for callcc */
686
+ struct st_table *ensure_rollback_table;
687
+
688
+ /* postponed_job (async-signal-safe, NOT thread-safe) */
689
+ struct rb_postponed_job_struct *postponed_job_buffer;
690
+ rb_atomic_t postponed_job_index;
691
+
692
+ int src_encoding_index;
693
+
694
+ /* workqueue (thread-safe, NOT async-signal-safe) */
695
+ struct list_head workqueue; /* <=> rb_workqueue_job.jnode */
696
+ rb_nativethread_lock_t workqueue_lock;
697
+
698
+ VALUE orig_progname, progname;
699
+ VALUE coverages, me2counter;
700
+ int coverage_mode;
701
+
702
+ st_table * defined_module_hash;
703
+
704
+ struct rb_objspace *objspace;
705
+
706
+ rb_at_exit_list *at_exit;
707
+
708
+ st_table *frozen_strings;
709
+
710
+ const struct rb_builtin_function *builtin_function_table;
711
+ int builtin_inline_index;
712
+
713
+ struct rb_id_table *negative_cme_table;
714
+
715
+ #ifndef VM_GLOBAL_CC_CACHE_TABLE_SIZE
716
+ #define VM_GLOBAL_CC_CACHE_TABLE_SIZE 1023
717
+ #endif
718
+ const struct rb_callcache *global_cc_cache_table[VM_GLOBAL_CC_CACHE_TABLE_SIZE]; // vm_eval.c
719
+
720
+ #if defined(USE_VM_CLOCK) && USE_VM_CLOCK
721
+ uint32_t clock;
722
+ #endif
723
+
724
+ /* params */
725
+ struct { /* size in byte */
726
+ size_t thread_vm_stack_size;
727
+ size_t thread_machine_stack_size;
728
+ size_t fiber_vm_stack_size;
729
+ size_t fiber_machine_stack_size;
730
+ } default_params;
731
+
732
+ short redefined_flag[BOP_LAST_];
733
+ } rb_vm_t;
734
+
735
+ /* default values */
736
+
737
+ #define RUBY_VM_SIZE_ALIGN 4096
738
+
739
+ #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
740
+ #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
741
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
742
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
743
+
744
+ #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
745
+ #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
746
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
747
+ #if defined(__powerpc64__)
748
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 32 * 1024 * sizeof(VALUE)) /* 128 KB or 256 KB */
749
+ #else
750
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
751
+ #endif
752
+
753
+ #if __has_feature(memory_sanitizer) || __has_feature(address_sanitizer)
754
+ /* It seems sanitizers consume A LOT of machine stacks */
755
+ #undef RUBY_VM_THREAD_MACHINE_STACK_SIZE
756
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE (1024 * 1024 * sizeof(VALUE))
757
+ #undef RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN
758
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 512 * 1024 * sizeof(VALUE))
759
+ #undef RUBY_VM_FIBER_MACHINE_STACK_SIZE
760
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 256 * 1024 * sizeof(VALUE))
761
+ #undef RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN
762
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 128 * 1024 * sizeof(VALUE))
763
+ #endif
764
+
765
+ /* optimize insn */
766
+ #define INTEGER_REDEFINED_OP_FLAG (1 << 0)
767
+ #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
768
+ #define STRING_REDEFINED_OP_FLAG (1 << 2)
769
+ #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
770
+ #define HASH_REDEFINED_OP_FLAG (1 << 4)
771
+ /* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */
772
+ #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
773
+ #define TIME_REDEFINED_OP_FLAG (1 << 7)
774
+ #define REGEXP_REDEFINED_OP_FLAG (1 << 8)
775
+ #define NIL_REDEFINED_OP_FLAG (1 << 9)
776
+ #define TRUE_REDEFINED_OP_FLAG (1 << 10)
777
+ #define FALSE_REDEFINED_OP_FLAG (1 << 11)
778
+ #define PROC_REDEFINED_OP_FLAG (1 << 12)
779
+
780
+ #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((GET_VM()->redefined_flag[(op)]&(klass)) == 0))
781
+
782
+ #ifndef VM_DEBUG_BP_CHECK
783
+ #define VM_DEBUG_BP_CHECK 0
784
+ #endif
785
+
786
+ #ifndef VM_DEBUG_VERIFY_METHOD_CACHE
787
+ #define VM_DEBUG_VERIFY_METHOD_CACHE (VMDEBUG != 0)
788
+ #endif
789
+
790
+ struct rb_captured_block {
791
+ VALUE self;
792
+ const VALUE *ep;
793
+ union {
794
+ const rb_iseq_t *iseq;
795
+ const struct vm_ifunc *ifunc;
796
+ VALUE val;
797
+ } code;
798
+ };
799
+
800
+ enum rb_block_handler_type {
801
+ block_handler_type_iseq,
802
+ block_handler_type_ifunc,
803
+ block_handler_type_symbol,
804
+ block_handler_type_proc
805
+ };
806
+
807
+ enum rb_block_type {
808
+ block_type_iseq,
809
+ block_type_ifunc,
810
+ block_type_symbol,
811
+ block_type_proc
812
+ };
813
+
814
+ struct rb_block {
815
+ union {
816
+ struct rb_captured_block captured;
817
+ VALUE symbol;
818
+ VALUE proc;
819
+ } as;
820
+ enum rb_block_type type;
821
+ };
822
+
823
+ typedef struct rb_control_frame_struct {
824
+ const VALUE *pc; /* cfp[0] */
825
+ VALUE *sp; /* cfp[1] */
826
+ const rb_iseq_t *iseq; /* cfp[2] */
827
+ VALUE self; /* cfp[3] / block[0] */
828
+ const VALUE *ep; /* cfp[4] / block[1] */
829
+ const void *block_code; /* cfp[5] / block[2] */ /* iseq or ifunc or forwarded block handler */
830
+ VALUE *__bp__; /* cfp[6] */ /* outside vm_push_frame, use vm_base_ptr instead. */
831
+
832
+ #if VM_DEBUG_BP_CHECK
833
+ VALUE *bp_check; /* cfp[7] */
834
+ #endif
835
+ // Return address for YJIT code
836
+ void *jit_return;
837
+ } rb_control_frame_t;
838
+
839
+ extern const rb_data_type_t ruby_threadptr_data_type;
840
+
841
+ static inline struct rb_thread_struct *
842
+ rb_thread_ptr(VALUE thval)
843
+ {
844
+ return (struct rb_thread_struct *)rb_check_typeddata(thval, &ruby_threadptr_data_type);
845
+ }
846
+
847
+ enum rb_thread_status {
848
+ THREAD_RUNNABLE,
849
+ THREAD_STOPPED,
850
+ THREAD_STOPPED_FOREVER,
851
+ THREAD_KILLED
852
+ };
853
+
854
+ #ifdef RUBY_JMP_BUF
855
+ typedef RUBY_JMP_BUF rb_jmpbuf_t;
856
+ #else
857
+ typedef void *rb_jmpbuf_t[5];
858
+ #endif
859
+
860
+ /*
861
+ the members which are written in EC_PUSH_TAG() should be placed at
862
+ the beginning and the end, so that entire region is accessible.
863
+ */
864
+ struct rb_vm_tag {
865
+ VALUE tag;
866
+ VALUE retval;
867
+ rb_jmpbuf_t buf;
868
+ struct rb_vm_tag *prev;
869
+ enum ruby_tag_type state;
870
+ unsigned int lock_rec;
871
+ };
872
+
873
+ STATIC_ASSERT(rb_vm_tag_buf_offset, offsetof(struct rb_vm_tag, buf) > 0);
874
+ STATIC_ASSERT(rb_vm_tag_buf_end,
875
+ offsetof(struct rb_vm_tag, buf) + sizeof(rb_jmpbuf_t) <
876
+ sizeof(struct rb_vm_tag));
877
+
878
+ struct rb_unblock_callback {
879
+ rb_unblock_function_t *func;
880
+ void *arg;
881
+ };
882
+
883
+ struct rb_mutex_struct;
884
+
885
+ typedef struct rb_ensure_entry {
886
+ VALUE marker;
887
+ VALUE (*e_proc)(VALUE);
888
+ VALUE data2;
889
+ } rb_ensure_entry_t;
890
+
891
+ typedef struct rb_ensure_list {
892
+ struct rb_ensure_list *next;
893
+ struct rb_ensure_entry entry;
894
+ } rb_ensure_list_t;
895
+
896
+ typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
897
+
898
+ typedef struct rb_fiber_struct rb_fiber_t;
899
+
900
+ struct rb_waiting_list {
901
+ struct rb_waiting_list *next;
902
+ struct rb_thread_struct *thread;
903
+ struct rb_fiber_struct *fiber;
904
+ };
905
+
906
+ struct rb_execution_context_struct {
907
+ /* execution information */
908
+ VALUE *vm_stack; /* must free, must mark */
909
+ size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */
910
+ rb_control_frame_t *cfp;
911
+
912
+ struct rb_vm_tag *tag;
913
+
914
+ /* interrupt flags */
915
+ rb_atomic_t interrupt_flag;
916
+ rb_atomic_t interrupt_mask; /* size should match flag */
917
+ #if defined(USE_VM_CLOCK) && USE_VM_CLOCK
918
+ uint32_t checked_clock;
919
+ #endif
920
+
921
+ rb_fiber_t *fiber_ptr;
922
+ struct rb_thread_struct *thread_ptr;
923
+
924
+ /* storage (ec (fiber) local) */
925
+ struct rb_id_table *local_storage;
926
+ VALUE local_storage_recursive_hash;
927
+ VALUE local_storage_recursive_hash_for_trace;
928
+
929
+ /* eval env */
930
+ const VALUE *root_lep;
931
+ VALUE root_svar;
932
+
933
+ /* ensure & callcc */
934
+ rb_ensure_list_t *ensure_list;
935
+
936
+ /* trace information */
937
+ struct rb_trace_arg_struct *trace_arg;
938
+
939
+ /* temporary places */
940
+ VALUE errinfo;
941
+ VALUE passed_block_handler; /* for rb_iterate */
942
+
943
+ uint8_t raised_flag; /* only 3 bits needed */
944
+
945
+ /* n.b. only 7 bits needed, really: */
946
+ BITFIELD(enum method_missing_reason, method_missing_reason, 8);
947
+
948
+ VALUE private_const_reference;
949
+
950
+ /* for GC */
951
+ struct {
952
+ VALUE *stack_start;
953
+ VALUE *stack_end;
954
+ size_t stack_maxsize;
955
+ RUBY_ALIGNAS(SIZEOF_VALUE) jmp_buf regs;
956
+ } machine;
957
+ };
958
+
959
+ #ifndef rb_execution_context_t
960
+ typedef struct rb_execution_context_struct rb_execution_context_t;
961
+ #define rb_execution_context_t rb_execution_context_t
962
+ #endif
963
+
964
+ // for builtin.h
965
+ #define VM_CORE_H_EC_DEFINED 1
966
+
967
+ // Set the vm_stack pointer in the execution context.
968
+ void rb_ec_set_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
969
+
970
+ // Initialize the vm_stack pointer in the execution context and push the initial stack frame.
971
+ // @param ec the execution context to update.
972
+ // @param stack a pointer to the stack to use.
973
+ // @param size the size of the stack, as in `VALUE stack[size]`.
974
+ void rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size);
975
+
976
+ // Clear (set to `NULL`) the vm_stack pointer.
977
+ // @param ec the execution context to update.
978
+ void rb_ec_clear_vm_stack(rb_execution_context_t *ec);
979
+
980
+ struct rb_ext_config {
981
+ bool ractor_safe;
982
+ };
983
+
984
+ typedef struct rb_ractor_struct rb_ractor_t;
985
+
986
+ #if defined(__linux__) || defined(__FreeBSD__)
987
+ # define RB_THREAD_T_HAS_NATIVE_ID
988
+ #endif
989
+
990
+ typedef struct rb_thread_struct {
991
+ struct list_node lt_node; // managed by a ractor
992
+ VALUE self;
993
+ rb_ractor_t *ractor;
994
+ rb_vm_t *vm;
995
+
996
+ rb_execution_context_t *ec;
997
+
998
+ VALUE last_status; /* $? */
999
+
1000
+ /* for cfunc */
1001
+ struct rb_calling_info *calling;
1002
+
1003
+ /* for load(true) */
1004
+ VALUE top_self;
1005
+ VALUE top_wrapper;
1006
+
1007
+ /* thread control */
1008
+ rb_nativethread_id_t thread_id;
1009
+ #ifdef NON_SCALAR_THREAD_ID
1010
+ rb_thread_id_string_t thread_id_string;
1011
+ #endif
1012
+ #ifdef RB_THREAD_T_HAS_NATIVE_ID
1013
+ int tid;
1014
+ #endif
1015
+ BITFIELD(enum rb_thread_status, status, 2);
1016
+ /* bit flags */
1017
+ unsigned int to_kill : 1;
1018
+ unsigned int abort_on_exception: 1;
1019
+ unsigned int report_on_exception: 1;
1020
+ unsigned int pending_interrupt_queue_checked: 1;
1021
+ int8_t priority; /* -3 .. 3 (RUBY_THREAD_PRIORITY_{MIN,MAX}) */
1022
+ uint32_t running_time_us; /* 12500..800000 */
1023
+
1024
+ native_thread_data_t native_thread_data;
1025
+ void *blocking_region_buffer;
1026
+
1027
+ VALUE thgroup;
1028
+ VALUE value;
1029
+
1030
+ /* temporary place of retval on OPT_CALL_THREADED_CODE */
1031
+ #if OPT_CALL_THREADED_CODE
1032
+ VALUE retval;
1033
+ #endif
1034
+
1035
+ /* async errinfo queue */
1036
+ VALUE pending_interrupt_queue;
1037
+ VALUE pending_interrupt_mask_stack;
1038
+
1039
+ /* interrupt management */
1040
+ rb_nativethread_lock_t interrupt_lock;
1041
+ struct rb_unblock_callback unblock;
1042
+ VALUE locking_mutex;
1043
+ struct rb_mutex_struct *keeping_mutexes;
1044
+
1045
+ struct rb_waiting_list *join_list;
1046
+
1047
+ union {
1048
+ struct {
1049
+ VALUE proc;
1050
+ VALUE args;
1051
+ int kw_splat;
1052
+ } proc;
1053
+ struct {
1054
+ VALUE (*func)(void *);
1055
+ void *arg;
1056
+ } func;
1057
+ } invoke_arg;
1058
+
1059
+ enum thread_invoke_type {
1060
+ thread_invoke_type_none = 0,
1061
+ thread_invoke_type_proc,
1062
+ thread_invoke_type_ractor_proc,
1063
+ thread_invoke_type_func
1064
+ } invoke_type;
1065
+
1066
+ /* statistics data for profiler */
1067
+ VALUE stat_insn_usage;
1068
+
1069
+ /* fiber */
1070
+ rb_fiber_t *root_fiber;
1071
+
1072
+ VALUE scheduler;
1073
+ unsigned blocking;
1074
+
1075
+ /* misc */
1076
+ VALUE name;
1077
+
1078
+ struct rb_ext_config ext_config;
1079
+
1080
+ #ifdef USE_SIGALTSTACK
1081
+ void *altstack;
1082
+ #endif
1083
+ } rb_thread_t;
1084
+
1085
+ typedef enum {
1086
+ VM_DEFINECLASS_TYPE_CLASS = 0x00,
1087
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
1088
+ VM_DEFINECLASS_TYPE_MODULE = 0x02,
1089
+ /* 0x03..0x06 is reserved */
1090
+ VM_DEFINECLASS_TYPE_MASK = 0x07
1091
+ } rb_vm_defineclass_type_t;
1092
+
1093
+ #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
1094
+ #define VM_DEFINECLASS_FLAG_SCOPED 0x08
1095
+ #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
1096
+ #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
1097
+ #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
1098
+ ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
1099
+
1100
+ /* iseq.c */
1101
+ RUBY_SYMBOL_EXPORT_BEGIN
1102
+
1103
+ /* node -> iseq */
1104
+ rb_iseq_t *rb_iseq_new (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum iseq_type);
1105
+ rb_iseq_t *rb_iseq_new_top (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent);
1106
+ rb_iseq_t *rb_iseq_new_main (const rb_ast_body_t *ast, VALUE path, VALUE realpath, const rb_iseq_t *parent);
1107
+ rb_iseq_t *rb_iseq_new_eval (const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, int isolated_depth);
1108
+ rb_iseq_t *rb_iseq_new_with_opt(const rb_ast_body_t *ast, VALUE name, VALUE path, VALUE realpath, VALUE first_lineno, const rb_iseq_t *parent, int isolated_depth,
1109
+ enum iseq_type, const rb_compile_option_t*);
1110
+
1111
+ struct iseq_link_anchor;
1112
+ struct rb_iseq_new_with_callback_callback_func {
1113
+ VALUE flags;
1114
+ VALUE reserved;
1115
+ void (*func)(rb_iseq_t *, struct iseq_link_anchor *, const void *);
1116
+ const void *data;
1117
+ };
1118
+ static inline struct rb_iseq_new_with_callback_callback_func *
1119
+ rb_iseq_new_with_callback_new_callback(
1120
+ void (*func)(rb_iseq_t *, struct iseq_link_anchor *, const void *), const void *ptr)
1121
+ {
1122
+ VALUE memo = rb_imemo_new(imemo_ifunc, (VALUE)func, (VALUE)ptr, Qundef, Qfalse);
1123
+ return (struct rb_iseq_new_with_callback_callback_func *)memo;
1124
+ }
1125
+ rb_iseq_t *rb_iseq_new_with_callback(const struct rb_iseq_new_with_callback_callback_func * ifunc,
1126
+ VALUE name, VALUE path, VALUE realpath, VALUE first_lineno,
1127
+ const rb_iseq_t *parent, enum iseq_type, const rb_compile_option_t*);
1128
+
1129
+ VALUE rb_iseq_disasm(const rb_iseq_t *iseq);
1130
+ int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
1131
+
1132
+ VALUE rb_iseq_coverage(const rb_iseq_t *iseq);
1133
+
1134
+ RUBY_EXTERN VALUE rb_cISeq;
1135
+ RUBY_EXTERN VALUE rb_cRubyVM;
1136
+ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
1137
+ RUBY_EXTERN VALUE rb_block_param_proxy;
1138
+ RUBY_SYMBOL_EXPORT_END
1139
+
1140
+ #define GetProcPtr(obj, ptr) \
1141
+ GetCoreDataFromValue((obj), rb_proc_t, (ptr))
1142
+
1143
+ typedef struct {
1144
+ const struct rb_block block;
1145
+ unsigned int is_from_method: 1; /* bool */
1146
+ unsigned int is_lambda: 1; /* bool */
1147
+ unsigned int is_isolated: 1; /* bool */
1148
+ } rb_proc_t;
1149
+
1150
+ RUBY_SYMBOL_EXPORT_BEGIN
1151
+ VALUE rb_proc_isolate(VALUE self);
1152
+ VALUE rb_proc_isolate_bang(VALUE self);
1153
+ VALUE rb_proc_ractor_make_shareable(VALUE self);
1154
+ RUBY_SYMBOL_EXPORT_END
1155
+
1156
+ typedef struct {
1157
+ VALUE flags; /* imemo header */
1158
+ rb_iseq_t *iseq;
1159
+ const VALUE *ep;
1160
+ const VALUE *env;
1161
+ unsigned int env_size;
1162
+ } rb_env_t;
1163
+
1164
+ extern const rb_data_type_t ruby_binding_data_type;
1165
+
1166
+ #define GetBindingPtr(obj, ptr) \
1167
+ GetCoreDataFromValue((obj), rb_binding_t, (ptr))
1168
+
1169
+ typedef struct {
1170
+ const struct rb_block block;
1171
+ const VALUE pathobj;
1172
+ unsigned short first_lineno;
1173
+ } rb_binding_t;
1174
+
1175
+ /* used by compile time and send insn */
1176
+
1177
+ enum vm_check_match_type {
1178
+ VM_CHECKMATCH_TYPE_WHEN = 1,
1179
+ VM_CHECKMATCH_TYPE_CASE = 2,
1180
+ VM_CHECKMATCH_TYPE_RESCUE = 3
1181
+ };
1182
+
1183
+ #define VM_CHECKMATCH_TYPE_MASK 0x03
1184
+ #define VM_CHECKMATCH_ARRAY 0x04
1185
+
1186
+ enum vm_special_object_type {
1187
+ VM_SPECIAL_OBJECT_VMCORE = 1,
1188
+ VM_SPECIAL_OBJECT_CBASE,
1189
+ VM_SPECIAL_OBJECT_CONST_BASE
1190
+ };
1191
+
1192
+ enum vm_svar_index {
1193
+ VM_SVAR_LASTLINE = 0, /* $_ */
1194
+ VM_SVAR_BACKREF = 1, /* $~ */
1195
+
1196
+ VM_SVAR_EXTRA_START = 2,
1197
+ VM_SVAR_FLIPFLOP_START = 2 /* flipflop */
1198
+ };
1199
+
1200
+ /* inline cache */
1201
+ typedef struct iseq_inline_constant_cache *IC;
1202
+ typedef struct iseq_inline_iv_cache_entry *IVC;
1203
+ typedef struct iseq_inline_cvar_cache_entry *ICVARC;
1204
+ typedef union iseq_inline_storage_entry *ISE;
1205
+ typedef const struct rb_callinfo *CALL_INFO;
1206
+ typedef const struct rb_callcache *CALL_CACHE;
1207
+ typedef struct rb_call_data *CALL_DATA;
1208
+
1209
+ typedef VALUE CDHASH;
1210
+
1211
+ #ifndef FUNC_FASTCALL
1212
+ #define FUNC_FASTCALL(x) x
1213
+ #endif
1214
+
1215
+ typedef rb_control_frame_t *
1216
+ (FUNC_FASTCALL(*rb_insn_func_t))(rb_execution_context_t *, rb_control_frame_t *);
1217
+
1218
+ #define VM_TAGGED_PTR_SET(p, tag) ((VALUE)(p) | (tag))
1219
+ #define VM_TAGGED_PTR_REF(v, mask) ((void *)((v) & ~mask))
1220
+
1221
+ #define GC_GUARDED_PTR(p) VM_TAGGED_PTR_SET((p), 0x01)
1222
+ #define GC_GUARDED_PTR_REF(p) VM_TAGGED_PTR_REF((p), 0x03)
1223
+ #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
1224
+
1225
+ enum {
1226
+ /* Frame/Environment flag bits:
1227
+ * MMMM MMMM MMMM MMMM ____ _FFF FFFF EEEX (LSB)
1228
+ *
1229
+ * X : tag for GC marking (It seems as Fixnum)
1230
+ * EEE : 3 bits Env flags
1231
+ * FF..: 7 bits Frame flags
1232
+ * MM..: 15 bits frame magic (to check frame corruption)
1233
+ */
1234
+
1235
+ /* frame types */
1236
+ VM_FRAME_MAGIC_METHOD = 0x11110001,
1237
+ VM_FRAME_MAGIC_BLOCK = 0x22220001,
1238
+ VM_FRAME_MAGIC_CLASS = 0x33330001,
1239
+ VM_FRAME_MAGIC_TOP = 0x44440001,
1240
+ VM_FRAME_MAGIC_CFUNC = 0x55550001,
1241
+ VM_FRAME_MAGIC_IFUNC = 0x66660001,
1242
+ VM_FRAME_MAGIC_EVAL = 0x77770001,
1243
+ VM_FRAME_MAGIC_RESCUE = 0x78880001,
1244
+ VM_FRAME_MAGIC_DUMMY = 0x79990001,
1245
+
1246
+ VM_FRAME_MAGIC_MASK = 0x7fff0001,
1247
+
1248
+ /* frame flag */
1249
+ VM_FRAME_FLAG_FINISH = 0x0020,
1250
+ VM_FRAME_FLAG_BMETHOD = 0x0040,
1251
+ VM_FRAME_FLAG_CFRAME = 0x0080,
1252
+ VM_FRAME_FLAG_LAMBDA = 0x0100,
1253
+ VM_FRAME_FLAG_MODIFIED_BLOCK_PARAM = 0x0200,
1254
+ VM_FRAME_FLAG_CFRAME_KW = 0x0400,
1255
+ VM_FRAME_FLAG_PASSED = 0x0800,
1256
+
1257
+ /* env flag */
1258
+ VM_ENV_FLAG_LOCAL = 0x0002,
1259
+ VM_ENV_FLAG_ESCAPED = 0x0004,
1260
+ VM_ENV_FLAG_WB_REQUIRED = 0x0008,
1261
+ VM_ENV_FLAG_ISOLATED = 0x0010,
1262
+ };
1263
+
1264
+ #define VM_ENV_DATA_SIZE ( 3)
1265
+
1266
+ #define VM_ENV_DATA_INDEX_ME_CREF (-2) /* ep[-2] */
1267
+ #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
1268
+ #define VM_ENV_DATA_INDEX_FLAGS ( 0) /* ep[ 0] */
1269
+ #define VM_ENV_DATA_INDEX_ENV ( 1) /* ep[ 1] */
1270
+
1271
+ #define VM_ENV_INDEX_LAST_LVAR (-VM_ENV_DATA_SIZE)
1272
+
1273
+ static inline void VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value);
1274
+
1275
+ static inline void
1276
+ VM_ENV_FLAGS_SET(const VALUE *ep, VALUE flag)
1277
+ {
1278
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1279
+ VM_ASSERT(FIXNUM_P(flags));
1280
+ VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags | flag);
1281
+ }
1282
+
1283
+ static inline void
1284
+ VM_ENV_FLAGS_UNSET(const VALUE *ep, VALUE flag)
1285
+ {
1286
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1287
+ VM_ASSERT(FIXNUM_P(flags));
1288
+ VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_FLAGS], flags & ~flag);
1289
+ }
1290
+
1291
+ static inline unsigned long
1292
+ VM_ENV_FLAGS(const VALUE *ep, long flag)
1293
+ {
1294
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
1295
+ VM_ASSERT(FIXNUM_P(flags));
1296
+ return flags & flag;
1297
+ }
1298
+
1299
+ static inline unsigned long
1300
+ VM_FRAME_TYPE(const rb_control_frame_t *cfp)
1301
+ {
1302
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_MAGIC_MASK);
1303
+ }
1304
+
1305
+ static inline int
1306
+ VM_FRAME_LAMBDA_P(const rb_control_frame_t *cfp)
1307
+ {
1308
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_LAMBDA) != 0;
1309
+ }
1310
+
1311
+ static inline int
1312
+ VM_FRAME_CFRAME_KW_P(const rb_control_frame_t *cfp)
1313
+ {
1314
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME_KW) != 0;
1315
+ }
1316
+
1317
+ static inline int
1318
+ VM_FRAME_FINISHED_P(const rb_control_frame_t *cfp)
1319
+ {
1320
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_FINISH) != 0;
1321
+ }
1322
+
1323
+ static inline int
1324
+ VM_FRAME_BMETHOD_P(const rb_control_frame_t *cfp)
1325
+ {
1326
+ return VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_BMETHOD) != 0;
1327
+ }
1328
+
1329
+ static inline int
1330
+ rb_obj_is_iseq(VALUE iseq)
1331
+ {
1332
+ return imemo_type_p(iseq, imemo_iseq);
1333
+ }
1334
+
1335
+ #if VM_CHECK_MODE > 0
1336
+ #define RUBY_VM_NORMAL_ISEQ_P(iseq) rb_obj_is_iseq((VALUE)iseq)
1337
+ #endif
1338
+
1339
+ static inline int
1340
+ VM_FRAME_CFRAME_P(const rb_control_frame_t *cfp)
1341
+ {
1342
+ int cframe_p = VM_ENV_FLAGS(cfp->ep, VM_FRAME_FLAG_CFRAME) != 0;
1343
+ VM_ASSERT(RUBY_VM_NORMAL_ISEQ_P(cfp->iseq) != cframe_p);
1344
+ return cframe_p;
1345
+ }
1346
+
1347
+ static inline int
1348
+ VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp)
1349
+ {
1350
+ return !VM_FRAME_CFRAME_P(cfp);
1351
+ }
1352
+
1353
+ #define RUBYVM_CFUNC_FRAME_P(cfp) \
1354
+ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
1355
+
1356
+ #define VM_GUARDED_PREV_EP(ep) GC_GUARDED_PTR(ep)
1357
+ #define VM_BLOCK_HANDLER_NONE 0
1358
+
1359
+ static inline int
1360
+ VM_ENV_LOCAL_P(const VALUE *ep)
1361
+ {
1362
+ return VM_ENV_FLAGS(ep, VM_ENV_FLAG_LOCAL) ? 1 : 0;
1363
+ }
1364
+
1365
+ static inline const VALUE *
1366
+ VM_ENV_PREV_EP(const VALUE *ep)
1367
+ {
1368
+ VM_ASSERT(VM_ENV_LOCAL_P(ep) == 0);
1369
+ return GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL]);
1370
+ }
1371
+
1372
+ static inline VALUE
1373
+ VM_ENV_BLOCK_HANDLER(const VALUE *ep)
1374
+ {
1375
+ VM_ASSERT(VM_ENV_LOCAL_P(ep));
1376
+ return ep[VM_ENV_DATA_INDEX_SPECVAL];
1377
+ }
1378
+
1379
+ #if VM_CHECK_MODE > 0
1380
+ int rb_vm_ep_in_heap_p(const VALUE *ep);
1381
+ #endif
1382
+
1383
+ static inline int
1384
+ VM_ENV_ESCAPED_P(const VALUE *ep)
1385
+ {
1386
+ VM_ASSERT(rb_vm_ep_in_heap_p(ep) == !!VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED));
1387
+ return VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED) ? 1 : 0;
1388
+ }
1389
+
1390
+ #if VM_CHECK_MODE > 0
1391
+ static inline int
1392
+ vm_assert_env(VALUE obj)
1393
+ {
1394
+ VM_ASSERT(imemo_type_p(obj, imemo_env));
1395
+ return 1;
1396
+ }
1397
+ #endif
1398
+
1399
+ RBIMPL_ATTR_NONNULL((1))
1400
+ static inline VALUE
1401
+ VM_ENV_ENVVAL(const VALUE *ep)
1402
+ {
1403
+ VALUE envval = ep[VM_ENV_DATA_INDEX_ENV];
1404
+ VM_ASSERT(VM_ENV_ESCAPED_P(ep));
1405
+ VM_ASSERT(vm_assert_env(envval));
1406
+ return envval;
1407
+ }
1408
+
1409
+ RBIMPL_ATTR_NONNULL((1))
1410
+ static inline const rb_env_t *
1411
+ VM_ENV_ENVVAL_PTR(const VALUE *ep)
1412
+ {
1413
+ return (const rb_env_t *)VM_ENV_ENVVAL(ep);
1414
+ }
1415
+
1416
+ static inline const rb_env_t *
1417
+ vm_env_new(VALUE *env_ep, VALUE *env_body, unsigned int env_size, const rb_iseq_t *iseq)
1418
+ {
1419
+ rb_env_t *env = (rb_env_t *)rb_imemo_new(imemo_env, (VALUE)env_ep, (VALUE)env_body, 0, (VALUE)iseq);
1420
+ env->env_size = env_size;
1421
+ env_ep[VM_ENV_DATA_INDEX_ENV] = (VALUE)env;
1422
+ return env;
1423
+ }
1424
+
1425
+ static inline void
1426
+ VM_FORCE_WRITE(const VALUE *ptr, VALUE v)
1427
+ {
1428
+ *((VALUE *)ptr) = v;
1429
+ }
1430
+
1431
+ static inline void
1432
+ VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value)
1433
+ {
1434
+ VM_ASSERT(RB_SPECIAL_CONST_P(special_const_value));
1435
+ VM_FORCE_WRITE(ptr, special_const_value);
1436
+ }
1437
+
1438
+ static inline void
1439
+ VM_STACK_ENV_WRITE(const VALUE *ep, int index, VALUE v)
1440
+ {
1441
+ VM_ASSERT(VM_ENV_FLAGS(ep, VM_ENV_FLAG_WB_REQUIRED) == 0);
1442
+ VM_FORCE_WRITE(&ep[index], v);
1443
+ }
1444
+
1445
+ const VALUE *rb_vm_ep_local_ep(const VALUE *ep);
1446
+ const VALUE *rb_vm_proc_local_ep(VALUE proc);
1447
+ void rb_vm_block_ep_update(VALUE obj, const struct rb_block *dst, const VALUE *ep);
1448
+ void rb_vm_block_copy(VALUE obj, const struct rb_block *dst, const struct rb_block *src);
1449
+
1450
+ VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp);
1451
+
1452
+ #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
1453
+ #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
1454
+
1455
+ #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
1456
+ ((void *)(ecfp) > (void *)(cfp))
1457
+
1458
+ static inline const rb_control_frame_t *
1459
+ RUBY_VM_END_CONTROL_FRAME(const rb_execution_context_t *ec)
1460
+ {
1461
+ return (rb_control_frame_t *)(ec->vm_stack + ec->vm_stack_size);
1462
+ }
1463
+
1464
+ static inline int
1465
+ RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
1466
+ {
1467
+ return !RUBY_VM_VALID_CONTROL_FRAME_P(cfp, RUBY_VM_END_CONTROL_FRAME(ec));
1468
+ }
1469
+
1470
+ static inline int
1471
+ VM_BH_ISEQ_BLOCK_P(VALUE block_handler)
1472
+ {
1473
+ if ((block_handler & 0x03) == 0x01) {
1474
+ #if VM_CHECK_MODE > 0
1475
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1476
+ VM_ASSERT(imemo_type_p(captured->code.val, imemo_iseq));
1477
+ #endif
1478
+ return 1;
1479
+ }
1480
+ else {
1481
+ return 0;
1482
+ }
1483
+ }
1484
+
1485
+ static inline VALUE
1486
+ VM_BH_FROM_ISEQ_BLOCK(const struct rb_captured_block *captured)
1487
+ {
1488
+ VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x01);
1489
+ VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
1490
+ return block_handler;
1491
+ }
1492
+
1493
+ static inline const struct rb_captured_block *
1494
+ VM_BH_TO_ISEQ_BLOCK(VALUE block_handler)
1495
+ {
1496
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1497
+ VM_ASSERT(VM_BH_ISEQ_BLOCK_P(block_handler));
1498
+ return captured;
1499
+ }
1500
+
1501
+ static inline int
1502
+ VM_BH_IFUNC_P(VALUE block_handler)
1503
+ {
1504
+ if ((block_handler & 0x03) == 0x03) {
1505
+ #if VM_CHECK_MODE > 0
1506
+ struct rb_captured_block *captured = (void *)(block_handler & ~0x03);
1507
+ VM_ASSERT(imemo_type_p(captured->code.val, imemo_ifunc));
1508
+ #endif
1509
+ return 1;
1510
+ }
1511
+ else {
1512
+ return 0;
1513
+ }
1514
+ }
1515
+
1516
+ static inline VALUE
1517
+ VM_BH_FROM_IFUNC_BLOCK(const struct rb_captured_block *captured)
1518
+ {
1519
+ VALUE block_handler = VM_TAGGED_PTR_SET(captured, 0x03);
1520
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler));
1521
+ return block_handler;
1522
+ }
1523
+
1524
+ static inline const struct rb_captured_block *
1525
+ VM_BH_TO_IFUNC_BLOCK(VALUE block_handler)
1526
+ {
1527
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1528
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler));
1529
+ return captured;
1530
+ }
1531
+
1532
+ static inline const struct rb_captured_block *
1533
+ VM_BH_TO_CAPT_BLOCK(VALUE block_handler)
1534
+ {
1535
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
1536
+ VM_ASSERT(VM_BH_IFUNC_P(block_handler) || VM_BH_ISEQ_BLOCK_P(block_handler));
1537
+ return captured;
1538
+ }
1539
+
1540
+ static inline enum rb_block_handler_type
1541
+ vm_block_handler_type(VALUE block_handler)
1542
+ {
1543
+ if (VM_BH_ISEQ_BLOCK_P(block_handler)) {
1544
+ return block_handler_type_iseq;
1545
+ }
1546
+ else if (VM_BH_IFUNC_P(block_handler)) {
1547
+ return block_handler_type_ifunc;
1548
+ }
1549
+ else if (SYMBOL_P(block_handler)) {
1550
+ return block_handler_type_symbol;
1551
+ }
1552
+ else {
1553
+ VM_ASSERT(rb_obj_is_proc(block_handler));
1554
+ return block_handler_type_proc;
1555
+ }
1556
+ }
1557
+
1558
+ static inline void
1559
+ vm_block_handler_verify(MAYBE_UNUSED(VALUE block_handler))
1560
+ {
1561
+ VM_ASSERT(block_handler == VM_BLOCK_HANDLER_NONE ||
1562
+ (vm_block_handler_type(block_handler), 1));
1563
+ }
1564
+
1565
+ static inline int
1566
+ vm_cfp_forwarded_bh_p(const rb_control_frame_t *cfp, VALUE block_handler)
1567
+ {
1568
+ return ((VALUE) cfp->block_code) == block_handler;
1569
+ }
1570
+
1571
+ static inline enum rb_block_type
1572
+ vm_block_type(const struct rb_block *block)
1573
+ {
1574
+ #if VM_CHECK_MODE > 0
1575
+ switch (block->type) {
1576
+ case block_type_iseq:
1577
+ VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_iseq));
1578
+ break;
1579
+ case block_type_ifunc:
1580
+ VM_ASSERT(imemo_type_p(block->as.captured.code.val, imemo_ifunc));
1581
+ break;
1582
+ case block_type_symbol:
1583
+ VM_ASSERT(SYMBOL_P(block->as.symbol));
1584
+ break;
1585
+ case block_type_proc:
1586
+ VM_ASSERT(rb_obj_is_proc(block->as.proc));
1587
+ break;
1588
+ }
1589
+ #endif
1590
+ return block->type;
1591
+ }
1592
+
1593
+ static inline void
1594
+ vm_block_type_set(const struct rb_block *block, enum rb_block_type type)
1595
+ {
1596
+ struct rb_block *mb = (struct rb_block *)block;
1597
+ mb->type = type;
1598
+ }
1599
+
1600
+ static inline const struct rb_block *
1601
+ vm_proc_block(VALUE procval)
1602
+ {
1603
+ VM_ASSERT(rb_obj_is_proc(procval));
1604
+ return &((rb_proc_t *)RTYPEDDATA_DATA(procval))->block;
1605
+ }
1606
+
1607
+ static inline const rb_iseq_t *vm_block_iseq(const struct rb_block *block);
1608
+ static inline const VALUE *vm_block_ep(const struct rb_block *block);
1609
+
1610
+ static inline const rb_iseq_t *
1611
+ vm_proc_iseq(VALUE procval)
1612
+ {
1613
+ return vm_block_iseq(vm_proc_block(procval));
1614
+ }
1615
+
1616
+ static inline const VALUE *
1617
+ vm_proc_ep(VALUE procval)
1618
+ {
1619
+ return vm_block_ep(vm_proc_block(procval));
1620
+ }
1621
+
1622
+ static inline const rb_iseq_t *
1623
+ vm_block_iseq(const struct rb_block *block)
1624
+ {
1625
+ switch (vm_block_type(block)) {
1626
+ case block_type_iseq: return rb_iseq_check(block->as.captured.code.iseq);
1627
+ case block_type_proc: return vm_proc_iseq(block->as.proc);
1628
+ case block_type_ifunc:
1629
+ case block_type_symbol: return NULL;
1630
+ }
1631
+ VM_UNREACHABLE(vm_block_iseq);
1632
+ return NULL;
1633
+ }
1634
+
1635
+ static inline const VALUE *
1636
+ vm_block_ep(const struct rb_block *block)
1637
+ {
1638
+ switch (vm_block_type(block)) {
1639
+ case block_type_iseq:
1640
+ case block_type_ifunc: return block->as.captured.ep;
1641
+ case block_type_proc: return vm_proc_ep(block->as.proc);
1642
+ case block_type_symbol: return NULL;
1643
+ }
1644
+ VM_UNREACHABLE(vm_block_ep);
1645
+ return NULL;
1646
+ }
1647
+
1648
+ static inline VALUE
1649
+ vm_block_self(const struct rb_block *block)
1650
+ {
1651
+ switch (vm_block_type(block)) {
1652
+ case block_type_iseq:
1653
+ case block_type_ifunc:
1654
+ return block->as.captured.self;
1655
+ case block_type_proc:
1656
+ return vm_block_self(vm_proc_block(block->as.proc));
1657
+ case block_type_symbol:
1658
+ return Qundef;
1659
+ }
1660
+ VM_UNREACHABLE(vm_block_self);
1661
+ return Qundef;
1662
+ }
1663
+
1664
+ static inline VALUE
1665
+ VM_BH_TO_SYMBOL(VALUE block_handler)
1666
+ {
1667
+ VM_ASSERT(SYMBOL_P(block_handler));
1668
+ return block_handler;
1669
+ }
1670
+
1671
+ static inline VALUE
1672
+ VM_BH_FROM_SYMBOL(VALUE symbol)
1673
+ {
1674
+ VM_ASSERT(SYMBOL_P(symbol));
1675
+ return symbol;
1676
+ }
1677
+
1678
+ static inline VALUE
1679
+ VM_BH_TO_PROC(VALUE block_handler)
1680
+ {
1681
+ VM_ASSERT(rb_obj_is_proc(block_handler));
1682
+ return block_handler;
1683
+ }
1684
+
1685
+ static inline VALUE
1686
+ VM_BH_FROM_PROC(VALUE procval)
1687
+ {
1688
+ VM_ASSERT(rb_obj_is_proc(procval));
1689
+ return procval;
1690
+ }
1691
+
1692
+ /* VM related object allocate functions */
1693
+ VALUE rb_thread_alloc(VALUE klass);
1694
+ VALUE rb_binding_alloc(VALUE klass);
1695
+ VALUE rb_proc_alloc(VALUE klass);
1696
+ VALUE rb_proc_dup(VALUE self);
1697
+
1698
+ /* for debug */
1699
+ extern void rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1700
+ extern void rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc);
1701
+ extern void rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp
1702
+ #if OPT_STACK_CACHING
1703
+ , VALUE reg_a, VALUE reg_b
1704
+ #endif
1705
+ );
1706
+
1707
+ #define SDR() rb_vmdebug_stack_dump_raw(GET_EC(), GET_EC()->cfp)
1708
+ #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_EC(), (cfp))
1709
+ void rb_vm_bugreport(const void *);
1710
+ typedef void (*ruby_sighandler_t)(int);
1711
+ RBIMPL_ATTR_FORMAT(RBIMPL_PRINTF_FORMAT, 4, 5)
1712
+ NORETURN(void rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *, const char *fmt, ...));
1713
+
1714
+ /* functions about thread/vm execution */
1715
+ RUBY_SYMBOL_EXPORT_BEGIN
1716
+ VALUE rb_iseq_eval(const rb_iseq_t *iseq);
1717
+ VALUE rb_iseq_eval_main(const rb_iseq_t *iseq);
1718
+ VALUE rb_iseq_path(const rb_iseq_t *iseq);
1719
+ VALUE rb_iseq_realpath(const rb_iseq_t *iseq);
1720
+ RUBY_SYMBOL_EXPORT_END
1721
+
1722
+ VALUE rb_iseq_pathobj_new(VALUE path, VALUE realpath);
1723
+ void rb_iseq_pathobj_set(const rb_iseq_t *iseq, VALUE path, VALUE realpath);
1724
+
1725
+ int rb_ec_frame_method_id_and_class(const rb_execution_context_t *ec, ID *idp, ID *called_idp, VALUE *klassp);
1726
+ void rb_ec_setup_exception(const rb_execution_context_t *ec, VALUE mesg, VALUE cause);
1727
+
1728
+ VALUE rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, int argc, const VALUE *argv, int kw_splat, VALUE block_handler);
1729
+
1730
+ VALUE rb_vm_make_proc_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda);
1731
+ static inline VALUE
1732
+ rb_vm_make_proc(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
1733
+ {
1734
+ return rb_vm_make_proc_lambda(ec, captured, klass, 0);
1735
+ }
1736
+
1737
+ static inline VALUE
1738
+ rb_vm_make_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass)
1739
+ {
1740
+ return rb_vm_make_proc_lambda(ec, captured, klass, 1);
1741
+ }
1742
+
1743
+ VALUE rb_vm_make_binding(const rb_execution_context_t *ec, const rb_control_frame_t *src_cfp);
1744
+ VALUE rb_vm_env_local_variables(const rb_env_t *env);
1745
+ const rb_env_t *rb_vm_env_prev_env(const rb_env_t *env);
1746
+ const VALUE *rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const ID *dynvars);
1747
+ void rb_vm_inc_const_missing_count(void);
1748
+ VALUE rb_vm_call_kw(rb_execution_context_t *ec, VALUE recv, VALUE id, int argc,
1749
+ const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat);
1750
+ MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec);
1751
+
1752
+ void rb_gvl_destroy(rb_global_vm_lock_t *gvl);
1753
+
1754
+ void rb_thread_start_timer_thread(void);
1755
+ void rb_thread_stop_timer_thread(void);
1756
+ void rb_thread_reset_timer_thread(void);
1757
+ void rb_thread_wakeup_timer_thread(int);
1758
+
1759
+ static inline void
1760
+ rb_vm_living_threads_init(rb_vm_t *vm)
1761
+ {
1762
+ list_head_init(&vm->waiting_fds);
1763
+ list_head_init(&vm->waiting_pids);
1764
+ list_head_init(&vm->workqueue);
1765
+ list_head_init(&vm->waiting_grps);
1766
+ list_head_init(&vm->ractor.set);
1767
+ }
1768
+
1769
+ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
1770
+ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1771
+ rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp);
1772
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
1773
+ void rb_vm_stack_to_heap(rb_execution_context_t *ec);
1774
+ void ruby_thread_init_stack(rb_thread_t *th);
1775
+ rb_thread_t * ruby_thread_from_native(void);
1776
+ int ruby_thread_set_native(rb_thread_t *th);
1777
+ int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, ID *called_idp, VALUE *klassp);
1778
+ void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp);
1779
+ MJIT_STATIC VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler);
1780
+
1781
+ void rb_vm_register_special_exception_str(enum ruby_special_exceptions sp, VALUE exception_class, VALUE mesg);
1782
+
1783
+ #define rb_vm_register_special_exception(sp, e, m) \
1784
+ rb_vm_register_special_exception_str(sp, e, rb_usascii_str_new_static((m), (long)rb_strlen_lit(m)))
1785
+
1786
+ void rb_gc_mark_machine_stack(const rb_execution_context_t *ec);
1787
+
1788
+ void rb_vm_rewrite_cref(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_cref_t **new_cref_ptr);
1789
+
1790
+ MJIT_STATIC const rb_callable_method_entry_t *rb_vm_frame_method_entry(const rb_control_frame_t *cfp);
1791
+
1792
+ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
1793
+
1794
+ #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) do { \
1795
+ STATIC_ASSERT(sizeof_sp, sizeof(*(sp)) == sizeof(VALUE)); \
1796
+ STATIC_ASSERT(sizeof_cfp, sizeof(*(cfp)) == sizeof(rb_control_frame_t)); \
1797
+ const struct rb_control_frame_struct *bound = (void *)&(sp)[(margin)]; \
1798
+ if (UNLIKELY((cfp) <= &bound[1])) { \
1799
+ vm_stackoverflow(); \
1800
+ } \
1801
+ } while (0)
1802
+
1803
+ #define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
1804
+ CHECK_VM_STACK_OVERFLOW0((cfp), (cfp)->sp, (margin))
1805
+
1806
+ VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, enum ruby_tag_type *stateptr);
1807
+
1808
+ rb_execution_context_t *rb_vm_main_ractor_ec(rb_vm_t *vm); // ractor.c
1809
+
1810
+ /* for thread */
1811
+
1812
+ #if RUBY_VM_THREAD_MODEL == 2
1813
+ MJIT_SYMBOL_EXPORT_BEGIN
1814
+
1815
+ RUBY_EXTERN struct rb_ractor_struct *ruby_single_main_ractor; // ractor.c
1816
+ RUBY_EXTERN rb_vm_t *ruby_current_vm_ptr;
1817
+ RUBY_EXTERN rb_event_flag_t ruby_vm_event_flags;
1818
+ RUBY_EXTERN rb_event_flag_t ruby_vm_event_enabled_global_flags;
1819
+ RUBY_EXTERN unsigned int ruby_vm_event_local_num;
1820
+
1821
+ MJIT_SYMBOL_EXPORT_END
1822
+
1823
+ #define GET_VM() rb_current_vm()
1824
+ #define GET_RACTOR() rb_current_ractor()
1825
+ #define GET_THREAD() rb_current_thread()
1826
+ #define GET_EC() rb_current_execution_context(true)
1827
+
1828
+ static inline rb_thread_t *
1829
+ rb_ec_thread_ptr(const rb_execution_context_t *ec)
1830
+ {
1831
+ return ec->thread_ptr;
1832
+ }
1833
+
1834
+ static inline rb_ractor_t *
1835
+ rb_ec_ractor_ptr(const rb_execution_context_t *ec)
1836
+ {
1837
+ const rb_thread_t *th = rb_ec_thread_ptr(ec);
1838
+ if (th) {
1839
+ VM_ASSERT(th->ractor != NULL);
1840
+ return th->ractor;
1841
+ }
1842
+ else {
1843
+ return NULL;
1844
+ }
1845
+ }
1846
+
1847
+ static inline rb_vm_t *
1848
+ rb_ec_vm_ptr(const rb_execution_context_t *ec)
1849
+ {
1850
+ const rb_thread_t *th = rb_ec_thread_ptr(ec);
1851
+ if (th) {
1852
+ return th->vm;
1853
+ }
1854
+ else {
1855
+ return NULL;
1856
+ }
1857
+ }
1858
+
1859
+ static inline rb_execution_context_t *
1860
+ rb_current_execution_context(bool expect_ec)
1861
+ {
1862
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
1863
+ #ifdef __APPLE__
1864
+ rb_execution_context_t *ec = rb_current_ec();
1865
+ #else
1866
+ rb_execution_context_t *ec = ruby_current_ec;
1867
+ #endif
1868
+ #else
1869
+ rb_execution_context_t *ec = native_tls_get(ruby_current_ec_key);
1870
+ #endif
1871
+ VM_ASSERT(!expect_ec || ec != NULL);
1872
+ return ec;
1873
+ }
1874
+
1875
+ static inline rb_thread_t *
1876
+ rb_current_thread(void)
1877
+ {
1878
+ const rb_execution_context_t *ec = GET_EC();
1879
+ return rb_ec_thread_ptr(ec);
1880
+ }
1881
+
1882
+ static inline rb_ractor_t *
1883
+ rb_current_ractor(void)
1884
+ {
1885
+ if (ruby_single_main_ractor) {
1886
+ return ruby_single_main_ractor;
1887
+ }
1888
+ else {
1889
+ const rb_execution_context_t *ec = GET_EC();
1890
+ return rb_ec_ractor_ptr(ec);
1891
+ }
1892
+ }
1893
+
1894
+ static inline rb_vm_t *
1895
+ rb_current_vm(void)
1896
+ {
1897
+ #if 0 // TODO: reconsider the assertions
1898
+ VM_ASSERT(ruby_current_vm_ptr == NULL ||
1899
+ ruby_current_execution_context_ptr == NULL ||
1900
+ rb_ec_thread_ptr(GET_EC()) == NULL ||
1901
+ rb_ec_thread_ptr(GET_EC())->status == THREAD_KILLED ||
1902
+ rb_ec_vm_ptr(GET_EC()) == ruby_current_vm_ptr);
1903
+ #endif
1904
+
1905
+ return ruby_current_vm_ptr;
1906
+ }
1907
+
1908
+ void rb_ec_vm_lock_rec_release(const rb_execution_context_t *ec,
1909
+ unsigned int recorded_lock_rec,
1910
+ unsigned int current_lock_rec);
1911
+
1912
+ static inline unsigned int
1913
+ rb_ec_vm_lock_rec(const rb_execution_context_t *ec)
1914
+ {
1915
+ rb_vm_t *vm = rb_ec_vm_ptr(ec);
1916
+
1917
+ if (vm->ractor.sync.lock_owner != rb_ec_ractor_ptr(ec)) {
1918
+ return 0;
1919
+ }
1920
+ else {
1921
+ return vm->ractor.sync.lock_rec;
1922
+ }
1923
+ }
1924
+
1925
+ #else
1926
+ #error "unsupported thread model"
1927
+ #endif
1928
+
1929
+ enum {
1930
+ TIMER_INTERRUPT_MASK = 0x01,
1931
+ PENDING_INTERRUPT_MASK = 0x02,
1932
+ POSTPONED_JOB_INTERRUPT_MASK = 0x04,
1933
+ TRAP_INTERRUPT_MASK = 0x08,
1934
+ TERMINATE_INTERRUPT_MASK = 0x10,
1935
+ VM_BARRIER_INTERRUPT_MASK = 0x20,
1936
+ };
1937
+
1938
+ #define RUBY_VM_SET_TIMER_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TIMER_INTERRUPT_MASK)
1939
+ #define RUBY_VM_SET_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, PENDING_INTERRUPT_MASK)
1940
+ #define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
1941
+ #define RUBY_VM_SET_TRAP_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TRAP_INTERRUPT_MASK)
1942
+ #define RUBY_VM_SET_TERMINATE_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, TERMINATE_INTERRUPT_MASK)
1943
+ #define RUBY_VM_SET_VM_BARRIER_INTERRUPT(ec) ATOMIC_OR((ec)->interrupt_flag, VM_BARRIER_INTERRUPT_MASK)
1944
+ #define RUBY_VM_INTERRUPTED(ec) ((ec)->interrupt_flag & ~(ec)->interrupt_mask & \
1945
+ (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
1946
+
1947
+ static inline bool
1948
+ RUBY_VM_INTERRUPTED_ANY(rb_execution_context_t *ec)
1949
+ {
1950
+ #if defined(USE_VM_CLOCK) && USE_VM_CLOCK
1951
+ uint32_t current_clock = rb_ec_vm_ptr(ec)->clock;
1952
+
1953
+ if (current_clock != ec->checked_clock) {
1954
+ ec->checked_clock = current_clock;
1955
+ RUBY_VM_SET_TIMER_INTERRUPT(ec);
1956
+ }
1957
+ #endif
1958
+ return ec->interrupt_flag & ~(ec)->interrupt_mask;
1959
+ }
1960
+
1961
+ VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt);
1962
+ int rb_signal_buff_size(void);
1963
+ int rb_signal_exec(rb_thread_t *th, int sig);
1964
+ void rb_threadptr_check_signal(rb_thread_t *mth);
1965
+ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
1966
+ void rb_threadptr_signal_exit(rb_thread_t *th);
1967
+ int rb_threadptr_execute_interrupts(rb_thread_t *, int);
1968
+ void rb_threadptr_interrupt(rb_thread_t *th);
1969
+ void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
1970
+ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
1971
+ void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
1972
+ VALUE rb_ec_get_errinfo(const rb_execution_context_t *ec);
1973
+ void rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo);
1974
+ void rb_execution_context_update(const rb_execution_context_t *ec);
1975
+ void rb_execution_context_mark(const rb_execution_context_t *ec);
1976
+ void rb_fiber_close(rb_fiber_t *fib);
1977
+ void Init_native_thread(rb_thread_t *th);
1978
+ int rb_vm_check_ints_blocking(rb_execution_context_t *ec);
1979
+
1980
+ // vm_sync.h
1981
+ void rb_vm_cond_wait(rb_vm_t *vm, rb_nativethread_cond_t *cond);
1982
+ void rb_vm_cond_timedwait(rb_vm_t *vm, rb_nativethread_cond_t *cond, unsigned long msec);
1983
+
1984
+ #define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec)
1985
+ static inline void
1986
+ rb_vm_check_ints(rb_execution_context_t *ec)
1987
+ {
1988
+ VM_ASSERT(ec == GET_EC());
1989
+ if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(ec))) {
1990
+ rb_threadptr_execute_interrupts(rb_ec_thread_ptr(ec), 0);
1991
+ }
1992
+ }
1993
+
1994
+ /* tracer */
1995
+
1996
+ struct rb_trace_arg_struct {
1997
+ rb_event_flag_t event;
1998
+ rb_execution_context_t *ec;
1999
+ const rb_control_frame_t *cfp;
2000
+ VALUE self;
2001
+ ID id;
2002
+ ID called_id;
2003
+ VALUE klass;
2004
+ VALUE data;
2005
+
2006
+ int klass_solved;
2007
+
2008
+ /* calc from cfp */
2009
+ int lineno;
2010
+ VALUE path;
2011
+ };
2012
+
2013
+ void rb_hook_list_mark(rb_hook_list_t *hooks);
2014
+ void rb_hook_list_free(rb_hook_list_t *hooks);
2015
+ void rb_hook_list_connect_tracepoint(VALUE target, rb_hook_list_t *list, VALUE tpval, unsigned int target_line);
2016
+ void rb_hook_list_remove_tracepoint(rb_hook_list_t *list, VALUE tpval);
2017
+
2018
+ void rb_exec_event_hooks(struct rb_trace_arg_struct *trace_arg, rb_hook_list_t *hooks, int pop_p);
2019
+
2020
+ #define EXEC_EVENT_HOOK_ORIG(ec_, hooks_, flag_, self_, id_, called_id_, klass_, data_, pop_p_) do { \
2021
+ const rb_event_flag_t flag_arg_ = (flag_); \
2022
+ rb_hook_list_t *hooks_arg_ = (hooks_); \
2023
+ if (UNLIKELY((hooks_arg_)->events & (flag_arg_))) { \
2024
+ /* defer evaluating the other arguments */ \
2025
+ rb_exec_event_hook_orig(ec_, hooks_arg_, flag_arg_, self_, id_, called_id_, klass_, data_, pop_p_); \
2026
+ } \
2027
+ } while (0)
2028
+
2029
+ static inline void
2030
+ rb_exec_event_hook_orig(rb_execution_context_t *ec, rb_hook_list_t *hooks, rb_event_flag_t flag,
2031
+ VALUE self, ID id, ID called_id, VALUE klass, VALUE data, int pop_p)
2032
+ {
2033
+ struct rb_trace_arg_struct trace_arg;
2034
+
2035
+ VM_ASSERT((hooks->events & flag) != 0);
2036
+
2037
+ trace_arg.event = flag;
2038
+ trace_arg.ec = ec;
2039
+ trace_arg.cfp = ec->cfp;
2040
+ trace_arg.self = self;
2041
+ trace_arg.id = id;
2042
+ trace_arg.called_id = called_id;
2043
+ trace_arg.klass = klass;
2044
+ trace_arg.data = data;
2045
+ trace_arg.path = Qundef;
2046
+ trace_arg.klass_solved = 0;
2047
+
2048
+ rb_exec_event_hooks(&trace_arg, hooks, pop_p);
2049
+ }
2050
+
2051
+ struct rb_ractor_pub {
2052
+ VALUE self;
2053
+ uint32_t id;
2054
+ rb_hook_list_t hooks;
2055
+ };
2056
+
2057
+ static inline rb_hook_list_t *
2058
+ rb_ec_ractor_hooks(const rb_execution_context_t *ec)
2059
+ {
2060
+ struct rb_ractor_pub *cr_pub = (struct rb_ractor_pub *)rb_ec_ractor_ptr(ec);
2061
+ return &cr_pub->hooks;
2062
+ }
2063
+
2064
+ #define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_) \
2065
+ EXEC_EVENT_HOOK_ORIG(ec_, rb_ec_ractor_hooks(ec_), flag_, self_, id_, called_id_, klass_, data_, 0)
2066
+
2067
+ #define EXEC_EVENT_HOOK_AND_POP_FRAME(ec_, flag_, self_, id_, called_id_, klass_, data_) \
2068
+ EXEC_EVENT_HOOK_ORIG(ec_, rb_ec_ractor_hooks(ec_), flag_, self_, id_, called_id_, klass_, data_, 1)
2069
+
2070
+ static inline void
2071
+ rb_exec_event_hook_script_compiled(rb_execution_context_t *ec, const rb_iseq_t *iseq, VALUE eval_script)
2072
+ {
2073
+ EXEC_EVENT_HOOK(ec, RUBY_EVENT_SCRIPT_COMPILED, ec->cfp->self, 0, 0, 0,
2074
+ NIL_P(eval_script) ? (VALUE)iseq :
2075
+ rb_ary_new_from_args(2, eval_script, (VALUE)iseq));
2076
+ }
2077
+
2078
+ void rb_vm_trap_exit(rb_vm_t *vm);
2079
+
2080
+ RUBY_SYMBOL_EXPORT_BEGIN
2081
+
2082
+ int rb_thread_check_trap_pending(void);
2083
+
2084
+ /* #define RUBY_EVENT_RESERVED_FOR_INTERNAL_USE 0x030000 */ /* from vm_core.h */
2085
+ #define RUBY_EVENT_COVERAGE_LINE 0x010000
2086
+ #define RUBY_EVENT_COVERAGE_BRANCH 0x020000
2087
+
2088
+ extern VALUE rb_get_coverages(void);
2089
+ extern void rb_set_coverages(VALUE, int, VALUE);
2090
+ extern void rb_clear_coverages(void);
2091
+ extern void rb_reset_coverages(void);
2092
+ extern void rb_resume_coverages(void);
2093
+ extern void rb_suspend_coverages(void);
2094
+
2095
+ void rb_postponed_job_flush(rb_vm_t *vm);
2096
+
2097
+ // ractor.c
2098
+ RUBY_EXTERN VALUE rb_eRactorUnsafeError;
2099
+ RUBY_EXTERN VALUE rb_eRactorIsolationError;
2100
+
2101
+ RUBY_SYMBOL_EXPORT_END
2102
+
2103
+ #endif /* RUBY_VM_CORE_H */