283 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5 975c2a45f1 Use rb_len_t for Array and String lengths in the VM
Argument counts stay `int` or `long`. The int range checks in proc.c and compile.c now depend on SIZEOF_VALUE so that they are kept once rb_len_t widens.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-09 14:00:15 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 3e96f16643 Require Mac OS X 10.6 or later
Mac OS X 10.6 came out in 2009, and the code removed here exists only for 10.5 and earlier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 07:04:09 +09:00
Hiroshi SHIBATAandClaude Opus 5.5 957caeef23 Drop support for Darwin on PowerPC
The last Mac OS X release for PowerPC Macs is 10.5, and nothing else runs this code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 07:04:09 +09:00
Nobuyoshi Nakada 050e89ae03 Honor the buffer size in Darwin backtrace
Deep native stacks can overrun the caller's buffer while reporting
a crash because the Darwin implementation ignores `size`.
2026-09-25 19:40:17 +09:00
Luke Gruber 47c424b767 Crash handler assumes box is present
rb_current_box_in_crash_report() calls GET_EC(), which assumes ec is
present. The crash handler should work when called from non-Ruby
threads (no ec).
2026-07-22 14:29:08 -04:00
Nobuyoshi Nakada ec002ff361 Bound VM dump strings 2026-07-15 13:28:39 +09:00
Koichi SasadaandClaude Fable 5 5e700b36c2 vm_dump.c: note when there is no Ruby execution context
rb_vm_bugreport() silently skipped the control frame information, Ruby
level backtrace, and threading sections when vm or ec was NULL, so the
report jumped straight to the machine register context with no explanation
of why no Ruby level information was shown. ec can be NULL for various
reasons (e.g. a process-directed signal delivered to a non-Ruby thread, or
simply a window where the current thread has no execution context yet).

