aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/signalvar.h
Commit message (Collapse)AuthorAgeFilesLines
* Patch annotation in sigdeferstopMateusz Guzik2020-12-131-1/+1
| | | | | | | | Probability flipped since sigdefer handling was moved away from regular VOP calls. Notes: svn path=/head/; revision=368616
* Remove an extraneous parameter from SIGIO_ASSERT_LOCKED()Mark Johnston2020-11-111-1/+1
| | | | | | | | Reported by: hselasky MFC with: r367588 Notes: svn path=/head/; revision=367590
* Fix a pair of races in SIGIO registrationMark Johnston2020-11-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | First, funsetownlst() list looks at the first element of the list to see whether it's processing a process or a process group list. Then it acquires the global sigio lock and processes the list. However, nothing prevents the first sigio tracker from being freed by a concurrent funsetown() before the sigio lock is acquired. Fix this by acquiring the global sigio lock immediately after checking whether the list is empty. Callers of funsetownlst() ensure that new sigio trackers cannot be added concurrently. Second, fsetown() uses funsetown() to remove an existing sigio structure from a file object. However, funsetown() uses a racy check to avoid the sigio lock, so two threads may call fsetown() on the same file object, both observe that no sigio tracker is present, and enqueue two sigio trackers for the same file object. However, if the file object is destroyed, funsetown() will only remove one sigio tracker, and funsetownlst() may later trigger a use-after-free when it clears the file object reference for each entry in the list. Fix this by introducing funsetown_locked(), which avoids the racy check. Reviewed by: kib Reported by: pho Tested by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27157 Notes: svn path=/head/; revision=367588
* Add sig_intr(9).Konstantin Belousov2020-10-041-0/+1
| | | | | | | | | | | | | | | | | | | | It gives the answer would the thread sleep according to current state of signals and suspensions. Of course the answer is racy and allows for false-negatives (no sleep when signal is delivered after process lock is dropped). Also the answer might change due to signal rescheduling among threads in multi-threaded process. Still it is the best approximation I can provide, to answering the question was the thread interrupted. Reviewed by: markj Tested by: pho, rmacklem Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D26628 Notes: svn path=/head/; revision=366429
* Refactor sleepq_catch_signals().Konstantin Belousov2020-10-041-0/+2
| | | | | | | | | | | | | | | | | | | | | | - Extract suspension check into sig_ast_checksusp() helper. - Extract signal check and calculation of the interruption errno into sig_ast_needsigchk() helper. The helpers are moved to kern_sig.c which is the proper place for signal-related code. Improve control flow in sleepq_catch_signals(), to handle ret == 0 (can sleep) and ret != 0 (interrupted) only once, by separating checking code into sleepq_check_ast_sq_locked(), which return value is interpreted at single location. Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D26628 Notes: svn path=/head/; revision=366428
* Return reschedule_signals() to being static again.Konstantin Belousov2020-03-101-2/+1
| | | | | | | | | | | | | It was used after sigfastblock_setpend() call in in ast() when current thread fast-blocks signals. Add a flag to sigfastblock_setpend() to request reschedule, and remove the direct use of the function from subr_trap.c Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=358855
* sys/signalvar.h: Fix opposite boolean sense in commentConrad Meyer2020-03-031-4/+4
| | | | | | | | | | | Correct the sense of the comment describing sigsetmasked() to match the code. It was exactly backwards. While here, convert the type/values of the predicate from pre-C99 int/1/0 to bool/true/false. No functional change. Notes: svn path=/head/; revision=358596
* sys/kern: quiet -Wwrite-stringsRyan Libby2020-02-231-1/+1
| | | | | | | | | | | | Quiet a variety of Wwrite-strings warnings in sys/kern at low-impact sites. This patch avoids addressing certain others which would need to plumb const through structure definitions. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D23798 Notes: svn path=/head/; revision=358258
* Do not read sigfastblock word on syscall entry.Konstantin Belousov2020-02-201-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On machines with SMAP, fueword executes two serializing instructions which can be seen in microbenchmarks. As a measure to restore microbenchmark numbers, only read the word on the attempt to deliver signal in ast(). If the word is set, signal is not delivered and word is kept, preventing interruption of interruptible sleeps by signals until userspace calls sigfastblock(UNBLOCK) which clears the word. This way, the spurious EINTR that userspace can see while in critical section is on first interruptible sleep, if a signal is pending, and on signal posting. It is believed that it is not important for rtld and lbithr critical sections. It might be visible for the application code e.g. for the callback of dl_iterate_phdr(3), but again the belief is that the non-compliance is acceptable. Most important is that the retry of the sleeping syscall does not interrupt unless additional signal is posted. For now I added the knob kern.sigfastblock_fetch_always to enable the word read on syscall entry to be able to diagnose possible issues due to spurious EINTR. While there, do some code restructuting to have all sigfastblock() handling located in kern_sig.c. Reviewed by: jeff Discussed with: mjg Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D23622 Notes: svn path=/head/; revision=358168
* Add a way to manage thread signal mask using shared word, instead of syscall.Konstantin Belousov2020-02-091-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A new syscall sigfastblock(2) is added which registers a uint32_t variable as containing the count of blocks for signal delivery. Its content is read by kernel on each syscall entry and on AST processing, non-zero count of blocks is interpreted same as the signal mask blocking all signals. The biggest downside of the feature that I see is that memory corruption that affects the registered fast sigblock location, would cause quite strange application misbehavior. For instance, the process would be immune to ^C (but killable by SIGKILL). With consumers (rtld and libthr added), benchmarks do not show a slow-down of the syscalls in micro-measurements, and macro benchmarks like buildworld do not demonstrate a difference. Part of the reason is that buildworld time is dominated by compiler, and clang already links to libthr. On the other hand, small utilities typically used by shell scripts have the total number of syscalls cut by half. The syscall is not exported from the stable libc version namespace on purpose. It is intended to be used only by our C runtime implementation internals. Tested by: pho Disscussed with: cem, emaste, jilles Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D12773 Notes: svn path=/head/; revision=357693
* rfork(2): add RFSPAWN flagKyle Evans2019-09-251-0/+1
| | | | | | | | | | | | | | When RFSPAWN is passed, rfork exhibits vfork(2) semantics but also resets signal handlers in the child during creation to avoid a point of corruption of parent state from the child. This flag will be used by posix_spawn(3) to handle potential signal issues. Reviewed by: jilles, kib Differential Revision: https://reviews.freebsd.org/D19058 Notes: svn path=/head/; revision=352711
* vfs: __predict common case in VFS_EPILOGUE/PROLOGUEMateusz Guzik2018-09-221-2/+2
| | | | | | | | | | | | | | | NFS is the only in-tree filesystem using the feature, but all ops test for it. Currently the resulting sigdefer calls have to be jumped over in the common case. This is a bandaid, longer term fix will move this feature away. Approved by: re (kib) Notes: svn path=/head/; revision=338885
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* Fix typo in comment.Konstantin Belousov2017-03-091-1/+1
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days Notes: svn path=/head/; revision=314960
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Defer ptracestop() signals that cannot be delivered immediatelyEric Badger2017-02-201-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | When a thread is stopped in ptracestop(), the ptrace(2) user may request a signal be delivered upon resumption of the thread. Heretofore, those signals were discarded unless ptracestop()'s caller was issignal(). Fix this by modifying ptracestop() to queue up signals requested by the ptrace user that will be delivered when possible. Take special care when the signal is SIGKILL (usually generated from a PT_KILL request); no new stop events should be triggered after a PT_KILL. Add a number of tests for the new functionality. Several tests were authored by jhb. PR: 212607 Reviewed by: kib Approved by: kib (mentor) MFC after: 2 weeks Sponsored by: Dell EMC In collaboration with: jhb Differential Revision: https://reviews.freebsd.org/D9260 Notes: svn path=/head/; revision=313992
* Provide helper macros to detect 'non-silent SBDRY' state and toKonstantin Belousov2016-07-031-2/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | calculate appropriate return value for stops. Simplify the code by using them. Fix typo in sig_suspend_threads(). The thread which sleep must be aborted is td2. (*) In issignal(), when handling stopping signal for thread in TD_SBDRY_INTR state, do not stop, this is wrong and fires assert. This is yet another place where execution should be forced out of SBDRY-protected region. For such case, return -1 from issignal() and translate it to corresponding error code in sleepq_catch_signals(). Assert that other consumers of cursig() are not affected by the new return value. (*) Micro-optimize, mostly VFS and VOP methods, by avoiding calling the functions when SIGDEFERSTOP_NOP non-change is requested. (**) Reported and tested by: pho (*) Requested by: bde (**) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Approved by: re (gjb) Notes: svn path=/head/; revision=302328
* Rewrite sigdeferstop(9) and sigallowstop(9) into more flexibleKonstantin Belousov2016-06-261-2/+14
| | | | | | | | | | | | | | | | framework allowing to set the suspension policy for the dynamic block. Extend the currently possible policies of stopping on interruptible sleeps and ignoring such sleeps by two more: do not suspend at interruptible sleeps, but interrupt them with either EINTR or ERESTART. Reviewed by: jilles Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Approved by: re (gjb) Notes: svn path=/head/; revision=302215
* Simplify AIO initialization now that it is standard.John Baldwin2016-03-091-0/+2
| | | | | | | | | | | | | | | | | | - Mark AIO system calls as STD and remove the helpers to dynamically register them. - Use COMPAT6 for the old system calls with the older sigevent instead of an 'o' prefix. - Simplify the POSIX configuration to note that AIO is always available. - Handle AIO in the default VOP_PATHCONF instead of special casing it in the pathconf() system call. fpathconf() is still hackish. - Remove freebsd32_aio_cancel() as it just called the native one directly. Reviewed by: kib Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D5589 Notes: svn path=/head/; revision=296572
* Make SIGSTOP working for sleeps done while waiting for fifo readers orKonstantin Belousov2015-01-181-1/+1
| | | | | | | | | | | writers in open(2), when the fifo is located on an NFS mount. Reported by: bde Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=277321
* Manage struct sigacts refcnt with atomics instead of a mutex.Mateusz Guzik2014-07-141-1/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=268634
* Partially revert r195702. Deferring stops is now implemented via a set ofJohn Baldwin2013-03-181-5/+1
| | | | | | | | | | | calls to toggle TDF_SBDRY rather than passing PBDRY to individual sleep calls. - Remove the stop_allowed parameters from cursig() and issignal(). issignal() checks TDF_SBDRY directly. - Remove the PBDRY and SLEEPQ_STOP_ON_BDRY flags. Notes: svn path=/head/; revision=248470
* Further refine the handling of stop signals in the NFS client. TheJohn Baldwin2013-02-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | changes in r246417 were incomplete as they did not add explicit calls to sigdeferstop() around all the places that previously passed SBDRY to _sleep(). In addition, nfs_getcacheblk() could trigger a write RPC from getblk() resulting in sigdeferstop() recursing. Rather than manually deferring stop signals in specific places, change the VFS_*() and VOP_*() methods to defer stop signals for filesystems which request this behavior via a new VFCF_SBDRY flag. Note that this has to be a VFC flag rather than a MNTK flag so that it works properly with VFS_MOUNT() when the mount is not yet fully constructed. For now, only the NFS clients are set this new flag in VFS_SET(). A few other related changes: - Add an assertion to ensure that TDF_SBDRY doesn't leak to userland. - When a lookup request uses VOP_READLINK() to follow a symlink, mark the request as being on behalf of the thread performing the lookup (cnp_thread) rather than using a NULL thread pointer. This causes NFS to properly handle signals during this VOP on an interruptible mount. PR: kern/176179 Reported by: Russell Cattelan (sigdeferstop() recursion) Reviewed by: kib MFC after: 1 month Notes: svn path=/head/; revision=247116
* Rework the handling of stop signals in the NFS client. The changes inJohn Baldwin2013-02-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 195702, 195703, and 195821 prevented a thread from suspending while holding locks inside of NFS by forcing the thread to fail sleeps with EINTR or ERESTART but defer the thread suspension to the user boundary. However, this had the effect that stopping a process during an NFS request could abort the request and trigger EINTR errors that were visible to userland processes (previously the thread would have suspended and completed the request once it was resumed). This change instead effectively masks stop signals while in the NFS client. It uses the existing TDF_SBDRY flag to effect this since SIGSTOP cannot be masked directly. Also, instead of setting PBDRY on individual sleeps, the NFS client now sets the TDF_SBDRY flag around each NFS request and stop signals are masked for all sleeps during that region (the previous change missed sleeps in lockmgr locks). The end result is that stop signals sent to threads performing an NFS request are completely ignored until after the NFS request has finished processing and the thread prepares to return to userland. This restores the behavior of stop signals being transparent to userland processes while still preventing threads from suspending while holding NFS locks. Reviewed by: kib MFC after: 1 month Notes: svn path=/head/; revision=246417
* In order to maximize the re-usability of kernel code in user space thisKip Macy2011-09-161-1/+1
| | | | | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz) Notes: svn path=/head/; revision=225617
* Create a global thread hash table to speed up thread lookup, useDavid Xu2010-10-091-1/+10
| | | | | | | | | | | | | rwlock to protect the table. In old code, thread lookup is done with process lock held, to find a thread, kernel has to iterate through process and thread list, this is quite inefficient. With this change, test shows in extreme case performance is dramatically improved. Earlier patch was reviewed by: jhb, julian Notes: svn path=/head/; revision=213642
* - Various style and whitespace fixes.John Baldwin2010-07-081-74/+64
| | | | | | | | | | - Make sugid_coredump and kern_logsigexit private to kern_sig.c. Submitted by: bde (partially) MFC after: 1 month Notes: svn path=/head/; revision=209819
* Move prototypes for kern_sigtimedwait() and kern_sigprocmask() toJohn Baldwin2010-06-301-4/+1
| | | | | | | <sys/syscallsubr.h> where all other kern_<syscall> prototypes live. Notes: svn path=/head/; revision=209613
* Sort function prototypes (since I didn't manage to insert tdksignal()John Baldwin2010-06-291-9/+9
| | | | | | | correctly). Notes: svn path=/head/; revision=209596
* Tweak the in-kernel API for sending signals to threads:John Baldwin2010-06-291-3/+3
| | | | | | | | | | | | | - Rename tdsignal() to tdsendsignal() and make it private to kern_sig.c. - Add tdsignal() and tdksignal() routines that mirror psignal() and pksignal() except that they accept a thread as an argument instead of a process. They send a signal to a specific thread rather than to an individual process. Reviewed by: kib Notes: svn path=/head/; revision=209592
* Staticise sigqueue manipulation functions used only in kern_sig.c.Konstantin Belousov2010-01-231-9/+1
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=202881
* When traced process is about to receive the signal, the process isKonstantin Belousov2010-01-201-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | stopped and debugger may modify or drop the signal. After the changes to keep process-targeted signals on the process sigqueue, another thread may note the old signal on the queue and act before the thread removes changed or dropped signal from the process queue. Since process is traced, it usually gets stopped. Or, if the same signal is delivered while process was stopped, the thread may erronously remove it, intending to remove the original signal. Remove the signal from the queue before notifying the debugger. Restore the siginfo to the head of sigqueue when signal is allowed to be delivered to the debugee, using newly introduced KSI_HEAD ksiginfo_t flag. This preserves required order of delivery. Always restore the unchanged signal on the curthread sigqueue, not to the process queue, since the thread is about to get it anyway, because sigmask cannot be changed. Handle failure of reinserting the siginfo into the queue by falling back to sq_kill method, calling sigqueue_add with NULL ksi. If debugger changed the signal to be delivered, use sigqueue_add() with NULL ksi instead of only setting sq_signals bit. Reported by: Gardner Bell <gbell72 rogers com> Analyzed and first version of fix by: Tijl Coosemans <tijl coosemans org> PR: 142757 Reviewed by: davidxu MFC after: 2 weeks Notes: svn path=/head/; revision=202692
* Implement sighold, sigignore, sigpause, sigrelse, sigset functionsKonstantin Belousov2009-11-261-1/+1
| | | | | | | | | | | | | from SUSv4 XSI. Note that the functions are obsoleted, and only provided to ease porting from System V-like systems. Since sigpause already exists in compat with different interface, XSI sigpause is named xsi_sigpause. Reviewed by: davidxu MFC after: 3 weeks Notes: svn path=/head/; revision=199827
* Among signal generation syscalls, only sigqueue(2) is allowed by POSIXKonstantin Belousov2009-11-171-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | to fail due to lack of resources to queue siginfo. Add KSI_SIGQ flag that allows sigqueue_add() to fail while trying to allocate memory for new siginfo. When the flag is not set, behaviour is the same as for KSI_TRAP: if memory cannot be allocated, set bit in sq_kill. KSI_TRAP is kept to preserve KBI. Add SI_KERNEL si_code, to be used in siginfo.si_code when signal is generated by kernel. Deliver siginfo when signal is generated by kill(2) family of syscalls (SI_USER with properly filled si_uid and si_pid), or by kernel (SI_KERNEL, mostly job control or SIGIO). Since KSI_SIGQ flag is not set for the ksi, low memory condition cause old behaviour. Keep psignal(9) KBI intact, but modify it to generate SI_KERNEL si_code. Pgsignal(9) and gsignal(9) now take ksi explicitely. Add pksignal(9) that behaves like psignal but takes ksi, and ddb kill command implemented as pksignal(..., ksi = NULL) to not do allocation while in debugger. While there, remove some register specifiers and use ANSI C prototypes. Reviewed by: davidxu MFC after: 1 month Notes: svn path=/head/; revision=199355
* In r198506, kern_sigsuspend() started doing cursig/postsig loop to makeKonstantin Belousov2009-11-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | sure that a signal was delivered to the thread before returning from syscall. Signal delivery puts new return frame on the user stack, and modifies trap frame to enter signal handler. As a consequence, syscall return code sets EINTR as error return for signal frame, instead of the syscall return. Also, for ia64, due to different registers layout for those two kind of frames, usermode sigsegfaulted when returned from signal handler. Use newly-introduced cpu_set_syscall_retval(9) to set syscall result, and return EJUSTRETURN from kern_sigsuspend() to prevent syscall return code from modifying this frame [1]. Another issue is that pending SIGCONT might be cancelled by SIGSTOP, causing postsig() not to deliver any catched signal [2]. Modify postsig() to return 1 if signal was posted, and 0 otherwise, and use this in the kern_sigsuspend loop. Proposed by: marcel [1] Noted by: davidxu [2] Reviewed by: marcel, davidxu MFC after: 1 month Notes: svn path=/head/; revision=199136
* Trapsignal() and postsig() call kern_sigprocmask() with both processKonstantin Belousov2009-10-301-0/+1
| | | | | | | | | | | | | | | lock and curproc->p_sigacts->ps_mtx. Reschedule_signals may need to have ps_mtx locked to decide and wakeup a thread, causing recursion on the mutex. Inform kern_sigprocmask() and reschedule_signals() about lock state of the ps_mtx by new flag SIGPROCMASK_PS_LOCKED to avoid recursion. Reported and tested by: keramida MFC after: 1 month Notes: svn path=/head/; revision=198670
* In kern_sigsuspend(), better manipulate thread signal mask usingKonstantin Belousov2009-10-271-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | kern_sigprocmask() to properly notify other possible candidate threads for signal delivery. Since sigsuspend() shall only return to usermode after a signal was delivered, do cursig/postsig loop immediately after waiting for signal, repeating the wait if wakeup was spurious due to race with other thread fetching signal from the process queue before us. Add thread_suspend_check() call to allow the thread to be stopped or killed while in loop. Modify last argument of kern_sigprocmask() from boolean to flags, allowing the function to be called with locked proc. Convertion of the callers that supplied 1 to the old argument will be done in the next commit, and due to SIGPROCMASK_OLD value equial to 1, code is formally correct in between. Reviewed by: davidxu Tested by: pho MFC after: 1 month Notes: svn path=/head/; revision=198506
* Currently, when signal is delivered to the process and there is a threadKonstantin Belousov2009-10-111-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | not blocking the signal, signal is placed on the thread sigqueue. If the selected thread is in kernel executing thr_exit() or sigprocmask() syscalls, then signal might be not delivered to usermode for arbitrary amount of time, and for exiting thread it is lost. Put process-directed signals to the process queue unconditionally, selecting the thread to deliver the signal only by the thread returning to usermode, since only then the thread can handle delivery of signal reliably. For exiting thread or thread that has blocked some signals, check whether the newly blocked signal is queued for the process, and try to find a thread to wakeup for delivery, in reschedule_signal(). For exiting thread, assume that all signals are blocked. Change cursig() and postsig() to look both into the thread and process signal queues. When there is a signal that thread returning to usermode could consume, TDF_NEEDSIGCHK flag is not neccessary set now. Do unlocked read of p_siglist and p_pendingcnt to check for queued signals. Note that thread that has a signal unblocked might get spurious wakeup and EINTR from the interruptible system call now, due to the possibility of being selected by reschedule_signals(), while other thread returned to usermode earlier and removed the signal from process queue. This should not cause compliance issues, since the thread has not blocked a signal and thus should be ready to receive it anyway. Reported by: Justin Teller <justin.teller gmail com> Reviewed by: davidxu, jilles MFC after: 1 month Notes: svn path=/head/; revision=197963
* Add new msleep(9) flag PBDY that shall be specified together withKonstantin Belousov2009-07-141-1/+5
| | | | | | | | | | | | | | | PCATCH, to indicate that thread shall not be stopped upon receipt of SIGSTOP until it reaches the kernel->usermode boundary. Also change thread_single(SINGLE_NO_EXIT) to only stop threads at the user boundary unconditionally. Tested by: pho Reviewed by: jhb Approved by: re (kensmith) Notes: svn path=/head/; revision=195702
* Fix for the panic("vm_thread_new: kstack allocation failed") andKonstantin Belousov2007-11-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | silent NULL pointer dereference in the i386 and sparc64 pmap_pinit() when the kmem_alloc_nofault() failed to allocate address space. Both functions now return error instead of panicing or dereferencing NULL. As consequence, vmspace_exec() and vmspace_unshare() returns the errno int. struct vmspace arg was added to vm_forkproc() to avoid dealing with failed allocation when most of the fork1() job is already done. The kernel stack for the thread is now set up in the thread_alloc(), that itself may return NULL. Also, allocation of the first process thread is performed in the fork1() to properly deal with stack allocation failure. proc_linkup() is separated into proc_linkup() called from fork1(), and proc_linkup0(), that is used to set up the kernel process (was known as swapper). In collaboration with: Peter Holm Reviewed by: jhb Notes: svn path=/head/; revision=173361
* Move some declaration of 32-bit signal structures into fileDavid Xu2006-10-051-0/+2
| | | | | | | freebsd32-signal.h, implement sigtimedwait and sigwaitinfo system calls. Notes: svn path=/head/; revision=163018
* Add signal set sq_kill to sigqueue structure, the member saves allDavid Xu2006-03-021-2/+3
| | | | | | | | signals sent by kill() syscall, without this, a signal sent by sigqueue() can cause a signal sent by kill() to be lost. Notes: svn path=/head/; revision=156213
* Sync with signal.h.David Xu2005-12-061-0/+1
| | | | Notes: svn path=/head/; revision=153159
* Add support for queueing SIGCHLD same as other UNIX systems did.David Xu2005-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | For each child process whose status has been changed, a SIGCHLD instance is queued, if the signal is stilling pending, and process changed status several times, signal information is updated to reflect latest process status. If wait() returns because the status of a child process is available, pending SIGCHLD signal associated with the child process is discarded. Any other pending SIGCHLD signals remain pending. The signal information is allocated at the same time when proc structure is allocated, if process signal queue is fully filled or there is a memory shortage, it can still send the signal to process. There is a booting time tunable kern.sigqueue.queue_sigchild which can control the behavior, setting it to zero disables the SIGCHLD queueing feature, the tunable will be removed if the function is proved that it is stable enough. Tested on: i386 (SMP and UP) Notes: svn path=/head/; revision=152185
* Cleanup some signal interfaces. Now the tdsignal function acceptsDavid Xu2005-11-031-10/+3
| | | | | | | | | | | | both proc pointer and thread pointer, if thread pointer is NULL, tdsignal automatically finds a thread, otherwise it sends signal to given thread. Add utility function psignal_event to send a realtime sigevent to a process according to the delivery requirement specified in struct sigevent. Notes: svn path=/head/; revision=151993
* Fix sigevent's POSIX incompatible problem by adding member fieldsDavid Xu2005-10-301-0/+9
| | | | | | | | | | sigev_notify_function and sigev_notify_attributes. AIO syscalls use sigevent, so they have to be adjusted. Reviewed by: alc Notes: svn path=/head/; revision=151867
* 1. Make ksiginfo_alloc and ksiginfo_free public.David Xu2005-10-231-1/+12
| | | | | | | | | 2. Introduce flags KSI_EXT and KSI_INS. The flag KSI_EXT allows a ksiginfo to be managed by outside code, the KSI_INS indicates sigqueue_add should directly insert passed ksiginfo into queue other than copy it. Notes: svn path=/head/; revision=151575
* 1. Change prototype of trapsignal and sendsig to use ksiginfo_t *, mostDavid Xu2005-10-141-3/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | changes in MD code are trivial, before this change, trapsignal and sendsig use discrete parameters, now they uses member fields of ksiginfo_t structure. For sendsig, this change allows us to pass POSIX realtime signal value to user code. 2. Remove cpu_thread_siginfo, it is no longer needed because we now always generate ksiginfo_t data and feed it to libpthread. 3. Add p_sigqueue to proc structure to hold shared signals which were blocked by all threads in the proc. 4. Add td_sigqueue to thread structure to hold all signals delivered to thread. 5. i386 and amd64 now return POSIX standard si_code, other arches will be fixed. 6. In this sigqueue implementation, pending signal set is kept as before, an extra siginfo list holds additional siginfo_t data for signals. kernel code uses psignal() still behavior as before, it won't be failed even under memory pressure, only exception is when deleting a signal, we should call sigqueue_delete to remove signal from sigqueue but not SIGDELSET. Current there is no kernel code will deliver a signal with additional data, so kernel should be as stable as before, a ksiginfo can carry more information, for example, allow signal to be delivered but throw away siginfo data if memory is not enough. SIGKILL and SIGSTOP have fast path in sigqueue_add, because they can not be caught or masked. The sigqueue() syscall allows user code to queue a signal to target process, if resource is unavailable, EAGAIN will be returned as specification said. Just before thread exits, signal queue memory will be freed by sigqueue_flush. Current, all signals are allowed to be queued, not only realtime signals. Earlier patch reviewed by: jhb, deischen Tested on: i386, amd64 Notes: svn path=/head/; revision=151316
* Add ksiginfo_t which is a wrapper of siginfo_t but allows us to carryDavid Xu2005-10-141-0/+39
| | | | | | | | | more information which should not be in siginfo_t. Reviewed by: jhb, deischen Notes: svn path=/head/; revision=151307
* /* -> /*- for license, minor formatting changesWarner Losh2005-01-071-1/+1
| | | | Notes: svn path=/head/; revision=139825