424 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5 803c68f0da Use rb_len_t for lengths in process.c and signal.c
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
Przemysław Buczkowski 548b5abc1e Haiku: use ucontext.h only on x86/x86-64
This follows the other operating systems. Without it, it won't build on arm64 and riscv64 ports.
2026-09-17 09:51:00 +09:00
Luke Gruber c4e06b4e30 Differentiate crash from other process sending signal
Recently we were debugging a Ruby crash by looking at a core dump and
realized that there was no crash, it was another process sending a
SIGABRT signal to the process. There was no differentiation in the crash
report for this case. Now, when another process sends a SIGABRT, SIGSEGV,
etc to a process it shows the PID of the sender. This way we can know right
away that it was not a real crash.

The crash message now looks like this:

```
[BUG] Aborted at 0x00000001831c150c (sent by pid 53859)
```

If "(sent by pid XXX)" or "(sent by another process)" is included in the crash
message, the signal was sent by another process.
2026-09-14 10:12:22 -04:00
Koichi SasadaandClaude 65424e1791 GC: per-Ractor local GC — VM (lock / roots / write barrier)
Make the VM-global GC roots per-Ractor so the main Ractor's ordinary
local GC runs lock-free.  Add the shareability and objspace-locality
checks to the write barrier, and split the VM-wide tables behind
finer-grained locks.

