debase-ruby_core_source 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -1
  3. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/addr2line.h +21 -0
  4. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ccan/check_type/check_type.h +63 -0
  6. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ccan/container_of/container_of.h +142 -0
  7. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ccan/list/list.h +635 -0
  8. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ccan/str/str.h +16 -0
  9. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/constant.h +43 -0
  10. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/dln.h +51 -0
  11. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/eval_intern.h +275 -0
  12. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/gc.h +107 -0
  13. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/id.h +210 -0
  14. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/insns.inc +107 -0
  15. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/insns_info.inc +752 -0
  16. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/internal.h +1198 -0
  17. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/iseq.h +158 -0
  18. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/known_errors.inc +746 -0
  19. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/method.h +144 -0
  20. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/node.h +544 -0
  21. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/node_name.inc +212 -0
  22. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/opt_sc.inc +734 -0
  23. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/optinsn.inc +83 -0
  24. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/optunifs.inc +124 -0
  25. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/parse.h +184 -0
  26. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/probes_helper.h +67 -0
  27. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/regenc.h +237 -0
  28. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/regint.h +972 -0
  29. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/regparse.h +363 -0
  30. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/revision.h +1 -0
  31. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/ruby_atomic.h +170 -0
  32. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/siphash.h +48 -0
  33. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/symbol.h +88 -0
  34. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/thread_pthread.h +54 -0
  35. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/thread_win32.h +36 -0
  36. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/timev.h +42 -0
  37. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/transcode_data.h +123 -0
  38. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/version.h +52 -0
  39. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm.inc +3372 -0
  40. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm_core.h +1163 -0
  41. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm_debug.h +37 -0
  42. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm_exec.h +182 -0
  43. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm_insnhelper.h +233 -0
  44. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vm_opts.h +56 -0
  45. data/lib/debase/ruby_core_source/ruby-2.2.7-p470/vmtc.inc +105 -0
  46. data/lib/debase/ruby_core_source/version.rb +1 -1
  47. metadata +45 -2
