xref: /onnv-gate/usr/src/ucblib/libucb/i386/sys/signal.c (revision 9694:78fafb281255)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9694SScott.Rotondo@Sun.COM  * Common Development and Distribution License (the "License").
6*9694SScott.Rotondo@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9694SScott.Rotondo@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
310Sstevel@tonic-gate  * under license from the Regents of the University of California.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate  * 4.3BSD signal compatibility functions
360Sstevel@tonic-gate  *
370Sstevel@tonic-gate  * the implementation interprets signal masks equal to -1 as "all of the
380Sstevel@tonic-gate  * signals in the signal set", thereby allowing signals with numbers
390Sstevel@tonic-gate  * above 32 to be blocked when referenced in code such as:
400Sstevel@tonic-gate  *
410Sstevel@tonic-gate  *	for (i = 0; i < NSIG; i++)
420Sstevel@tonic-gate  *		mask |= sigmask(i)
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #include <sys/types.h>
460Sstevel@tonic-gate #include <ucontext.h>
470Sstevel@tonic-gate #include <signal.h>
480Sstevel@tonic-gate #include <errno.h>
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #undef	BUS_OBJERR	/* namespace conflict */
510Sstevel@tonic-gate #include <sys/siginfo.h>
520Sstevel@tonic-gate #include "libc.h"
530Sstevel@tonic-gate 
540Sstevel@tonic-gate #pragma weak sigvechandler = _sigvechandler
550Sstevel@tonic-gate #pragma weak sigsetmask = _sigsetmask
560Sstevel@tonic-gate #pragma weak sigblock = _sigblock
570Sstevel@tonic-gate #pragma weak sigpause = usigpause
580Sstevel@tonic-gate #pragma weak sigvec = _sigvec
590Sstevel@tonic-gate #pragma weak sigstack = _sigstack
600Sstevel@tonic-gate #pragma weak signal = usignal
610Sstevel@tonic-gate #pragma weak siginterrupt = _siginterrupt
620Sstevel@tonic-gate 
630Sstevel@tonic-gate #define	set2mask(setp) ((setp)->__sigbits[0])
640Sstevel@tonic-gate #define	mask2set(mask, setp) \
650Sstevel@tonic-gate 	((mask) == -1 ? sigfillset(setp) : \
660Sstevel@tonic-gate 	    (sigemptyset(setp), (((setp)->__sigbits[0]) = (int)(mask))))
670Sstevel@tonic-gate 
680Sstevel@tonic-gate void (*_siguhandler[NSIG])() = { 0 };
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /* forward declarations */
710Sstevel@tonic-gate int ucbsigsetmask(int);
720Sstevel@tonic-gate int ucbsigblock(int);
730Sstevel@tonic-gate int ucbsigvec(int, struct sigvec *, struct sigvec *);
740Sstevel@tonic-gate int ucbsigpause(int);
750Sstevel@tonic-gate int ucbsiginterrupt(int, int);
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate  * sigvechandler is the real signal handler installed for all
790Sstevel@tonic-gate  * signals handled in the 4.3BSD compatibility interface - it translates
800Sstevel@tonic-gate  * SVR4 signal hander arguments into 4.3BSD signal handler arguments
810Sstevel@tonic-gate  * and then calls the real handler
820Sstevel@tonic-gate  */
830Sstevel@tonic-gate 
84*9694SScott.Rotondo@Sun.COM static void ucbsigvechandler();
850Sstevel@tonic-gate void
_sigvechandler(int sig,siginfo_t * sip,ucontext_t * ucp)860Sstevel@tonic-gate _sigvechandler(int sig, siginfo_t *sip, ucontext_t *ucp)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	ucbsigvechandler(sig, sip, ucp);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate 
920Sstevel@tonic-gate static void
ucbsigvechandler(int sig,siginfo_t * sip,ucontext_t * ucp)930Sstevel@tonic-gate ucbsigvechandler(int sig, siginfo_t *sip, ucontext_t *ucp)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate 	struct sigcontext sc;
960Sstevel@tonic-gate 	int code;
970Sstevel@tonic-gate 	char *addr;
980Sstevel@tonic-gate 	int i, j;
990Sstevel@tonic-gate 	int gwinswitch = 0;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	sc.sc_onstack = ((ucp->uc_stack.ss_flags & SS_ONSTACK) != 0);
1020Sstevel@tonic-gate 	sc.sc_mask = set2mask(&ucp->uc_sigmask);
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #if defined(__amd64)
1050Sstevel@tonic-gate 	sc.sc_sp = (long)ucp->uc_mcontext.gregs[REG_RSP];
1060Sstevel@tonic-gate 	sc.sc_pc = (long)ucp->uc_mcontext.gregs[REG_RIP];
1070Sstevel@tonic-gate 	sc.sc_ps = (long)ucp->uc_mcontext.gregs[REG_RFL];
1080Sstevel@tonic-gate 	sc.sc_r0 = (long)ucp->uc_mcontext.gregs[REG_RAX];
1090Sstevel@tonic-gate 	sc.sc_r1 = (long)ucp->uc_mcontext.gregs[REG_RDX];
1100Sstevel@tonic-gate #else
1110Sstevel@tonic-gate 	sc.sc_sp = (int)ucp->uc_mcontext.gregs[UESP];
1120Sstevel@tonic-gate 	sc.sc_pc = (int)ucp->uc_mcontext.gregs[EIP];
1130Sstevel@tonic-gate 	sc.sc_ps = (int)ucp->uc_mcontext.gregs[EFL];
1140Sstevel@tonic-gate 	sc.sc_r0 = (int)ucp->uc_mcontext.gregs[EAX];
1150Sstevel@tonic-gate 	sc.sc_r1 = (int)ucp->uc_mcontext.gregs[EDX];
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 	/*
1190Sstevel@tonic-gate 	 * Translate signal codes from new to old.
1200Sstevel@tonic-gate 	 * /usr/include/sys/siginfo.h contains new codes.
1210Sstevel@tonic-gate 	 * /usr/ucbinclude/sys/signal.h contains old codes.
1220Sstevel@tonic-gate 	 */
1230Sstevel@tonic-gate 	code = 0;
1240Sstevel@tonic-gate 	addr = SIG_NOADDR;
1250Sstevel@tonic-gate 	if (sip != NULL && SI_FROMKERNEL(sip)) {
1260Sstevel@tonic-gate 		addr = sip->si_addr;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 		switch (sig) {
1290Sstevel@tonic-gate 		case SIGILL:
1300Sstevel@tonic-gate 		case SIGFPE:
1310Sstevel@tonic-gate 			code = ILL_ILLINSTR_FAULT;
1320Sstevel@tonic-gate 			break;
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 		case SIGBUS:
1350Sstevel@tonic-gate 			switch (sip->si_code) {
1360Sstevel@tonic-gate 			case BUS_ADRALN:
1370Sstevel@tonic-gate 				code = BUS_ALIGN;
1380Sstevel@tonic-gate 				break;
1390Sstevel@tonic-gate 			case BUS_ADRERR:
1400Sstevel@tonic-gate 				code = BUS_HWERR;
1410Sstevel@tonic-gate 				break;
1420Sstevel@tonic-gate 			default:	/* BUS_OBJERR */
1430Sstevel@tonic-gate 				code = FC_MAKE_ERR(sip->si_errno);
1440Sstevel@tonic-gate 				break;
1450Sstevel@tonic-gate 			}
1460Sstevel@tonic-gate 			break;
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 		case SIGSEGV:
1490Sstevel@tonic-gate 			switch (sip->si_code) {
1500Sstevel@tonic-gate 			case SEGV_MAPERR:
1510Sstevel@tonic-gate 				code = SEGV_NOMAP;
1520Sstevel@tonic-gate 				break;
1530Sstevel@tonic-gate 			case SEGV_ACCERR:
1540Sstevel@tonic-gate 				code = SEGV_PROT;
1550Sstevel@tonic-gate 				break;
1560Sstevel@tonic-gate 			default:
1570Sstevel@tonic-gate 				code = FC_MAKE_ERR(sip->si_errno);
1580Sstevel@tonic-gate 				break;
1590Sstevel@tonic-gate 			}
1600Sstevel@tonic-gate 			break;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 		default:
1630Sstevel@tonic-gate 			addr = SIG_NOADDR;
1640Sstevel@tonic-gate 			break;
1650Sstevel@tonic-gate 		}
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	(*_siguhandler[sig])(sig, code, &sc, addr);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	if (sc.sc_onstack)
1710Sstevel@tonic-gate 		ucp->uc_stack.ss_flags |= SS_ONSTACK;
1720Sstevel@tonic-gate 	else
1730Sstevel@tonic-gate 		ucp->uc_stack.ss_flags &= ~SS_ONSTACK;
1740Sstevel@tonic-gate 	mask2set(sc.sc_mask, &ucp->uc_sigmask);
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate #if defined(__amd64)
1770Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[REG_RSP] = (long)sc.sc_sp;
1780Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[REG_RIP] = (long)sc.sc_pc;
1790Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[REG_RFL] = (long)sc.sc_ps;
1800Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[REG_RAX] = (long)sc.sc_r0;
1810Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[REG_RDX] = (long)sc.sc_r1;
1820Sstevel@tonic-gate #else
1830Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[UESP] = (int)sc.sc_sp;
1840Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[EIP] = (int)sc.sc_pc;
1850Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[EFL] = (int)sc.sc_ps;
1860Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[EAX] = (int)sc.sc_r0;
1870Sstevel@tonic-gate 	ucp->uc_mcontext.gregs[EDX] = (int)sc.sc_r1;
1880Sstevel@tonic-gate #endif
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	setcontext(ucp);
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate int
_sigsetmask(int mask)1940Sstevel@tonic-gate _sigsetmask(int mask)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate 	return (ucbsigsetmask(mask));
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate int
ucbsigsetmask(int mask)2000Sstevel@tonic-gate ucbsigsetmask(int mask)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate 	sigset_t oset;
2030Sstevel@tonic-gate 	sigset_t nset;
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	(void) sigprocmask(0, (sigset_t *)0, &nset);
2060Sstevel@tonic-gate 	mask2set(mask, &nset);
2070Sstevel@tonic-gate 	(void) sigprocmask(SIG_SETMASK, &nset, &oset);
2080Sstevel@tonic-gate 	return (set2mask(&oset));
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate int
_sigblock(int mask)2120Sstevel@tonic-gate _sigblock(int mask)
2130Sstevel@tonic-gate {
2140Sstevel@tonic-gate 	return (ucbsigblock(mask));
2150Sstevel@tonic-gate }
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate int
ucbsigblock(int mask)2180Sstevel@tonic-gate ucbsigblock(int mask)
2190Sstevel@tonic-gate {
2200Sstevel@tonic-gate 	sigset_t oset;
2210Sstevel@tonic-gate 	sigset_t nset;
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	(void) sigprocmask(0, (sigset_t *)0, &nset);
2240Sstevel@tonic-gate 	mask2set(mask, &nset);
2250Sstevel@tonic-gate 	(void) sigprocmask(SIG_BLOCK, &nset, &oset);
2260Sstevel@tonic-gate 	return (set2mask(&oset));
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate int
usigpause(int mask)2300Sstevel@tonic-gate usigpause(int mask)
2310Sstevel@tonic-gate {
2320Sstevel@tonic-gate 	return (ucbsigpause(mask));
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate int
ucbsigpause(int mask)2360Sstevel@tonic-gate ucbsigpause(int mask)
2370Sstevel@tonic-gate {
2380Sstevel@tonic-gate 	sigset_t set, oset;
2390Sstevel@tonic-gate 	int ret;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 	(void) sigprocmask(0, (sigset_t *)0, &set);
2420Sstevel@tonic-gate 	oset = set;
2430Sstevel@tonic-gate 	mask2set(mask, &set);
2440Sstevel@tonic-gate 	ret = sigsuspend(&set);
2450Sstevel@tonic-gate 	(void) sigprocmask(SIG_SETMASK, &oset, (sigset_t *)0);
2460Sstevel@tonic-gate 	return (ret);
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate int
_sigvec(int sig,struct sigvec * nvec,struct sigvec * ovec)2500Sstevel@tonic-gate _sigvec(int sig, struct sigvec *nvec, struct sigvec *ovec)
2510Sstevel@tonic-gate {
2520Sstevel@tonic-gate 	return (ucbsigvec(sig, nvec, ovec));
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate int
ucbsigvec(int sig,struct sigvec * nvec,struct sigvec * ovec)2560Sstevel@tonic-gate ucbsigvec(int sig, struct sigvec *nvec, struct sigvec *ovec)
2570Sstevel@tonic-gate {
2580Sstevel@tonic-gate 	struct sigaction nact;
2590Sstevel@tonic-gate 	struct sigaction oact;
2600Sstevel@tonic-gate 	struct sigaction *nactp;
2610Sstevel@tonic-gate 	void (*ohandler)(), (*nhandler)();
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	if (sig <= 0 || sig >= NSIG) {
2640Sstevel@tonic-gate 		errno = EINVAL;
2650Sstevel@tonic-gate 		return (-1);
2660Sstevel@tonic-gate 	}
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	if ((intptr_t)ovec == -1 || (intptr_t)nvec == -1) {
2690Sstevel@tonic-gate 		errno = EFAULT;
2700Sstevel@tonic-gate 		return (-1);
2710Sstevel@tonic-gate 	}
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate 	ohandler = _siguhandler[sig];
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	if (nvec) {
2760Sstevel@tonic-gate 		_sigaction(sig, (struct sigaction *)0, &nact);
2770Sstevel@tonic-gate 		nhandler = nvec->sv_handler;
2780Sstevel@tonic-gate 		/*
2790Sstevel@tonic-gate 		 * To be compatible with the behavior of SunOS 4.x:
2800Sstevel@tonic-gate 		 * If the new signal handler is SIG_IGN or SIG_DFL,
2810Sstevel@tonic-gate 		 * do not change the signal's entry in the handler array.
2820Sstevel@tonic-gate 		 * This allows a child of vfork(2) to set signal handlers
2830Sstevel@tonic-gate 		 * to SIG_IGN or SIG_DFL without affecting the parent.
2840Sstevel@tonic-gate 		 */
2850Sstevel@tonic-gate 		if (nhandler != SIG_DFL && nhandler != SIG_IGN) {
2860Sstevel@tonic-gate 			_siguhandler[sig] = nhandler;
2870Sstevel@tonic-gate 			nact.sa_handler = (void (*)())ucbsigvechandler;
2880Sstevel@tonic-gate 		} else {
2890Sstevel@tonic-gate 			nact.sa_handler = nhandler;
2900Sstevel@tonic-gate 		}
2910Sstevel@tonic-gate 		mask2set(nvec->sv_mask, &nact.sa_mask);
2920Sstevel@tonic-gate 		if (sig == SIGKILL || sig == SIGSTOP)
2930Sstevel@tonic-gate 			nact.sa_handler = SIG_DFL;
2940Sstevel@tonic-gate 		nact.sa_flags = SA_SIGINFO;
2950Sstevel@tonic-gate 		if (!(nvec->sv_flags & SV_INTERRUPT))
2960Sstevel@tonic-gate 			nact.sa_flags |= SA_RESTART;
2970Sstevel@tonic-gate 		if (nvec->sv_flags & SV_RESETHAND)
2980Sstevel@tonic-gate 			nact.sa_flags |= SA_RESETHAND;
2990Sstevel@tonic-gate 		if (nvec->sv_flags & SV_ONSTACK)
3000Sstevel@tonic-gate 			nact.sa_flags |= SA_ONSTACK;
3010Sstevel@tonic-gate 		nactp = &nact;
3020Sstevel@tonic-gate 	} else
3030Sstevel@tonic-gate 		nactp = (struct sigaction *)0;
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	if (_sigaction(sig, nactp, &oact) < 0) {
3060Sstevel@tonic-gate 		_siguhandler[sig] = ohandler;
3070Sstevel@tonic-gate 		return (-1);
3080Sstevel@tonic-gate 	}
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	if (ovec) {
3110Sstevel@tonic-gate 		if (oact.sa_handler == SIG_DFL || oact.sa_handler == SIG_IGN)
3120Sstevel@tonic-gate 			ovec->sv_handler = oact.sa_handler;
3130Sstevel@tonic-gate 		else
3140Sstevel@tonic-gate 			ovec->sv_handler = ohandler;
3150Sstevel@tonic-gate 		ovec->sv_mask = set2mask(&oact.sa_mask);
3160Sstevel@tonic-gate 		ovec->sv_flags = 0;
3170Sstevel@tonic-gate 		if (oact.sa_flags & SA_ONSTACK)
3180Sstevel@tonic-gate 			ovec->sv_flags |= SV_ONSTACK;
3190Sstevel@tonic-gate 		if (oact.sa_flags & SA_RESETHAND)
3200Sstevel@tonic-gate 			ovec->sv_flags |= SV_RESETHAND;
3210Sstevel@tonic-gate 		if (!(oact.sa_flags & SA_RESTART))
3220Sstevel@tonic-gate 			ovec->sv_flags |= SV_INTERRUPT;
3230Sstevel@tonic-gate 	}
3240Sstevel@tonic-gate 
3250Sstevel@tonic-gate 	return (0);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate int
_sigstack(struct sigstack * nss,struct sigstack * oss)3290Sstevel@tonic-gate _sigstack(struct sigstack *nss, struct sigstack *oss)
3300Sstevel@tonic-gate {
3310Sstevel@tonic-gate 	struct sigaltstack nalt;
3320Sstevel@tonic-gate 	struct sigaltstack oalt;
3330Sstevel@tonic-gate 	struct sigaltstack *naltp;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 	if (nss) {
3360Sstevel@tonic-gate 		/*
3370Sstevel@tonic-gate 		 * assumes stack growth is down (like sparc and x86)
3380Sstevel@tonic-gate 		 */
3390Sstevel@tonic-gate 		nalt.ss_sp = nss->ss_sp - SIGSTKSZ;
3400Sstevel@tonic-gate 		nalt.ss_size = SIGSTKSZ;
3410Sstevel@tonic-gate 		nalt.ss_flags = 0;
3420Sstevel@tonic-gate 		naltp = &nalt;
3430Sstevel@tonic-gate 	} else
3440Sstevel@tonic-gate 		naltp = (struct sigaltstack *)0;
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate 	if (sigaltstack(naltp, &oalt) < 0)
3470Sstevel@tonic-gate 		return (-1);
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	if (oss) {
3500Sstevel@tonic-gate 		/*
3510Sstevel@tonic-gate 		 * assumes stack growth is down (like sparc and x86)
3520Sstevel@tonic-gate 		 */
3530Sstevel@tonic-gate 		oss->ss_sp = oalt.ss_sp + oalt.ss_size;
3540Sstevel@tonic-gate 		oss->ss_onstack = ((oalt.ss_flags & SS_ONSTACK) != 0);
3550Sstevel@tonic-gate 	}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 	return (0);
3580Sstevel@tonic-gate }
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate void (*
ucbsignal(int s,void (* a)())3610Sstevel@tonic-gate ucbsignal(int s, void (*a)()))()
3620Sstevel@tonic-gate {
3630Sstevel@tonic-gate 	struct sigvec osv;
3640Sstevel@tonic-gate 	struct sigvec nsv;
3650Sstevel@tonic-gate 	static int mask[NSIG];
3660Sstevel@tonic-gate 	static int flags[NSIG];
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	nsv.sv_handler = a;
3690Sstevel@tonic-gate 	nsv.sv_mask = mask[s];
3700Sstevel@tonic-gate 	nsv.sv_flags = flags[s];
3710Sstevel@tonic-gate 	if (ucbsigvec(s, &nsv, &osv) < 0)
3720Sstevel@tonic-gate 		return (SIG_ERR);
3730Sstevel@tonic-gate 	if (nsv.sv_mask != osv.sv_mask || nsv.sv_flags != osv.sv_flags) {
3740Sstevel@tonic-gate 		mask[s] = nsv.sv_mask = osv.sv_mask;
3750Sstevel@tonic-gate 		flags[s] = nsv.sv_flags =
376*9694SScott.Rotondo@Sun.COM 		    osv.sv_flags & ~(SV_RESETHAND|SV_INTERRUPT);
3770Sstevel@tonic-gate 		if (ucbsigvec(s, &nsv, (struct sigvec *)0) < 0)
3780Sstevel@tonic-gate 			return (SIG_ERR);
3790Sstevel@tonic-gate 	}
3800Sstevel@tonic-gate 	return (osv.sv_handler);
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate void (*
usignal(int s,void (* a)())3840Sstevel@tonic-gate usignal(int s, void (*a)()))()
3850Sstevel@tonic-gate {
3860Sstevel@tonic-gate 	return (ucbsignal(s, a));
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate /*
3900Sstevel@tonic-gate  * Set signal state to prevent restart of system calls
3910Sstevel@tonic-gate  * after an instance of the indicated signal.
3920Sstevel@tonic-gate  */
3930Sstevel@tonic-gate int
_siginterrupt(int sig,int flag)3940Sstevel@tonic-gate _siginterrupt(int sig, int flag)
3950Sstevel@tonic-gate {
3960Sstevel@tonic-gate 	return (ucbsiginterrupt(sig, flag));
3970Sstevel@tonic-gate }
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate int
ucbsiginterrupt(int sig,int flag)4000Sstevel@tonic-gate ucbsiginterrupt(int sig, int flag)
4010Sstevel@tonic-gate {
4020Sstevel@tonic-gate 	struct sigvec sv;
4030Sstevel@tonic-gate 	int ret;
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate 	if ((ret = ucbsigvec(sig, 0, &sv)) < 0)
4060Sstevel@tonic-gate 		return (ret);
4070Sstevel@tonic-gate 	if (flag)
4080Sstevel@tonic-gate 		sv.sv_flags |= SV_INTERRUPT;
4090Sstevel@tonic-gate 	else
4100Sstevel@tonic-gate 		sv.sv_flags &= ~SV_INTERRUPT;
4110Sstevel@tonic-gate 	return (ucbsigvec(sig, &sv, 0));
4120Sstevel@tonic-gate }
413