SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
NAME
sigvec - software signal facilities
SYNOPSIS
#include <signal.h>
struct sigvec {
int (*svhandler)();
int svmask;
int svflags;
};
sigvec(sig, vec, ovec)
int sig;
struct sigvec *vec, *ovec;
DESCRIPTION
The system 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
one 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 may also specify that a
default action is to be taken by the system when a signal
occurs. Normally, signal handlers execute on the current
stack of the process. This may be changed, on a per-handler
basis, so that signals are taken on a special signal stack.
All signals have the same priority. Signal routines execute
with the signal that caused their invocation blocked, but
other signals may yet occur. A global signal mask defines
the set of signals currently blocked from delivery to a pro-
cess. The signal mask for a process is initialized from
that of its parent (normally 0). It may be changed with a
sigblock(2) or sigsetmask(2) call, or when a signal is
delivered to the process.
When a signal condition arises for a process, the signal is
added to a set of signals pending for the process. If the
signal is not currently blocked by the process then it is
delivered to the process. When a signal is delivered, the
current state of the process is saved, a new signal mask is
calculated (as described below), and the signal handler is
invoked. The call to the handler is arranged so that if the
signal handling routine returns normally the process will
resume execution in the context from before the signal's
delivery. If the process wishes to resume in a different
context, then it must arrange to restore the previous con-
text itself.
Printed 11/19/92 Page 1
SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
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 sig-
nal to be delivered, and or'ing in the signal mask associ-
ated with the handler to be invoked.
sigvec assigns a handler for a specific signal. If vec is
non-zero, it specifies a handler routine and mask to be used
when delivering the specified signal. Further, if the
SV_ONSTACK bit is set in sv_flags, the system will deliver
the signal to the process on a signal stack, specified with
sigstack(2). If ovec is non-zero, the previous handling
information for the signal is returned to the user.
The following is a list of all signals with names as in the
include file <signal.h>:
SIGHUP 1 hangup
SIGINT 2 interrupt
SIGQUIT 3* quit
SIGILL 4* illegal instruction
SIGTRAP 5* trace trap
SIGIOT 6* IOT instruction
SIGXCPU 7 cpu time limit exceeded
SIGFPE 8* floating point exception
SIGKILL 9 kill (cannot be caught 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
SIGUSR1 16 User defined signal 1
SIGUSR2 17 User defined signal 2
SIGCHLD 18@ child status has changed
SIGXFSZ 19 file size limit exceeded
SIGSTOP 20'
|+'stop (cannot be caught or ignored)
SIGTSTP 21'
|+'stop signal generated from keyboard
SIGIO 23@ I/O is possible on a descriptor (see fcntl(2))
SIGURG 24@ urgent condition present on socket
SIGWINCH 25@ Window size change
SIGVTALRM 26 virtual time alarm (see getitimer(2))
SIGPROF 27 profiling timer alarm (see getitimer(2))
SIGCONT 28@ continue after stop
SIGTTIN 29'
|+'background read attempted from control terminal
SIGTTOU 30'
|+'background write attempted to control terminal
SIGLOST 31 resource lost (eg, record-lock)
The starred signals in the list above cause a core image if
not caught or ignored.
Page 2 Printed 11/19/92
SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
Once a signal handler is installed, it remains installed
until another sigvec call is made, or an execve(2) is per-
formed. The default action for a signal may be reinstated
by setting sv_handler to SIG_DFL; this default is termina-
tion (with a core image for starred signals) except for sig-
nals marked with @ or '
|+'. Signals marked with @ are dis-
carded 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, the
call is normally restarted. The call can be forced to ter-
minate prematurely with an EINTR error return by setting the
SV_INTERRUPT bit in sv_flags. The affected system calls are
read(2) or write(2) on a slow device (such as a terminal;
but not a file) and during a wait(2).
After a fork(2) or vfork(2) the child inherits all signals,
the signal mask, the signal stack, and the restart/interrupt
flags.
execve(2) resets all caught signals to default action and
resets all signals to be caught on the user stack. Ignored
signals remain ignored; the signal mask remains the same;
signals that interrupt system calls continue to do so.
NOTES
The mask specified in vec is not allowed to block SIGKILL,
SIGSTOP, or SIGCONT. This is done silently by the system.
The SV_INTERRUPT flag is not available in 4.2BSD, hence it
should not be used if backward compatibility is needed.
RETURN VALUE
A 0 value indicated that the call succeeded. A -1 return
value indicates an error occurred and errno set to indicated
the reason.
ERRORS
sigvec will fail and no new signal handler will be installed
if one of the following occurs:
[EFAULT] Either vec or ovec points to memory that
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.
Printed 11/19/92 Page 3
SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
[EINVAL] An attempt is made to ignore SIGCONT (by
default SIGCONT is ignored).
SEE ALSO
kill(1), ptrace(2), cacheflush(2), kill(2), sigblock(2),
sigsetmask(2), sigpause(2), sigreturn(2), sigstack(2),
sigvec(2), setjmp(3), siginterrupt(3), emulate_branch(3),
fpc(3), tty(4).
R2010 Floating Point Coprocessor Architecture Engineering
R2360 Floating Point Board Product Description
NOTES (MIPS)
The handler routine can be declared:
handler(sig, code, scp)
int sig, code;
struct sigcontext *scp;
Here sig is the signal number. MIPS hardware exceptions are
mapped to specific signals as defined by the table below.
code is a parameter that is either a constant as given below
or zero. scp is a pointer to the sigcontext structure
(defined in <signal.h>), that is the context at the time of
the signal and is used to restore the context if the signal
handler returns.
The following defines the mapping of MIPS hardware excep-
tions to signals and codes. All of these symbols are
defined in either <signal.h> or <mips/cpu.h>:
Hardware exception Signal Code
Integer overflow SIGFPE EXC_OV
Segmentation violation SIGSEGV SEXC_SEGV
Illegal Instruction SIGILL EXC_II
Coprocessor Unusable SIGILL SEXC_CPU
Data Bus Error SIGBUS EXC_DBE
Instruction Bus Error SIGBUS EXC_IBE
Read Address Error SIGBUS EXC_RADE
Write Address Error SIGBUS EXC_WADE
User Breakpoint (used by debuggers) SIGTRAP BRK_USERBP
Kernel Breakpoint (used by prom) SIGTRAP BRK_KERNELBP
Taken Branch Delay Emulation SIGTRAP BRK_BD_TAKEN
Not Taken Branch Delay Emulation SIGTRAP BRK_BD_NOTTAKEN
User Single Step (used by debuggers) SIGTRAP BRK_SSTEPBP
Overflow Check SIGTRAP BRK_OVERFLOW
Divide by Zero Check SIGTRAP BRK_DIVZERO
Range Error Check SIGTRAP BRK_RANGE
When a signal handler is reached, the program counter in the
signal context structure (sc_pc) points at the instruction
that caused the exception as modified by the branch delay
bit in the cause register. The cause register at the time
Page 4 Printed 11/19/92
SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
of the exception is also saved in the sigcontext structure
(sc_cause). If the instruction that caused the exception is
at a valid user address it can be retrieved with the follow-
ing code sequence:
if (scp->sc_cause & CAUSE_BD) {
branch_instruction = *(unsigned long *)(scp->sc_pc);
exception_instruction = *(unsigned long *)(scp->sc_pc + 4);
} else
exception_instruction = *(unsigned long *)(scp->sc_pc);
Where CAUSE_BD is defined in <mips/cpu.h>.
The signal handler may fix the cause of the exception and
re-execute the instruction, emulate the instruction and then
step over it or perform some non-local goto such as a
longjump() or an exit().
If corrective action is performed in the signal handler and
the instruction that caused the exception would then execute
without a further exception, the signal handler simply
returns and re-executes the instruction (even when the
branch delay bit is set).
If execution is to continue after stepping over the instruc-
tion that caused the exception the program counter must be
advanced. If the branch delay bit is set the program
counter is set to the target of the branch else it is incre-
mented by 4. This can be done with the following code
sequence:
if (scp->sc_cause & CAUSE_BD)
emulate_branch(scp, branch_instruction);
else
scp->sc_pc += 4;
emulate_branch() modifies the program counter value in the
sigcontext structure to the target of the branch instruc-
tion. See emulate_branch(3) for more details.
For SIGFPE's generated by floating-point instructions (code
== 0) the floating-point control and status register at the
time of the exception is also saved in the sigcontext struc-
ture (sc_fpc_csr). This register has the information on
which exceptions have occurred. When a signal handler is
entered the register contains the value at the time of the
exception but with the exceptions bits cleared. On a return
from the signal handler the exception bits in the floating-
point control and status register are also cleared so that
another SIGFPE will not occur (all other bits are restored
from sc_fpc_csr).
Printed 11/19/92 Page 5
SIGVEC(2-BSD) RISC/os Reference Manual SIGVEC(2-BSD)
If the floating-point unit is a R2360 (a floating-point
board) and a SIGFPE is generated by the floating-point unit
(code == 0) and program counter does not point at the
instruction that caused the exception. In this case the
instruction that caused the exception is in the floating-
point instruction exception register. The floating-point
instruction exception register at the time of the exception
is also saved in the sigcontext structure (sc_fpc_eir). In
this case the instruction that caused the exception can be
retrieved with the following code sequence:
union fpc_irr fpc_irr;
fpc_irr.fi_word = get_fpc_irr();
if (sig == SIGFPE && code == 0 &&
fpc_irr.fi_struct.implementation == IMPLEMENTATION_R2360)
exception_instruction = scp->sc_fpc_eir;
The union fpc_irr, and the constant IMPLEMENTATION_R2360 are
defined in <mips/fpu.h>. For the description of the routine
get_fpc_irr() see fpc(3). All other floating-point imple-
mentations are handled in the normal manner with the
instruction that caused the exception at the program counter
as modified by the branch delay bit.
For SIGSEGV and SIGBUS errors the faulting virtual address
is saved in sc_badvaddr in the signal context structure.
The SIGTRAP's caused by break instructions noted in the
above table and all other yet to be defined break instruc-
tions fill the code parameter with the first argument to the
break instruction (bits 25-16 of the instruction).
Page 6 Printed 11/19/92