debase-ruby_core_source 0.10.17 → 0.10.18

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