summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_sig.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Use uppercases for defines.mpi2021-03-211-6/+6
| | | | | | No functional change. ok semarie@
* Kill SINGLE_PTRACE and use SINGLE_SUSPEND which has almost the same semanticmpi2021-03-121-11/+7
| | | | | | | | single_thread_set() is modified to explicitly indicated when waiting until sibling threads are parked is required. This is obviously not required if a traced thread is switching away from a CPU after handling a STOP signal. ok claudio@
* Revert commitid: AZrsCSWEYDm7XWuv;claudio2021-03-081-6/+10
| | | | | | Kill SINGLE_PTRACE and use SINGLE_SUSPEND which has almost the same semantic. This diff did not properly kill SINGLE_PTRACE and broke RAMDISK kernels.
* Move a KERNEL_ASSERT_LOCKED() from single_thread_clear() to cursig().mpi2021-03-081-6/+3
| | | | | | | | Ze big lock is currently necessary to ensure that two sibling threads are not racing against each other when processing signals. However it is not strickly necessary to unpark sibling threads. ok claudio@
* Kill SINGLE_PTRACE and use SINGLE_SUSPEND which has almost the same semantic.mpi2021-03-081-10/+6
| | | | | | | | single_thread_set() is modified to explicitly indicated when waiting until sibling threads are parked is required. This is obviously not required if a traced thread is switching away from a CPU after handling a STOP signal. ok claudio@
* Merge issignal() and CURSIG() in preparation for turning it mp-safe.mpi2021-03-041-12/+20
| | | | | | This makes appear some redundant & racy checks. ok semarie@
* Move single_thread_set() out of KERNEL_LOCK().mpi2021-02-151-6/+1
| | | | | | | Use the SCHED_LOCK() to ensure `ps_thread' isn't being modified by a sibling when entering tsleep(9) w/o KERNEL_LOCK(). ok visa@
* Revert the convertion of per-process thread into a SMR_TAILQ.mpi2021-02-081-5/+5
| | | | | We did not reach a consensus about using SMR to unlock single_thread_set() so there's no point in keeping this change.
* Simplify sleep_setup API to two operations in preparation for splittingmpi2021-02-081-2/+2
| | | | | | | | | | | | the SCHED_LOCK(). Putting a thread on a sleep queue is reduce to the following: sleep_setup(); /* check condition or release lock */ sleep_finish(); Previous version ok cheloha@, jmatthew@, ok claudio@
* Refactor klist insertion and removalvisa2020-12-251-3/+3
| | | | | | | | | | | | Rename klist_{insert,remove}() to klist_{insert,remove}_locked(). These functions assume that the caller has locked the klist. The current state of locking remains intact because the kernel lock is still used with all klists. Add new functions klist_insert() and klist_remove() that lock the klist internally. This allows some code simplification. OK mpi@
* sigsuspend(2): change wmesg from "pause" to "sigsusp"cheloha2020-12-231-2/+2
| | | | | | | | Make it obvious where the thread is blocked. "pause" is ambiguous. Tweaked by kettenis@. Probably ok kettenis@.
* Convert the per-process thread list into a SMR_TAILQ.mpi2020-12-071-5/+5
| | | | | | | Currently all iterations are done under KERNEL_LOCK() and therefor use the *_LOCKED() variant. From and ok claudio@
* Prevent a TOCTOU race in single_thread_set() by extending the scope of the lock.mpi2020-12-041-11/+23
| | | | | | | Make sure `ps_single' is set only once by checking then updating it without releasing the lock. Analyzed by and ok claudio@
* Revert previous extension of the SCHED_LOCK(), the state isn't passed down.mpi2020-12-021-23/+9
| | | | Panic reported by dhill@
* Prevent a TOCTOU race in single_thread_set() by extending the scope of the lock.mpi2020-12-021-9/+23
| | | | | | | Make sure `ps_single' is set only once by checking then updating it without releasing the lock. Analyzed by and ok claudio@
* In case of failure, call sigexit() from trapsignal instead of sensig().mpi2020-11-081-3/+11
| | | | | | | Simplify MD code and reduce the amount of recursion into the signal code which helps when dealing with locks. ok cheloha@, deraadt@
* Move duplicated code to send an uncatchable SIGABRT into a function.mpi2020-09-161-1/+18
| | | | ok claudio@
* Unbreak tree. Instead of passing struct process to siginit() just pass theclaudio2020-09-131-3/+2
| | | | struct sigacts since that is the only thing that is modified by siginit.
* Introduce a helper to check if a signal is ignored or masked by a thread.mpi2020-09-091-1/+17
| | | | ok claudio@, pirofti@
* Fix a race in single-thread mode switchingvisa2020-08-261-14/+15
| | | | | | | | | | | | | | | | | | | Extend the scope of SCHED_LOCK() to better synchronize single_thread_set(), single_thread_clear() and single_thread_check(). This prevents threads from suspending before single_thread_set() has finished. If a thread suspended early, ps_singlecount might get decremented too much, which in turn could make single_thread_wait() get stuck. The race could be triggered for example by trying to stop a multithreaded process with a debugger. When triggered, the race prevents the debugger from finishing a wait4(2) call on the debuggee. This kind of gdb hang was reported by Julian Smith on misc@. Unfortunately, single-thread mode switching still has issues and hangs are still possible. OK mpi@
* Push KERNEL_LOCK/UNLOCK() dance inside trapsignal().mpi2020-08-191-1/+3
| | | | ok kettenis@, visa@
* Raise SPL when modifying ps_klist to prevent a race with interrupts.visa2020-06-151-1/+7
| | | | | | | The list can be accessed from interrupt context if a signal is sent from an interrupt handler. OK anton@ cheloha@ mpi@
* Remove misleading XXX about locking of ps_klist. All of the kqueuevisa2020-06-141-2/+1
| | | | subsystem and ps_klist handling still run under the kernel lock.
* Abstract the head of knote lists. This allows extending the lists,visa2020-04-071-3/+3
| | | | | | for example, with locking assertions. OK mpi@, anton@
* Use atomic operations to update ps_singlecount. This makesclaudio2020-03-201-18/+29
| | | | | | | single_thread_check() safe to be called without KERNEL_LOCK(). single_thread_wait() needs to use sleep_setup() and sleep_finish() instead of tsleep() to make sure no wakeup() is lost. Input kettenis@, with and OK visa@
* Restart child process scan in dowait4() if single_thread_wait() sleeps.visa2020-03-181-5/+13
| | | | | | | | | | | | This ensures that the conditions checked are still in force. The sleep breaks atomicity, allowing another thread to alter the state. single_thread_set() should return immediately after sleep when called from dowait4() because there is no guarantee that the process pr still exists. When called from single_thread_set(), the process is that of the calling thread, which prevents process pr from disappearing. OK anton@, mpi@, claudio@
* Rename "sigacts" flag field to avoid conflict with the "process" one.mpi2020-03-131-10/+10
| | | | | | | | | | This shows that atomic_* operations should not be necessery to write to this field unlike with the process one. The advantage of using a somewhat-unique prefix for struct member is moot when multiple definitions use the same prefix :o) From Amit Kulkarni, ok claudio@
* Move the sigprop definition and the other bits under SIGPROP intoclaudio2020-03-111-2/+41
| | | | | | kern_sig.c where they are currently added by the include. While doing that mark the sigprop array as const. OK mpi@ anton@ millert@
* Remove sigacts structure sharing. The only process that used sharing wasclaudio2020-02-211-35/+1
| | | | | | | proc0 which is used for kthreads and idle threads. proc0 and all those other kernel threads don't handle signals so there is no benefit in sharing. Simplifies the code a fair bit since the refcnt is gone. OK kettenis@
* Adjust a comment, no functional changeclaudio2020-02-211-2/+2
|
* Replace field f_isfd with field f_flags in struct filterops to allowvisa2020-02-201-2/+2
| | | | | | adding more filter properties without cluttering the struct. OK mpi@, anton@
* Remove the indirection via timeout for proc_stop_sweep(). Using a softclaudio2020-02-191-13/+13
| | | | | | | | interrupt is enough to defer the signal handling. This is a leftover from the times where not all archs had generic soft interrupts. It is possible that the defer signal handling to a soft interrupt will be removed at a later stage. Input anton@, mpi@ OK kettenis@
* Consistently perform atomic writes to the ps_flags field of structanton2020-02-151-3/+3
| | | | | | process. ok bluhm@ claudio@ visa@
* Push the KERNEL_LOCK() insidge pgsigio() and selwakeup().mpi2020-02-141-1/+3
| | | | | | | | | | | The 3 subsystems: signal, poll/select and kqueue can now be addressed separatly. Note that bpf(4) and audio(4) currently delay the wakeups to a separate context in order to respect the KERNEL_LOCK() requirement. Sockets (UDP, TCP) and pipes spin to grab the lock for the sames reasons. ok anton@, visa@
* Back out previous. Nothing wrong with the diff per se but I should haveanton2020-02-011-3/+1
| | | | asked for more oks; my bad!
* Grab the kernel lock in pgsigio() as it's strictly needed whileanton2020-02-011-1/+3
| | | | | | | | | | operating on the process structure and issuing signals. This is similar to what sigio_setown() already does. With this in place, the pipe subsystem is no longer required to grab the kernel lock before calling pgsigio(). ok visa@
* Split `p_priority' into `p_runpri' and `p_slppri'.mpi2020-01-301-4/+4
| | | | | | | | | | | Using different fields to remember in which runqueue or sleepqueue threads currently are will make it easier to split the SCHED_LOCK(). With this change, the (potentially boosted) sleeping priority is no longer overwriting the thread priority. This let us get rids of the logic required to synchronize `p_priority' with `p_usrpri'. Tested by many, ok visa@
* Introduce wakeup_proc() a function to un-SSTOP/SSLEEP a thread.mpi2020-01-161-2/+2
| | | | | | | This moves most of the SCHED_LOCK() related to protecting the sleepqueue and its states to kern/kern_sync.c Name suggestion from jsg@, ok kettenis@, visa@
* Introduce TIMESPEC_TO_NSEC() and use it to convert userland facingmpi2020-01-141-13/+7
| | | | | | tsleep(9) to tsleep_nsec(9). ok bluhm@
* Unify handling of ioctls FIOSETOWN/SIOCSPGRP/TIOCSPGRP andvisa2020-01-081-5/+16
| | | | | | | | | | | | FIOGETOWN/SIOCGPGRP/TIOCGPGRP. Do this by determining the meaning of the ID parameter inside the sigio code. Also add cases for FIOSETOWN and FIOGETOWN where there have been TIOCSPGRP and TIOCGPGRP before. These changes allow removing the ID translation from sys_fcntl() and sys_ioctl(). Idea from NetBSD OK mpi@, claudio@
* Retire csignal() the last users were converted to use pgsigio(9) instead.claudio2020-01-031-28/+1
| | | | OK visa@ anton@
* Use C99 designated initializers with struct filterops. In addition,visa2019-12-311-3/+7
| | | | | | make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
* Convert infinite sleeps to {m,t}sleep_nsec(9).mpi2019-12-191-3/+3
| | | | ok visa@
* Replace p_xstat with ps_xexit and ps_xsigguenther2019-12-111-13/+12
| | | | | | | | | Convert those to a consolidated status when needed in wait4(), kevent(), and sysctl() Pass exit code and signal separately to exit1() (This also serves as prep for adding waitid(2)) ok mpi@
* Fix vn_open to require an op of 0, and 0 or KERNELPATH only as flags.beck2019-10-061-2/+3
| | | | | | | | sweep tree to correct NDIINT op and flags ahead of time. document the requirement. This allows KERNELPATH to be used to bypass unveil for crash dumps with nosuidcoredump=2 or 3 ok visa@ deraadt@ florian@
* sysctl global nosuidcoredump was being inspected twice inside coredump(),deraadt2019-10-031-23/+24
| | | | | with a sleep between. Reorganize the code for a single check. ok anton beck florian mpi
* avoid large MAXPATHLEN object on the stack in coredump(), by allocatingderaadt2019-08-071-6/+11
| | | | | it from the pool. ok bluhm visa
* Stop sleeping at PUSER.mpi2019-07-101-2/+2
| | | | | | | This allows to enforce that sleeping priorities will now always be < PUSER. ok visa@, ratchov@
* Make resource limit access MP-safe. So far, the copy-on-write sharingvisa2019-06-211-3/+2
| | | | | | | | | | of resource limit structs has been done between processes. By applying copy-on-write also between threads, threads can read rlimits in a nearly lock-free manner. Inspired by code in DragonFly BSD and FreeBSD. OK mpi@, agreement from jmatthew@ and anton@
* When killing a process, the signal is handled by any thread thatbluhm2019-05-131-22/+32
| | | | | | | | | | does not block the signal. If all threads block the signal, we delivered it to the main thread. This does not conform to POSIX. If any thread unblocks the signal, it should be delivered immediately to this thread. Mark such signals pending at the process instead of a single thread. Then any thread can handle it later. OK kettenis@ guenther@