1*01869ca4Swiz.\" $NetBSD: signal.9,v 1.24 2017/07/03 21:28:48 wiz Exp $ 23acbaeb0Sthorpej.\" 33acbaeb0Sthorpej.\" Copyright (c) 1996, 2002 The NetBSD Foundation, Inc. 43acbaeb0Sthorpej.\" All rights reserved. 53acbaeb0Sthorpej.\" 63acbaeb0Sthorpej.\" This code is derived from software contributed to The NetBSD Foundation 73acbaeb0Sthorpej.\" by Paul Kranenburg and Jason R. Thorpe. 83acbaeb0Sthorpej.\" 93acbaeb0Sthorpej.\" Redistribution and use in source and binary forms, with or without 103acbaeb0Sthorpej.\" modification, are permitted provided that the following conditions 113acbaeb0Sthorpej.\" are met: 123acbaeb0Sthorpej.\" 1. Redistributions of source code must retain the above copyright 133acbaeb0Sthorpej.\" notice, this list of conditions and the following disclaimer. 143acbaeb0Sthorpej.\" 2. Redistributions in binary form must reproduce the above copyright 153acbaeb0Sthorpej.\" notice, this list of conditions and the following disclaimer in the 163acbaeb0Sthorpej.\" documentation and/or other materials provided with the distribution. 173acbaeb0Sthorpej.\" 183acbaeb0Sthorpej.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 193acbaeb0Sthorpej.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 203acbaeb0Sthorpej.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 213acbaeb0Sthorpej.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 223acbaeb0Sthorpej.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 233acbaeb0Sthorpej.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 243acbaeb0Sthorpej.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 253acbaeb0Sthorpej.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 263acbaeb0Sthorpej.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 273acbaeb0Sthorpej.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 283acbaeb0Sthorpej.\" POSSIBILITY OF SUCH DAMAGE. 293acbaeb0Sthorpej.\" 303b3385bdSjruoho.Dd April 29, 2010 313acbaeb0Sthorpej.Dt SIGNAL 9 323acbaeb0Sthorpej.Os 333acbaeb0Sthorpej.Sh NAME 343acbaeb0Sthorpej.Nm signal , 353acbaeb0Sthorpej.Nm siginit , 363acbaeb0Sthorpej.Nm sigactsinit , 373acbaeb0Sthorpej.Nm sigactsunshare , 383acbaeb0Sthorpej.Nm sigactsfree , 393acbaeb0Sthorpej.Nm execsigs , 403acbaeb0Sthorpej.Nm sigaction1 , 413acbaeb0Sthorpej.Nm sigprocmask1 , 423acbaeb0Sthorpej.Nm sigpending1 , 433acbaeb0Sthorpej.Nm sigsuspend1 , 443acbaeb0Sthorpej.Nm sigaltstack1 , 453acbaeb0Sthorpej.Nm pgsignal , 46c9a477dbSjruoho.Nm kpgsignal , 473acbaeb0Sthorpej.Nm psignal , 48c9a477dbSjruoho.Nm kpsignal , 493acbaeb0Sthorpej.Nm issignal , 503acbaeb0Sthorpej.Nm postsig , 513acbaeb0Sthorpej.Nm killproc , 523acbaeb0Sthorpej.Nm sigexit , 53245108acSchristos.Nm trapsignal , 543acbaeb0Sthorpej.Nm sendsig , 553acbaeb0Sthorpej.Nm sigcode , 566fddba0bSenami.Nm sigtramp 573acbaeb0Sthorpej.Nd software signal facilities 583acbaeb0Sthorpej.Sh SYNOPSIS 59472351e1Swiz.In sys/signal.h 60472351e1Swiz.In sys/signalvar.h 613acbaeb0Sthorpej.Ft void 623acbaeb0Sthorpej.Fn siginit "struct proc *p" 633acbaeb0Sthorpej.Ft void 649b64ec26Sjruoho.Fn sigactsinit "struct proc *pp" "int share" 653acbaeb0Sthorpej.Ft void 66ebf3ebe7Sisaki.Fn sigactsunshare "struct proc *p" 673acbaeb0Sthorpej.Ft void 683acbaeb0Sthorpej.Fn sigactsfree "struct proc *p" 693acbaeb0Sthorpej.Ft void 703acbaeb0Sthorpej.Fn execsigs "struct proc *p" 713acbaeb0Sthorpej.Ft int 729b64ec26Sjruoho.Fn sigaction1 "struct lwp *l" "int signum" "const struct sigaction *nsa" \ 733acbaeb0Sthorpej "struct sigaction *osa" "void *tramp" "int vers" 743acbaeb0Sthorpej.Ft int 759b64ec26Sjruoho.Fn sigprocmask1 "struct lwp *l" "int how" "const sigset_t *nss" \ 763acbaeb0Sthorpej "sigset_t *oss" 773acbaeb0Sthorpej.Ft void 789b64ec26Sjruoho.Fn sigpending1 "struct lwp *l" "sigset_t *ss" 793acbaeb0Sthorpej.Ft int 809b64ec26Sjruoho.Fn sigsuspend1 "struct lwp *l" "const sigset_t *ss" 813acbaeb0Sthorpej.Ft int 829b64ec26Sjruoho.Fn sigaltstack1 "struct lwp *l" "const struct sigaltstack *nss" \ 833acbaeb0Sthorpej "struct sigaltstack *oss" 843acbaeb0Sthorpej.Ft void 853acbaeb0Sthorpej.Fn pgsignal "struct pgrp *pgrp" "int signum" "int checkctty" 863acbaeb0Sthorpej.Ft void 87245108acSchristos.Fn kpgsignal "struct pgrp *pgrp" "ksiginfo_t *ks" "void *data" "int checkctty" 883acbaeb0Sthorpej.Ft void 893acbaeb0Sthorpej.Fn psignal "struct proc *p" "int signum" 903acbaeb0Sthorpej.Ft void 91245108acSchristos.Fn kpsignal "struct proc *p" "ksiginfo_t *ks" "void *data" 923acbaeb0Sthorpej.Ft int 937d7fe4b7Srpaulo.Fn issignal "struct lwp *l" 943acbaeb0Sthorpej.Ft void 953acbaeb0Sthorpej.Fn postsig "int signum" 963acbaeb0Sthorpej.Ft void 9708a69f7dSmanu.Fn killproc "struct proc *p" "const char *why" 983acbaeb0Sthorpej.Ft void 999b64ec26Sjruoho.Fn sigexit "struct lwp *l" "int signum" 1003acbaeb0Sthorpej.Ft void 1019b64ec26Sjruoho.Fn trapsignal "struct lwp *l" "const ksiginfo_t *ks" 102245108acSchristos.Ft void 103d68cb7dfSchristos.Fn sendsig "const ksiginfo_t *ks" "const sigset_t *mask" 1043acbaeb0Sthorpej.Sh DESCRIPTION 1053acbaeb0SthorpejThe system defines a set of signals that may be delivered to a process. 1063acbaeb0SthorpejThese functions implement the kernel portion of the signal facility. 1073acbaeb0Sthorpej.Pp 1083acbaeb0SthorpejSignal numbers used throughout the kernel signal facilities should 1093acbaeb0Sthorpejalways be within the range of 1103acbaeb0Sthorpej.Bq 1- Ns NSIG . 1113acbaeb0Sthorpej.Pp 1123acbaeb0SthorpejMost of the kernel's signal infrastructure is implemented in 113770eef21Swizmachine-independent code. 114770eef21SwizMachine-dependent code provides support for invoking a process's 115770eef21Swizsignal handler, restoring context when the signal handler returns, 116770eef21Swizgenerating signals when hardware traps occur, triggering the delivery 117770eef21Swizof signals when a process is about to return from the kernel to userspace. 1183acbaeb0Sthorpej.Pp 1193acbaeb0SthorpejThe signal state for a process is contained in 1203acbaeb0Sthorpej.Fa struct sigctx . 1213acbaeb0SthorpejThis includes the list of signals with delivery pending, 1223acbaeb0Sthorpejinformation about the signal handler stack, the signal mask, and the 1233acbaeb0Sthorpejaddress of the signal trampoline. 1243acbaeb0Sthorpej.Pp 1253acbaeb0SthorpejThe registered signal handlers for a process are recorded in 1263acbaeb0Sthorpej.Fa struct sigacts . 1273acbaeb0SthorpejThis structure may be shared by multiple processes. 1283acbaeb0Sthorpej.Pp 1293acbaeb0SthorpejThe kernel's signal facilities are implemented by the following 1303acbaeb0Sthorpejfunctions: 1313acbaeb0Sthorpej.Bl -tag -width XXXXX 13234f98fcdSjruoho.It Fn siginit "p" 1333acbaeb0Sthorpej.Pp 1343acbaeb0SthorpejThis function initializes the signal state of 1353acbaeb0Sthorpej.Va proc0 136770eef21Swizto the system default. 137770eef21SwizThis signal state is then inherited by 1383acbaeb0Sthorpej.Xr init 8 1393acbaeb0Sthorpejwhen it is started by the kernel. 1409b64ec26Sjruoho.It Fn sigactsinit "pp" "share" 1413acbaeb0Sthorpej.Pp 1423acbaeb0SthorpejThis function creates an initial 1433acbaeb0Sthorpej.Fa struct sigacts 1443acbaeb0Sthorpejfor the process 1459b64ec26Sjruoho.Fa pp . 1463acbaeb0SthorpejIf the 1473acbaeb0Sthorpej.Fa share 1483acbaeb0Sthorpejargument is non-zero, then 1499b64ec26Sjruoho.Fa pp 1503acbaeb0Sthorpejshares the 1513acbaeb0Sthorpej.Fa struct sigacts 1529b64ec26Sjruohoby holding a reference. 1533acbaeb0SthorpejOtherwise, 1549b64ec26Sjruoho.Fa pp 1553acbaeb0Sthorpejreceives a new 1563acbaeb0Sthorpej.Fa struct sigacts 1579b64ec26Sjruohowhich is copied from the parent. 15834f98fcdSjruoho.It Fn sigactsunshare "p" 1593acbaeb0Sthorpej.Pp 1603acbaeb0SthorpejThis function causes the process 1613acbaeb0Sthorpej.Fa p 1623acbaeb0Sthorpejto no longer share its 1633acbaeb0Sthorpej.Fa struct sigacts 1643acbaeb0SthorpejThe current state of the signal actions is maintained in the new copy. 16534f98fcdSjruoho.It Fn sigactsfree "p" 1663acbaeb0Sthorpej.Pp 1673acbaeb0SthorpejThis function decrements the reference count on the 1683acbaeb0Sthorpej.Fa struct sigacts 1693acbaeb0Sthorpejof process 1703acbaeb0Sthorpej.Fa p . 1713acbaeb0SthorpejIf the reference count reaches zero, the 1723acbaeb0Sthorpej.Fa struct sigacts 1733acbaeb0Sthorpejis freed. 17434f98fcdSjruoho.It Fn execsigs "p" 1753acbaeb0Sthorpej.Pp 1763acbaeb0SthorpejThis function is used to reset the signal state of the process 1773acbaeb0Sthorpej.Fa p 1783acbaeb0Sthorpejto the system defaults when the process execs a new program image. 1799b64ec26Sjruoho.It Fn sigaction1 "l" "signum" "nsa" "osa" "tramp" "vers" 1803acbaeb0Sthorpej.Pp 1813acbaeb0SthorpejThis function implements the 1823acbaeb0Sthorpej.Xr sigaction 2 183770eef21Swizsystem call. 184770eef21SwizThe 1853acbaeb0Sthorpej.Fa tramp 1863acbaeb0Sthorpejand 1873acbaeb0Sthorpej.Fa vers 1883acbaeb0Sthorpejarguments provide support for userspace signal trampolines. 1893acbaeb0SthorpejTrampoline version 0 is reserved for the legacy kernel-provided 1903acbaeb0Sthorpejsignal trampoline; 1913acbaeb0Sthorpej.Fa tramp 1929ff10e96Swizmust be 1939ff10e96Swiz.Dv NULL 1949ff10e96Swizin this case. 195770eef21SwizOtherwise, 1963acbaeb0Sthorpej.Fa vers 1973acbaeb0Sthorpejspecifies the ABI of the trampoline specified by 1983acbaeb0Sthorpej.Fa tramp . 199190d4218SwizThe signal trampoline ABI is machine-dependent, and must be coordinated 2003acbaeb0Sthorpejwith the 2013acbaeb0Sthorpej.Fn sendsig 2023acbaeb0Sthorpejfunction. 2039b64ec26Sjruoho.It Fn sigprocmask1 "l" "how" "nss" "oss" 2043acbaeb0Sthorpej.Pp 2053acbaeb0SthorpejThis function implements the 2063acbaeb0Sthorpej.Xr sigprocmask 2 2073acbaeb0Sthorpejsystem call. 2089b64ec26Sjruoho.It Fn sigpending1 "l" "ss" 2093acbaeb0Sthorpej.Pp 2103acbaeb0SthorpejThis function implements the 2113acbaeb0Sthorpej.Xr sigpending 2 2123acbaeb0Sthorpejsystem call. 2139b64ec26Sjruoho.It Fn sigsuspend1 "l" "ss" 2143acbaeb0Sthorpej.Pp 2153acbaeb0SthorpejThis function implements the 2163acbaeb0Sthorpej.Xr sigsuspend 2 2173acbaeb0Sthorpejsystem call. 2189b64ec26Sjruoho.It Fn sigaltstack1 "l" "nss" "oss" 2193acbaeb0Sthorpej.Pp 2203acbaeb0SthorpejThis function implements the 2213acbaeb0Sthorpej.Xr sigaltstack 2 2223acbaeb0Sthorpejsystem call. 22334f98fcdSjruoho.It Fn pgsignal "pgrp" "signum" "checkctty" 2243acbaeb0Sthorpej.Pp 225245108acSchristosThis is a wrapper function for 226245108acSchristos.Fn kpgsignal 227245108acSchristoswhich is described below. 22834f98fcdSjruoho.It Fn kpgsignal "pgrp" "ks" "data" "checkctty" 229245108acSchristos.Pp 2303acbaeb0SthorpejSchedule the signal 231*01869ca4Swiz.Fa ks->ksi_signo 2323acbaeb0Sthorpejto be delivered to all members of the process group 2333acbaeb0Sthorpej.Fa pgrp . 2343acbaeb0SthorpejIf 2353acbaeb0Sthorpej.Fa checkctty 2363acbaeb0Sthorpejis non-zero, the signal is only sent to processes which have a 237770eef21Swizcontrolling terminal. 238245108acSchristosThe 239245108acSchristos.Fa data 240245108acSchristosargument and the complete signal scheduling semantics are described in the 241245108acSchristos.Fn kpsignal 242245108acSchristosfunction below. 2439b64ec26Sjruoho.It Fn trapsignal "l" "ks" 2443acbaeb0Sthorpej.Pp 2453acbaeb0SthorpejSends the signal 246*01869ca4Swiz.Fa ks->ksi_signo 2479b64ec26Sjruohocaused by a hardware trap to the current process. 2489b64ec26Sjruoho.\" 2499b64ec26Sjruoho.\" XXX: Check for reality in 2010. 2509b64ec26Sjruoho.\" 2519b64ec26Sjruoho.\" This function is meant to be called by machine-dependent trap handling 2529b64ec26Sjruoho.\" code, through the 253*01869ca4Swiz.\" .Dv p->p_emul->e_trapsignal 2549b64ec26Sjruoho.\" function pointer because some emulations define their own trapsignal 2559b64ec26Sjruoho.\" functions that remap the signal information to what the emulation 2569b64ec26Sjruoho.\" expects. 25734f98fcdSjruoho.It Fn psignal "p" "signum" 2583acbaeb0Sthorpej.Pp 259245108acSchristosThis is a wrapper function for 260ebf3ebe7Sisaki.Fn kpsignal 261245108acSchristoswhich is described below. 26234f98fcdSjruoho.It Fn kpsignal "p" "ks" "data" 263245108acSchristos.Pp 2643acbaeb0SthorpejSchedule the signal 265*01869ca4Swiz.Fa ks->ksi_signo 2663acbaeb0Sthorpejto be delivered to the process 2673acbaeb0Sthorpej.Fa p . 268245108acSchristosThe 269245108acSchristos.Fa data 2709ff10e96Swizargument, if not 2719ff10e96Swiz.Dv NULL , 2729ff10e96Swizpoints to the file descriptor data that caused the 273245108acSchristossignal to be generated in the 274245108acSchristos.Li SIGIO 275245108acSchristoscase. 276245108acSchristos.Pp 2773acbaeb0SthorpejWith a few exceptions noted below, the target process signal disposition is 2783acbaeb0Sthorpejupdated and is marked as runnable, so further handling of the signal is done 2793acbaeb0Sthorpejin the context of the target process after a context switch; see 2803acbaeb0Sthorpej.Fn issignal 2813acbaeb0Sthorpejbelow. 2823acbaeb0SthorpejNote that 283245108acSchristos.Fn kpsignal 2843acbaeb0Sthorpejdoes not by itself cause a context switch to happen. 2853acbaeb0Sthorpej.Pp 2863acbaeb0SthorpejThe target process is not marked as runnable in the following cases: 2873acbaeb0Sthorpej.Bl -bullet -offset indent 2883acbaeb0Sthorpej.It 289770eef21SwizThe target process is sleeping uninterruptibly. 290770eef21SwizThe signal will be noticed when the process returns from the system 291770eef21Swizcall or trap. 2923acbaeb0Sthorpej.It 2933acbaeb0SthorpejThe target process is currently ignoring the signal. 2943acbaeb0Sthorpej.It 2953acbaeb0SthorpejIf a stop signal is sent to a sleeping process that takes the 2963acbaeb0Sthorpejdefault action 2973acbaeb0Sthorpej.Pq see Xr sigaction 2 , 2983acbaeb0Sthorpejthe process is stopped without awakening it. 2993acbaeb0Sthorpej.It 3003acbaeb0SthorpejSIGCONT 3013acbaeb0Sthorpejrestarts a stopped process 3023acbaeb0Sthorpej.Pq or puts them back to sleep 3033acbaeb0Sthorpejregardless of the signal action 3043acbaeb0Sthorpej.Pq e.g., blocked or ignored . 3053acbaeb0Sthorpej.El 3063acbaeb0Sthorpej.Pp 3073acbaeb0SthorpejIf the target process is being traced, 308245108acSchristos.Fn kpsignal 3093acbaeb0Sthorpejbehaves as if the target process were taking the default action for 3103acbaeb0Sthorpej.Fa signum . 3113acbaeb0SthorpejThis allows the tracing process to be notified of the signal. 31234f98fcdSjruoho.It Fn issignal "l" 3133acbaeb0Sthorpej.Pp 3149b64ec26SjruohoThis function determines which signal, if any, 3159b64ec26Sjruohois to be posted to the current process. 3163acbaeb0SthorpejA signal is to be posted if: 3173acbaeb0Sthorpej.Bl -bullet -offset indent 3183acbaeb0Sthorpej.It 3193acbaeb0SthorpejThe signal has a handler provided by the program image. 3203acbaeb0Sthorpej.It 3213acbaeb0SthorpejThe signal should cause the process to dump core and/or terminate. 3223acbaeb0Sthorpej.It 3233acbaeb0SthorpejThe signal should interrupt the current system call. 3243acbaeb0Sthorpej.El 3253acbaeb0Sthorpej.Pp 3263acbaeb0SthorpejSignals which cause the process to be stopped are handled within 3273acbaeb0Sthorpej.Fn issignal 3283acbaeb0Sthorpejdirectly. 3293acbaeb0Sthorpej.Pp 3303acbaeb0Sthorpej.Fn issignal 3313acbaeb0Sthorpejshould be called by machine-dependent code when returning to 3323acbaeb0Sthorpejuserspace from a system call or other trap or interrupt by 3333acbaeb0Sthorpejusing the following code: 3343acbaeb0Sthorpej.Bd -literal -offset indent 3353acbaeb0Sthorpejwhile (signum = CURSIG(curproc)) 3363acbaeb0Sthorpej postsig(signum); 3373acbaeb0Sthorpej.Ed 3383acbaeb0Sthorpej.Pp 33934f98fcdSjruoho.It Fn postsig "signum" 3403acbaeb0Sthorpej.Pp 3413acbaeb0SthorpejThe 3423acbaeb0Sthorpej.Fn postsig 3433acbaeb0Sthorpejfunction is used to invoke the action for the signal 3443acbaeb0Sthorpej.Fa signum 345770eef21Swizin the current process. 346770eef21SwizIf the default action of a signal is to terminate the process, and the 347770eef21Swizsignal does not have a registered handler, the process exits using 3483acbaeb0Sthorpej.Fn sigexit , 3493acbaeb0Sthorpejdumping a core image if necessary. 35034f98fcdSjruoho.It Fn killproc "p" "why" 3513acbaeb0Sthorpej.Pp 352770eef21SwizThis function sends a SIGKILL signal to the specified process. 353770eef21SwizThe message provided by 3543acbaeb0Sthorpej.Fa why 3553acbaeb0Sthorpejis sent to the system log and is also displayed on the process's 3563acbaeb0Sthorpejcontrolling terminal. 3579b64ec26Sjruoho.It Fn sigexit "l" "signum" 3583acbaeb0Sthorpej.Pp 3599b64ec26SjruohoThis function forces the current process to exit with the signal 3603acbaeb0Sthorpej.Fa signum , 361770eef21Swizgenerating a core file if appropriate. 362770eef21SwizNo checks are made for masked or caught signals; the process always exits. 36334f98fcdSjruoho.It Fn sendsig "ks" "mask" 3643acbaeb0Sthorpej.Pp 3653acbaeb0SthorpejThis function is provided by machine-dependent code, and is used to 3663acbaeb0Sthorpejinvoke a signal handler for the current process. 3673acbaeb0Sthorpej.Fn sendsig 3683acbaeb0Sthorpejmust prepare the registers and stack of the current process to 3693acbaeb0Sthorpejinvoke the signal handler stored in the process's 3703acbaeb0Sthorpej.Fa struct sigacts . 3713acbaeb0SthorpejThis may include switching to an alternate signal 372770eef21Swizstack specified by the process. 373770eef21SwizThe previous register, stack, and signal state are stored in a 374245108acSchristos.Fa ucontext_t , 3753acbaeb0Sthorpejwhich is then copied out to the user's stack. 3763acbaeb0Sthorpej.Pp 377190d4218SwizThe registers and stack must be set up to invoke the signal handler as 3783acbaeb0Sthorpejfollows: 3793acbaeb0Sthorpej.Bd -literal -offset indent 380245108acSchristos(*handler)(int signum, siginfo_t *info, void *ctx) 3813acbaeb0Sthorpej.Ed 3823acbaeb0Sthorpej.Pp 3833acbaeb0Sthorpejwhere 3843acbaeb0Sthorpej.Fa signum 3853acbaeb0Sthorpejis the signal number, 386245108acSchristos.Fa info 387245108acSchristoscontains additional signal specific information when 388245108acSchristos.Li SA_SIGINFO 389245108acSchristosis specified when setting up the signal handler. 390245108acSchristos.Fa ctx 391245108acSchristosis the pointer to 392245108acSchristos.Fa ucontext_t 393770eef21Swizon the user's stack. 394770eef21SwizThe registers and stack must also arrange for the signal handler to 395770eef21Swizreturn to the signal trampoline. 3963acbaeb0SthorpejThe trampoline is then used to return to the code which was executing 3973acbaeb0Sthorpejwhen the signal was delivered using the 398245108acSchristos.Xr setcontext 2 3993acbaeb0Sthorpejsystem call. 4003acbaeb0Sthorpej.Pp 4013acbaeb0SthorpejFor performance reasons, it is recommended that 4023acbaeb0Sthorpej.Fn sendsig 4033acbaeb0Sthorpejarrange for the signal handler to be invoked directly on architectures 404770eef21Swizwhere it is convenient to do so. 405770eef21SwizIn this case, the trampoline is used only for the signal return path. 406770eef21SwizIf it is not feasible to directly invoke the signal handler, the 407770eef21Swiztrampoline is also used to invoke the handler, performing any final 408770eef21Swizset up that was not possible for 4093acbaeb0Sthorpej.Fn sendsig 4103acbaeb0Sthorpejto perform. 4113acbaeb0Sthorpej.Pp 4123acbaeb0Sthorpej.Fn sendsig 413770eef21Swizmust invoke the signal trampoline with the correct ABI. 414770eef21SwizThe ABI of the signal trampoline is specified on a per-signal basis in the 4153acbaeb0Sthorpej.Fn sigacts 416770eef21Swizstructure for the process. 417770eef21SwizTrampoline version 0 is reserved for the legacy kernel-provided, 418770eef21Swizon-stack signal trampoline. 419770eef21SwizAll other trampoline versions indicate a specific trampoline ABI. 420770eef21SwizThis ABI is coordinated with machine-dependent code in the system 421770eef21SwizC library. 4223acbaeb0Sthorpej.El 4233acbaeb0Sthorpej.Ss SIGNAL TRAMPOLINE 4243acbaeb0SthorpejThe signal trampoline is a special piece of code which provides 425770eef21Swizsupport for invoking the signal handlers for a process. 426770eef21SwizThe trampoline is used to return from the signal handler back to the 427770eef21Swizcode which was executing when the signal was delivered, and is also used 428770eef21Swizto invoke the handler itself on architectures where it is not feasible to 429770eef21Swizhave the kernel invoke the handler directly. 4303acbaeb0Sthorpej.Pp 4313acbaeb0SthorpejIn traditional 4323acbaeb0Sthorpej.Ux 4333acbaeb0Sthorpejsystems, the signal trampoline, also referred to as the 4343acbaeb0Sthorpej.Dq sigcode , 4353acbaeb0Sthorpejis provided by the kernel and copied to the top of the user's 4363acbaeb0Sthorpejstack when a new process is created or a new program image is 437770eef21Swizexec'd. 438770eef21SwizStarting in 4393acbaeb0Sthorpej.Nx 2.0 , 440770eef21Swizthe signal trampoline is provided by the system C library. 441770eef21SwizThis allows for more flexibility when the signal facility is extended, 4423acbaeb0Sthorpejmakes dealing with signals easier in debuggers, such as 4433acbaeb0Sthorpej.Xr gdb 1 , 4443acbaeb0Sthorpejand may also enhance system security by allowing the kernel to 4453acbaeb0Sthorpejdisallow execution of code on the stack. 4463acbaeb0Sthorpej.Pp 447770eef21SwizThe signal trampoline is specified on a per-signal basis. 448770eef21SwizThe correct trampoline is selected automatically by the C library 4493acbaeb0Sthorpejwhen a signal handler is registered by a process. 4503acbaeb0Sthorpej.Pp 4513acbaeb0SthorpejSignal trampolines have a special naming convention which enables 4523acbaeb0Sthorpejdebuggers to determine the characteristics of the signal handler 453770eef21Swizand its arguments. 454770eef21SwizTrampoline functions are named like so: 4553acbaeb0Sthorpej.Bd -literal -offset indent 456*01869ca4Swiz__sigtramp_<flavor>_<version> 4573acbaeb0Sthorpej.Ed 4583acbaeb0Sthorpej.Pp 4593acbaeb0Sthorpejwhere: 4603acbaeb0Sthorpej.Bl -tag -width versionXX 4619ff10e96Swiz.It Aq flavor 462770eef21SwizThe flavor of the signal handler. 463770eef21SwizThe following flavors are valid: 4643acbaeb0Sthorpej.Bl -tag -width sigcontextXX 4653acbaeb0Sthorpej.It sigcontext 466245108acSchristosSpecifies a traditional BSD-style (deprecated) signal handler with the 467245108acSchristosfollowing signature: 4683acbaeb0Sthorpej.Bd -literal 4693acbaeb0Sthorpejvoid (*handler)(int signum, 4703acbaeb0Sthorpej int code, 4713acbaeb0Sthorpej struct sigcontext *scp); 4723acbaeb0Sthorpej.Ed 4733acbaeb0Sthorpej.It siginfo 4743acbaeb0SthorpejSpecifies a POSIX-style signal handler with the following signature: 4753acbaeb0Sthorpej.Bd -literal 4763acbaeb0Sthorpejvoid (*handler)(int signum, 477245108acSchristos siginfo_t *si, 4783acbaeb0Sthorpej void *uc); 4793acbaeb0Sthorpej.Ed 4803acbaeb0Sthorpej.Pp 481245108acSchristosNote: sigcontext style signal handlers are deprecated, and retained only 482245108acSchristosfor compatibility with older binaries. 4833acbaeb0Sthorpej.El 4849ff10e96Swiz.It Aq version 485770eef21SwizSpecifies the ABI version of the signal trampoline. 486770eef21SwizThe trampoline ABI is coordinated with the machine-dependent kernel 4873acbaeb0Sthorpej.Fn sendsig 4883acbaeb0Sthorpejfunction. 489245108acSchristosThe trampoline version needs to be unique even across different trampoline 490245108acSchristosflavors, in order to simplify trampoline selection in the kernel. 4913acbaeb0Sthorpej.El 4923acbaeb0Sthorpej.Pp 4933acbaeb0SthorpejThe following is an example if a signal trampoline name which indicates 4943acbaeb0Sthorpejthat the trampoline is used for traditional BSD-style signal handlers 4953acbaeb0Sthorpejand implements version 1 of the signal trampoline ABI: 4963acbaeb0Sthorpej.Bd -literal -offset indent 4973acbaeb0Sthorpej__sigtramp_sigcontext_1 4983acbaeb0Sthorpej.Ed 499245108acSchristos.Pp 500245108acSchristosThe current signal trampoline is: 501245108acSchristos.Bd -literal -offset indent 502245108acSchristos__sigtramp_siginfo_2 503b77e6250Syamt.Ed 5043acbaeb0Sthorpej.Sh SEE ALSO 5053acbaeb0Sthorpej.Xr sigaction 2 , 5063acbaeb0Sthorpej.Xr signal 7 , 50753d643b5Sad.Xr condvar 9 508