summaryrefslogtreecommitdiff
path: root/signal.c
AgeCommit message (Collapse)Author
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29trap_handler: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29signm2signo: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-06thread_pthread.c: allocate sigaltstack before pthread_createYusuke Endoh
A new (not-initialized-yet) pthread attempts to allocate sigaltstack by using xmalloc. It may cause GC, but because the thread is not initialized yet, ruby_native_thread_p() returns false, which leads to "[FATAL] failed to allocate memory" and exit. In fact, we can observe the error message in the log of OpenBSD CI: https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20200306T083005Z.log.html.gz This changeset allocates sigaltstack before pthread is created.
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-11-18Deprecate rb_eval_cmd, add rb_eval_cmd_kwJeremy Evans
rb_eval_cmd takes a safe level, and now that $SAFE is deprecated, it should be deprecated as well. Replace with rb_eval_cmd_kw, which takes a keyword flag. Switch the two callers to this function. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-10-09Share ruby_sighandler_t definitionNobuyoshi Nakada
2019-10-09signal.c: save the original sighandlers for fatal signalsYusuke Endoh
On Android, a signal handler that is not SIG_DFL is set by default for SIGSEGV. Ruby's install_sighandler inserts Ruby's handler only when the signal has no handler, so it does not insert Ruby's SEGV report handler, which caused some test failures. This changeset forces to install Ruby's handler for some fatal signals (sigbus, sigsegv, and sigill). They keep the original handlers, and call them when the interpreter receives the signals.
2019-10-09error.c (rb_bug_for_fatal_signal): renamed from rb_bug_contextYusuke Endoh
Just refactoring. The name "rb_bug_context" is completely unclear for me. (Can you see that "context" means "machine register context"?) The context is available only when a fatal signal (sigbus, sigsegv, or sigill) is received; in fact, the function is used only for fatal signals. So, I think the name should be changed.
2019-10-09signal.c (ruby_abort): move the definition for refactoringYusuke Endoh
The three functions for fatal signals, sigbus, sigsegv, and sigill, are a family. The definition of ruby_abort had interrupted them for no reason. This change just moves the definition after the family.
2019-10-05signal.c: Use MINSIGSTKSZ by casting to intYusuke Endoh
MINSIGSTKSZ is unsigned int in OpenBSD, which makes a warning of comparison: ``` signal.c:535:14: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare] if (size < MINSIGSTKSZ) ~~~~ ^ ~~~~~~~~~~~ 1 warning generated. ``` https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20191004T200009Z.log.html.gz
2019-08-29move docs around [ci skip]卜部昌平
To properly generate documents.
2019-08-29drop-in type check for rb_define_module_function卜部昌平
We can check the function pointer passed to rb_define_module_function like how we do so in rb_define_method. The difference is that this changeset reveales lots of atiry mismatches.
2019-08-27signal.c: Don't mark ruby_abort as NORETURN on SolarisYusuke Endoh
to suppress a warning. ``` signal.c: In function 'ruby_abort': signal.c:987:1: warning: 'noreturn' function does return } ^ ```
2019-08-13Renamed ruby_finalize_{0,1}Nobuyoshi Nakada
And pass rb_execution_context_t as an argument.
2019-08-01* expand tabs.git
2019-08-01signal.c: make signame_prefix a nul-terminated stringYusuke Endoh
gcc 9.1.0 warns this. ``` signal.c:258:46: warning: '%.*s' directive argument is not a nul-terminated string [-Wformat-overflow=] 258 | rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'", | ^~~~ 259 | prefix, signame_prefix, vsig); | ~~~~~~~~~~~~~~ signal.c:200:19: note: referenced argument declared here 200 | static const char signame_prefix[3] = "SIG"; | ^~~~~~~~~~~~~~ ``` https://rubyci.org/logs/rubyci.s3.amazonaws.com/ubuntu/ruby-master/log/20190801T033009Z.log.html.gz
2019-07-26Document acceptance of negative pid in Process.kill [ci skip]Jeremy Evans
Fixes [Bug #13501]
2019-03-28[DOC] fix markups [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-25refactoring debug_counter.ko1
* debug_counter.h: add comments for each counters. * debug_counter.h: add some counters (see added comments for details). * obj_newobj * obj_newobj_slowpath * obj_newobj_wb_unprotected * obj_hash_empty * obj_hash_under4 * obj_hash_ge4 * obj_hash_ge8 * heap_xmalloc * heap_xrealloc * heap_xfree * gc.c: add some debug counters (see the above list). * debug_counter.c (rb_debug_counter_show_results): accept a header message. * signal.c (ruby_default_signal): show debug counter results and malloc info (rb_malloc_info_show_results()) before SIGNAL exit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-22Fix for old names of mcontext registersnobu
c.f. https://github.com/mistydemeo/tigerbrew/issues/473 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64812 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-21Remove -Wno-parentheses flag.nobu
[Fix GH-1958] From: Jun Aruga <jaruga@redhat.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64806 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-09-10signal.c: consider non-sigaltstack platformsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-21Re-Revert "Temporary revert "process.c: dead code when no SIGCHLD""naruse
This re-reverts commit r64447. The issue was machine side problem. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-18Temporary revert "process.c: dead code when no SIGCHLD"naruse
This reverts commit r64407. Maybe it breaks http://mswinci.japaneast.cloudapp.azure.com/vc12-x64/ruby-trunk/log/20180817T095734Z.fail.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-18thread.c (sleep_*): reduce the effect of spurious interruptsnormal
Spurious interrupts from SIGCHLD cause Mutex#sleep (via ConditionVariable#wait) to return early and breaks some use cases. Since these are outside the programs's control with MJIT, we will only consider pending interrupts (e.g. those from Thread#run) and signals which cause a Ruby-level Signal.trap handler to fire as "spurious" wakeups. [ruby-core:88537] [Feature #15002] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-17process.c: dead code when no SIGCHLDnobu
* process.c (ruby_waitpid_all): nothing to do unless SIGCHLD is available. * signal.c (ruby_nocldwait): used only if SIGCHLD is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-17signal.c: no SIGCHLD, no sigchld_hitnobu
* signal.c (sigchld_hit): if SIGCHLD is not available, this variable never sets. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-13thread_pthread.c: eliminate timer thread by restructuring GVLnormal
This reverts commit 194a6a2c68e9c8a3536b24db18ceac87535a6051 (r64203). Race conditions which caused the original reversion will be fixed in the subsequent commit. [ruby-core:88360] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06thread_pthread.c: restore timer-thread for now :<normal
[ruby-core:88306] Revert "process.c: ensure th->interrupt lock is held when migrating" This reverts commit 5ca416bdf6b6785cb20f139c2c514eda005fe42f (r64201) Revert "process.c (rb_waitpid): reduce sigwait_fd bouncing" This reverts commit 217bdd776fbeea3bfd0b9324eefbfcec3b1ccb3e (r64200). Revert "test/ruby/test_thread.rb (test_thread_timer_and_interrupt): add timeouts" This reverts commit 9f395f11202fc3c7edbd76f5aa6ce1f8a1e752a9 (r64199). Revert "thread_pthread.c (native_sleep): reduce ppoll sleeps" This reverts commit b3aa256c4d43d3d7e9975ec18eb127f45f623c9b (r64193). Revert "thread.c (consume_communication_pipe): do not retry after short read" This reverts commit 291a82f748de56e65fac10edefc51ec7a54a82d4 (r64185). Revert "test/ruby/test_io.rb (test_race_gets_and_close): timeout each thread" This reverts commit 3dbd8d1f66537f968f0461ed8547460b3b1241b3 (r64184). Revert "thread_pthread.c (gvl_acquire_common): persist timeout across calls" This reverts commit 8c2ae6e3ed072b06fc3cbc34fa8a14b2acbb49d5 (r64165). Revert "test/ruby/test_io.rb (test_race_gets_and_close): use SIGABRT on timeout" This reverts commit 931cda4db8afd6b544a8d85a6815765a9c417213 (r64135). Revert "thread_pthread.c (gvl_yield): do ubf wakeups when uncontended" This reverts commit 508f00314f46c08b6e9b0141c01355d24954260c (r64133). Revert "thread_pthread.h (native_thread_data): split condvars on some platforms" This reverts commit a038bf238bd9a24bf1e1622f618a27db261fc91b (r64124). Revert "process.c (waitpid_nogvl): prevent conflicting use of sleep_cond" This reverts commit 7018acc946882f21d519af7c42ccf84b22a46b27 (r64117). Revert "thread_pthread.c (rb_sigwait_sleep): th may be 0 from MJIT" This reverts commit 56491afc7916fb24f5c4dc2c632fb93fa7063992 (r64116). Revert "thread*.c: waiting on sigwait_fd performs periodic ubf wakeups" This reverts commit ab47a57a46e70634d049e4da20a5441c7a14cdec (r64115). Revert "thread_pthread.c (gvl_destroy): make no-op on GVL bits" This reverts commit 95cae748171f4754b97f4ba54da2ae62a8d484fd (r64114). Revert "thread_pthread.c (rb_sigwait_sleep): fix uninitialized poll set in UBF case" This reverts commit 4514362948fdb914c6138b12d961d92e9c0fee6c (r64113). Revert "thread_pthread.c (rb_sigwait_sleep): re-fix [Bug #5343] harder" This reverts commit 26b8a70bb309c7a367b9134045508b5b5a580a77 (r64111). Revert "thread.c: move ppoll wrapper into thread_pthread.c" This reverts commit 3dc7727d22fecbc355597edda25d2a245bf55ba1 (r64110). Revert "thread.c: move ppoll wrapper before thread_pthread.c" This reverts commit 2fa1e2e3c3c5c4b3ce84730dee4bcbe9d81b8e35 (r64109). Revert "thread_pthread.c (ubf_select): refix [Bug #5343]" This reverts commit 4c1ab82f0623eca91a95d2a44053be22bbce48ad (r64108). Revert "thread_win32.c: suppress warnings by -Wsuggest-attribute" This reverts commit 6a9b63e39075c53870933fbac5c1065f7d22047c (r64159). Revert "thread_pthread: remove timer-thread by restructuring GVL" This reverts commit 708bfd21156828526fe72de2cedecfaca6647dc1 (r64107). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-29thread_pthread: remove timer-thread by restructuring GVLnormal
To reduce resource use and reduce CI failure; remove timer-thread. Single-threaded Ruby processes (including forked children) will never see extra thread overhead. This prevents glibc and jemalloc from going into multi-threaded mode and initializing locks or causing fragmentation via arena explosion. The GVL is implements its own wait-queue as a ccan/list to permit controlling wakeup order. Timeslice under contention is handled by a designated timer thread (similar to choosing a "patrol_thread" for current deadlock checking). There is only one self-pipe, now, as wakeups for timeslice are done independently using condition variables. This reduces FD pressure slightly. Signal handling is handled directly by a Ruby Thread (instead of timer-thread) by exposing signal self-pipe to callers of rb_thread_fd_select, native_sleep, rb_wait_for_single_fd, etc... Acquiring, using, and releasing the self-pipe is exposed via 4 new internal functions: 1) rb_sigwait_fd_get - exclusively acquire timer_thread_pipe.normal[0] 2) rb_sigwait_fd_sleep - sleep and wait for signal (and no other FDs) 3) rb_sigwait_fd_put - release acquired result from rb_sigwait_fd_get 4) rb_sigwait_fd_migrate - migrate signal handling to another thread after calling rb_sigwait_fd_put. rb_sigwait_fd_migrate is necessary for waitpid callers because only one thread can wait on self-pipe at a time, otherwise a deadlock will occur if threads fight over the self-pipe. TRAP_INTERRUPT_MASK is now set for the main thread directly in signal handler via rb_thread_wakeup_timer_thread. Originally, I wanted to use POSIX timers (timer_create/timer_settime) for this. Unfortunately, this proved unfeasible as Mutex#sleep resumes on spurious wakeups and test/thread/test_cv.rb::test_condvar_timed_wait failed. Using pthread_sigmask to mask out SIGVTALRM fixed that test, but test/fiddle/test_function.rb::test_nogvl_poll proved there'd be some unavoidable (and frequent) incompatibilities from that approach. Finally, this allows us to drop thread_destruct_lock and interrupt current ec directly. We don't need to rely on vm->thread_destruct_lock or a coherent vm->running_thread on any platform. Separate timer-thread for time slice and signal handling is relegated to thread_win32.c, now. [ruby-core:88088] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-08signal.c: preserve trap(:CHLD, "IGNORE") behavior with SIGCHLDnormal
We need to preserve "IGNORE" behavior from Ruby 2.5 and earlier. We can't rely on SA_NOCLDWAIT any more, since we always need system() and MJIT to work; so we fake that behavior using dedicated reaper (currently in timer-thread). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-05unrevert r63852 but keep SIGCHLD path disabled for win32normal
Reading win32/win32.c waitpid implementation, maybe waitpid(-1, ...) on that platform will never conflict with mjit use of waitpid. In any case, I've added WAITPID_USE_SIGCHLD macro to vm_core.h so it can be easy for Linux/BSD users to test (hopefully!) win32-compatible code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04signal.c: packed signalsnobu
* signal.c (signals): pack signal names instead of references. * signal.c (signm2signo): also reject too long signal name. [ruby-core:87767] [Bug #14893] reapply r63841 and r63842, which are unrelated to r63758 but had been wrongly reverted by r63852. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-04Revert r63758 and related commitsnaruse
The change is unstable on Windows. Please re-commit it when it correctly supports Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-03Fix compile errorkazu
signal.c:69:10: error: variably modified ‘signm’ at file scope char signm[LONGEST_SIGNAME + 1]; ^ git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-03signal.c: packed signalsnobu
* signal.c (signals): pack signal names instead of references. * signal.c (signm2signo): also reject too long signal name. [ruby-core:87767] [Bug #14893] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63841 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-30use SIGCHLD_LOSSY to enable waitpid polling modenormal
Some systems lack SIGCHLD or have incomplete SIGCHLD implementations. So enable polling mode for them. [ruby-core:87705] [Bug #14867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-29signal.c: use ATOMIC_EXCHANGE for sigchld_hitnormal
sig_atomic_t may not be sufficient for multi-threaded applications if the sighandler runs on a different CPU than timer thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27signal.c: fix braino in fake_grantfdnormal
[Bug #14871] Is neon down? I missed ruby-core notifications on this. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-27hijack SIGCHLD handler for internal usenormal
Use a global SIGCHLD handler to guard all callers of rb_waitpid. To work safely with multi-threaded programs, we introduce a VM-wide waitpid_lock to be acquired BEFORE fork/vfork spawns the process. This is to be combined with the new ruby_waitpid_locked function used by mjit.c in a non-Ruby thread. Ruby-level SIGCHLD handlers registered with Signal.trap(:CHLD) continues to work as before and there should be no regressions in any existing use cases. Splitting the wait queues for PID > 0 and groups (PID <= 0) ensures we favor PID > 0 callers. The disabling of SIGCHLD in rb_f_system is longer necessary, as we use deferred signal handling and no longer make ANY blocking waitpid syscalls in other threads which could "beat" the waitpid call made by rb_f_system. We prevent SIGCHLD from firing in normal Ruby Threads and only enable it in the timer-thread, to prevent spurious wakeups from in test/-ext-/gvl/test_last_thread.rb with MJIT enabled. I've tried to guard as much of the code for RUBY_SIGCHLD==0 using C "if" statements rather than CPP "#if" so to reduce the likelyhood of portability problems as the compiler will see more code. We also work to suppress false-positives from Process.wait(-1, Process::WNOHANG) to quiets warnings from spec/ruby/core/process/wait2_spec.rb with MJIT enabled. Lastly, we must implement rb_grantpt for ext/pty. We need a MJIT-compatible way of supporting grantpt(3) which may spawn the `pt_chown' binary and call waitpid(2) on it. [ruby-core:87605] [Ruby trunk Bug#14867] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63758 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-15signal.c: follow up r63435nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-20simplify altstack and enable reuse with thread cachenormal
Instead of allocating and registering the altstack in different places, do it together to reduce code and improve readability. When thread cache is enabled, storing altstack in rb_thread_t is wasteful and we may reuse altstack in the same pthread. This also lets us clearly allow use of xmalloc to allow GC to recover from ENOMEM. [ruby-core:85621] [Feature #14487] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63213 b2dd03c8-39d4-4d8f-98ff-823fe69b080e