Co-authored-by: Claude <noreply@anthropic.com>
2026-08-07 16:27:53 +09:00
Samuel Williams ef67c37750 Respect handle_interrupt for default SIGINT. (#17533)
[[Bug #22133]]
2026-07-10 18:08:46 +12:00
Alan Wu 3a5a46f8ad Avoid infinite recursion when raising SIGABRT in SIGABRT handler
When VM state is corrupted enough, we can call abort() from the SIGABRT
handler. Previously, we would spam until the stack is full:

    ABRT received in SEGV handler
    SEGV received in ABRT handler
    ABRT received in SEGV handler
    ABRT received in ABRT handler
    ABRT received in ABRT handler
    ABRT received in ABRT handler
    [...]

We've seen this on CI:
https://github.com/ruby/ruby/actions/runs/26591192708/job/78350130653

To test this situation locally, temporarily patch in a call to abort()
in rb_bug_for_fatal_signal() then use `Process.kill(:ABRT, Process.pid)`.

Fix by restoring the default signal handler before aborting.
2026-06-01 16:25:09 -04:00
Peter Zhu df68535055 [DOC] Improve docs for Signal.trap 2025-12-19 21:38:12 -05:00
Nobuyoshi Nakada 7f41c3e7b1 Add rb_eval_cmd_call_kw to shortcut 2025-12-04 18:07:49 +09:00
Nobuyoshi Nakada a0cd81e005 Remove stale check
Any objects with `call` method can be accepted as trap handlers, and
the check for `Proc` type is useless since ruby/ruby@29f5911cf5.
2025-11-30 21:39:26 +09:00
Peter Zhu 2315349b8a Handle SIGABRT and output bug report
SIGABRT is for abnormal termination so we should handle it to output a bug
report. Specifically, glibc malloc uses it to exit when there is corruption.
For example, the following script produces a double free:

    mem = Fiddle.malloc(10)
    Fiddle.free(mem)
    Fiddle.free(mem)

Before this patch, it just outputs the following and exits:

    free(): double free detected in tcache 2

After this patch, it also outputs a bug report:

    free(): double free detected in tcache 2
    test.rb:11: [BUG] Aborted at 0x000003e8000ab65c
2025-11-24 14:32:53 -08:00
John HawthornandNobuyoshi Nakada 0d0c051b19 Don't check for stack overflow when ec is NULL (#14236)
Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
2025-08-15 10:41:39 -07:00
Erik Berlin eab4a0bc8d Fix race condition in signal handler query (#13712)
* Fix race condition in signal handler query

* Initialize signal lock dynamically and reset after fork

* Fix signal handler mutex initialization conditions
2025-06-28 13:55:59 +09:00
Nobuyoshi Nakada b1c09faf67 Win32: Use SIG_GET to get the current value of the signal 2025-06-26 17:38:36 +09:00
Nobuyoshi Nakada af6b98f7a2 Make the critical level an enum 2025-06-23 20:03:48 +09:00
Peter Zhu 99cc100cdf Remove dead rb_malloc_info_show_results 2025-06-04 14:07:19 -04:00
John Hawthorn e7f97eb2f3 Use atomic load for signal buff size 2025-05-20 09:56:31 -07:00
Luke Gruber 1d4822a175 Get ractor message passing working with > 1 thread sending/receiving values in same ractor
Rework ractors so that any ractor action (Ractor.receive, Ractor#send, Ractor.yield, Ractor#take,
Ractor.select) will operate on the thread that called the action. It will put that thread to sleep if
it's a blocking function and it needs to put it to sleep, and the awakening action (Ractor.yield,
Ractor#send) will wake up the blocked thread.

Before this change every blocking ractor action was associated with the ractor struct and its fields.
If a ractor called Ractor.receive, its wait status was wait_receiving, and when another ractor calls
r.send on it, it will look for that status in the ractor struct fields and wake it up. The problem was that
what if 2 threads call blocking ractor actions in the same ractor. Imagine if 1 thread has called Ractor.receive
and another r.take. Then, when a different ractor calls r.send on it, it doesn't know which ruby thread is associated
to which ractor action, so what ruby thread should it schedule? This change moves some fields onto the ruby thread
itself so that ruby threads are the ones that have ractor blocking statuses, and threads are then specifically scheduled
when unblocked.

Fixes [#17624]
Fixes [#21037]
2025-05-13 13:23:57 -07:00
Nobuyoshi Nakada b42afa1dbc Suppress gcc 15 unterminated-string-initialization warnings 2025-04-30 20:04:10 +09:00
刘皓 45e814d116 Fix jump buffer leak in WASI builds 2025-04-27 15:47:30 +09:00
Nobuyoshi Nakada 5dc155351a Do not allocate new objects at machine stack overflow 2025-04-24 17:28:18 +09:00
Peter Zhu eedb30d385 Use rb_gc_enable/rb_gc_disable_no_rest instead of ruby_disable_gc
We should use the rb_gc_enable/rb_gc_disable_no_rest APIs instead of
directly setting the ruby_disable_gc variable.
2024-12-05 16:21:37 -05:00
Nobuyoshi Nakada 8350b48cfa Import patches for old macOS from MacPorts 2024-09-26 10:32:30 +09:00
Nobuyoshi Nakada 3ac6a03b2e Revert "hijack SIGCHLD handler for internal use"
This reverts commit 054a412d54.
SIGCHLD `waidpid`, `waitpid_lock` and related code, have been removed
at ruby/ruby#7527.
2024-04-04 21:48:14 +09:00
Nobuyoshi Nakada f928e60d41 Check if a fatal signal is from kernel
On Linux, `siginfo_t` uses a union for each `si_code`, and the field
corresponding to `si_pid` does not belong to the `_sigfault` field for
SIGSEGV.  It actually overlaps the `si_addr` field, which is usually
non-zero on stack overflow.

https://github.com/ruby/ruby/pull/10201#issuecomment-2034723244
2024-04-03 23:14:52 +09:00
Peter ZhuandAlan Wu 1e7ee871cb Disregard si_addr for fatal signals sent from other processes
Previously, when another process sends a fatal signals such as SIGBUS
to Ruby, we could mis-interpret it as a stack overflow Ruby itself
generated. When the si_pid field is set on the signal, we shouldn't
check the si_addr field to check for stack overflow.

> Signals sent with kill(2) and sigqueue(3) fill in si_pid and si_uid.

Co-authored-by: Alan Wu <alanwu@ruby-lang.org>
2024-03-12 09:43:49 -04:00
Yusuke Endoh 25d74b9527 Do not include a backtick in error messages and backtraces
[Feature #16495]
2024-02-15 18:42:31 +09:00
Yusuke Endoh f73ae05819 Prefer sa_handler to sa_sigaction in Wasm
Previously the code assigns `handler` function pointer, which accepts
one argument, to `sigact.sa_sigaction`, which accepts three argument.
This mismatch is not allowed in Wasm.

I don't see the reason to use `sa_sigaction` here, so this change
assigns to `sa_handler`, which accepts one argument, in Wasm.
2024-01-30 21:18:48 +09:00
Yuta Saito b5f33ba76f signal.c: Fix undefined reset_sigmask use on Emscripten
3c47114991 added a call to `reset_sigmask`
but the guard condition didn't match with the condition used to define
`reset_sigmask`.
2023-12-19 12:40:43 +09:00
Alan Wu 3c47114991 Unmask signal before re-raising fatal signal
On Linux, while the signal handler runs, that signal is masked, so in
the rb_bug_for_fatal_signal() code path we didn't get the default signal
action as intended. See signal(7). It worked fine on macOS, though.

Before:

    $ ./miniruby -e 'Process.kill :SIGSEGV, Process.pid'
    <snip>
    Aborted (core dumped)

After:

    $ ./miniruby -e 'Process.kill :SIGSEGV, Process.pid'
    <snip>
    Segmentation fault (core dumped)

Follow-up for 1ac0afab4d "rb_bug_for_fatal_signal: exit with the right
signal".
2023-12-18 18:19:53 -05:00
Takashi Kokubun 9f0065a077 Initialize interrupt queue before signal handlers (#9196) 2023-12-11 21:12:08 -08:00
Nobuyoshi Nakada d1992d6df2 Reset signal handler before aborting due to sanitizer
When aborting by a sanitizer, `SIGILL` or something is raised and
often results in raising the same signal infinitely.
2023-07-19 00:06:53 +09:00
Nobuyoshi Nakada ebeecbd575 Unify writev and write operations in check_reserved_signal_ 2023-07-19 00:06:53 +09:00
Nobuyoshi Nakada 1c4a523006 Move posix_signal declaration internal with prefix ruby_ 2023-07-17 21:31:59 +09:00
Samuel Williams 4d1ca2e1f9 Ensure SIGCHLD always uses a signal handler. (#7819) 2023-05-16 12:49:06 +09:00
Samuel Williams ab7bb38aca Remove explicit SIGCHLD handling. (#7816)
* Remove unused SIGCHLD handling.

* Remove unused `init_sigchld`.

* Remove unnecessary `#define RUBY_SIGCHLD (0)`.

* Remove unused `SIGCHLD_LOSSY`.
2023-05-15 23:14:51 +09:00
Kunshan Wang c7067ed13d Use the rb_sys_fail_str macro in signal.c
Let signal.c include "internal/error.h" explicitly to ensure that the
identifier rb_sys_fail_str in signal.c refers to the macro defined in
"internal/error.h" instead of the actual function.

That macro reads errno before evaluating its argument.  Without this
change, the rb_signo2signm(sig) expression in the "trap" function in
signal.c will overwrite the errno before the actual rb_sys_fail_str
function reads the errno.
2023-05-15 15:12:30 +09:00
Samuel Williams 7fd53eeb46 Remove SIGCHLD waidpid. (#7527)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-15 19:48:27 +13:00
Samuel Williams ac65ce16e9 Revert SIGCHLD changes to diagnose CI failures. (#7517)
* Revert "Remove special handling of `SIGCHLD`. (#7482)"

This reverts commit 44a0711eab.

* Revert "Remove prototypes for functions that are no longer used. (#7497)"

This reverts commit 4dce12bead.

* Revert "Remove SIGCHLD `waidpid`. (#7476)"

This reverts commit 1658e7d966.

* Fix change to rjit variable name.
2023-03-14 20:07:59 +13:00
Samuel Williams 44a0711eab Remove special handling of SIGCHLD. (#7482) 2023-03-09 21:48:50 +13:00
Samuel Williams 1658e7d966 Remove SIGCHLD waidpid. (#7476)
* Remove `waitpid_lock` and related code.

* Remove un-necessary test.

* Remove `rb_thread_sleep_interruptible` dead code.
2023-03-09 16:05:47 +13:00
Nobuyoshi Nakada f527a0911d [DOC] [Bug #19290] fix formatting 2023-01-01 14:50:39 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Takashi Kokubun 5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Yusuke Endoh f336a3eb6c Use free instead of xfree to free altstack
The altstack memory of a thread may be free'ed even after the VM is
destructed. After that, GC is no longer available, so calling xfree
may lead to a segfault.

This changeset uses the bare free function to free the altstack memory
instead of xfree. [Bug #18126]
2021-09-06 14:22:24 +09:00
Nobuyoshi Nakada 95e7aed82b SIGILL can raise at stack overflow on Linux too [Bug #18084] 2021-08-18 17:23:27 +09:00
Nobuyoshi Nakada 574f3af36e Rewind execution tags more at stack overflow [Bug #18084] 2021-08-18 17:23:19 +09:00
Benoit Daloze 0764d323d8 Fix -Wundef warnings for patterns #if HAVE
* See [Feature #17752]
* Using this to detect them:
  git grep -P 'if\s+HAVE' | grep -Pv 'HAVE_LONG_LONG|/ChangeLog|HAVE_TYPEOF'
2021-05-04 14:56:55 +02:00
Gannon McGibbon 9e0075a3d9 Replace "iff" with "if and only if"
iff means if and only if, but readers without that knowledge might
assume this to be a spelling mistake. To me, this seems like
exclusionary language that is unnecessary. Simply using "if and only if"
instead should suffice.
2021-01-19 12:06:45 -08:00
Nobuyoshi Nakada 0df67a4695 Signal handler type should be void 2020-12-12 17:02:42 +09:00