ibcs2_signal.c revision 20203
10SN/A/* 29330SN/A * Copyright (c) 1995 Scott Bartram 30SN/A * Copyright (c) 1995 Steven Wallace 40SN/A * All rights reserved. 50SN/A * 60SN/A * Redistribution and use in source and binary forms, with or without 72362SN/A * modification, are permitted provided that the following conditions 80SN/A * are met: 92362SN/A * 1. Redistributions of source code must retain the above copyright 100SN/A * notice, this list of conditions and the following disclaimer. 110SN/A * 2. Redistributions in binary form must reproduce the above copyright 120SN/A * notice, this list of conditions and the following disclaimer in the 130SN/A * documentation and/or other materials provided with the distribution. 140SN/A * 3. The name of the author may not be used to endorse or promote products 150SN/A * derived from this software without specific prior written permission 160SN/A * 170SN/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 180SN/A * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 190SN/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 200SN/A * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 212362SN/A * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 222362SN/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232362SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 240SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 250SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 260SN/A * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 270SN/A * 280SN/A * $Id: ibcs2_signal.c,v 1.6 1995/10/21 20:33:43 swallace Exp $ 290SN/A */ 300SN/A 310SN/A#include <sys/param.h> 320SN/A#include <sys/systm.h> 330SN/A#include <sys/namei.h> 340SN/A#include <sys/proc.h> 350SN/A#include <sys/filedesc.h> 360SN/A#include <sys/ioctl.h> 370SN/A#include <sys/mount.h> 380SN/A#include <sys/kernel.h> 390SN/A#include <sys/signal.h> 400SN/A#include <sys/signalvar.h> 410SN/A#include <sys/malloc.h> 420SN/A#include <sys/sysproto.h> 430SN/A 440SN/A#include <i386/ibcs2/ibcs2_types.h> 450SN/A#include <i386/ibcs2/ibcs2_signal.h> 460SN/A#include <i386/ibcs2/ibcs2_proto.h> 470SN/A#include <i386/ibcs2/ibcs2_xenix.h> 480SN/A#include <i386/ibcs2/ibcs2_util.h> 490SN/A 500SN/A#define sigemptyset(s) bzero((s), sizeof(*(s))) 510SN/A#define sigismember(s, n) (*(s) & sigmask(n)) 520SN/A#define sigaddset(s, n) (*(s) |= sigmask(n)) 530SN/A 540SN/A#define ibcs2_sigmask(n) (1 << ((n) - 1)) 550SN/A#define ibcs2_sigemptyset(s) bzero((s), sizeof(*(s))) 560SN/A#define ibcs2_sigismember(s, n) (*(s) & ibcs2_sigmask(n)) 570SN/A#define ibcs2_sigaddset(s, n) (*(s) |= ibcs2_sigmask(n)) 580SN/A 590SN/Astatic void ibcs2_to_bsd_sigset __P((const ibcs2_sigset_t *, sigset_t *)); 600SN/Astatic void bsd_to_ibcs2_sigset __P((const sigset_t *, ibcs2_sigset_t *)); 610SN/Astatic void ibcs2_to_bsd_sigaction __P((struct ibcs2_sigaction *, 620SN/A struct sigaction *)); 630SN/Astatic void bsd_to_ibcs2_sigaction __P((struct sigaction *, 640SN/A struct ibcs2_sigaction *)); 650SN/A 66430SN/Aint bsd_to_ibcs2_sig[] = { 67430SN/A 0, /* 0 */ 680SN/A IBCS2_SIGHUP, /* 1 */ 690SN/A IBCS2_SIGINT, /* 2 */ 700SN/A IBCS2_SIGQUIT, /* 3 */ 710SN/A IBCS2_SIGILL, /* 4 */ 720SN/A IBCS2_SIGTRAP, /* 5 */ 730SN/A IBCS2_SIGABRT, /* 6 */ 740SN/A IBCS2_SIGEMT, /* 7 */ 750SN/A IBCS2_SIGFPE, /* 8 */ 760SN/A IBCS2_SIGKILL, /* 9 */ 770SN/A IBCS2_SIGBUS, /* 10 */ 780SN/A IBCS2_SIGSEGV, /* 11 */ 790SN/A IBCS2_SIGSYS, /* 12 */ 800SN/A IBCS2_SIGPIPE, /* 13 */ 810SN/A IBCS2_SIGALRM, /* 14 */ 820SN/A IBCS2_SIGTERM, /* 15 */ 830SN/A 0, /* 16 - SIGURG */ 840SN/A IBCS2_SIGSTOP, /* 17 */ 850SN/A IBCS2_SIGTSTP, /* 18 */ 860SN/A IBCS2_SIGCONT, /* 19 */ 870SN/A IBCS2_SIGCLD, /* 20 */ 880SN/A IBCS2_SIGTTIN, /* 21 */ 890SN/A IBCS2_SIGTTOU, /* 22 */ 900SN/A IBCS2_SIGPOLL, /* 23 */ 910SN/A 0, /* 24 - SIGXCPU */ 920SN/A 0, /* 25 - SIGXFSZ */ 930SN/A IBCS2_SIGVTALRM, /* 26 */ 940SN/A IBCS2_SIGPROF, /* 27 */ 950SN/A IBCS2_SIGWINCH, /* 28 */ 960SN/A 0, /* 29 */ 970SN/A IBCS2_SIGUSR1, /* 30 */ 980SN/A IBCS2_SIGUSR2, /* 31 */ 990SN/A}; 1000SN/A 1010SN/Astatic int ibcs2_to_bsd_sig[] = { 1020SN/A 0, /* 0 */ 1030SN/A SIGHUP, /* 1 */ 1040SN/A SIGINT, /* 2 */ 1050SN/A SIGQUIT, /* 3 */ 1060SN/A SIGILL, /* 4 */ 10715252Svadim SIGTRAP, /* 5 */ 10815252Svadim SIGABRT, /* 6 */ 10915252Svadim SIGEMT, /* 7 */ 11015252Svadim SIGFPE, /* 8 */ 11115252Svadim SIGKILL, /* 9 */ 11215252Svadim SIGBUS, /* 10 */ 11315252Svadim SIGSEGV, /* 11 */ 11415252Svadim SIGSYS, /* 12 */ 11515252Svadim SIGPIPE, /* 13 */ 11615252Svadim SIGALRM, /* 14 */ 11715252Svadim SIGTERM, /* 15 */ 11815252Svadim SIGUSR1, /* 16 */ 11915252Svadim SIGUSR2, /* 17 */ 12015252Svadim SIGCHLD, /* 18 */ 12115252Svadim 0, /* 19 - SIGPWR */ 12215252Svadim SIGWINCH, /* 20 */ 12315252Svadim 0, /* 21 */ 12415252Svadim SIGIO, /* 22 */ 12515252Svadim SIGSTOP, /* 23 */ 12615252Svadim SIGTSTP, /* 24 */ 1270SN/A SIGCONT, /* 25 */ 1280SN/A SIGTTIN, /* 26 */ 12915252Svadim SIGTTOU, /* 27 */ 13015252Svadim SIGVTALRM, /* 28 */ 13115252Svadim SIGPROF, /* 29 */ 13215252Svadim 0, /* 30 */ 13315252Svadim 0, /* 31 */ 13415252Svadim}; 1350SN/A 13615252Svadimvoid 13715252Svadimibcs2_to_bsd_sigset(iss, bss) 13815252Svadim const ibcs2_sigset_t *iss; 13915252Svadim sigset_t *bss; 14015252Svadim{ 14115252Svadim int i, newsig; 14215252Svadim 14315252Svadim sigemptyset(bss); 14415252Svadim for (i = 1; i < IBCS2_NSIG; i++) { 14515252Svadim if (ibcs2_sigismember(iss, i)) { 14615252Svadim newsig = ibcs2_to_bsd_sig[i]; 14715252Svadim if (newsig) 1480SN/A sigaddset(bss, newsig); 1490SN/A } 1500SN/A } 1510SN/A} 1520SN/A 1530SN/Astatic void 1540SN/Absd_to_ibcs2_sigset(bss, iss) 1550SN/A const sigset_t *bss; 1560SN/A ibcs2_sigset_t *iss; 1570SN/A{ 1580SN/A int i, newsig; 1590SN/A 1600SN/A ibcs2_sigemptyset(iss); 1610SN/A for (i = 1; i < NSIG; i++) { 1620SN/A if (sigismember(bss, i)) { 1630SN/A newsig = bsd_to_ibcs2_sig[i]; 1640SN/A if (newsig) 1650SN/A ibcs2_sigaddset(iss, newsig); 1660SN/A } 1670SN/A } 1680SN/A} 1690SN/A 1700SN/Astatic void 1710SN/Aibcs2_to_bsd_sigaction(isa, bsa) 1720SN/A struct ibcs2_sigaction *isa; 1730SN/A struct sigaction *bsa; 1740SN/A{ 1750SN/A 1760SN/A bsa->sa_handler = isa->sa_handler; 1770SN/A ibcs2_to_bsd_sigset(&isa->sa_mask, &bsa->sa_mask); 1780SN/A bsa->sa_flags = 0; /* ??? SA_NODEFER */ 1790SN/A if ((isa->sa_flags & IBCS2_SA_NOCLDSTOP) != 0) 1800SN/A bsa->sa_flags |= SA_NOCLDSTOP; 1810SN/A} 1820SN/A 1830SN/Astatic void 1840SN/Absd_to_ibcs2_sigaction(bsa, isa) 1850SN/A struct sigaction *bsa; 1860SN/A struct ibcs2_sigaction *isa; 1870SN/A{ 1880SN/A 1890SN/A isa->sa_handler = bsa->sa_handler; 1900SN/A bsd_to_ibcs2_sigset(&bsa->sa_mask, &isa->sa_mask); 1910SN/A isa->sa_flags = 0; 1920SN/A if ((bsa->sa_flags & SA_NOCLDSTOP) != 0) 1930SN/A isa->sa_flags |= IBCS2_SA_NOCLDSTOP; 1940SN/A} 1950SN/A 1960SN/Aint 1970SN/Aibcs2_sigaction(p, uap, retval) 1980SN/A register struct proc *p; 1990SN/A struct ibcs2_sigaction_args *uap; 2000SN/A int *retval; 2010SN/A{ 2020SN/A struct ibcs2_sigaction *nisa, *oisa, tmpisa; 2030SN/A struct sigaction *nbsa, *obsa, tmpbsa; 2040SN/A struct sigaction_args sa; 2050SN/A caddr_t sg; 2060SN/A int error; 2070SN/A 2080SN/A sg = stackgap_init(); 2090SN/A nisa = SCARG(uap, act); 2100SN/A oisa = SCARG(uap, oact); 2110SN/A 2120SN/A if (oisa != NULL) 2130SN/A obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); 2140SN/A else 2158204SN/A obsa = NULL; 2168204SN/A 2178204SN/A if (nisa != NULL) { 2188204SN/A nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); 2198204SN/A if ((error = copyin(nisa, &tmpisa, sizeof(tmpisa))) != 0) 2208204SN/A return error; 2218204SN/A ibcs2_to_bsd_sigaction(&tmpisa, &tmpbsa); 2228204SN/A if ((error = copyout(&tmpbsa, nbsa, sizeof(tmpbsa))) != 0) 2238204SN/A return error; 2248204SN/A } else 2258204SN/A nbsa = NULL; 2268204SN/A 2278204SN/A SCARG(&sa, signum) = ibcs2_to_bsd_sig[SCARG(uap, sig)]; 2288204SN/A SCARG(&sa, nsa) = nbsa; 2298204SN/A SCARG(&sa, osa) = obsa; 2308204SN/A 2318204SN/A if ((error = sigaction(p, &sa, retval)) != 0) 2328204SN/A return error; 2338204SN/A 2348204SN/A if (oisa != NULL) { 2358204SN/A if ((error = copyin(obsa, &tmpbsa, sizeof(tmpbsa))) != 0) 2368204SN/A return error; 2378204SN/A bsd_to_ibcs2_sigaction(&tmpbsa, &tmpisa); 2388204SN/A if ((error = copyout(&tmpisa, oisa, sizeof(tmpisa))) != 0) 2398204SN/A return error; 2408204SN/A } 2418204SN/A 2428204SN/A return 0; 2438204SN/A} 2448204SN/A 2450SN/Aint 2460SN/Aibcs2_sigsys(p, uap, retval) 2470SN/A register struct proc *p; 2480SN/A struct ibcs2_sigsys_args *uap; 2490SN/A int *retval; 2500SN/A{ 2510SN/A struct sigaction sa; 2520SN/A int signum = ibcs2_to_bsd_sig[IBCS2_SIGNO(SCARG(uap, sig))]; 2530SN/A int error; 2540SN/A caddr_t sg = stackgap_init(); 2550SN/A 2560SN/A if (signum <= 0 || signum >= IBCS2_NSIG) { 2570SN/A if (IBCS2_SIGCALL(SCARG(uap, sig)) == IBCS2_SIGNAL_MASK || 2580SN/A IBCS2_SIGCALL(SCARG(uap, sig)) == IBCS2_SIGSET_MASK) 2590SN/A *retval = (int)IBCS2_SIG_ERR; 2600SN/A return EINVAL; 2610SN/A } 2620SN/A 2630SN/A switch (IBCS2_SIGCALL(SCARG(uap, sig))) { 2640SN/A case IBCS2_SIGSET_MASK: 2650SN/A /* 2660SN/A * Check for SIG_HOLD action. 2670SN/A * Otherwise, perform signal() except with different sa_flags. 2680SN/A */ 2690SN/A if (SCARG(uap, fp) != IBCS2_SIG_HOLD) { 2700SN/A /* add sig to mask before exececuting signal handler */ 2710SN/A sa.sa_flags = 0; 2720SN/A goto ibcs2_sigset; 2730SN/A } 2740SN/A /* else fallthrough to sighold */ 2750SN/A 2760SN/A case IBCS2_SIGHOLD_MASK: 2770SN/A { 2780SN/A struct sigprocmask_args sa; 2790SN/A 2800SN/A SCARG(&sa, how) = SIG_BLOCK; 2810SN/A SCARG(&sa, mask) = sigmask(signum); 2820SN/A return sigprocmask(p, &sa, retval); 2830SN/A } 2840SN/A 2850SN/A case IBCS2_SIGNAL_MASK: 2860SN/A { 2870SN/A struct sigaction_args sa_args; 2880SN/A struct sigaction *nbsa, *obsa; 2890SN/A 2900SN/A /* do not automatically block signal */ 2910SN/A sa.sa_flags = SA_NODEFER; 2920SN/A#ifdef SA_RESETHAND 2930SN/A if((signum != IBCS2_SIGILL) && 2940SN/A (signum != IBCS2_SIGTRAP) && 2950SN/A (signum != IBCS2_SIGPWR)) 2960SN/A /* set to SIG_DFL before executing handler */ 2970SN/A sa.sa_flags |= SA_RESETHAND; 2980SN/A#endif 2990SN/A ibcs2_sigset: 3000SN/A nbsa = stackgap_alloc(&sg, sizeof(struct sigaction)); 3010SN/A obsa = stackgap_alloc(&sg, sizeof(struct sigaction)); 3020SN/A SCARG(&sa_args, signum) = signum; 3030SN/A SCARG(&sa_args, nsa) = nbsa; 3040SN/A SCARG(&sa_args, osa) = obsa; 3050SN/A 3060SN/A sa.sa_handler = SCARG(uap, fp); 3070SN/A sigemptyset(&sa.sa_mask); 3080SN/A#if 0 3090SN/A if (signum != SIGALRM) 3100SN/A sa.sa_flags |= SA_RESTART; 3110SN/A#endif 3120SN/A *retval = (int)IBCS2_SIG_ERR; /* init error return */ 3130SN/A 3140SN/A /* perform native sigaction() */ 3150SN/A if ((error = copyout(&sa, nbsa, sizeof(sa))) != 0) 3160SN/A return error; 3170SN/A if ((error = sigaction(p, &sa_args, retval)) != 0) { 3180SN/A DPRINTF(("signal: sigaction failed: %d\n", 3190SN/A error)); 3200SN/A return error; 3210SN/A } 3220SN/A if ((error = copyin(obsa, &sa, sizeof(sa))) != 0) 3230SN/A return error; 3240SN/A *retval = (int)sa.sa_handler; 3250SN/A 3260SN/A /* special sigset() check */ 3270SN/A if(IBCS2_SIGCALL(SCARG(uap, sig)) == IBCS2_SIGSET_MASK) 3280SN/A /* check to make sure signal is not blocked */ 3290SN/A if(sigismember(&p->p_sigmask, signum)) { 3300SN/A /* return SIG_HOLD and unblock signal*/ 3310SN/A *retval = (int)IBCS2_SIG_HOLD; 3320SN/A p->p_sigmask &= ~sigmask(signum); 3330SN/A } 3340SN/A 3350SN/A return 0; 3360SN/A } 3370SN/A 3380SN/A case IBCS2_SIGRELSE_MASK: 3390SN/A { 3400SN/A struct sigprocmask_args sa; 3410SN/A 3420SN/A SCARG(&sa, how) = SIG_UNBLOCK; 3430SN/A SCARG(&sa, mask) = sigmask(signum); 3440SN/A return sigprocmask(p, &sa, retval); 3450SN/A } 3460SN/A 3470SN/A case IBCS2_SIGIGNORE_MASK: 3480SN/A { 3490SN/A struct sigaction_args sa_args; 3500SN/A struct sigaction *bsa; 3510SN/A 3520SN/A bsa = stackgap_alloc(&sg, sizeof(struct sigaction)); 3530SN/A SCARG(&sa_args, signum) = signum; 3540SN/A SCARG(&sa_args, nsa) = bsa; 3550SN/A SCARG(&sa_args, osa) = NULL; 3560SN/A 3570SN/A sa.sa_handler = SIG_IGN; 3580SN/A sigemptyset(&sa.sa_mask); 3590SN/A sa.sa_flags = 0; 3600SN/A if ((error = copyout(&sa, bsa, sizeof(sa))) != 0) 3610SN/A return error; 3620SN/A if ((error = sigaction(p, &sa_args, retval)) != 0) { 3630SN/A DPRINTF(("sigignore: sigaction failed\n")); 3640SN/A return error; 3650SN/A } 3660SN/A return 0; 3670SN/A } 3680SN/A 3690SN/A case IBCS2_SIGPAUSE_MASK: 3700SN/A { 3710SN/A struct sigsuspend_args sa; 3720SN/A 3730SN/A SCARG(&sa, mask) = p->p_sigmask &~ sigmask(signum); 3740SN/A return sigsuspend(p, &sa, retval); 3750SN/A } 3760SN/A 3770SN/A default: 3780SN/A return ENOSYS; 3790SN/A } 3800SN/A} 3810SN/A 3820SN/Aint 3830SN/Aibcs2_sigprocmask(p, uap, retval) 3840SN/A register struct proc *p; 3850SN/A struct ibcs2_sigprocmask_args *uap; 3860SN/A int *retval; 3870SN/A{ 3880SN/A ibcs2_sigset_t iss; 3890SN/A sigset_t bss; 3900SN/A int error = 0; 3910SN/A 3920SN/A if (SCARG(uap, oset) != NULL) { 3930SN/A /* Fix the return value first if needed */ 3940SN/A bsd_to_ibcs2_sigset(&p->p_sigmask, &iss); 3950SN/A if ((error = copyout(&iss, SCARG(uap, oset), sizeof(iss))) != 0) 3960SN/A return error; 3970SN/A } 3980SN/A 3990SN/A if (SCARG(uap, set) == NULL) 4000SN/A /* Just examine */ 4010SN/A return 0; 4020SN/A 4030SN/A if ((error = copyin(SCARG(uap, set), &iss, sizeof(iss))) != 0) 4040SN/A return error; 4050SN/A 4060SN/A ibcs2_to_bsd_sigset(&iss, &bss); 4070SN/A 4080SN/A (void) splhigh(); 4090SN/A 4100SN/A switch (SCARG(uap, how)) { 4110SN/A case IBCS2_SIG_BLOCK: 4120SN/A p->p_sigmask |= bss & ~sigcantmask; 4130SN/A break; 4140SN/A 4150SN/A case IBCS2_SIG_UNBLOCK: 4160SN/A p->p_sigmask &= ~bss; 4170SN/A break; 4180SN/A 4190SN/A case IBCS2_SIG_SETMASK: 4200SN/A p->p_sigmask = bss & ~sigcantmask; 4210SN/A break; 4220SN/A 4230SN/A default: 4240SN/A error = EINVAL; 4250SN/A break; 4260SN/A } 4270SN/A 4280SN/A (void) spl0(); 4290SN/A 4300SN/A return error; 4310SN/A} 4320SN/A 4330SN/Aint 4340SN/Aibcs2_sigpending(p, uap, retval) 4350SN/A register struct proc *p; 4360SN/A struct ibcs2_sigpending_args *uap; 4370SN/A int *retval; 4380SN/A{ 4390SN/A sigset_t bss; 4400SN/A ibcs2_sigset_t iss; 4410SN/A 4420SN/A bss = p->p_siglist & p->p_sigmask; 4430SN/A bsd_to_ibcs2_sigset(&bss, &iss); 4440SN/A 4450SN/A return copyout(&iss, SCARG(uap, mask), sizeof(iss)); 4460SN/A} 4470SN/A 4480SN/Aint 4490SN/Aibcs2_sigsuspend(p, uap, retval) 4500SN/A register struct proc *p; 4510SN/A struct ibcs2_sigsuspend_args *uap; 4520SN/A int *retval; 4530SN/A{ 4540SN/A ibcs2_sigset_t sss; 4550SN/A sigset_t bss; 4560SN/A struct sigsuspend_args sa; 4570SN/A int error; 4580SN/A 4590SN/A if ((error = copyin(SCARG(uap, mask), &sss, sizeof(sss))) != 0) 4600SN/A return error; 4610SN/A 4620SN/A ibcs2_to_bsd_sigset(&sss, &bss); 4630SN/A 4640SN/A SCARG(&sa, mask) = bss; 4650SN/A return sigsuspend(p, &sa, retval); 4660SN/A} 4670SN/A 4680SN/Aint 4690SN/Aibcs2_pause(p, uap, retval) 4700SN/A register struct proc *p; 4710SN/A struct ibcs2_pause_args *uap; 4720SN/A int *retval; 4730SN/A{ 4740SN/A struct sigsuspend_args bsa; 4750SN/A 4760SN/A SCARG(&bsa, mask) = p->p_sigmask; 4770SN/A return sigsuspend(p, &bsa, retval); 4780SN/A} 4790SN/A 480430SN/Aint 4810SN/Aibcs2_kill(p, uap, retval) 4820SN/A register struct proc *p; 4830SN/A struct ibcs2_kill_args *uap; 4840SN/A int *retval; 4850SN/A{ 4860SN/A struct kill_args ka; 4870SN/A 4880SN/A SCARG(&ka, pid) = SCARG(uap, pid); 4890SN/A SCARG(&ka, signum) = ibcs2_to_bsd_sig[SCARG(uap, signo)]; 4900SN/A return kill(p, &ka, retval); 4910SN/A} 4920SN/A