Emit an explicit note under the "Control frame information" header in that
case, without speculating about the cause. This makes the report
self-explanatory and keeps the section present, so test_crash_report no
longer fails intermittently when ec happens to be NULL.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-14 20:59:17 +09:00
Peter Zhu a0ceb1fed4 Don't dump memory map in crash report when modular GC enabled
MMTk reserves a large amount of memory, which can cause the memory maps
to take a long time to generate and thus cause test timeouts.
2026-06-09 15:24:37 +09:00
Satoshi Tagomori 012b72fdd6 [Box] dump the effective box on the control frame info 2026-05-27 02:27:12 +09:00
Takashi Kokubun ee60b99b2f Rename rb_cfp_iseq to CFP_ISEQ and rb_cfp_pc to CFP_PC
Rename for consistency with ISEQ_BODY naming convention. Remove the
separate rb_cfp_has_iseq/rb_cfp_has_pc wrappers — CFP_ISEQ and CFP_PC
return NULL for missing values, which works directly in if conditions.
2026-03-27 16:26:12 -07:00
Takashi Kokubun 226f37059e Rename cfp->iseq to cfp->_iseq and rb_zjit_cfp_iseq to rb_cfp_iseq
Per tenderlove's review, every cfp->iseq read should go through an
accessor that accounts for JITFrame. Rename the field to _iseq so
direct access causes a compile error, and rename the accessors to
drop the zjit prefix (rb_cfp_iseq, rb_cfp_has_iseq, rb_cfp_pc,
rb_cfp_has_pc).
2026-03-27 16:26:12 -07:00
Takashi KokubunandAlan Wu c8f97943ef ZJIT: Lightweight Frames
Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2026-03-27 16:26:12 -07:00
Takashi Kokubun 4a08bb7e24 Fix crash reporter NULL dereference with ractors (#16561)
rb_ec_ractor_ptr(ec) can return NULL when ec->thread_ptr is NULL
(e.g. when crashing from a GC free function). Dereferencing the
NULL return value crashes the bug reporter itself, causing "Crashed
while printing bug report" and losing all diagnostic information.

Similarly, ec->thread_ptr can be NULL, so guard the scheduler check.
2026-03-26 07:34:07 -07:00
Samuel Williams 180020e1e5 Fix io_pwrite fiber scheduler hook. (#15428)
Fix io_pwrite fiber scheduler hook.
2025-12-06 20:35:08 +13:00
Sergey Fedorov 4870fbd04a vm_dump.c: unbreak unwind on powerpc (#14650) 2025-11-17 12:49:56 +13:00
Nobuyoshi Nakada 201ed7541b Suppress sign-compare warnings 2025-11-07 23:46:00 +09:00
Satoshi Tagomori 19d4663d2f Use RUBY_BOX environment variable instead of RUBY_NAMESPACE 2025-11-07 13:14:54 +09:00
Satoshi Tagomori d2a587c791 renaming internal data structures and functions from namespace to box 2025-11-07 13:14:54 +09:00
Satoshi Tagomori fa4c04a7f7 Use CFUNC namespace only for IFUNC frames, its behavior should be unchanged 2025-11-03 02:06:11 +09:00
Satoshi Tagomori c78895b1d6 Add "Namespace detection information" section in bug reports
* To show environments stack when the current namespace is unexpected or
  namespace detection is broken
* It is displayed only when RUBY_BUGREPORT_NAMESPACE_ENV=1 is specified
2025-10-13 17:41:36 +09:00
Satoshi Tagomori 25c893af6d Add a control frame column "n:xxxx" as namespace id in crash reports 2025-10-07 22:18:29 +09:00
Satoshi Tagomori 9a0e857c35 Stop displaying current namespace when it crashed
To avoid crashes during displaying crash reports.
2025-10-07 22:18:29 +09:00
Satoshi Tagomori 4f47327287 Update current namespace management by using control frames and lexical contexts
to fix inconsistent and wrong current namespace detections.

This includes:
* Moving load_path and related things from rb_vm_t to rb_namespace_t to simplify
  accessing those values via namespace (instead of accessing either vm or ns)
* Initializing root_namespace earlier and consolidate builtin_namespace into root_namespace
* Adding VM_FRAME_FLAG_NS_REQUIRE for checkpoints to detect a namespace to load/require files
* Removing implicit refinements in the root namespace which was used to determine
  the namespace to be loaded (replaced by VM_FRAME_FLAG_NS_REQUIRE)
* Removing namespaces from rb_proc_t because its namespace can be identified by lexical context
* Starting to use ep[VM_ENV_DATA_INDEX_SPECVAL] to store the current namespace when
  the frame type is MAGIC_TOP or MAGIC_CLASS (block handlers don't exist in this case)
2025-09-29 01:15:38 +09:00
Alan Wu 1a52c42e61 Always use assert-free APIs when profiling and crashing
rb_profile_frames() is used by profilers in a way such that it can run
on any instruction in the binary, and it crashed previously in the
following situation in `RUBY_DEBUG` builds:

```
* thread #1, queue = 'com.apple.main-thread', stop reason = step over
    frame #0: 0x00000001002827f0 miniruby`vm_make_env_each(ec=0x0000000101866b00, cfp=0x000000080c91bee8) at vm.c:992:74
   989              }
   990
   991              vm_make_env_each(ec, prev_cfp);
-> 992              VM_FORCE_WRITE_SPECIAL_CONST(&ep[VM_ENV_DATA_INDEX_SPECVAL], VM_GUARDED_PREV_EP(prev_cfp->ep));
   993          }
   994      }
   995      else {
(lldb) call rb_profile_frames(0, 100, $2, $3)
/Users/alan/ruby/vm_core.h:1448: Assertion Failed: VM_ENV_FLAGS:FIXNUM_P(flags)
ruby 3.5.0dev (2025-09-23T20:20:04Z master 06b7a70837) +PRISM [arm64-darwin25]

-- Crash Report log information --------------------------------------------
   See Crash Report log file in one of the following locations:
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.
Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0008 p:---- s:0029 e:000028 CFUNC  :lambda
/Users/alan/ruby/vm_core.h:1448: Assertion Failed: VM_ENV_FLAGS:FIXNUM_P(flags)
ruby 3.5.0dev (2025-09-23T20:20:04Z master 06b7a70837) +PRISM [arm64-darwin25]

-- Crash Report log information --------------------------------------------
<snip>
```

There is a small window where the control frame is invalid and fails the
assert.

The double crash also shows that in `RUBY_DEBUG` builds, the crash reporter was
previously not resilient to corrupt frame state. In release builds, it
prints more info.

Add unchecked APIs for the crash reporter and profilers so they work
as well in `RUBY_DEBUG` builds as non-debug builds.
2025-09-25 18:30:12 -04:00
Jean Boussier e042e10644 vm_dump.c: avoid USE_MN_THREADS is not defined warning 2025-05-05 15:55:42 +02:00
Jean Boussier 3a2e56e685 Fix USE_MN_THREADS=0 builds on macOS
This was recently broken.
2025-05-05 15:34:32 +02:00
Nobuyoshi Nakada 229784d160 [Bug #21150] macOS: unwinding coroutine workaround is only for arm64 2025-04-05 10:31:20 +09:00
Nobuyoshi Nakada 1bc57b5e0e [Bug #21150] macOS: Temporary workaround at unwinding coroutine
On arm64 macOS, libunwind (both of system library and homebrew
llvm-18) seems not to handle our coroutine switching code.
2025-02-21 17:53:16 +09:00
Hiroshi SHIBATA 9bbcbc3f36 glibc and musl didn't provide A1-A7, FP and S3-S8 constants.
* https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/loongarch/sys/ucontext.h
* https://git.musl-libc.org/cgit/musl/tree/arch/loongarch64/bits/signal.h
2025-01-07 08:00:22 +09:00
Nobuyoshi Nakada e4a4dea2c0 Win32: Fix the macro for arm64 on mswin
Visual C defines `_M_`-prefixed macros for the target architectures.
2024-12-17 20:25:06 +09:00
Peter Zhu 2da70aac25 Don't output memory map in crash report for ASAN
ASAN maps a large amount of memory, which makes the memory map section
massive.
2024-12-12 14:07:56 -05:00
Yusuke EndohandSamuel Williams 6c5a808b86 Use rb_fiber_scheduler_get() instead of rb_fiber_scheduler_current()
rb_fiber_scheduler_current() may return nil depending on whether the
scheduler is being prevented for some reason, e.g., Fiber.blocking{}.

Co-Authored-By: Samuel Williams <samuel.williams@oriontransfer.co.nz>
2024-11-05 19:48:00 +09:00
Yusuke Endoh 2d2d363012 Let vm_dump show whether the fiber scheduler is enabled or not
... just for the case.
2024-11-05 17:48:01 +09:00
Hiroshi SHIBATA 71b253cdf3 Added LARCH_REG_FP to dump results 2024-09-26 17:53:21 +09:00
Hiroshi SHIBATA a07bf6d5ff Use constants for register numbers 2024-09-26 17:53:21 +09:00
Hiroshi SHIBATA bdee1772b2 Removed duplicated dumps 2024-09-26 17:53:21 +09:00
Nobuyoshi Nakada 8350b48cfa Import patches for old macOS from MacPorts 2024-09-26 10:32:30 +09:00
Pierrick Bouvier 784fdecc4c windows-arm64 support (#8995)
* [win32] fix compilation for windows-arm64

Credits to MSYS2 Ruby package using this patch.

* [win32] nm use full options

Fix compilation error when using MSYS2 environment.
Credits to MSYS2 Ruby package using this patch.

* [win32] detect llvm-windres (used for windows-arm64)

When adding preprocessor option for llvm-windres (using clang as
parameter), it fails. Thus, do not add this.

It's needed to be able to compile windows-arm64 version, because MSYS2
toolchain is LLVM based (instead of GCC/binutils).

* [win32] pioinfo detection for windows-arm64

This fixes "unexpected ucrtbase.dll" for native windows-arm64 ruby
binary. It does not solve issue with x64 version emulated on this
platform.

Value of pioinfo pointer can be found in ucrtbase.dll at latest adrp/add
sequence before return of _isatty function. This works for both release
and debug ucrt.

Due to the nature of aarch64 ISA (vs x86 or x64), it's needed to
disassemble instructions to retrieve offset value, which is a bit more
complicated than matching specific string patterns.

Details about adrp/add usage can be found in this blog post:
https://devblogs.microsoft.com/oldnewthing/20220809-00/?p=106955
For instruction decoding, the Arm documentation was used as a reference.
2023-11-23 17:17:28 +09:00
Nobuyoshi Nakada 9859dbc7fd Fix leaked symbols on FreeBSD [ci skip] 2023-10-12 15:07:42 +09:00
Nobuyoshi Nakada 5eef125afe Dump backtraces to an arbitrary stream when using libprocstat 2023-09-26 09:02:37 +09:00
Nobuyoshi Nakada d2cc4437a1 Labels cannot at the end of block 2023-09-26 08:31:51 +09:00
Nobuyoshi Nakada ca2594535d Add a missing label 2023-09-26 02:15:38 +09:00
Nobuyoshi Nakada 85984a53e8 Abort dumping when output failed 2023-09-25 22:57:28 +09:00
Nobuyoshi Nakada ac244938e8 Dump backtraces to an arbitrary stream 2023-09-25 22:57:28 +09:00
Takashi Kokubun 38be9a9b72 Clean up OPT_STACK_CACHING (#8132) 2023-07-27 17:27:05 -07:00
Alan Wu f302e725e1 Remove __bp__ and speed-up bmethod calls (#8060)
Remove rb_control_frame_t::__bp__ and optimize bmethod calls

This commit removes the __bp__ field from rb_control_frame_t. It was
introduced to help MJIT, but since MJIT was replaced by RJIT, we can use
vm_base_ptr() to compute it from the SP of the previous control frame
instead. Removing the field avoids needing to set it up when pushing new
frames.

Simply removing __bp__ would cause crashes since RJIT and YJIT used a
slightly different stack layout for bmethod calls than the interpreter.
At the moment of the call, the two layouts looked as follows:

                   ┌────────────┐    ┌────────────┐
                   │ frame_base │    │ frame_base │
                   ├────────────┤    ├────────────┤
                   │    ...     │    │    ...     │
                   ├────────────┤    ├────────────┤
                   │    args    │    │    args    │
                   ├────────────┤    └────────────┘<─prev_frame_sp
                   │  receiver  │
    prev_frame_sp─>└────────────┘
                     RJIT & YJIT      interpreter

Essentially, vm_base_ptr() needs to compute the address to frame_base
given prev_frame_sp in the diagrams. The presence of the receiver
created an off-by-one situation.

Make the interpreter use the layout the JITs use for iseq-to-iseq
bmethod calls. Doing so removes unnecessary argument shifting and
vm_exec_core() re-entry from the interpreter, yielding a speed
improvement visible through `benchmark/vm_defined_method.yml`:

     patched:   7578743.1 i/s
      master:   4796596.3 i/s - 1.58x  slower

C-to-iseq bmethod calls now store one more VALUE than before, but that
should have negligible impact on overall performance.

Note that re-entering vm_exec_core() used to be necessary for firing
TracePoint events, but that's no longer the case since
9121e57a5f.

Closes ruby/ruby#6428
2023-07-17 13:57:58 -04:00
Alan Wu 2f81bb793f Add thread and ractor counts to bug reports
This is useful for crash triaging. It also helps to hint extension
developers about the misuse of `rb_thread_call_without_gvl()`.

Example:

    $ ./miniruby -e 'Ractor.new{Ractor.receive};
        Thread.new{sleep}; Process.kill:SEGV,Process.pid'
    <snip>
    -- Threading information ---------------------------------------------------
    Total ractor count: 2
    Ruby thread count for this ractor: 2
2023-03-16 10:46:30 -04:00
Nobuyoshi Nakada da0e6b99c7 Move dump_machine_register definitions 2023-02-23 11:25:56 +09:00
小MAO钓鱼andzangruochen 65ef20d2a7 Add support for LoongArch (#7343)
* vm_dump.c: Dump machine registers on loongarch64 Linux.

* coroutines: Support for native loongarch64 coroutines.

---------

Co-authored-by: zangruochen <zangruochen@loongson.cn>
2023-02-22 13:11:33 +09:00
Matt Valentine-House 72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00