sigvec.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 371 行

2
371
字号
.\" SCCSID: @(#)sigvec.2	2.3	6/8/87.TH sigvec 2 RISC.ie t .ds d \(dg.el .ds d \z'|+'.ie t .ds b \(bu.el .ds b @.SH Namesigvec \- software signal facilities.SH Syntax.nf.B #include <signal.h>.PP.B struct sigvec {.B	void		(*sv_handler)();.B	sigset_t	sv_mask;.B	int		sv_flags;.B };.PP.B sigvec(sig, vec, ovec).B int sig;.B struct sigvec *vec, *ovec;.fi.SH Description.NXB "sigvec system call".NXB "signal handler" "assigning"The system defines a set of signals that can 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 can specify ahandler to which a signal is delivered, or specify that a signal is to be blocked or ignored .A process can also specify that a default action is to be takenby the system when a signal occurs.Normally, signal handlers execute on the current stackof the process.  This can be changed, on a per-handler basis,so that signals are taken on a specialsignal stack..PPAll signals have the same priority.Signal routines execute with the signal that caused theirinvocation blocked, but other signals can occur.A global signal mask defines the set of signals currently blocked from deliveryto a process.  The signal mask for a process is initializedfrom that of its parent (normally, 0).  Itcan be changed with a.MS sigblock 2or.MS sigsetmask 2call, or when a signal is delivered to the process..PPWhen a signalcondition arises for a process, the signal is added to a set ofsignals pending for the process.  If the signal is not currentlyblocked by the process, it is delivered to the process.  When a signalis delivered, the current state of the process is saved,a new signal mask is calculated (as described later), and the signal handler is invoked.  The call to the handleris arranged so that, if the signal handling routine returnsnormally, the process resumes execution in the contextfrom before the signal's delivery.If the process wishes to resume in a different context, itmust arrange to restore the previous context itself..PPWhen a signal is delivered to a process, a new signal mask isinstalled for the duration of the process's signal handler(or until a.PN sigblockor.PN sigsetmaskcall is made).This mask is formed by taking the current signal mask,adding the signal to be delivered, and ORingin the signal mask associated with the handler to be invoked..PPThe.PN sigvecSystem call assigns a handler for a specific signal.  If.I vecis nonzero, itspecifies a handler routine and maskto be used when delivering the specified signal.Further, if the SV_ONSTACK bit is set in.IR sv_flags ,the system delivers the signal to the process on a signal stack,specified with .MS sigstack 2 .If .I ovecis nonzero, the previous handling information for the signalis returned to the user..PPThe following is a list of all signalswith names as in the include file .PN <signal.h> :.NXR "sigvec system call" "signal list".PP.nf.ta \w'SIGVTALRM 'u +\w'15*  'uSIGHUP	1	HangupSIGINT	2	InterruptSIGQUIT	3*	QuitSIGILL	4*	Illegal instructionSIGTRAP	5*	Trace trapSIGIOT	6*	IOT instructionSIGEMT	7*	EMT instructionSIGFPE	8*	Floating point exceptionSIGKILL	9	Kill (cannot be caught, blocked, or ignored)SIGBUS	10*	Bus errorSIGSEGV	11*	Segmentation violationSIGSYS	12*	Bad argument to system callSIGPIPE	13	Write on a pipe with no one to read itSIGALRM	14	Alarm clockSIGTERM	15	Software termination signalSIGURG	16.	Urgent condition present on socketSIGSTOP	17+	Stop (cannot be caught, blocked, or ignored)SIGTSTP	18+	Stop signal generated from keyboardSIGCONT	19.	Continue after stop (cannot be blocked)SIGCHLD	20.	Child status has changedSIGTTIN	21+	Background read attempted from control terminalSIGTTOU	22+	Background write attempted to control terminalSIGIO	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.  Window size changeSIGLOST	29	Lock not reclaimed after server recoverySIGUSR1	30	User-defined signal 1SIGUSR2	31	User-defined signal 2SIGCLD		System V name for SIGCHLDSIGABRT		X/OPEN name for SIGIOT.fi.PPThe signals marked with asterisks (*) in this list cause a core imageif not caught or ignored.  Explanations of the meaning of the periods (.)and plus signs (+) are included in the following paragraph..PPOnce a signal handler is installed, it remains installeduntil another.PN sigveccall is made or an .MS execve 2is performed.The default action for a signal can be reinstated by setting.I sv_handlerto SIG_DFL. This default is termination(with a core image for signals marked with asterisks (*)),except for signals marked with periods (.) or plus signs (+).Signals marked with periods (.) are discarded if the actionis SIG_DFL. Signals marked with plus signs (+) cause the process to stop.If.I sv_handleris SIG_IGN, the signal is subsequently ignored,and pending instances of the signal are discarded..PPIf a caught signal occursduring certain system calls,the call is normally restarted.The call can be forced to terminate prematurely with anEINTR error return, by setting the SV_INTERRUPT bit in.IR sv_flags .The affected system calls are.PN read ,.PN write ,or.PN ioctlon a slow device (such as a terminal, but not a file),.PN flock ,and.PN wait ..PPAfter a .PN fork or.PN vfork ,the child inheritsall signals, the signal mask, the signal stack,and the restart/interrupt flags..PPThe.PN execvesystem call resets allcaught signals to default action andresets 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..PPThe mask specified in .I vecis not allowed to block SIGKILL, SIGSTOP, or SIGCONT.  Thisis done silently by the system..PPThe SV_INTERRUPT flag is not available in ULTRIX 2.0 or earlier versions.Therefore, it should not be used if backward compatibility is needed..SH Return ValuesA zero (0) value indicates that the call succeeded.  A \-1 return valueindicates an error occurred, and.I errnois set to indicated the reason..SH Diagnostics.NXR "sigvec system call" "diagnostics"The.PN sigvecsystem callfails and no new signal handler is installed, if oneof the following occurs:.TP 15[EFAULT]Either.I vecor .I ovecpoints to memory that is not a valid part of the processaddress space..TP 15[EINVAL].I Sigis not a valid signal number..TP 15[EINVAL]An attempt is made to ignore or supply a handler for SIGKILLor SIGSTOP..TP 15[EINVAL]An attempt is made to ignore SIGCONT (by default SIGCONTis ignored)..SH Notes The handler routine can be declared:.EXvoid handler(sig, code, scp)int sig, code;struct sigcontext *scp;.EEHere.I sigis the signal number.MIPS hardware exceptions are mapped to specific signals as defined bythe following table..I Codeis a parameter that is either a constant or zero.  The.I scpis a pointer to the.I sigcontextstructure (defined in.PN <signal.h> ,that is the context at the time of the signal and isused to restore the context, if the signal handler returns..PPThe following defines the mapping of MIPS hardware exceptions to signalsand codes.  All of these symbols are defined in either.RI < signal.h >or.RI < mips/cpu.h >:.PP.ta \w'     User Single Step (used by debuggers)   'u +\w'15*  'u +8n.nf.B Hardware exception	Signal	Code.sp +.5Integer overflow	SIGFPE	EXC_OVSegmentation violation	SIGSEGV	SEXC_SEGVIllegal instruction	SIGILL	EXC_IICoprocessor unusable	SIGILL	SEXC_CPUData bus error	SIGBUS	EXC_DBEInstruction bus error	SIGBUS	EXC_IBERead address error	SIGBUS	EXC_RADEWrite address error	SIGBUS	EXC_WADEUser breakpoint (used by debuggers)	SIGTRAP	BRK_USERBPKernel breakpoint (used by prom)	SIGTRAP	BRK_KERNELBPTaken branch delay emulation 	SIGTRAP	BRK_BD_TAKENNot taken branch delay emulation	SIGTRAP	BRK_BD_NOTTAKENUser single step (used by debuggers)	SIGTRAP	BRK_SSTEPBPOverflow check	SIGTRAP	BRK_OVERFLOWDivide by zero check	SIGTRAP	BRK_DIVZERORange error check	SIGTRAP	BRK_RANGE.fi.PPWhen a signal handler is reached, the program counter in the signal contextstructure.RI ( sc_pc )points at the instruction that caused the exception, as modified by the.I "branch delay"bit in the.I causeregister.The.I causeregister at the time of the exception is also saved in the sigcontextstructure.RI ( sc_cause ).If the instruction that caused the exception is at a valid user address, itcan be retrieved with the following code sequence:.EXif(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);.EECAUSE_BD is defined in.PN <mips/cpu.h> ..PPThe signal handler can fix the cause of the exception and re-execute theinstruction, emulate the instruction and then step over it, or perform somenonlocal redirection, such as a.PN longjump()or an.PN exit() ..PPIf corrective action is performed in the signal handler and the instructionthat caused the exception would then execute without a further exception, thesignal handler simply returns and re-executes the instruction (even when the.I "branch delay"bit is set)..PPIf execution is to continue after stepping over the instruction that caused theexception, the program counter must be advanced.  If the.I "branch delay"bit is set, the program counter is set to the target of the branch. Otherwise, it is incremented by four.  This can be done with the following code sequence:.EXif(scp->sc_cause & CAUSE_BD)    emulate_branch(scp, branch_instruction);else    scp->sc_pc += 4;.EE.I Emulate_branch()modifies the program counter value in the sigcontext structure to the targetof the branch instruction.  See.MS emulate_branch 3for more details..PPFor SIGFPE's generated by floating-point instructions.RI ( code== 0) the.I "floating-point control and status"register at the time of the exception is also saved in the sigcontext structure.RI ( 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 timeof the exception but with the.I "exceptions bits"cleared.On a return from the signal handler, the exception bitsin the floating-point control and status register are also cleared sothat another SIGFPE will not occur (all other bits are restored from.IR sc_fpc_csr )..PPFor SIGSEGV and SIGBUS errors, the faulting virtual address is saved in.I sc_badvaddrin the signal context structure..PPThe SIGTRAPs caused by.PN breakinstructions noted in the previous table and all other yet to be defined.PN breakinstructions fill the.I codeparameter with the first argument to the.PN breakinstruction (bits 25-16 of the instruction)..SH See Alsokill(1), kill(2), ptrace(2), sigblock(2), sigpause(2), sigsetmask(2),sigstack(2), setjmp(3), siginterrupt(3), tty(4).NXE "sigvec system call".NXE "signal handler" "assigning"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?