xref: /freebsd/lib/libc/compat-43/sigvec.2 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1.\" Copyright (c) 1980, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd April 2, 2022
29.Dt SIGVEC 2
30.Os
31.Sh NAME
32.Nm sigvec
33.Nd software signal facilities
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.In signal.h
38.Bd -literal
39struct sigvec {
40        void     (*sv_handler)();
41	int      sv_mask;
42	int      sv_flags;
43};
44.Ed
45.Ft int
46.Fn sigvec "int sig" "struct sigvec *vec" "struct sigvec *ovec"
47.Sh DESCRIPTION
48.Bf -symbolic
49This interface is made obsolete by
50.Xr sigaction 2 .
51.Ef
52.Pp
53The system defines a set of signals that may be delivered to a process.
54Signal delivery resembles the occurrence of a hardware interrupt:
55the signal is blocked from further occurrence, the current process
56context is saved, and a new one is built.
57A process may specify a
58.Em handler
59to which a signal is delivered, or specify that a signal is to be
60.Em blocked
61or
62.Em ignored .
63A process may also specify that a default action is to be taken
64by the system when a signal occurs.
65Normally, signal handlers execute on the current stack
66of the process.
67This may be changed, on a per-handler basis,
68so that signals are taken on a special
69.Em "signal stack" .
70.Pp
71All signals have the same
72.Em priority .
73Signal routines execute with the signal that caused their
74invocation
75.Em blocked ,
76but other signals may yet occur.
77A global
78.Em "signal mask"
79defines the set of signals currently blocked from delivery
80to a process.
81The signal mask for a process is initialized
82from that of its parent (normally 0).
83It
84may be changed with a
85.Xr sigblock 2
86or
87.Xr sigsetmask 2
88call, or when a signal is delivered to the process.
89.Pp
90When a signal
91condition arises for a process, the signal is added to a set of
92signals pending for the process.
93If the signal is not currently
94.Em blocked
95by the process then it is delivered to the process.
96When a signal
97is delivered, the current state of the process is saved,
98a new signal mask is calculated (as described below),
99and the signal handler is invoked.
100The call to the handler
101is arranged so that if the signal handling routine returns
102normally the process will resume execution in the context
103from before the signal's delivery.
104If the process wishes to resume in a different context, then it
105must arrange to restore the previous context itself.
106.Pp
107When a signal is delivered to a process a new signal mask is
108installed for the duration of the process' signal handler
109(or until a
110.Xr sigblock 2
111or
112.Xr sigsetmask 2
113call is made).
114This mask is formed by taking the current signal mask,
115adding the signal to be delivered, and
116.Em or Ns 'ing
117in the signal mask associated with the handler to be invoked.
118.Pp
119The
120.Fn sigvec
121function
122assigns a handler for a specific signal.
123If
124.Fa vec
125is non-zero, it
126specifies a handler routine and mask
127to be used when delivering the specified signal.
128Further, if the
129.Dv SV_ONSTACK
130bit is set in
131.Fa sv_flags ,
132the system will deliver the signal to the process on a
133.Em "signal stack" ,
134specified with
135.Xr sigaltstack 2 .
136If
137.Fa ovec
138is non-zero, the previous handling information for the signal
139is returned to the user.
140.Pp
141The following is a list of all signals
142with names as in the include file
143.In signal.h :
144.Bl -column SIGVTALARMXX "create core imagexxx"
145.It Sy "NAME	Default Action	Description"
146.It Dv SIGHUP No "	terminate process" "	terminal line hangup"
147.It Dv SIGINT No "	terminate process" "	interrupt program"
148.It Dv SIGQUIT No "	create core image" "	quit program"
149.It Dv SIGILL No "	create core image" "	illegal instruction"
150.It Dv SIGTRAP No "	create core image" "	trace trap"
151.It Dv SIGABRT No "	create core image" Ta Xr abort 3
152call (formerly
153.Dv SIGIOT )
154.It Dv SIGEMT No "	create core image" "	emulate instruction executed"
155.It Dv SIGFPE No "	create core image" "	floating-point exception"
156.It Dv SIGKILL No "	terminate process" "	kill program"
157.It Dv SIGBUS No "	create core image" "	bus error"
158.It Dv SIGSEGV No "	create core image" "	segmentation violation"
159.It Dv SIGSYS No "	create core image" "	non-existent system call invoked"
160.It Dv SIGPIPE No "	terminate process" "	write on a pipe with no reader"
161.It Dv SIGALRM No "	terminate process" "	real-time timer expired"
162.It Dv SIGTERM No "	terminate process" "	software termination signal"
163.It Dv SIGURG No "	discard signal" "	urgent condition present on socket"
164.It Dv SIGSTOP No "	stop process" "	stop (cannot be caught or ignored)"
165.It Dv SIGTSTP No "	stop process" "	stop signal generated from keyboard"
166.It Dv SIGCONT No "	discard signal" "	continue after stop"
167.It Dv SIGCHLD No "	discard signal" "	child status has changed"
168.It Dv SIGTTIN No "	stop process" "	background read attempted from control terminal"
169.It Dv SIGTTOU No "	stop process" "	background write attempted to control terminal"
170.It Dv SIGIO No "	discard signal" Tn "	I/O"
171is possible on a descriptor (see
172.Xr fcntl 2 )
173.It Dv SIGXCPU No "	terminate process" "	cpu time limit exceeded (see"
174.Xr setrlimit 2 )
175.It Dv SIGXFSZ No "	terminate process" "	file size limit exceeded (see"
176.Xr setrlimit 2 )
177.It Dv SIGVTALRM No "	terminate process" "	virtual time alarm (see"
178.Xr setitimer 2 )
179.It Dv SIGPROF No "	terminate process" "	profiling timer alarm (see"
180.Xr setitimer 2 )
181.It Dv SIGWINCH No "	discard signal" "	Window size change"
182.It Dv SIGINFO No "	discard signal" "	status request from keyboard"
183.It Dv SIGUSR1 No "	terminate process" "	User defined signal 1"
184.It Dv SIGUSR2 No "	terminate process" "	User defined signal 2"
185.El
186.Pp
187Once a signal handler is installed, it remains installed
188until another
189.Fn sigvec
190call is made, or an
191.Xr execve 2
192is performed.
193A signal-specific default action may be reset by
194setting
195.Fa sv_handler
196to
197.Dv SIG_DFL .
198The defaults are process termination, possibly with core dump;
199no action; stopping the process; or continuing the process.
200See the above signal list for each signal's default action.
201If
202.Fa sv_handler
203is
204.Dv SIG_IGN
205current and pending instances
206of the signal are ignored and discarded.
207.Pp
208If a signal is caught during the system calls listed below,
209the call is normally restarted.
210The call can be forced to terminate prematurely with an
211.Er EINTR
212error return by setting the
213.Dv SV_INTERRUPT
214bit in
215.Fa sv_flags .
216The affected system calls include
217.Xr read 2 ,
218.Xr write 2 ,
219.Xr sendto 2 ,
220.Xr recvfrom 2 ,
221.Xr sendmsg 2
222and
223.Xr recvmsg 2
224on a communications channel or a slow device (such as a terminal,
225but not a regular file)
226and during a
227.Xr wait 2
228or
229.Xr ioctl 2 .
230However, calls that have already committed are not restarted,
231but instead return a partial success (for example, a short read count).
232.Pp
233After a
234.Xr fork 2
235or
236.Xr vfork 2
237all signals, the signal mask, the signal stack,
238and the restart/interrupt flags are inherited by the child.
239.Pp
240The
241.Xr execve 2
242system call reinstates the default
243action for all signals which were caught and
244resets all signals to be caught on the user stack.
245Ignored signals remain ignored;
246the signal mask remains the same;
247signals that interrupt system calls continue to do so.
248.Sh NOTES
249The mask specified in
250.Fa vec
251is not allowed to block
252.Dv SIGKILL
253or
254.Dv SIGSTOP .
255This is done silently by the system.
256.Pp
257The
258.Dv SV_INTERRUPT
259flag is not available in
260.Bx 4.2 ,
261hence it should not be used if backward compatibility is needed.
262.Sh RETURN VALUES
263.Rv -std sigvec
264.Sh EXAMPLES
265On the
266.Tn VAX\-11
267The handler routine can be declared:
268.Bd -literal -offset indent
269void handler(sig, code, scp)
270int sig, code;
271struct sigcontext *scp;
272.Ed
273.Pp
274Here
275.Fa sig
276is the signal number, into which the hardware faults and traps are
277mapped as defined below.
278The
279.Fa code
280argument
281is either a constant
282as given below or, for compatibility mode faults, the code provided by
283the hardware (Compatibility mode faults are distinguished from the
284other
285.Dv SIGILL
286traps by having
287.Dv PSL_CM
288set in the psl).
289The
290.Fa scp
291argument
292is a pointer to the
293.Fa sigcontext
294structure (defined in
295.In signal.h ) ,
296used to restore the context from before the signal.
297.Sh ERRORS
298The
299.Fn sigvec
300function
301will fail and no new signal handler will be installed if one
302of the following occurs:
303.Bl -tag -width Er
304.It Bq Er EFAULT
305Either
306.Fa vec
307or
308.Fa ovec
309points to memory that is not a valid part of the process
310address space.
311.It Bq Er EINVAL
312The
313.Fa sig
314argument
315is not a valid signal number.
316.It Bq Er EINVAL
317An attempt is made to ignore or supply a handler for
318.Dv SIGKILL
319or
320.Dv SIGSTOP .
321.El
322.Sh SEE ALSO
323.Xr kill 1 ,
324.Xr kill 2 ,
325.Xr ptrace 2 ,
326.Xr sigaction 2 ,
327.Xr sigaltstack 2 ,
328.Xr sigblock 2 ,
329.Xr sigpause 2 ,
330.Xr sigprocmask 2 ,
331.Xr sigsetmask 2 ,
332.Xr sigsuspend 2 ,
333.Xr setjmp 3 ,
334.Xr siginterrupt 3 ,
335.Xr signal 3 ,
336.Xr sigsetops 3 ,
337.Xr tty 4
338.Sh HISTORY
339A
340.Fn sigvec
341system call first appeared in
342.Bx 4.2 .
343It was reimplemented as a wrapper around
344.Xr sigaction 2
345in
346.Bx 4.3 Reno .
347.Sh BUGS
348This manual page is still confusing.
349