Home | History | Annotate | Line # | Download | only in common
linux_sigaction.c revision 1.4
      1  1.4  fvdl /*	$NetBSD: linux_sigaction.c,v 1.4 1995/06/22 21:34:39 fvdl Exp $	*/
      2  1.1  fvdl 
      3  1.1  fvdl /*
      4  1.1  fvdl  * Copyright (c) 1995 Frank van der Linden
      5  1.1  fvdl  * All rights reserved.
      6  1.1  fvdl  *
      7  1.1  fvdl  * Redistribution and use in source and binary forms, with or without
      8  1.1  fvdl  * modification, are permitted provided that the following conditions
      9  1.1  fvdl  * are met:
     10  1.1  fvdl  * 1. Redistributions of source code must retain the above copyright
     11  1.1  fvdl  *    notice, this list of conditions and the following disclaimer.
     12  1.1  fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  fvdl  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  fvdl  *    documentation and/or other materials provided with the distribution.
     15  1.1  fvdl  * 3. All advertising materials mentioning features or use of this software
     16  1.1  fvdl  *    must display the following acknowledgement:
     17  1.1  fvdl  *      This product includes software developed for the NetBSD Project
     18  1.1  fvdl  *      by Frank van der Linden
     19  1.1  fvdl  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  fvdl  *    derived from this software without specific prior written permission
     21  1.1  fvdl  *
     22  1.1  fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  fvdl  *
     33  1.1  fvdl  * heavily from: svr4_signal.c,v 1.7 1995/01/09 01:04:21 christos Exp
     34  1.1  fvdl  */
     35  1.1  fvdl 
     36  1.1  fvdl #include <sys/param.h>
     37  1.1  fvdl #include <sys/systm.h>
     38  1.1  fvdl #include <sys/namei.h>
     39  1.1  fvdl #include <sys/proc.h>
     40  1.1  fvdl #include <sys/filedesc.h>
     41  1.1  fvdl #include <sys/ioctl.h>
     42  1.1  fvdl #include <sys/mount.h>
     43  1.1  fvdl #include <sys/kernel.h>
     44  1.1  fvdl #include <sys/signal.h>
     45  1.1  fvdl #include <sys/signalvar.h>
     46  1.1  fvdl #include <sys/malloc.h>
     47  1.4  fvdl #include <sys/exec.h>
     48  1.1  fvdl 
     49  1.1  fvdl #include <sys/syscallargs.h>
     50  1.1  fvdl 
     51  1.1  fvdl #include <compat/linux/linux_types.h>
     52  1.1  fvdl #include <compat/linux/linux_syscallargs.h>
     53  1.1  fvdl #include <compat/linux/linux_util.h>
     54  1.1  fvdl #include <compat/linux/linux_signal.h>
     55  1.1  fvdl 
     56  1.1  fvdl /*
     57  1.3  fvdl  * Most of ths stuff in this file is taken from Christos' SVR4 emul
     58  1.1  fvdl  * code. The things that need to be done are largely the same, so
     59  1.1  fvdl  * re-inventing the wheel doesn't make much sense.
     60  1.1  fvdl  */
     61  1.1  fvdl 
     62  1.1  fvdl /*
     63  1.1  fvdl  * Some boring signal conversion functions. Just a switch() for all signals;
     64  1.1  fvdl  * return the converted signal number, 0 if not supported.
     65  1.1  fvdl  */
     66  1.1  fvdl 
     67  1.1  fvdl int
     68  1.1  fvdl bsd_to_linux_sig(sig)
     69  1.1  fvdl 	int sig;
     70  1.1  fvdl {
     71  1.1  fvdl 	switch(sig) {
     72  1.1  fvdl 	case SIGHUP:
     73  1.1  fvdl 		return LINUX_SIGHUP;
     74  1.1  fvdl 	case SIGINT:
     75  1.1  fvdl 		return LINUX_SIGINT;
     76  1.1  fvdl 	case SIGQUIT:
     77  1.1  fvdl 		return LINUX_SIGQUIT;
     78  1.1  fvdl 	case SIGILL:
     79  1.1  fvdl 		return LINUX_SIGILL;
     80  1.1  fvdl 	case SIGTRAP:
     81  1.1  fvdl 		return LINUX_SIGTRAP;
     82  1.1  fvdl 	case SIGABRT:
     83  1.1  fvdl 		return LINUX_SIGABRT;
     84  1.1  fvdl 	case SIGFPE:
     85  1.1  fvdl 		return LINUX_SIGFPE;
     86  1.1  fvdl 	case SIGKILL:
     87  1.1  fvdl 		return LINUX_SIGKILL;
     88  1.1  fvdl 	case SIGBUS:
     89  1.1  fvdl 		return LINUX_SIGBUS;
     90  1.1  fvdl 	case SIGSEGV:
     91  1.1  fvdl 		return LINUX_SIGSEGV;
     92  1.1  fvdl 	case SIGPIPE:
     93  1.1  fvdl 		return LINUX_SIGPIPE;
     94  1.1  fvdl 	case SIGALRM:
     95  1.1  fvdl 		return LINUX_SIGALRM;
     96  1.1  fvdl 	case SIGTERM:
     97  1.1  fvdl 		return LINUX_SIGTERM;
     98  1.1  fvdl 	case SIGURG:
     99  1.1  fvdl 		return LINUX_SIGURG;
    100  1.1  fvdl 	case SIGSTOP:
    101  1.1  fvdl 		return LINUX_SIGSTOP;
    102  1.1  fvdl 	case SIGTSTP:
    103  1.1  fvdl 		return LINUX_SIGTSTP;
    104  1.1  fvdl 	case SIGCONT:
    105  1.1  fvdl 		return LINUX_SIGCONT;
    106  1.1  fvdl 	case SIGCHLD:
    107  1.1  fvdl 		return LINUX_SIGCHLD;
    108  1.1  fvdl 	case SIGTTIN:
    109  1.1  fvdl 		return LINUX_SIGTTIN;
    110  1.1  fvdl 	case SIGTTOU:
    111  1.1  fvdl 		return LINUX_SIGTTOU;
    112  1.1  fvdl 	case SIGIO:
    113  1.1  fvdl 		return LINUX_SIGIO;
    114  1.1  fvdl 	case SIGXCPU:
    115  1.1  fvdl 		return LINUX_SIGXCPU;
    116  1.1  fvdl 	case SIGXFSZ:
    117  1.1  fvdl 		return LINUX_SIGXFSZ;
    118  1.1  fvdl 	case SIGVTALRM:
    119  1.1  fvdl 		return LINUX_SIGVTALRM;
    120  1.1  fvdl 	case SIGPROF:
    121  1.1  fvdl 		return LINUX_SIGPROF;
    122  1.1  fvdl 	case SIGWINCH:
    123  1.1  fvdl 		return LINUX_SIGWINCH;
    124  1.1  fvdl 	case SIGUSR1:
    125  1.1  fvdl 		return LINUX_SIGUSR1;
    126  1.1  fvdl 	case SIGUSR2:
    127  1.1  fvdl 		return LINUX_SIGUSR2;
    128  1.1  fvdl 	/* Not supported: EMT, SYS, INFO */
    129  1.1  fvdl 	}
    130  1.1  fvdl 	return 0;
    131  1.1  fvdl }
    132  1.1  fvdl 
    133  1.1  fvdl int
    134  1.1  fvdl linux_to_bsd_sig(sig)
    135  1.1  fvdl 	int sig;
    136  1.1  fvdl {
    137  1.1  fvdl 	switch(sig) {
    138  1.1  fvdl 	case LINUX_SIGHUP:
    139  1.1  fvdl 		return SIGHUP;
    140  1.1  fvdl 	case LINUX_SIGINT:
    141  1.1  fvdl 		return SIGINT;
    142  1.1  fvdl 	case LINUX_SIGQUIT:
    143  1.1  fvdl 		return SIGQUIT;
    144  1.1  fvdl 	case LINUX_SIGILL:
    145  1.1  fvdl 		return SIGILL;
    146  1.1  fvdl 	case LINUX_SIGTRAP:
    147  1.1  fvdl 		return SIGTRAP;
    148  1.1  fvdl 	case LINUX_SIGABRT:
    149  1.1  fvdl 		return SIGABRT;
    150  1.1  fvdl 	case LINUX_SIGBUS:
    151  1.1  fvdl 		return SIGBUS;
    152  1.1  fvdl 	case LINUX_SIGFPE:
    153  1.1  fvdl 		return SIGFPE;
    154  1.1  fvdl 	case LINUX_SIGKILL:
    155  1.1  fvdl 		return SIGKILL;
    156  1.1  fvdl 	case LINUX_SIGUSR1:
    157  1.1  fvdl 		return SIGUSR1;
    158  1.1  fvdl 	case LINUX_SIGSEGV:
    159  1.1  fvdl 		return SIGSEGV;
    160  1.1  fvdl 	case LINUX_SIGUSR2:
    161  1.1  fvdl 		return SIGUSR2;
    162  1.1  fvdl 	case LINUX_SIGPIPE:
    163  1.1  fvdl 		return SIGPIPE;
    164  1.1  fvdl 	case LINUX_SIGALRM:
    165  1.1  fvdl 		return SIGALRM;
    166  1.1  fvdl 	case LINUX_SIGTERM:
    167  1.1  fvdl 		return SIGTERM;
    168  1.1  fvdl 	case LINUX_SIGCHLD:
    169  1.1  fvdl 		return SIGCHLD;
    170  1.1  fvdl 	case LINUX_SIGCONT:
    171  1.1  fvdl 		return SIGCONT;
    172  1.1  fvdl 	case LINUX_SIGSTOP:
    173  1.1  fvdl 		return SIGSTOP;
    174  1.1  fvdl 	case LINUX_SIGTSTP:
    175  1.1  fvdl 		return SIGTSTP;
    176  1.1  fvdl 	case LINUX_SIGTTIN:
    177  1.1  fvdl 		return SIGTTIN;
    178  1.1  fvdl 	case LINUX_SIGTTOU:
    179  1.1  fvdl 		return SIGTTOU;
    180  1.1  fvdl 	case LINUX_SIGURG:
    181  1.1  fvdl 		return SIGURG;
    182  1.1  fvdl 	case LINUX_SIGXCPU:
    183  1.1  fvdl 		return SIGXCPU;
    184  1.1  fvdl 	case LINUX_SIGXFSZ:
    185  1.1  fvdl 		return SIGXFSZ;
    186  1.1  fvdl 	case LINUX_SIGVTALRM:
    187  1.1  fvdl 		return SIGVTALRM;
    188  1.1  fvdl 	case LINUX_SIGPROF:
    189  1.1  fvdl 		return SIGPROF;
    190  1.1  fvdl 	case LINUX_SIGWINCH:
    191  1.1  fvdl 		return SIGWINCH;
    192  1.1  fvdl 	case LINUX_SIGIO:
    193  1.1  fvdl 		return SIGIO;
    194  1.1  fvdl 	/* Not supported: STKFLT, PWR */
    195  1.1  fvdl 	}
    196  1.1  fvdl 	return 0;
    197  1.1  fvdl }
    198  1.1  fvdl 
    199  1.1  fvdl /*
    200  1.1  fvdl  * Ok, we know that Linux and BSD signals both are just an unsigned int.
    201  1.1  fvdl  * Don't bother to use the sigismember() stuff for now.
    202  1.1  fvdl  */
    203  1.1  fvdl static void
    204  1.1  fvdl linux_to_bsd_sigset(lss, bss)
    205  1.1  fvdl 	const linux_sigset_t *lss;
    206  1.1  fvdl 	sigset_t *bss;
    207  1.1  fvdl {
    208  1.1  fvdl 	int i, newsig;
    209  1.1  fvdl 
    210  1.1  fvdl 	*bss = (sigset_t) 0;
    211  1.1  fvdl 	for (i = 1; i <= LINUX_NSIG; i++) {
    212  1.1  fvdl 		if (*lss & sigmask(i)) {
    213  1.1  fvdl 			newsig = linux_to_bsd_sig(i);
    214  1.1  fvdl 			if (newsig)
    215  1.1  fvdl 				*bss |= sigmask(newsig);
    216  1.1  fvdl 		}
    217  1.1  fvdl 	}
    218  1.1  fvdl }
    219  1.1  fvdl 
    220  1.1  fvdl void
    221  1.1  fvdl bsd_to_linux_sigset(bss, lss)
    222  1.1  fvdl 	const sigset_t *bss;
    223  1.1  fvdl 	linux_sigset_t *lss;
    224  1.1  fvdl {
    225  1.1  fvdl 	int i, newsig;
    226  1.1  fvdl 
    227  1.1  fvdl 	*lss = (linux_sigset_t) 0;
    228  1.1  fvdl 	for (i = 1; i <= NSIG; i++) {
    229  1.1  fvdl 		if (*bss & sigmask(i)) {
    230  1.1  fvdl 			newsig = bsd_to_linux_sig(i);
    231  1.1  fvdl 			if (newsig)
    232  1.1  fvdl 				*lss |= sigmask(newsig);
    233  1.1  fvdl 		}
    234  1.1  fvdl 	}
    235  1.1  fvdl }
    236  1.1  fvdl 
    237  1.1  fvdl /*
    238  1.1  fvdl  * Convert between Linux and BSD sigaction structures. Linux has
    239  1.1  fvdl  * one extra field (sa_restorer) which we don't support. The Linux
    240  1.1  fvdl  * SA_ONESHOT and SA_NOMASK flags (which together form the old
    241  1.1  fvdl  * SysV signal behavior) are silently ignored. XXX
    242  1.1  fvdl  */
    243  1.1  fvdl void
    244  1.1  fvdl linux_to_bsd_sigaction(lsa, bsa)
    245  1.1  fvdl 	struct linux_sigaction *lsa;
    246  1.1  fvdl 	struct sigaction *bsa;
    247  1.1  fvdl {
    248  1.1  fvdl 	bsa->sa_handler = lsa->sa_handler;
    249  1.1  fvdl 	linux_to_bsd_sigset(&bsa->sa_mask, &lsa->sa_mask);
    250  1.1  fvdl 	bsa->sa_flags = 0;
    251  1.1  fvdl 	bsa->sa_flags |= cvtto_bsd_mask(lsa->sa_flags, LINUX_SA_NOCLDSTOP,
    252  1.1  fvdl 	    SA_NOCLDSTOP);
    253  1.1  fvdl 	bsa->sa_flags |= cvtto_bsd_mask(lsa->sa_flags, LINUX_SA_ONSTACK,
    254  1.1  fvdl 	    SA_ONSTACK);
    255  1.1  fvdl 	bsa->sa_flags |= cvtto_bsd_mask(lsa->sa_flags, LINUX_SA_RESTART,
    256  1.1  fvdl 	    SA_RESTART);
    257  1.1  fvdl }
    258  1.1  fvdl 
    259  1.1  fvdl void
    260  1.1  fvdl bsd_to_linux_sigaction(bsa, lsa)
    261  1.1  fvdl 	struct sigaction *bsa;
    262  1.1  fvdl 	struct linux_sigaction *lsa;
    263  1.1  fvdl {
    264  1.1  fvdl 	lsa->sa_handler = bsa->sa_handler;
    265  1.1  fvdl 	bsd_to_linux_sigset(&lsa->sa_mask, &bsa->sa_mask);
    266  1.1  fvdl 	lsa->sa_flags = 0;
    267  1.1  fvdl 	lsa->sa_flags |= cvtto_linux_mask(bsa->sa_flags, SA_NOCLDSTOP,
    268  1.1  fvdl 	    LINUX_SA_NOCLDSTOP);
    269  1.1  fvdl 	lsa->sa_flags |= cvtto_linux_mask(bsa->sa_flags, SA_ONSTACK,
    270  1.1  fvdl 	    LINUX_SA_ONSTACK);
    271  1.1  fvdl 	lsa->sa_flags |= cvtto_linux_mask(bsa->sa_flags, SA_RESTART,
    272  1.1  fvdl 	    LINUX_SA_RESTART);
    273  1.1  fvdl 	lsa->sa_restorer = NULL;
    274  1.1  fvdl }
    275  1.1  fvdl 
    276  1.1  fvdl 
    277  1.1  fvdl /*
    278  1.1  fvdl  * The Linux sigaction() system call. Do the usual conversions,
    279  1.1  fvdl  * and just call sigaction(). Some flags and values are silently
    280  1.1  fvdl  * ignored (see above).
    281  1.1  fvdl  */
    282  1.1  fvdl int
    283  1.1  fvdl linux_sigaction(p, uap, retval)
    284  1.1  fvdl 	register struct proc *p;
    285  1.1  fvdl 	struct linux_sigaction_args /* {
    286  1.1  fvdl 		syscallarg(int) signum;
    287  1.1  fvdl 		syscallarg(struct linux_sigaction *) nsa;
    288  1.1  fvdl 		syscallarg(struct linux_sigaction *) osa;
    289  1.1  fvdl 	} */ *uap;
    290  1.1  fvdl 	register_t *retval;
    291  1.1  fvdl {
    292  1.1  fvdl 	struct sigaction *nbsda = NULL, *obsda = NULL, tmpbsda;
    293  1.1  fvdl 	struct linux_sigaction *nlsa, *olsa, tmplsa;
    294  1.1  fvdl 	struct sigaction_args sa;
    295  1.1  fvdl 	caddr_t sg;
    296  1.1  fvdl 	int error;
    297  1.1  fvdl 
    298  1.1  fvdl 	sg = stackgap_init();
    299  1.1  fvdl 	olsa = SCARG(uap, osa);
    300  1.1  fvdl 	nlsa = SCARG(uap, nsa);
    301  1.1  fvdl 
    302  1.1  fvdl 	if (olsa != NULL)
    303  1.1  fvdl 		obsda = stackgap_alloc(&sg, sizeof (struct sigaction));
    304  1.1  fvdl 
    305  1.1  fvdl 	if (nlsa != NULL) {
    306  1.1  fvdl 		nbsda = stackgap_alloc(&sg, sizeof (struct sigaction));
    307  1.1  fvdl 		if ((error = copyin(nlsa, &tmplsa, sizeof tmplsa)))
    308  1.1  fvdl 			return error;
    309  1.1  fvdl 		linux_to_bsd_sigaction(&tmplsa, &tmpbsda);
    310  1.1  fvdl 		if ((error = copyout(&tmpbsda, nbsda, sizeof tmpbsda)))
    311  1.1  fvdl 			return error;
    312  1.1  fvdl 	}
    313  1.1  fvdl 
    314  1.1  fvdl 	SCARG(&sa, signum) = linux_to_bsd_sig(SCARG(uap, signum));
    315  1.1  fvdl 	SCARG(&sa, nsa) = nbsda;
    316  1.1  fvdl 	SCARG(&sa, osa) = obsda;
    317  1.1  fvdl 
    318  1.1  fvdl 	if ((error = sigaction(p, &sa, retval)))
    319  1.1  fvdl 		return error;
    320  1.1  fvdl 
    321  1.1  fvdl 	if (olsa != NULL) {
    322  1.1  fvdl 		if ((error = copyin(obsda, &tmpbsda, sizeof tmpbsda)))
    323  1.1  fvdl 			return error;
    324  1.1  fvdl 		bsd_to_linux_sigaction(&tmpbsda, &tmplsa);
    325  1.1  fvdl 		if ((error = copyout(&tmplsa, olsa, sizeof tmplsa)))
    326  1.1  fvdl 			return error;
    327  1.1  fvdl 	}
    328  1.1  fvdl 	return 0;
    329  1.1  fvdl }
    330  1.1  fvdl 
    331  1.1  fvdl /*
    332  1.1  fvdl  * The Linux signal() system call. I think that the signal() in the C
    333  1.1  fvdl  * library actually calls sigaction, so I doubt this one is ever used.
    334  1.1  fvdl  * But hey, it can't hurt having it here. The same restrictions as for
    335  1.1  fvdl  * sigaction() apply.
    336  1.1  fvdl  */
    337  1.1  fvdl int
    338  1.1  fvdl linux_signal(p, uap, retval)
    339  1.1  fvdl 	register struct proc *p;
    340  1.1  fvdl 	struct linux_signal_args /* {
    341  1.1  fvdl 		syscallarg(int) sig;
    342  1.1  fvdl 		syscallarg(linux_handler_t) handler;
    343  1.1  fvdl 	} */ *uap;
    344  1.1  fvdl 	register_t *retval;
    345  1.1  fvdl {
    346  1.1  fvdl 	caddr_t sg;
    347  1.1  fvdl 	struct sigaction_args sa_args;
    348  1.1  fvdl 	struct sigaction *osa, *nsa, tmpsa;
    349  1.1  fvdl 	int error;
    350  1.1  fvdl 
    351  1.1  fvdl 	sg = stackgap_init();
    352  1.1  fvdl 	nsa = stackgap_alloc(&sg, sizeof *nsa);
    353  1.1  fvdl 	osa = stackgap_alloc(&sg, sizeof *osa);
    354  1.1  fvdl 
    355  1.1  fvdl 	tmpsa.sa_handler = SCARG(uap, handler);
    356  1.1  fvdl 	tmpsa.sa_mask = (sigset_t) 0;
    357  1.1  fvdl 	tmpsa.sa_flags = 0;
    358  1.1  fvdl 	if ((error = copyout(&tmpsa, nsa, sizeof tmpsa)))
    359  1.1  fvdl 		return error;
    360  1.1  fvdl 
    361  1.1  fvdl 	SCARG(&sa_args, signum) = linux_to_bsd_sig(SCARG(uap, sig));
    362  1.1  fvdl 	SCARG(&sa_args, osa) = osa;
    363  1.1  fvdl 	SCARG(&sa_args, nsa) = nsa;
    364  1.1  fvdl 	if ((error = sigaction(p, &sa_args, retval)))
    365  1.1  fvdl 		return error;
    366  1.1  fvdl 
    367  1.1  fvdl 	if ((error = copyin(osa, &tmpsa, sizeof *osa)))
    368  1.1  fvdl 		return error;
    369  1.1  fvdl 	retval[0] = (register_t) tmpsa.sa_handler;
    370  1.1  fvdl 
    371  1.1  fvdl 	return 0;
    372  1.1  fvdl }
    373  1.1  fvdl 
    374  1.1  fvdl /*
    375  1.1  fvdl  * This is just a copy of the svr4 compat one. I feel so creative now.
    376  1.1  fvdl  */
    377  1.1  fvdl int
    378  1.1  fvdl linux_sigprocmask(p, uap, retval)
    379  1.1  fvdl 	register struct proc *p;
    380  1.1  fvdl 	register struct linux_sigprocmask_args /* {
    381  1.1  fvdl 		syscallarg(int) how;
    382  1.1  fvdl 		syscallarg(linux_sigset_t *) set;
    383  1.1  fvdl 		syscallarg(linux_sigset_t * oset;
    384  1.1  fvdl 	} */ *uap;
    385  1.1  fvdl 	register_t *retval;
    386  1.1  fvdl {
    387  1.1  fvdl 	linux_sigset_t ss;
    388  1.1  fvdl 	sigset_t bs;
    389  1.1  fvdl 	int error = 0;
    390  1.1  fvdl 
    391  1.1  fvdl 	*retval = 0;
    392  1.1  fvdl 
    393  1.1  fvdl 	if (SCARG(uap, oset) != NULL) {
    394  1.1  fvdl 		/* Fix the return value first if needed */
    395  1.1  fvdl 		bsd_to_linux_sigset(&p->p_sigmask, &ss);
    396  1.1  fvdl 		if ((error = copyout(&ss, SCARG(uap, oset), sizeof(ss))) != 0)
    397  1.1  fvdl 			return error;
    398  1.1  fvdl 	}
    399  1.1  fvdl 
    400  1.1  fvdl 	if (SCARG(uap, set) == NULL)
    401  1.1  fvdl 		/* Just examine */
    402  1.1  fvdl 		return 0;
    403  1.1  fvdl 
    404  1.1  fvdl 	if ((error = copyin(SCARG(uap, set), &ss, sizeof(ss))) != 0)
    405  1.1  fvdl 		return error;
    406  1.1  fvdl 
    407  1.1  fvdl 	linux_to_bsd_sigset(&ss, &bs);
    408  1.1  fvdl 
    409  1.1  fvdl 	(void) splhigh();
    410  1.1  fvdl 
    411  1.1  fvdl 	switch (SCARG(uap, how)) {
    412  1.1  fvdl 	case LINUX_SIG_BLOCK:
    413  1.1  fvdl 		p->p_sigmask |= bs & ~sigcantmask;
    414  1.1  fvdl 		break;
    415  1.1  fvdl 
    416  1.1  fvdl 	case LINUX_SIG_UNBLOCK:
    417  1.1  fvdl 		p->p_sigmask &= ~bs;
    418  1.1  fvdl 		break;
    419  1.1  fvdl 
    420  1.1  fvdl 	case LINUX_SIG_SETMASK:
    421  1.1  fvdl 		p->p_sigmask = bs & ~sigcantmask;
    422  1.1  fvdl 		break;
    423  1.1  fvdl 
    424  1.1  fvdl 	default:
    425  1.1  fvdl 		error = EINVAL;
    426  1.1  fvdl 		break;
    427  1.1  fvdl 	}
    428  1.1  fvdl 
    429  1.1  fvdl 	(void) spl0();
    430  1.1  fvdl 
    431  1.1  fvdl 	return error;
    432  1.1  fvdl }
    433  1.1  fvdl 
    434  1.1  fvdl /*
    435  1.1  fvdl  * The functions below really make no distinction between an int
    436  1.1  fvdl  * and [linux_]sigset_t. This is ok for now, but it might break
    437  1.1  fvdl  * sometime. Then again, sigset_t is trusted to be an int everywhere
    438  1.1  fvdl  * else in the kernel too.
    439  1.1  fvdl  */
    440  1.1  fvdl /* ARGSUSED */
    441  1.1  fvdl int
    442  1.1  fvdl linux_siggetmask(p, uap, retval)
    443  1.1  fvdl 	struct proc *p;
    444  1.1  fvdl 	void *uap;
    445  1.1  fvdl 	register_t *retval;
    446  1.1  fvdl {
    447  1.1  fvdl 	bsd_to_linux_sigset(&p->p_sigmask, (linux_sigset_t *) retval);
    448  1.1  fvdl 	return 0;
    449  1.1  fvdl }
    450  1.1  fvdl 
    451  1.1  fvdl /*
    452  1.1  fvdl  * The following three functions fiddle with a process' signal mask.
    453  1.1  fvdl  * Convert the signal masks because of the different signal
    454  1.1  fvdl  * values for Linux. The need for this is the reason why
    455  1.1  fvdl  * they are here, and have not been mapped directly.
    456  1.1  fvdl  */
    457  1.1  fvdl int
    458  1.1  fvdl linux_sigsetmask(p, uap, retval)
    459  1.1  fvdl 	struct proc *p;
    460  1.1  fvdl 	struct linux_sigsetmask_args /* {
    461  1.1  fvdl 		syscallarg(linux_sigset_t) mask;
    462  1.1  fvdl 	} */ *uap;
    463  1.1  fvdl 	register_t *retval;
    464  1.1  fvdl {
    465  1.1  fvdl 	linux_sigset_t mask;
    466  1.1  fvdl 	sigset_t bsdsig;
    467  1.1  fvdl 
    468  1.1  fvdl 	bsd_to_linux_sigset(&p->p_sigmask, (linux_sigset_t *) retval);
    469  1.1  fvdl 
    470  1.1  fvdl 	mask = SCARG(uap, mask);
    471  1.1  fvdl 	bsd_to_linux_sigset(&mask, &bsdsig);
    472  1.1  fvdl 
    473  1.1  fvdl 	splhigh();
    474  1.1  fvdl 	p->p_sigmask = bsdsig & ~sigcantmask;
    475  1.1  fvdl 	spl0();
    476  1.1  fvdl 
    477  1.1  fvdl 	return 0;
    478  1.1  fvdl }
    479  1.1  fvdl 
    480  1.1  fvdl int
    481  1.1  fvdl linux_sigpending(p, uap, retval)
    482  1.1  fvdl 	struct proc *p;
    483  1.1  fvdl 	struct linux_sigpending_args /* {
    484  1.1  fvdl 		syscallarg(linux_sigset_t *) mask;
    485  1.1  fvdl 	} */ *uap;
    486  1.1  fvdl 	register_t *retval;
    487  1.1  fvdl {
    488  1.1  fvdl 	sigset_t bsdsig;
    489  1.1  fvdl 	linux_sigset_t linuxsig;
    490  1.1  fvdl 
    491  1.1  fvdl 	bsdsig = p->p_siglist & p->p_sigmask;
    492  1.1  fvdl 
    493  1.1  fvdl 	bsd_to_linux_sigset(&bsdsig, &linuxsig);
    494  1.1  fvdl 	return copyout(&linuxsig, SCARG(uap, mask), sizeof linuxsig);
    495  1.1  fvdl }
    496  1.1  fvdl 
    497  1.1  fvdl int
    498  1.1  fvdl linux_sigsuspend(p, uap, retval)
    499  1.1  fvdl 	struct proc *p;
    500  1.1  fvdl 	struct linux_sigsuspend_args /* {
    501  1.3  fvdl 		syscallarg(caddr_t) restart;
    502  1.3  fvdl 		syscallarg(int) oldmask;
    503  1.1  fvdl 		syscallarg(int) mask;
    504  1.1  fvdl 	} */ *uap;
    505  1.1  fvdl 	register_t *retval;
    506  1.1  fvdl {
    507  1.1  fvdl 	struct sigsuspend_args ssa;
    508  1.1  fvdl 
    509  1.1  fvdl 	linux_to_bsd_sigset(&SCARG(uap, mask), &SCARG(&ssa, mask));
    510  1.1  fvdl 	return sigsuspend(p, &ssa, retval);
    511  1.3  fvdl }
    512  1.3  fvdl 
    513  1.3  fvdl /*
    514  1.3  fvdl  * The deprecated pause(2), which is really just an instance
    515  1.3  fvdl  * of sigsuspend(2).
    516  1.3  fvdl  */
    517  1.3  fvdl int
    518  1.3  fvdl linux_pause(p, uap, retval)
    519  1.3  fvdl 	struct proc *p;
    520  1.3  fvdl 	void *uap;
    521  1.3  fvdl 	register_t *retval;
    522  1.3  fvdl {
    523  1.3  fvdl 	struct sigsuspend_args bsa;
    524  1.3  fvdl 
    525  1.3  fvdl 	SCARG(&bsa, mask) = p->p_sigmask;
    526  1.3  fvdl 	return sigsuspend(p, &bsa, retval);
    527  1.1  fvdl }
    528  1.1  fvdl 
    529  1.1  fvdl /*
    530  1.1  fvdl  * Once more: only a signal conversion is needed.
    531  1.1  fvdl  */
    532  1.1  fvdl int
    533  1.1  fvdl linux_kill(p, uap, retval)
    534  1.1  fvdl 	struct proc *p;
    535  1.1  fvdl 	struct linux_kill_args /* {
    536  1.1  fvdl 		syscallarg(int) pid;
    537  1.1  fvdl 		syscallarg(int) signum;
    538  1.1  fvdl 	} */ *uap;
    539  1.1  fvdl 	register_t *retval;
    540  1.1  fvdl {
    541  1.1  fvdl 	SCARG(uap, signum) = linux_to_bsd_sig(SCARG(uap, signum));
    542  1.1  fvdl 	return kill(p, (struct kill_args *) uap, retval);
    543  1.1  fvdl }
    544