SIGVEC(2)

NAME
sigvec - software signal facilities

SYNOPSIS
#include <signal.h>

struct sigvec {
	int	(*sv_handler)();
	int	sv_mask;
	int	sv_onstack;
};

sigvec(sig, vec, ovec)
	int sig;
	struct sigvec *vec, *ovec;

DESCRIPTION
DYNIX defines a set of signals that may be delivered to a process. Signal delivery resembles the occurrence of a hardware interrupt—the signal is blocked from further occurrence, the current process context is saved, and a new process context is built. A process may specify a handler to which a signal is delivered, or specify that a signal is to be blocked or ignored. A process can tell the system to take a default action when a signal occurs. Normally, signal handlers execute on the current stack of the process. Processes can change this on a per-handler basis, so that signals are taken on a special signal stack, with a sigstack(2) system call.

Signals have the same priority. While a signal handler is executing, the signal that caused its invocation is blocked; however, other signals are not blocked. When a signal condition arises for a process, the signal is added to the set of signals pending for the process. If the process has not blocked the signal, the signal is delivered to the process. When a process receives a signal, the current state of the process is saved, a new signal mask is calculated, and sv_handler is invoked. The call to the signal handler is arranged so that if the signal handling routine returns normally, the process resumes execution in the context from before the signal's delivery. If the process wishes to resume in a different context, it must arrange to restore the previous context itself.

Signal Mask

A global signal mask defines the set of signals currently blocked from delivery to a process. The signal mask for a process is initialized from that of its parent, which is usually 0. The process can change signal mask with a sigblock(2) or sigsetmask(2) call, or DYNIX changes it when it delivers a signal to the process.

When a signal is delivered to a process, a new signal mask is installed for the duration of the process' signal handler or until a sigblock or sigsetmask call is made. This mask is formed by taking the current signal mask, adding the signal to be delivered, and or'ing in the signal mask associated with the handler to be invoked.

Signal Handler

Sigvec assigns a handler for a specific signal. If vec is non-zero, it specifies a handler routine (sv_handler) and mask (sv_mask) to be used when delivering the specified signal. Further, if sv_onstack is 1, DYNIX delivers the signal to the process on a signal stack, as previously specified by sigstack(2). If ovec is non-zero, the previous handling information for the signal is returned to the user process.

The following is the list of signals as defined in <signal.h>:

SIGHUP	1	hangup
SIGINT	2	interrupt
SIGQUIT	3*	quit
SIGILL	4*	illegal instruction
SIGTRAP	5*	trace trap
SIGIOT	6*	IOT instruction
SIGEMT	7*	EMT instruction
SIGFPE	8*	floating point exception
SIGKILL	9	kill (cannot be caught, blocked, or ignored)
SIGBUS	10*	bus error
SIGSEGV	11*	segmentation violation
SIGSYS	12*	bad argument to system call
SIGPIPE	13	write on a pipe with no one to read it
SIGALRM	14	alarm clock
SIGTERM	15	software termination signal
SIGURG	16@	urgent condition present on socket
SIGSTOP	17'|+'	stop (cannot be caught, blocked, or ignored)
SIGTSTP	18'|+'	stop signal generated from keyboard
SIGCONT	19@	continue after stop (cannot be blocked)
SIGCHLD	20@	child status has changed
SIGTTIN	21'|+'	background read attempted from control terminal
SIGTTOU	22'|+'	background write attempted to control terminal
SIGIO	23@	i/o is possible on a descriptor (see fcntl(2))
SIGXCPU	24	cpu time limit exceeded (see setrlimit(2))
SIGXFSZ	25	file size limit exceeded (see setrlimit(2))
SIGVTALRM	26	virtual time alarm (see setitimer(2))
SIGPROF	27	profiling timer alarm (see setitimer(2))
SIGWINCH	28@	used by PCI to signal a window size change
SIGUSR1	30	user-defined signal 1
SIGUSR2	31	user-defined signal 2

If the starred signals in the previous list are not caught or ignored, a core image is generated.

Once a signal handler is installed, it remains installed until another sigvec call is made, or an execve(2) is performed. The default action for a signal may be reinstated by setting sv_handler to SIG_DFL; this default is termination (with a core image for starred signals) except for signals marked with @ or '|+'. Signals marked with @ are discarded if the action is SIG_DFL; signals marked with '|+' cause the process to stop. If sv_handler is SIG_IGN the signal is subsequently ignored, and pending instances of the signal are discarded.

If a caught signal occurs during certain system calls, causing the call to terminate prematurely, the call is automatically restarted. In particular this can occur during a read or write(2) on a slow device (such as a terminal; but not a file) and during a wait(2). Note that if the read or write(2) have already completed some of the request, they will just return what they have finished.

After a fork(2) or vfork(2) the child inherits all signals, the signal mask, and the signal stack.

Execve(2) resets all caught signals to default action; ignored signals remain ignored; the signal mask remains the same; the signal stack state is reset.