@@ -0,0 +1,1163 @@
1
+ /**********************************************************************
2
+
3
+ vm_core.h -
4
+
5
+ $Author: usa $
6
+ created at: 04/01/01 19:41:38 JST
7
+
8
+ Copyright (C) 2004-2007 Koichi Sasada
9
+
10
+ **********************************************************************/
11
+
12
+ #ifndef RUBY_VM_CORE_H
13
+ #define RUBY_VM_CORE_H
14
+
15
+ #define RUBY_VM_THREAD_MODEL 2
16
+
17
+ #include "ruby/ruby.h"
18
+ #include "ruby/st.h"
19
+
20
+ #include "node.h"
21
+ #include "vm_debug.h"
22
+ #include "vm_opts.h"
23
+ #include "id.h"
24
+ #include "method.h"
25
+ #include "ruby_atomic.h"
26
+ #include "ccan/list/list.h"
27
+
28
+ #include "ruby/thread_native.h"
29
+ #if defined(_WIN32)
30
+ #include "thread_win32.h"
31
+ #elif defined(HAVE_PTHREAD_H)
32
+ #include "thread_pthread.h"
33
+ #endif
34
+
35
+ #ifndef ENABLE_VM_OBJSPACE
36
+ #ifdef _WIN32
37
+ /*
38
+ * TODO: object space independent st_table.
39
+ * socklist needs st_table in rb_w32_sysinit(), before object space
40
+ * initialization.
41
+ * It is too early now to change st_hash_type, since it breaks binary
42
+ * compatibility.
43
+ */
44
+ #define ENABLE_VM_OBJSPACE 0
45
+ #else
46
+ #define ENABLE_VM_OBJSPACE 1
47
+ #endif
48
+ #endif
49
+
50
+ #include <setjmp.h>
51
+ #include <signal.h>
52
+
53
+ #ifndef NSIG
54
+ # define NSIG (_SIGMAX + 1) /* For QNX */
55
+ #endif
56
+
57
+ #define RUBY_NSIG NSIG
58
+
59
+ #ifdef HAVE_STDARG_PROTOTYPES
60
+ #include <stdarg.h>
61
+ #define va_init_list(a,b) va_start((a),(b))
62
+ #else
63
+ #include <varargs.h>
64
+ #define va_init_list(a,b) va_start((a))
65
+ #endif
66
+
67
+ #if defined(SIGSEGV) && defined(HAVE_SIGALTSTACK) && defined(SA_SIGINFO) && !defined(__NetBSD__)
68
+ #define USE_SIGALTSTACK
69
+ #endif
70
+
71
+ /*****************/
72
+ /* configuration */
73
+ /*****************/
74
+
75
+ /* gcc ver. check */
76
+ #if defined(__GNUC__) && __GNUC__ >= 2
77
+
78
+ #if OPT_TOKEN_THREADED_CODE
79
+ #if OPT_DIRECT_THREADED_CODE
80
+ #undef OPT_DIRECT_THREADED_CODE
81
+ #endif
82
+ #endif
83
+
84
+ #else /* defined(__GNUC__) && __GNUC__ >= 2 */
85
+
86
+ /* disable threaded code options */
87
+ #if OPT_DIRECT_THREADED_CODE
88
+ #undef OPT_DIRECT_THREADED_CODE
89
+ #endif
90
+ #if OPT_TOKEN_THREADED_CODE
91
+ #undef OPT_TOKEN_THREADED_CODE
92
+ #endif
93
+ #endif
94
+
95
+ #ifdef __native_client__
96
+ #undef OPT_DIRECT_THREADED_CODE
97
+ #endif
98
+
99
+ /* call threaded code */
100
+ #if OPT_CALL_THREADED_CODE
101
+ #if OPT_DIRECT_THREADED_CODE
102
+ #undef OPT_DIRECT_THREADED_CODE
103
+ #endif /* OPT_DIRECT_THREADED_CODE */
104
+ #if OPT_STACK_CACHING
105
+ #undef OPT_STACK_CACHING
106
+ #endif /* OPT_STACK_CACHING */
107
+ #endif /* OPT_CALL_THREADED_CODE */
108
+
109
+ typedef unsigned long rb_num_t;
110
+
111
+ /* iseq data type */
112
+
113
+ struct iseq_compile_data_ensure_node_stack;
114
+
115
+ typedef struct rb_compile_option_struct rb_compile_option_t;
116
+
117
+
118
+ struct iseq_inline_cache_entry {
119
+ rb_serial_t ic_serial;
120
+ union {
121
+ size_t index;
122
+ VALUE value;
123
+ } ic_value;
124
+ };
125
+
126
+ union iseq_inline_storage_entry {
127
+ struct {
128
+ struct rb_thread_struct *running_thread;
129
+ VALUE value;
130
+ } once;
131
+ struct iseq_inline_cache_entry cache;
132
+ };
133
+
134
+ /* to avoid warning */
135
+ struct rb_thread_struct;
136
+ struct rb_control_frame_struct;
137
+
138
+ typedef struct rb_call_info_kw_arg_struct {
139
+ int keyword_len;
140
+ VALUE keywords[1];
141
+ } rb_call_info_kw_arg_t;
142
+
143
+ /* rb_call_info_t contains calling information including inline cache */
144
+ typedef struct rb_call_info_struct {
145
+ /* fixed at compile time */
146
+ ID mid;
147
+
148
+ unsigned int flag;
149
+ int orig_argc;
150
+ rb_iseq_t *blockiseq;
151
+ rb_call_info_kw_arg_t *kw_arg;
152
+
153
+ /* inline cache: keys */
154
+ rb_serial_t method_state;
155
+ rb_serial_t class_serial;
156
+ VALUE klass;
157
+
158
+ /* inline cache: values */
159
+ const rb_method_entry_t *me;
160
+ VALUE defined_class;
161
+
162
+ /* temporary values for method calling */
163
+ struct rb_block_struct *blockptr;
164
+ VALUE recv;
165
+ int argc;
166
+ union {
167
+ int opt_pc; /* used by iseq */
168
+ int index; /* used by ivar */
169
+ int missing_reason; /* used by method_missing */
170
+ int inc_sp; /* used by cfunc */
171
+ } aux;
172
+
173
+ VALUE (*call)(struct rb_thread_struct *th, struct rb_control_frame_struct *cfp, struct rb_call_info_struct *ci);
174
+ } rb_call_info_t;
175
+
176
+ #if 1
177
+ #define GetCoreDataFromValue(obj, type, ptr) do { \
178
+ (ptr) = (type*)DATA_PTR(obj); \
179
+ } while (0)
180
+ #else
181
+ #define GetCoreDataFromValue(obj, type, ptr) Data_Get_Struct((obj), type, (ptr))
182
+ #endif
183
+
184
+ #define GetISeqPtr(obj, ptr) \
185
+ GetCoreDataFromValue((obj), rb_iseq_t, (ptr))
186
+
187
+ typedef struct rb_iseq_location_struct {
188
+ const VALUE path;
189
+ const VALUE absolute_path;
190
+ const VALUE base_label;
191
+ const VALUE label;
192
+ VALUE first_lineno; /* TODO: may be unsigned short */
193
+ } rb_iseq_location_t;
194
+
195
+ struct rb_iseq_struct;
196
+
197
+ struct rb_iseq_struct {
198
+ /***************/
199
+ /* static data */
200
+ /***************/
201
+
202
+ enum iseq_type {
203
+ ISEQ_TYPE_TOP,
204
+ ISEQ_TYPE_METHOD,
205
+ ISEQ_TYPE_BLOCK,
206
+ ISEQ_TYPE_CLASS,
207
+ ISEQ_TYPE_RESCUE,
208
+ ISEQ_TYPE_ENSURE,
209
+ ISEQ_TYPE_EVAL,
210
+ ISEQ_TYPE_MAIN,
211
+ ISEQ_TYPE_DEFINED_GUARD
212
+ } type; /* instruction sequence type */
213
+ #if defined(WORDS_BIGENDIAN) && (SIZEOF_VALUE > SIZEOF_INT)
214
+ char dummy[SIZEOF_VALUE - SIZEOF_INT]; /* [Bug #10037][ruby-core:63721] */
215
+ #endif
216
+ int stack_max; /* for stack overflow check */
217
+
218
+ rb_iseq_location_t location;
219
+
220
+ VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
221
+ unsigned int iseq_size;
222
+ unsigned int line_info_size;
223
+
224
+ const VALUE mark_ary; /* Array: includes operands which should be GC marked */
225
+ const VALUE coverage; /* coverage array */
226
+
227
+ /* insn info, must be freed */
228
+ struct iseq_line_info_entry *line_info_table;
229
+
230
+ ID *local_table; /* must free */
231
+ int local_table_size;
232
+
233
+ /* sizeof(vars) + 1 */
234
+ int local_size;
235
+
236
+ union iseq_inline_storage_entry *is_entries;
237
+ int is_size;
238
+
239
+ int callinfo_size;
240
+ rb_call_info_t *callinfo_entries;
241
+
242
+ /**
243
+ * parameter information
244
+ *
245
+ * def m(a1, a2, ..., aM, # mandatory
246
+ * b1=(...), b2=(...), ..., bN=(...), # optional
247
+ * *c, # rest
248
+ * d1, d2, ..., dO, # post
249
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
250
+ * **f, # keyword_rest
251
+ * &g) # block
252
+ * =>
253
+ *
254
+ * lead_num = M
255
+ * opt_num = N
256
+ * rest_start = M+N
257
+ * post_start = M+N+(*1)
258
+ * post_num = O
259
+ * keyword_num = K
260
+ * block_start = M+N+(*1)+O+K
261
+ * keyword_bits = M+N+(*1)+O+K+(&1)
262
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
263
+ */
264
+
265
+ struct {
266
+ struct {
267
+ unsigned int has_lead : 1;
268
+ unsigned int has_opt : 1;
269
+ unsigned int has_rest : 1;
270
+ unsigned int has_post : 1;
271
+ unsigned int has_kw : 1;
272
+ unsigned int has_kwrest : 1;
273
+ unsigned int has_block : 1;
274
+
275
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
276
+ } flags;
277
+
278
+ int size;
279
+
280
+ int lead_num;
281
+ int opt_num;
282
+ int rest_start;
283
+ int post_start;
284
+ int post_num;
285
+ int block_start;
286
+
287
+ VALUE *opt_table; /* (opt_num + 1) entries. */
288
+ /* opt_num and opt_table:
289
+ *
290
+ * def foo o1=e1, o2=e2, ..., oN=eN
291
+ * #=>
292
+ * # prologue code
293
+ * A1: e1
294
+ * A2: e2
295
+ * ...
296
+ * AN: eN
297
+ * AL: body
298
+ * opt_num = N
299
+ * opt_table = [A1, A2, ..., AN, AL]
300
+ */
301
+
302
+ struct rb_iseq_param_keyword {
303
+ int num;
304
+ int required_num;
305
+ int bits_start;
306
+ int rest_start;
307
+ ID *table;
308
+ VALUE *default_values;
309
+ } *keyword;
310
+ } param;
311
+
312
+ /* catch table */
313
+ struct iseq_catch_table *catch_table;
314
+
315
+ /* for child iseq */
316
+ struct rb_iseq_struct *parent_iseq;
317
+ struct rb_iseq_struct *local_iseq;
318
+
319
+ /****************/
320
+ /* dynamic data */
321
+ /****************/
322
+
323
+ VALUE self;
324
+ const VALUE orig; /* non-NULL if its data have origin */
325
+
326
+ /* block inlining */
327
+ /*
328
+ * NODE *node;
329
+ * void *special_block_builder;
330
+ * void *cached_special_block_builder;
331
+ * VALUE cached_special_block;
332
+ */
333
+
334
+ /* klass/module nest information stack (cref) */
335
+ NODE * const cref_stack;
336
+ const VALUE klass;
337
+
338
+ /* misc */
339
+ ID defined_method_id; /* for define_method */
340
+ rb_num_t flip_cnt;
341
+
342
+ /* used at compile time */
343
+ struct iseq_compile_data *compile_data;
344
+
345
+ /* original iseq, before encoding
346
+ * used for debug/dump (TODO: union with compile_data) */
347
+ VALUE *iseq;
348
+ };
349
+
350
+ enum ruby_special_exceptions {
351
+ ruby_error_reenter,
352
+ ruby_error_nomemory,
353
+ ruby_error_sysstack,
354
+ ruby_error_closed_stream,
355
+ ruby_special_error_count
356
+ };
357
+
358
+ enum ruby_basic_operators {
359
+ BOP_PLUS,
360
+ BOP_MINUS,
361
+ BOP_MULT,
362
+ BOP_DIV,
363
+ BOP_MOD,
364
+ BOP_EQ,
365
+ BOP_EQQ,
366
+ BOP_LT,
367
+ BOP_LE,
368
+ BOP_LTLT,
369
+ BOP_AREF,
370
+ BOP_ASET,
371
+ BOP_LENGTH,
372
+ BOP_SIZE,
373
+ BOP_EMPTY_P,
374
+ BOP_SUCC,
375
+ BOP_GT,
376
+ BOP_GE,
377
+ BOP_NOT,
378
+ BOP_NEQ,
379
+ BOP_MATCH,
380
+ BOP_FREEZE,
381
+
382
+ BOP_LAST_
383
+ };
384
+
385
+ #define GetVMPtr(obj, ptr) \
386
+ GetCoreDataFromValue((obj), rb_vm_t, (ptr))
387
+
388
+ struct rb_vm_struct;
389
+ typedef void rb_vm_at_exit_func(struct rb_vm_struct*);
390
+ typedef struct rb_at_exit_list {
391
+ rb_vm_at_exit_func *func;
392
+ struct rb_at_exit_list *next;
393
+ } rb_at_exit_list;
394
+
395
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
396
+ struct rb_objspace;
397
+ void rb_objspace_free(struct rb_objspace *);
398
+ #endif
399
+
400
+ typedef struct rb_hook_list_struct {
401
+ struct rb_event_hook_struct *hooks;
402
+ rb_event_flag_t events;
403
+ int need_clean;
404
+ } rb_hook_list_t;
405
+
406
+ typedef struct rb_vm_struct {
407
+ VALUE self;
408
+
409
+ rb_global_vm_lock_t gvl;
410
+ rb_nativethread_lock_t thread_destruct_lock;
411
+
412
+ struct rb_thread_struct *main_thread;
413
+ struct rb_thread_struct *running_thread;
414
+
415
+ struct list_head living_threads;
416
+ size_t living_thread_num;
417
+ VALUE thgroup_default;
418
+
419
+ int running;
420
+ int thread_abort_on_exception;
421
+ int trace_running;
422
+ volatile int sleeper;
423
+
424
+ /* object management */
425
+ VALUE mark_object_ary;
426
+
427
+ const VALUE special_exceptions[ruby_special_error_count];
428
+
429
+ /* load */
430
+ VALUE top_self;
431
+ VALUE load_path;
432
+ VALUE load_path_snapshot;
433
+ VALUE load_path_check_cache;
434
+ VALUE expanded_load_path;
435
+ VALUE loaded_features;
436
+ VALUE loaded_features_snapshot;
437
+ struct st_table *loaded_features_index;
438
+ struct st_table *loading_table;
439
+
440
+ /* signal */
441
+ struct {
442
+ VALUE cmd;
443
+ int safe;
444
+ } trap_list[RUBY_NSIG];
445
+
446
+ /* hook */
447
+ rb_hook_list_t event_hooks;
448
+
449
+ /* relation table of ensure - rollback for callcc */
450
+ struct st_table *ensure_rollback_table;
451
+
452
+ /* postponed_job */
453
+ struct rb_postponed_job_struct *postponed_job_buffer;
454
+ int postponed_job_index;
455
+
456
+ int src_encoding_index;
457
+
458
+ VALUE verbose, debug, orig_progname, progname;
459
+ VALUE coverages;
460
+
461
+ struct unlinked_method_entry_list_entry *unlinked_method_entry_list;
462
+
463
+ VALUE defined_module_hash;
464
+
465
+ #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
466
+ struct rb_objspace *objspace;
467
+ #endif
468
+
469
+ rb_at_exit_list *at_exit;
470
+
471
+ VALUE *defined_strings;
472
+ st_table *frozen_strings;
473
+
474
+ /* params */
475
+ struct { /* size in byte */
476
+ size_t thread_vm_stack_size;
477
+ size_t thread_machine_stack_size;
478
+ size_t fiber_vm_stack_size;
479
+ size_t fiber_machine_stack_size;
480
+ } default_params;
481
+
482
+ short redefined_flag[BOP_LAST_];
483
+ } rb_vm_t;
484
+
485
+ /* default values */
486
+
487
+ #define RUBY_VM_SIZE_ALIGN 4096
488
+
489
+ #define RUBY_VM_THREAD_VM_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
490
+ #define RUBY_VM_THREAD_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
491
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE ( 128 * 1024 * sizeof(VALUE)) /* 512 KB or 1024 KB */
492
+ #define RUBY_VM_THREAD_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
493
+
494
+ #define RUBY_VM_FIBER_VM_STACK_SIZE ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
495
+ #define RUBY_VM_FIBER_VM_STACK_SIZE_MIN ( 2 * 1024 * sizeof(VALUE)) /* 8 KB or 16 KB */
496
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE ( 64 * 1024 * sizeof(VALUE)) /* 256 KB or 512 KB */
497
+ #define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
498
+
499
+ /* optimize insn */
500
+ #define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
501
+ #define FLOAT_REDEFINED_OP_FLAG (1 << 1)
502
+ #define STRING_REDEFINED_OP_FLAG (1 << 2)
503
+ #define ARRAY_REDEFINED_OP_FLAG (1 << 3)
504
+ #define HASH_REDEFINED_OP_FLAG (1 << 4)
505
+ #define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
506
+ #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
507
+ #define TIME_REDEFINED_OP_FLAG (1 << 7)
508
+ #define REGEXP_REDEFINED_OP_FLAG (1 << 8)
509
+
510
+ #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((GET_VM()->redefined_flag[(op)]&(klass)) == 0))
511
+
512
+ #ifndef VM_DEBUG_BP_CHECK
513
+ #define VM_DEBUG_BP_CHECK 0
514
+ #endif
515
+
516
+ #ifndef VM_DEBUG_VERIFY_METHOD_CACHE
517
+ #define VM_DEBUG_VERIFY_METHOD_CACHE 0
518
+ #endif
519
+
520
+ typedef struct rb_control_frame_struct {
521
+ VALUE *pc; /* cfp[0] */
522
+ VALUE *sp; /* cfp[1] */
523
+ rb_iseq_t *iseq; /* cfp[2] */
524
+ VALUE flag; /* cfp[3] */
525
+ VALUE self; /* cfp[4] / block[0] */
526
+ VALUE klass; /* cfp[5] / block[1] */
527
+ VALUE *ep; /* cfp[6] / block[2] */
528
+ rb_iseq_t *block_iseq; /* cfp[7] / block[3] */
529
+ VALUE proc; /* cfp[8] / block[4] */
530
+ const rb_method_entry_t *me;/* cfp[9] */
531
+
532
+ #if VM_DEBUG_BP_CHECK
533
+ VALUE *bp_check; /* cfp[10] */
534
+ #endif
535
+ } rb_control_frame_t;
536
+
537
+ typedef struct rb_block_struct {
538
+ VALUE self; /* share with method frame if it's only block */
539
+ VALUE klass; /* share with method frame if it's only block */
540
+ VALUE *ep; /* share with method frame if it's only block */
541
+ rb_iseq_t *iseq;
542
+ VALUE proc;
543
+ } rb_block_t;
544
+
545
+ extern const rb_data_type_t ruby_threadptr_data_type;
546
+
547
+ #define GetThreadPtr(obj, ptr) \
548
+ TypedData_Get_Struct((obj), rb_thread_t, &ruby_threadptr_data_type, (ptr))
549
+
550
+ enum rb_thread_status {
551
+ THREAD_RUNNABLE,
552
+ THREAD_STOPPED,
553
+ THREAD_STOPPED_FOREVER,
554
+ THREAD_KILLED
555
+ };
556
+
557
+ typedef RUBY_JMP_BUF rb_jmpbuf_t;
558
+
559
+ /*
560
+ the members which are written in TH_PUSH_TAG() should be placed at
561
+ the beginning and the end, so that entire region is accessible.
562
+ */
563
+ struct rb_vm_tag {
564
+ VALUE tag;
565
+ VALUE retval;
566
+ rb_jmpbuf_t buf;
567
+ struct rb_vm_tag *prev;
568
+ };
569
+
570
+ struct rb_vm_protect_tag {
571
+ struct rb_vm_protect_tag *prev;
572
+ };
573
+
574
+ struct rb_unblock_callback {
575
+ rb_unblock_function_t *func;
576
+ void *arg;
577
+ };
578
+
579
+ struct rb_mutex_struct;
580
+
581
+ struct rb_thread_struct;
582
+ typedef struct rb_thread_list_struct{
583
+ struct rb_thread_list_struct *next;
584
+ struct rb_thread_struct *th;
585
+ } rb_thread_list_t;
586
+
587
+
588
+ typedef struct rb_ensure_entry {
589
+ VALUE marker;
590
+ VALUE (*e_proc)(ANYARGS);
591
+ VALUE data2;
592
+ } rb_ensure_entry_t;
593
+
594
+ typedef struct rb_ensure_list {
595
+ struct rb_ensure_list *next;
596
+ struct rb_ensure_entry entry;
597
+ } rb_ensure_list_t;
598
+
599
+ typedef char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) * 2 + 3];
600
+
601
+ typedef struct rb_fiber_struct rb_fiber_t;
602
+
603
+ typedef struct rb_thread_struct {
604
+ struct list_node vmlt_node;
605
+ VALUE self;
606
+ rb_vm_t *vm;
607
+
608
+ /* execution information */
609
+ VALUE *stack; /* must free, must mark */
610
+ size_t stack_size; /* size in word (byte size / sizeof(VALUE)) */
611
+ rb_control_frame_t *cfp;
612
+ int safe_level;
613
+ int raised_flag;
614
+ VALUE last_status; /* $? */
615
+
616
+ /* passing state */
617
+ int state;
618
+
619
+ int waiting_fd;
620
+
621
+ /* for rb_iterate */
622
+ const rb_block_t *passed_block;
623
+
624
+ /* for bmethod */
625
+ const rb_method_entry_t *passed_bmethod_me;
626
+
627
+ /* for cfunc */
628
+ rb_call_info_t *passed_ci;
629
+
630
+ /* for load(true) */
631
+ VALUE top_self;
632
+ VALUE top_wrapper;
633
+
634
+ /* eval env */
635
+ rb_block_t *base_block;
636
+
637
+ VALUE *root_lep;
638
+ VALUE root_svar;
639
+
640
+ /* thread control */
641
+ rb_nativethread_id_t thread_id;
642
+ #ifdef NON_SCALAR_THREAD_ID
643
+ rb_thread_id_string_t thread_id_string;
644
+ #endif
645
+ enum rb_thread_status status;
646
+ int to_kill;
647
+ int priority;
648
+
649
+ native_thread_data_t native_thread_data;
650
+ void *blocking_region_buffer;
651
+
652
+ VALUE thgroup;
653
+ VALUE value;
654
+
655
+ /* temporary place of errinfo */
656
+ VALUE errinfo;
657
+
658
+ /* temporary place of retval on OPT_CALL_THREADED_CODE */
659
+ #if OPT_CALL_THREADED_CODE
660
+ VALUE retval;
661
+ #endif
662
+
663
+ /* async errinfo queue */
664
+ VALUE pending_interrupt_queue;
665
+ VALUE pending_interrupt_mask_stack;
666
+ int pending_interrupt_queue_checked;
667
+
668
+ rb_atomic_t interrupt_flag;
669
+ unsigned long interrupt_mask;
670
+ rb_nativethread_lock_t interrupt_lock;
671
+ rb_nativethread_cond_t interrupt_cond;
672
+ struct rb_unblock_callback unblock;
673
+ VALUE locking_mutex;
674
+ struct rb_mutex_struct *keeping_mutexes;
675
+
676
+ struct rb_vm_tag *tag;
677
+ struct rb_vm_protect_tag *protect_tag;
678
+
679
+ /*! Thread-local state of evaluation context.
680
+ *
681
+ * If negative, this thread is evaluating the main program.
682
+ * If positive, this thread is evaluating a program under Kernel::eval
683
+ * family.
684
+ */
685
+ int parse_in_eval;
686
+
687
+ /*! Thread-local state of compiling context.
688
+ *
689
+ * If non-zero, the parser does not automatically print error messages to
690
+ * stderr. */
691
+ int mild_compile_error;
692
+
693
+ /* storage */
694
+ st_table *local_storage;
695
+ VALUE local_storage_recursive_hash;
696
+ VALUE local_storage_recursive_hash_for_trace;
697
+
698
+ rb_thread_list_t *join_list;
699
+
700
+ VALUE first_proc;
701
+ VALUE first_args;
702
+ VALUE (*first_func)(ANYARGS);
703
+
704
+ /* for GC */
705
+ struct {
706
+ VALUE *stack_start;
707
+ VALUE *stack_end;
708
+ size_t stack_maxsize;
709
+ #ifdef __ia64
710
+ VALUE *register_stack_start;
711
+ VALUE *register_stack_end;
712
+ size_t register_stack_maxsize;
713
+ #endif
714
+ jmp_buf regs;
715
+ } machine;
716
+
717
+ /* statistics data for profiler */
718
+ VALUE stat_insn_usage;
719
+
720
+ /* tracer */
721
+ rb_hook_list_t event_hooks;
722
+ struct rb_trace_arg_struct *trace_arg; /* trace information */
723
+
724
+ /* fiber */
725
+ rb_fiber_t *fiber;
726
+ rb_fiber_t *root_fiber;
727
+ rb_jmpbuf_t root_jmpbuf;
728
+
729
+ /* ensure & callcc */
730
+ rb_ensure_list_t *ensure_list;
731
+
732
+ /* misc */
733
+ int method_missing_reason;
734
+ int abort_on_exception;
735
+ #ifdef USE_SIGALTSTACK
736
+ void *altstack;
737
+ #endif
738
+ unsigned long running_time_us;
739
+ } rb_thread_t;
740
+
741
+ typedef enum {
742
+ VM_DEFINECLASS_TYPE_CLASS = 0x00,
743
+ VM_DEFINECLASS_TYPE_SINGLETON_CLASS = 0x01,
744
+ VM_DEFINECLASS_TYPE_MODULE = 0x02,
745
+ /* 0x03..0x06 is reserved */
746
+ VM_DEFINECLASS_TYPE_MASK = 0x07
747
+ } rb_vm_defineclass_type_t;
748
+
749
+ #define VM_DEFINECLASS_TYPE(x) ((rb_vm_defineclass_type_t)(x) & VM_DEFINECLASS_TYPE_MASK)
750
+ #define VM_DEFINECLASS_FLAG_SCOPED 0x08
751
+ #define VM_DEFINECLASS_FLAG_HAS_SUPERCLASS 0x10
752
+ #define VM_DEFINECLASS_SCOPED_P(x) ((x) & VM_DEFINECLASS_FLAG_SCOPED)
753
+ #define VM_DEFINECLASS_HAS_SUPERCLASS_P(x) \
754
+ ((x) & VM_DEFINECLASS_FLAG_HAS_SUPERCLASS)
755
+
756
+ /* iseq.c */
757
+ RUBY_SYMBOL_EXPORT_BEGIN
758
+
759
+ /* node -> iseq */
760
+ VALUE rb_iseq_new(NODE*, VALUE, VALUE, VALUE, VALUE, enum iseq_type);
761
+ VALUE rb_iseq_new_top(NODE *node, VALUE name, VALUE path, VALUE absolute_path, VALUE parent);
762
+ VALUE rb_iseq_new_main(NODE *node, VALUE path, VALUE absolute_path);
763
+ VALUE rb_iseq_new_with_bopt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, VALUE);
764
+ VALUE rb_iseq_new_with_opt(NODE*, VALUE, VALUE, VALUE, VALUE, VALUE, enum iseq_type, const rb_compile_option_t*);
765
+
766
+ /* src -> iseq */
767
+ VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line);
768
+ VALUE rb_iseq_compile_on_base(VALUE src, VALUE file, VALUE line, rb_block_t *base_block);
769
+ VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
770
+
771
+ VALUE rb_iseq_disasm(VALUE self);
772
+ int rb_iseq_disasm_insn(VALUE str, const VALUE *iseqval, size_t pos, const rb_iseq_t *iseq, VALUE child);
773
+ const char *ruby_node_name(int node);
774
+
775
+ RUBY_EXTERN VALUE rb_cISeq;
776
+ RUBY_EXTERN VALUE rb_cRubyVM;
777
+ RUBY_EXTERN VALUE rb_cEnv;
778
+ RUBY_EXTERN VALUE rb_mRubyVMFrozenCore;
779
+ RUBY_SYMBOL_EXPORT_END
780
+
781
+ #define GetProcPtr(obj, ptr) \
782
+ GetCoreDataFromValue((obj), rb_proc_t, (ptr))
783
+
784
+ typedef struct {
785
+ rb_block_t block;
786
+
787
+ VALUE envval; /* for GC mark */
788
+ VALUE blockprocval;
789
+ int8_t safe_level; /* 0..3 */
790
+ int8_t is_from_method; /* bool */
791
+ int8_t is_lambda; /* bool */
792
+ } rb_proc_t;
793
+
794
+ #define GetEnvPtr(obj, ptr) \
795
+ GetCoreDataFromValue((obj), rb_env_t, (ptr))
796
+
797
+ typedef struct {
798
+ int env_size;
799
+ int local_size;
800
+ VALUE prev_envval; /* for GC mark */
801
+ rb_block_t block;
802
+ VALUE env[1]; /* flexible array */
803
+ } rb_env_t;
804
+
805
+ extern const rb_data_type_t ruby_binding_data_type;
806
+
807
+ #define GetBindingPtr(obj, ptr) \
808
+ GetCoreDataFromValue((obj), rb_binding_t, (ptr))
809
+
810
+ typedef struct {
811
+ VALUE env;
812
+ VALUE path;
813
+ VALUE blockprocval; /* for GC mark */
814
+ unsigned short first_lineno;
815
+ } rb_binding_t;
816
+
817
+ /* used by compile time and send insn */
818
+
819
+ enum vm_check_match_type {
820
+ VM_CHECKMATCH_TYPE_WHEN = 1,
821
+ VM_CHECKMATCH_TYPE_CASE = 2,
822
+ VM_CHECKMATCH_TYPE_RESCUE = 3
823
+ };
824
+
825
+ #define VM_CHECKMATCH_TYPE_MASK 0x03
826
+ #define VM_CHECKMATCH_ARRAY 0x04
827
+
828
+ #define VM_CALL_ARGS_SPLAT (0x01 << 1) /* m(*args) */
829
+ #define VM_CALL_ARGS_BLOCKARG (0x01 << 2) /* m(&block) */
830
+ #define VM_CALL_FCALL (0x01 << 3) /* m(...) */
831
+ #define VM_CALL_VCALL (0x01 << 4) /* m */
832
+ #define VM_CALL_TAILCALL (0x01 << 5) /* located at tail position */
833
+ #define VM_CALL_SUPER (0x01 << 6) /* super */
834
+ #define VM_CALL_OPT_SEND (0x01 << 7) /* internal flag */
835
+ #define VM_CALL_ARGS_SIMPLE (0x01 << 8) /* (ci->flag & (SPLAT|BLOCKARG)) && ci->blockiseq == NULL && ci->kw_arg == NULL */
836
+
837
+ enum vm_special_object_type {
838
+ VM_SPECIAL_OBJECT_VMCORE = 1,
839
+ VM_SPECIAL_OBJECT_CBASE,
840
+ VM_SPECIAL_OBJECT_CONST_BASE
841
+ };
842
+
843
+ #define VM_FRAME_MAGIC_METHOD 0x11
844
+ #define VM_FRAME_MAGIC_BLOCK 0x21
845
+ #define VM_FRAME_MAGIC_CLASS 0x31
846
+ #define VM_FRAME_MAGIC_TOP 0x41
847
+ #define VM_FRAME_MAGIC_CFUNC 0x61
848
+ #define VM_FRAME_MAGIC_PROC 0x71
849
+ #define VM_FRAME_MAGIC_IFUNC 0x81
850
+ #define VM_FRAME_MAGIC_EVAL 0x91
851
+ #define VM_FRAME_MAGIC_LAMBDA 0xa1
852
+ #define VM_FRAME_MAGIC_RESCUE 0xb1
853
+ #define VM_FRAME_MAGIC_MASK_BITS 8
854
+ #define VM_FRAME_MAGIC_MASK (~(~(VALUE)0<<VM_FRAME_MAGIC_MASK_BITS))
855
+
856
+ #define VM_FRAME_TYPE(cfp) ((cfp)->flag & VM_FRAME_MAGIC_MASK)
857
+
858
+ /* other frame flag */
859
+ #define VM_FRAME_FLAG_PASSED 0x0100
860
+ #define VM_FRAME_FLAG_FINISH 0x0200
861
+ #define VM_FRAME_FLAG_BMETHOD 0x0400
862
+ #define VM_FRAME_TYPE_FINISH_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_FINISH) != 0)
863
+ #define VM_FRAME_TYPE_BMETHOD_P(cfp) (((cfp)->flag & VM_FRAME_FLAG_BMETHOD) != 0)
864
+
865
+ #define RUBYVM_CFUNC_FRAME_P(cfp) \
866
+ (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC)
867
+
868
+ /* inline cache */
869
+ typedef struct iseq_inline_cache_entry *IC;
870
+ typedef rb_call_info_t *CALL_INFO;
871
+
872
+ void rb_vm_change_state(void);
873
+
874
+ typedef VALUE CDHASH;
875
+
876
+ #ifndef FUNC_FASTCALL
877
+ #define FUNC_FASTCALL(x) x
878
+ #endif
879
+
880
+ typedef rb_control_frame_t *
881
+ (FUNC_FASTCALL(*rb_insn_func_t))(rb_thread_t *, rb_control_frame_t *);
882
+
883
+ #define GC_GUARDED_PTR(p) ((VALUE)((VALUE)(p) | 0x01))
884
+ #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03))
885
+ #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01)
886
+
887
+ /*
888
+ * block frame:
889
+ * ep[ 0]: prev frame
890
+ * ep[-1]: CREF (for *_eval)
891
+ *
892
+ * method frame:
893
+ * ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG)
894
+ */
895
+
896
+ #define VM_ENVVAL_BLOCK_PTR_FLAG 0x02
897
+ #define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG)
898
+ #define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG)
899
+ #define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v))
900
+ #define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v)))
901
+
902
+ #define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0]))
903
+ #define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0]))
904
+ #define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0])
905
+
906
+ VALUE *rb_vm_ep_local_ep(VALUE *ep);
907
+ rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp);
908
+
909
+ #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1)
910
+ #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1)
911
+ #define RUBY_VM_END_CONTROL_FRAME(th) \
912
+ ((rb_control_frame_t *)((th)->stack + (th)->stack_size))
913
+ #define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp) \
914
+ ((void *)(ecfp) > (void *)(cfp))
915
+ #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
916
+ (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
917
+
918
+ #define RUBY_VM_IFUNC_P(ptr) RB_TYPE_P((VALUE)(ptr), T_NODE)
919
+ #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
920
+ ((ptr) && !RUBY_VM_IFUNC_P(ptr))
921
+
922
+ #define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp) ((rb_block_t *)(&(cfp)->self))
923
+ #define RUBY_VM_GET_CFP_FROM_BLOCK_PTR(b) \
924
+ ((rb_control_frame_t *)((VALUE *)(b) - 4))
925
+ /* magic number `4' is depend on rb_control_frame_t layout. */
926
+
927
+ /* VM related object allocate functions */
928
+ VALUE rb_thread_alloc(VALUE klass);
929
+ VALUE rb_proc_wrap(VALUE klass, rb_proc_t *); /* may use with rb_proc_alloc */
930
+ VALUE rb_binding_alloc(VALUE klass);
931
+
932
+ /* for debug */
933
+ extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *);
934
+ extern void rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *_pc);
935
+ extern void rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp);
936
+
937
+ #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp)
938
+ #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp))
939
+ void rb_vm_bugreport(const void *);
940
+ NORETURN(void rb_bug_context(const void *, const char *fmt, ...));
941
+
942
+ /* functions about thread/vm execution */
943
+ RUBY_SYMBOL_EXPORT_BEGIN
944
+ VALUE rb_iseq_eval(VALUE iseqval);
945
+ VALUE rb_iseq_eval_main(VALUE iseqval);
946
+ RUBY_SYMBOL_EXPORT_END
947
+ int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp);
948
+
949
+ VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
950
+ int argc, const VALUE *argv, const rb_block_t *blockptr);
951
+ VALUE rb_vm_make_proc_lambda(rb_thread_t *th, const rb_block_t *block, VALUE klass, int8_t is_lambda);
952
+ VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass);
953
+ VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp);
954
+ VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp);
955
+ VALUE rb_vm_env_local_variables(VALUE envval);
956
+ VALUE *rb_binding_add_dynavars(rb_binding_t *bind, int dyncount, const ID *dynvars);
957
+ void rb_vm_inc_const_missing_count(void);
958
+ void rb_vm_gvl_destroy(rb_vm_t *vm);
959
+ VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc,
960
+ const VALUE *argv, const rb_method_entry_t *me,
961
+ VALUE defined_class);
962
+ void rb_unlink_method_entry(rb_method_entry_t *me);
963
+ void rb_gc_mark_unlinked_live_method_entries(void *pvm);
964
+
965
+ void rb_thread_start_timer_thread(void);
966
+ void rb_thread_stop_timer_thread(int);
967
+ void rb_thread_reset_timer_thread(void);
968
+ void rb_thread_wakeup_timer_thread(void);
969
+
970
+ static inline void
971
+ rb_vm_living_threads_init(rb_vm_t *vm)
972
+ {
973
+ list_head_init(&vm->living_threads);
974
+ vm->living_thread_num = 0;
975
+ }
976
+
977
+ static inline void
978
+ rb_vm_living_threads_insert(rb_vm_t *vm, rb_thread_t *th)
979
+ {
980
+ list_add_tail(&vm->living_threads, &th->vmlt_node);
981
+ vm->living_thread_num++;
982
+ }
983
+
984
+ static inline void
985
+ rb_vm_living_threads_remove(rb_vm_t *vm, rb_thread_t *th)
986
+ {
987
+ list_del(&th->vmlt_node);
988
+ vm->living_thread_num--;
989
+ }
990
+
991
+ int ruby_thread_has_gvl_p(void);
992
+ typedef int rb_backtrace_iter_func(void *, VALUE, int, VALUE);
993
+ rb_control_frame_t *rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
994
+ rb_control_frame_t *rb_vm_get_binding_creatable_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp);
995
+ int rb_vm_get_sourceline(const rb_control_frame_t *);
996
+ VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method);
997
+ void rb_vm_stack_to_heap(rb_thread_t *th);
998
+ void ruby_thread_init_stack(rb_thread_t *th);
999
+ int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp);
1000
+ void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
1001
+
1002
+ void rb_vm_register_special_exception(enum ruby_special_exceptions sp, VALUE exception_class, const char *mesg);
1003
+
1004
+ void rb_gc_mark_machine_stack(rb_thread_t *th);
1005
+
1006
+ int rb_autoloading_value(VALUE mod, ID id, VALUE* value);
1007
+
1008
+ void rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr);
1009
+
1010
+ #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack]
1011
+
1012
+ #define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */
1013
+ #define VM_STACK_OVERFLOWED_P(cfp, sp, margin) \
1014
+ (!RUBY_CONST_ASSERT(sizeof(*(sp)) == sizeof(VALUE)) || \
1015
+ !RUBY_CONST_ASSERT(sizeof(*(cfp)) == sizeof(rb_control_frame_t)) || \
1016
+ ((rb_control_frame_t *)((sp) + (margin)) + 1) >= (cfp))
1017
+ #define WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) \
1018
+ if (LIKELY(!VM_STACK_OVERFLOWED_P(cfp, sp, margin))) {(void)0;} else /* overflowed */
1019
+ #define CHECK_VM_STACK_OVERFLOW0(cfp, sp, margin) \
1020
+ WHEN_VM_STACK_OVERFLOWED(cfp, sp, margin) vm_stackoverflow()
1021
+ #define CHECK_VM_STACK_OVERFLOW(cfp, margin) \
1022
+ WHEN_VM_STACK_OVERFLOWED(cfp, (cfp)->sp, margin) vm_stackoverflow()
1023
+
1024
+ /* for thread */
1025
+
1026
+ #if RUBY_VM_THREAD_MODEL == 2
1027
+ extern rb_thread_t *ruby_current_thread;
1028
+ extern rb_vm_t *ruby_current_vm;
1029
+ extern rb_event_flag_t ruby_vm_event_flags;
1030
+
1031
+ #define GET_VM() ruby_current_vm
1032
+
1033
+ #ifndef OPT_CALL_CFUNC_WITHOUT_FRAME
1034
+ #define OPT_CALL_CFUNC_WITHOUT_FRAME 0
1035
+ #endif
1036
+
1037
+ static inline rb_thread_t *
1038
+ GET_THREAD(void)
1039
+ {
1040
+ rb_thread_t *th = ruby_current_thread;
1041
+ #if OPT_CALL_CFUNC_WITHOUT_FRAME
1042
+ if (UNLIKELY(th->passed_ci != 0)) {
1043
+ void vm_call_cfunc_push_frame(rb_thread_t *th);
1044
+ vm_call_cfunc_push_frame(th);
1045
+ }
1046
+ #endif
1047
+ return th;
1048
+ }
1049
+
1050
+ #define rb_thread_set_current_raw(th) (void)(ruby_current_thread = (th))
1051
+ #define rb_thread_set_current(th) do { \
1052
+ if ((th)->vm->running_thread != (th)) { \
1053
+ (th)->running_time_us = 0; \
1054
+ } \
1055
+ rb_thread_set_current_raw(th); \
1056
+ (th)->vm->running_thread = (th); \
1057
+ } while (0)
1058
+
1059
+ #else
1060
+ #error "unsupported thread model"
1061
+ #endif
1062
+
1063
+ enum {
1064
+ TIMER_INTERRUPT_MASK = 0x01,
1065
+ PENDING_INTERRUPT_MASK = 0x02,
1066
+ POSTPONED_JOB_INTERRUPT_MASK = 0x04,
1067
+ TRAP_INTERRUPT_MASK = 0x08
1068
+ };
1069
+
1070
+ #define RUBY_VM_SET_TIMER_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TIMER_INTERRUPT_MASK)
1071
+ #define RUBY_VM_SET_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, PENDING_INTERRUPT_MASK)
1072
+ #define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, POSTPONED_JOB_INTERRUPT_MASK)
1073
+ #define RUBY_VM_SET_TRAP_INTERRUPT(th) ATOMIC_OR((th)->interrupt_flag, TRAP_INTERRUPT_MASK)
1074
+ #define RUBY_VM_INTERRUPTED(th) ((th)->interrupt_flag & ~(th)->interrupt_mask & (PENDING_INTERRUPT_MASK|TRAP_INTERRUPT_MASK))
1075
+ #define RUBY_VM_INTERRUPTED_ANY(th) ((th)->interrupt_flag & ~(th)->interrupt_mask)
1076
+
1077
+ int rb_signal_buff_size(void);
1078
+ void rb_signal_exec(rb_thread_t *th, int sig);
1079
+ void rb_threadptr_check_signal(rb_thread_t *mth);
1080
+ void rb_threadptr_signal_raise(rb_thread_t *th, int sig);
1081
+ void rb_threadptr_signal_exit(rb_thread_t *th);
1082
+ void rb_threadptr_execute_interrupts(rb_thread_t *, int);
1083
+ void rb_threadptr_interrupt(rb_thread_t *th);
1084
+ void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th);
1085
+ void rb_threadptr_pending_interrupt_clear(rb_thread_t *th);
1086
+ void rb_threadptr_pending_interrupt_enque(rb_thread_t *th, VALUE v);
1087
+ int rb_threadptr_pending_interrupt_active_p(rb_thread_t *th);
1088
+
1089
+ #define RUBY_VM_CHECK_INTS_BLOCKING(th) do { \
1090
+ if (UNLIKELY(!rb_threadptr_pending_interrupt_empty_p(th))) { \
1091
+ th->pending_interrupt_queue_checked = 0; \
1092
+ RUBY_VM_SET_INTERRUPT(th); \
1093
+ rb_threadptr_execute_interrupts(th, 1); \
1094
+ } \
1095
+ else if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
1096
+ rb_threadptr_execute_interrupts(th, 1); \
1097
+ } \
1098
+ } while (0)
1099
+
1100
+ #define RUBY_VM_CHECK_INTS(th) do { \
1101
+ if (UNLIKELY(RUBY_VM_INTERRUPTED_ANY(th))) { \
1102
+ rb_threadptr_execute_interrupts(th, 0); \
1103
+ } \
1104
+ } while (0)
1105
+
1106
+ /* tracer */
1107
+ struct rb_trace_arg_struct {
1108
+ rb_event_flag_t event;
1109
+ rb_thread_t *th;
1110
+ rb_control_frame_t *cfp;
1111
+ VALUE self;
1112
+ ID id;
1113
+ VALUE klass;
1114
+ VALUE data;
1115
+
1116
+ int klass_solved;
1117
+
1118
+ /* calc from cfp */
1119
+ int lineno;
1120
+ VALUE path;
1121
+ };
1122
+
1123
+ void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
1124
+ void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg);
1125
+
1126
+ #define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
1127
+ if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
1128
+ if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
1129
+ struct rb_trace_arg_struct trace_arg; \
1130
+ trace_arg.event = (flag_); \
1131
+ trace_arg.th = (th_); \
1132
+ trace_arg.cfp = (trace_arg.th)->cfp; \
1133
+ trace_arg.self = (self_); \
1134
+ trace_arg.id = (id_); \
1135
+ trace_arg.klass = (klass_); \
1136
+ trace_arg.data = (data_); \
1137
+ trace_arg.path = Qundef; \
1138
+ trace_arg.klass_solved = 0; \
1139
+ if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
1140
+ else rb_threadptr_exec_event_hooks(&trace_arg); \
1141
+ } \
1142
+ } \
1143
+ } while (0)
1144
+
1145
+ #define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
1146
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
1147
+
1148
+ #define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
1149
+ EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
1150
+
1151
+ RUBY_SYMBOL_EXPORT_BEGIN
1152
+
1153
+ int rb_thread_check_trap_pending(void);
1154
+
1155
+ extern VALUE rb_get_coverages(void);
1156
+ extern void rb_set_coverages(VALUE);
1157
+ extern void rb_reset_coverages(void);
1158
+
1159
+ void rb_postponed_job_flush(rb_vm_t *vm);
1160
+
1161
+ RUBY_SYMBOL_EXPORT_END
1162
+
1163
+ #endif /* RUBY_VM_CORE_H */