1111 Commits

Author SHA1 Message Date
Shizuo Fujita
553f19d9b2
[DOC] Fix the $? description of Process::Status.wait (#18109)
The documentation says that Process::Status.wait sets the thread-local
variable $? when there are child processes, but it never does.
rb_process_status_wait does not call rb_last_status_set, and $? is left
untouched:

    $?                        # => nil
    Process.spawn('cat /nop') # => 4996
    Process::Status.wait      # => #<Process::Status: pid 4996 exit 1>
    $?                        # => nil

The existing example showed this as well: the pid displayed for $?
(1155508) did not match the pid of the returned status (1155880),
contradicting the surrounding text.

Since $? is never set, the "does not set thread-local variable $?"
note in the no-child-process case is now redundant and has been folded
into the general description.
2026-07-30 15:24:42 +09:00
Ajay Krishnan
7521a308b0
[DOC] Fix Kernel#system exception condition 2026-07-26 11:16:45 -04:00
Jean Boussier
8645a948c0 Right size temporary dump objects
The Range Marshal compat dumper would allocate
an Object with no size information, hence get a 32B slot
with enough space for 2 ivars, then insert 3 ivars causing
it to spill.

This isn't a big problem, but somewhat shows that the interface
isn't WVA aware.

By introducing `rb_class_allocate_instance_capa` we can directly
allocate an object with enough room.
2026-07-22 23:52:01 +02:00
Hiroshi SHIBATA
201dece9d7 Eager load the error decoration gems from Process.warmup
The decoration gems are loaded lazily on the first error display, which
in a pre-forking server happens after fork in each child. That loads
their code outside copy-on-write shared memory and busts method caches
at runtime when they prepend Exception#detailed_message.

Process.warmup, called before the first fork by such servers, now loads
them eagerly so the prepended decorators land in shared memory and the
cache invalidation happens during boot.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 11:49:03 +09:00
Nobuyoshi Nakada
878d20ef1b Use bounded strings in process and cwd handling
Track explicit lengths while parsing command strings and comparing the
current directory. This avoids relying on Ruby string terminators and
makes separators in the generated argument buffer explicit.
2026-07-15 13:28:39 +09:00
Hiroshi SHIBATA
4659696b19 Remove BSD/OS (BSDi) support
BSD/OS was discontinued in 2003 and the bsdi* target has been
unbuildable for decades. This also removes the BROKEN_SETREUID and
BROKEN_SETREGID fallbacks in process.c, which no other platform
ever defined.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 10:34:40 +09:00
Sharon Rosner
b072acf0c1
Add rb_process_status_for to intern/process.h. (#15213)
[Feature #21704]
2026-07-12 12:41:23 +12:00
Daisuke Fujimura (fd0)
9e195b7a51 process.c: remove unreachable CYGWIN32 code path 2026-07-11 21:39:08 +09:00
Nobuyoshi Nakada
b17078a0de
Suppress unused-function warnings 2026-07-07 18:39:52 +09:00
John Hawthorn
daffaaee73 Mark most TypedData types as THREAD_SAFE_FREE
Set RUBY_TYPED_THREAD_SAFE_FREE on TypedData types whose dfree function
is trivially safe, and only frees its own memory

Types not yet marked as THREAD_SAFE_FREE:
- id2ref_tbl_type: sets the process-global id2ref_tbl to NULL.
- mutex_data_type: unlinks itself from another thread's keeping_mutexes list.
- autoload_data_type: deletes nodes from a shared intrusive list.
- autoload_const_type: deletes itself from a shared list.
- rb_cont_data_type: mutates the shared fiber pool and the global first_jit_cont list.
- rb_fiber_data_type: delegates to cont_free.
- FiberPoolDataType: mutates shared fiber pool free-lists.
- ractor_data_type: reconfigures global VM event-hook flags and call caches.
- exported_object_registry: frees a global table under the VM lock.
- rb_box_data_type (Box::Entry): unlinks classext from other live class and module objects.
- box_ext_cleanup_type: dereferences another String object and calls unlink.
- monitor_data_type: uses the default free, so the flag has no effect.

Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
2026-06-23 13:30:26 -07:00
Jean Boussier
78495ca415 imemo_tmp_buffer: skip marking when useless
In many place ALLOC_V / ALLOCV_N is used as a safer `alloca`,
and to behave like stack memory, `ALLOCV` does scan its buffer
for references using `rb_gc_mark_locations`.

The problem is that it's quite slow, and in many cases, the
temporary buffer is known not to contain any references.

e.g. `ALLOCV_N(uint32_t, buf0, len)` can't possibly contain references,
as the element size is too small.
2026-06-16 16:52:32 +02:00
Nobuyoshi Nakada
fcb4746845 Show the class in a message for non-Symbol wrong exec-options 2026-05-24 18:40:59 +09:00
Nobuyoshi Nakada
3d137cf5fd
Remove duplicate GC guard
Now there is a guard also in `execarg_parent_end` since
commit:9ae6ee5a59e74e629f73222938b53a6eae8d2ded.
2026-05-23 18:01:33 +09:00
John Hawthorn
c1f70394c9 Remove rb_imemo_tmpbuf_set_ptr 2026-02-24 09:39:35 -08:00
Kuba Suder
bea48adbca
[DOC] fixed pid shown in the doc comment on fork 2026-01-28 02:48:37 +00:00
Stan Lo
4cd6661e18
Reorganize page documentations (#15154)
Re-organize page docs
2025-11-27 20:12:24 +00:00
Nobuyoshi Nakada
45fcb9d590
Adjust indent [ci skip] 2025-11-24 17:30:47 +09:00
Peter Zhu
390220579b Replace vfork with fork for ASAN
Older versions of ASAN do not support vfork. See https://github.com/google/sanitizers/issues/925
2025-11-23 10:54:44 -08:00
Peter Zhu
2447380894 Run rb_gc_before_fork after before_exec
before_exec stops the timer thread, which requires locking the Ractor
scheduler lock. This may deadlock if rb_gc_before_fork locks the VM.
2025-11-20 14:30:42 -08:00
Ricardo Trindade
48eb907f6b
[DOC] Fix formatting of seconds parameter in documentation
There's an additional colon sign in the documentation for Process.clock_gettime
2025-09-24 19:06:24 +09:00
Peter Zhu
b0ce1fd549 Combine rb_imemo_tmpbuf_auto_free_pointer and rb_imemo_tmpbuf_new 2025-09-15 09:25:20 -04:00
Jean Boussier
5bcc639b34 Disallow forking from non-main ractor
[Bug #17516]

`fork(2)` only leave the calling thread alive in the child.
Because of this forking from the non-main ractor can easily
leave the VM in a corrupted state.

It may be possible in the future to carefully allow forking from non-main
Ractor, but shot term it's preferable to add this restriction.
2025-06-24 15:10:40 +01:00
Nobuyoshi Nakada
edaa27ce45
Suppress warnings by gcc-13 with -Og 2025-06-05 22:33:02 +09:00
Nobuyoshi Nakada
aad9fa2853
Use RB_VM_LOCKING 2025-05-25 15:22:43 +09:00
John Hawthorn
d7ad53f249 Acquire VM lock around fork
Otherwise it might be held by another Ractor, causing a deadlock in the
new process.
2025-05-08 10:53:28 -07:00
Nobuyoshi Nakada
4a67ef09cc
[Feature #21116] Extract RJIT as a third-party gem 2025-02-13 18:01:03 +09:00
Nobuyoshi Nakada
e433e6515e
[DOC] Exclude 'Class' and 'Module' from RDoc's autolinking 2025-01-02 12:36:06 +09:00
Nobuyoshi Nakada
b4ec22fe6c
[DOC] Exclude 'Method' from RDoc's autolinking 2025-01-02 12:23:49 +09:00
Nobuyoshi Nakada
d441d35107
[DOC] Exclude 'Process' from RDoc's autolinking 2025-01-02 11:58:15 +09:00
Hiroshi SHIBATA
9967eccc54 Removed Process::Status#& and Process::Status#>> 2024-12-25 20:10:18 +09:00
Yusuke Endoh
c07fb79150 Avoid file descriptor leak
`extra_fd` was leaked if `fd_set_cloexec` fails -- I can't think of any
chance of that happening here, but just in case.

Coverity Scan found this issue.
2024-12-18 11:10:05 +09:00
Alan Wu
0c9c6efc20 Add missing fiber nil check to avoid slow rb_check_funcall()
Check for nil like other callers of rb_fiber_scheduler_current().
2024-12-09 16:20:01 -05:00
Matt Valentine-House
551be8219e Place all non-default GC API behind USE_SHARED_GC
So that it doesn't get included in the generated binaries for builds
that don't support loading shared GC modules

Co-Authored-By: Peter Zhu <peter@peterzhu.ca>
2024-11-25 13:05:23 +00:00
Samuel Williams
86e8a36e77
Revert "Direct access to fptr->fd should prefer to use the internal/io.h. (#11793)"
This reverts commit 6ea0dcc9781931129e77540097712f6196d49fde that was accidentally merged.
2024-10-04 08:25:43 +00:00
Samuel Williams
6ea0dcc978
Direct access to fptr->fd should prefer to use the internal/io.h. (#11793) 2024-10-04 07:44:23 +00:00
Nobuyoshi Nakada
dc8c382266
Fix bug at fork on FreeBSD
The main thread in a forked process appears not to own the read-write
lock.
2024-09-19 18:08:12 +09:00
Nobuyoshi Nakada
c193ca5218
Adjust indent [ci skip] 2024-09-19 14:33:32 +09:00
Nobuyoshi Nakada
d80a81c152
Constify struct getpwnam_r_args::login 2024-09-13 09:28:51 +09:00
Jeremy Evans
ad761ad2d0 Release GVL for get{pwnam,pwuid,grgid,grnam}_r calls in process.c
Do not release GVL around get{pwuid,pwnam,grgid,grnam} calls,
as doing so is not thread-safe.  Another C extension could have
a concurrent call, and derefencing the returned pointer from
these calls could result in a segfault.

Have rb_home_dir_of call rb_getpwdirnam_for_login if available,
so it can use getpwnam_r and release GVL in a thread-safe manner.

This is related to GVL releasing work in [Bug #20587].
2024-09-12 07:24:02 -07:00
Jean Boussier
63cbe3f6ac Proof of Concept: Allow to prevent fork from happening in known fork unsafe API
[Feature #20590]

For better of for worse, fork(2) remain the primary provider of
parallelism in Ruby programs. Even though it's frowned uppon in
many circles, and a lot of literature will simply state that only
async-signal safe APIs are safe to use after `fork()`, in practice
most APIs work well as long as you are careful about not forking
while another thread is holding a pthread mutex.

One of the APIs that is known cause fork safety issues is `getaddrinfo`.
If you fork while another thread is inside `getaddrinfo`, a mutex
may be left locked in the child, with no way to unlock it.

I think we could reduce the impact of these problem by preventing
in for the most notorious and common cases, by locking around
`fork(2)` and known unsafe APIs with a read-write lock.
2024-09-05 11:43:46 +02:00
Nobuyoshi Nakada
08e142b209 Refactor getlogin and getpw* functions
- Extract functions to check not-found conditions
- Set the length to the result of `rb_getlogin`
- Reentrant versions return an error numeber but not `errno`
- Check maybe-undefined macros with `defined`
2024-09-05 16:55:54 +09:00
Nobuyoshi Nakada
566f2eb501
Merge rb_fork_ruby2 into rb_fork_ruby 2024-08-19 15:36:49 +09:00
Nobuyoshi Nakada
cccffeff2f
Fix missing variable
It seems like no one has tried to compile on a platform without
`setsid` for almost a quarter of a century.
2024-04-07 21:16:26 +09:00
Nobuyoshi Nakada
b5b54c19f6
Unify ERRMSG1 and ERRMSG2 to ERRMSG_FMT variadic macro 2024-04-07 16:43:52 +09:00
Joshua Young
e07178d526
[DOC] Fix scope resolution operator typo in Process#wait docs 2024-04-01 01:06:10 +00:00
Samuel Williams
a7ff264477
Don't clear pending interrupts in the parent process. (#10365) 2024-03-27 10:10:07 +13:00
Nobuyoshi Nakada
5baee82c76
[DOC] Mention about executable file and fallback to sh 2024-03-01 13:11:29 +09:00
Nobuyoshi Nakada
8bff7e996c
[DOC] Move "Execution Shell on Windows" under "Execution Shell" 2024-01-29 17:16:49 +09:00
Nobuyoshi Nakada
2defa9f4ae
[DOC] Elaborate exceptional behaviors on Windows 2024-01-24 12:44:40 +09:00
Nobuyoshi Nakada
769bb924b2
[DOC] Tips for space containing exe_path 2024-01-24 12:44:40 +09:00