NOTES
The mask specified in vec is not allowed to block SIGKILL, SIGSTOP, or SIGCONT. This is enforced silently by the system.

Signals do not stack. If two or more identical signals are sent to the process before the the process signal handler is called or the default action is taken, the second and subsequent consecutive identical signals are lost.

The handler routine can be declared: handler(sig, code, scp)
    int sig, code;
    struct sigcontext *scp; Here sig is the signal number, into which the hardware faults and traps are mapped as defined below. Code is a parameter as given below. Scp is a pointer to the sigcontext structure defined in <signal.h>, which is used to restore the pre-signal context.

Balance Series

The following table shows the mapping of hardware traps to signals and codes as are defined in either <signal.h> or <machine/fpu.h>.

The following codes are associated with the SIGFPE floating point exception:

Code	Hardware condition

FPE_INTDIV_TRAP	Integer division by zero
FPE_FLTUND_TRAP	Floating underflow trap
FPE_FLTOVF_TRAP	Floating overflow trap
FPE_FLTDIV_TRAP	Floating division by zero
FPE_FLTILL_TRAP	Floating illegal instruction
FPE_FLTINV_TRAP	Floating invalid operation
FPE_FLTIER_TRAP	Floating inexact result

The following codes are associated with the SIGILL illegal instruction:

Code	Hardware condition

ILL_PRIVIN_FAULT	Privileged instruction fault
ILL_RESOP_FAULT	Reserved operand fault

When a user process causes a segmentation violation (SIGVEC), the code parameter contains the address that caused the violation. Otherwise, code is set to zero for all other signals:

Code	Signal	Hardware condition

0	SIGTRAP	Trace pending
0	SIGTRAP	Bpt instruction
0	SIGEMT	Flag trap

Unlike other processor architectures, such as the VAX, the stacked PC for a signal resulting from a hardware trap designates the instruction causing the trap, not the following instruction. Therefore, a hardware trap signal handler that returns without changing the context will attempt to execute the failed instruction repeatedly.

Symmetry Series

The following table shows the mapping of hardware traps to signals and codes as are defined in either <signal.h> or <machine/fpu.h>.

The following codes are associated with the SIGFPE floating point exception:

Code	Hardware condition

FPE_FLTINV_TRAP	Floating invalid operation
FPE_FLTDEN_TRAP	Floating denormal trap
FPE_FLTDIV_TRAP	Floating division by zero
FPE_FLTOVF_TRAP	Floating overflow trap
FPE_FLTUND_TRAP	Floating underflow trap
FPE_FLTPRE_TRAP	Floating precision trap
FPE_FLTSTK_TRAP	Floating stack overflow/underflow
FPE_INTDIV_TRAP	Integer division by zero
FPE_INTOVF_TRAP	Integer overflow (into)

FPE_NOFPA_AVAIL	No Weitek 1167 FPA's in the system

The following codes are associated with the SIGILL floating point exception:

Code	Hardware condition

ILL_PRIVIN_FAULT	Privileged instruction fault
ILL_RESOP_FAULT	Reserved operand fault

In addition, the following signals are defined for the Weitek 1167 floating point hardware:

Code	Hardware condition

FPA_PCR_AE	Accumulated exceptions
FPA_PCR_AE_DE	Data chain exception
FPA_PCR_AE_UOE	Unimplemented op-code exception
FPA_PCR_AE_PE	Precision exception
FPA_PCR_AE_UE	Underflow exception
FPA_PCR_AE_OE	Overflow exception
FPA_PCR_AE_ZE	Zero divide exception
FPA_PCR_AE_EE	Enabled exception (1 == interrupt)
FPA_PCR_AE_IE	Invalid operation exception

Note that floating-point context is saved and restored across all signal handlers EXCEPT SIGFPE handlers. In the case of a SIGFPE, the corresponding handler inherits the floating-point context of the interrupted procedure. And, on return from the SIGFPE handler, the interrupted procedure inherits any modifications the signal handler made to its floating-point state. Thus, floating-point applications can reset the faulting state directly in the fpu/fpa hardware from within the SIGFPE handler. All other signal handlers receive initialized fpu/fpa state and, on normal return, the fpu/fpa context of the interrupted procedure is restored.

RETURN VALUES
If the call succeeds, signal returns a 0. If the call fails, signal returns a -1 and sets errno to indicate the reason.

ERRORS
Sigvec fails and no new signal handler is installed if one of the following errors occurs:

[EFAULT]
    Either vec or ovec points to memory which is not a valid part of the process address space.

[EINVAL]
    Sig is not a valid signal number.

[EINVAL]
    An attempt is made to ignore or supply a handler for SIGKILL or SIGSTOP.

[EINVAL]
    An attempt is made to ignore SIGCONT (by default SIGCONT is ignored).

SEE ALSO
kill(1), ptrace(2), kill(2), sigblock(2), sigpause(2), sigsetmask(2), sigstack(2), sigvec(2), setjmp(3), tty(4)