Home | History | Annotate | Line # | Download | only in common
      1  1.22  riastrad /*	$NetBSD: kern_sig_13.c,v 1.22 2021/09/07 11:43:02 riastradh Exp $	*/
      2   1.1    kleink 
      3   1.1    kleink /*-
      4   1.3   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1    kleink  * All rights reserved.
      6   1.1    kleink  *
      7   1.1    kleink  * This code is derived from software contributed to The NetBSD Foundation
      8   1.3   mycroft  * by Charles M. Hannum.
      9   1.1    kleink  *
     10   1.1    kleink  * Redistribution and use in source and binary forms, with or without
     11   1.1    kleink  * modification, are permitted provided that the following conditions
     12   1.1    kleink  * are met:
     13   1.1    kleink  * 1. Redistributions of source code must retain the above copyright
     14   1.1    kleink  *    notice, this list of conditions and the following disclaimer.
     15   1.1    kleink  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    kleink  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    kleink  *    documentation and/or other materials provided with the distribution.
     18   1.1    kleink  *
     19   1.1    kleink  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1    kleink  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1    kleink  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1    kleink  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1    kleink  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1    kleink  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1    kleink  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1    kleink  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1    kleink  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1    kleink  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1    kleink  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1    kleink  */
     31   1.6     lukem 
     32   1.6     lukem #include <sys/cdefs.h>
     33  1.22  riastrad __KERNEL_RCSID(0, "$NetBSD: kern_sig_13.c,v 1.22 2021/09/07 11:43:02 riastradh Exp $");
     34  1.21  pgoyette 
     35  1.21  pgoyette #if defined(_KERNEL_OPT)
     36  1.21  pgoyette #include "opt_compat_netbsd.h"
     37  1.21  pgoyette #endif
     38   1.1    kleink 
     39   1.1    kleink #include <sys/param.h>
     40   1.1    kleink #include <sys/proc.h>
     41   1.1    kleink #include <sys/signal.h>
     42   1.3   mycroft #include <sys/signalvar.h>
     43   1.1    kleink #include <sys/systm.h>
     44   1.1    kleink 
     45  1.21  pgoyette #include <sys/syscall.h>
     46  1.21  pgoyette #include <sys/syscallvar.h>
     47   1.1    kleink #include <sys/syscallargs.h>
     48   1.1    kleink 
     49   1.2    kleink #include <machine/limits.h>
     50   1.2    kleink 
     51  1.10  christos #include <compat/sys/signal.h>
     52  1.10  christos #include <compat/sys/signalvar.h>
     53   1.1    kleink #include <compat/common/compat_util.h>
     54  1.15       dsl #include <compat/common/compat_sigaltstack.h>
     55  1.21  pgoyette #include <compat/common/compat_mod.h>
     56  1.21  pgoyette 
     57  1.21  pgoyette static const struct syscall_package kern_sig_13_syscalls[] = {
     58  1.21  pgoyette         { SYS_compat_13_sigaction13, 0, (sy_call_t *)compat_13_sys_sigaction },
     59  1.21  pgoyette         { SYS_compat_13_sigaltstack13, 0,
     60  1.21  pgoyette 	    (sy_call_t *)compat_13_sys_sigaltstack },
     61  1.21  pgoyette         { SYS_compat_13_sigpending13, 0,
     62  1.21  pgoyette 	    (sy_call_t *)compat_13_sys_sigpending },
     63  1.21  pgoyette         { SYS_compat_13_sigprocmask13, 0,
     64  1.21  pgoyette 	    (sy_call_t *)compat_13_sys_sigprocmask },
     65  1.21  pgoyette         { SYS_compat_13_sigsuspend13, 0,
     66  1.21  pgoyette 	    (sy_call_t *)compat_13_sys_sigsuspend },
     67  1.21  pgoyette 	/* compat_13_sigreturn13 is in MD code! */
     68  1.21  pgoyette         { SYS_compat_13_sigreturn13, 0, (sy_call_t *)compat_13_sys_sigreturn },
     69  1.21  pgoyette 	{ 0, 0, NULL }
     70  1.21  pgoyette };
     71   1.3   mycroft 
     72   1.3   mycroft void
     73  1.16       dsl native_sigset13_to_sigset(const sigset13_t *oss, sigset_t *ss)
     74   1.3   mycroft {
     75   1.3   mycroft 
     76  1.22  riastrad 	memset(ss, 0, sizeof(*ss));
     77   1.3   mycroft 	ss->__bits[0] = *oss;
     78   1.3   mycroft 	ss->__bits[1] = 0;
     79   1.3   mycroft 	ss->__bits[2] = 0;
     80   1.3   mycroft 	ss->__bits[3] = 0;
     81   1.3   mycroft }
     82   1.3   mycroft 
     83   1.3   mycroft void
     84  1.16       dsl native_sigset_to_sigset13(const sigset_t *ss, sigset13_t *oss)
     85   1.3   mycroft {
     86   1.3   mycroft 
     87   1.3   mycroft 	*oss = ss->__bits[0];
     88   1.3   mycroft }
     89   1.3   mycroft 
     90   1.3   mycroft void
     91  1.16       dsl native_sigaction13_to_sigaction(const struct sigaction13 *osa, struct sigaction *sa)
     92   1.3   mycroft {
     93   1.3   mycroft 
     94  1.22  riastrad 	memset(sa, 0, sizeof(*sa));
     95   1.8  christos 	sa->sa_handler = osa->osa_handler;
     96   1.8  christos 	native_sigset13_to_sigset(&osa->osa_mask, &sa->sa_mask);
     97   1.8  christos 	sa->sa_flags = osa->osa_flags;
     98   1.3   mycroft }
     99   1.3   mycroft 
    100   1.3   mycroft void
    101  1.16       dsl native_sigaction_to_sigaction13(const struct sigaction *sa, struct sigaction13 *osa)
    102   1.3   mycroft {
    103   1.3   mycroft 
    104  1.22  riastrad 	memset(osa, 0, sizeof(*osa));
    105   1.8  christos 	osa->osa_handler = sa->sa_handler;
    106   1.8  christos 	native_sigset_to_sigset13(&sa->sa_mask, &osa->osa_mask);
    107   1.8  christos 	osa->osa_flags = sa->sa_flags;
    108   1.3   mycroft }
    109   1.3   mycroft 
    110   1.1    kleink int
    111  1.17       dsl compat_13_sys_sigaltstack(struct lwp *l, const struct compat_13_sys_sigaltstack_args *uap, register_t *retval)
    112   1.1    kleink {
    113  1.17       dsl 	/* {
    114   1.1    kleink 		syscallarg(const struct sigaltstack13 *) nss;
    115   1.1    kleink 		syscallarg(struct sigaltstack13 *) oss;
    116  1.17       dsl 	} */
    117  1.15       dsl 	compat_sigaltstack(uap, sigaltstack13, SS_ONSTACK, SS_DISABLE);
    118   1.3   mycroft }
    119   1.1    kleink 
    120   1.3   mycroft int
    121  1.17       dsl compat_13_sys_sigaction(struct lwp *l, const struct compat_13_sys_sigaction_args *uap, register_t *retval)
    122   1.3   mycroft {
    123  1.17       dsl 	/* {
    124   1.3   mycroft 		syscallarg(int) signum;
    125   1.3   mycroft 		syscallarg(const struct sigaction13 *) nsa;
    126   1.3   mycroft 		syscallarg(struct sigaction13 *) osa;
    127  1.17       dsl 	} */
    128   1.3   mycroft 	struct sigaction13 nesa, oesa;
    129   1.3   mycroft 	struct sigaction nbsa, obsa;
    130   1.3   mycroft 	int error;
    131   1.1    kleink 
    132   1.3   mycroft 	if (SCARG(uap, nsa)) {
    133   1.3   mycroft 		error = copyin(SCARG(uap, nsa), &nesa, sizeof(nesa));
    134   1.3   mycroft 		if (error)
    135   1.1    kleink 			return (error);
    136   1.3   mycroft 		native_sigaction13_to_sigaction(&nesa, &nbsa);
    137   1.3   mycroft 	}
    138  1.14        ad 	error = sigaction1(l, SCARG(uap, signum),
    139   1.7   thorpej 	    SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
    140   1.7   thorpej 	    NULL, 0);
    141   1.3   mycroft 	if (error)
    142   1.3   mycroft 		return (error);
    143   1.3   mycroft 	if (SCARG(uap, osa)) {
    144   1.3   mycroft 		native_sigaction_to_sigaction13(&obsa, &oesa);
    145   1.3   mycroft 		error = copyout(&oesa, SCARG(uap, osa), sizeof(oesa));
    146   1.3   mycroft 		if (error)
    147   1.1    kleink 			return (error);
    148   1.3   mycroft 	}
    149   1.3   mycroft 	return (0);
    150   1.3   mycroft }
    151   1.1    kleink 
    152   1.3   mycroft int
    153  1.17       dsl compat_13_sys_sigprocmask(struct lwp *l, const struct compat_13_sys_sigprocmask_args *uap, register_t *retval)
    154   1.3   mycroft {
    155  1.17       dsl 	/* {
    156   1.3   mycroft 		syscallarg(int) how;
    157   1.3   mycroft 		syscallarg(int) mask;
    158  1.17       dsl 	} */
    159   1.9   thorpej 	struct proc *p = l->l_proc;
    160   1.3   mycroft 	sigset13_t ness, oess;
    161   1.3   mycroft 	sigset_t nbss, obss;
    162   1.3   mycroft 	int error;
    163   1.1    kleink 
    164   1.3   mycroft 	ness = SCARG(uap, mask);
    165   1.3   mycroft 	native_sigset13_to_sigset(&ness, &nbss);
    166  1.18        ad 	mutex_enter(p->p_lock);
    167  1.14        ad 	error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
    168  1.18        ad 	mutex_exit(p->p_lock);
    169   1.3   mycroft 	if (error)
    170   1.1    kleink 		return (error);
    171   1.3   mycroft 	native_sigset_to_sigset13(&obss, &oess);
    172   1.3   mycroft 	*retval = oess;
    173   1.3   mycroft 	return (0);
    174   1.3   mycroft }
    175   1.1    kleink 
    176   1.3   mycroft int
    177  1.17       dsl compat_13_sys_sigpending(struct lwp *l, const void *v, register_t *retval)
    178   1.3   mycroft {
    179   1.3   mycroft 	sigset13_t ess;
    180   1.3   mycroft 	sigset_t bss;
    181   1.1    kleink 
    182  1.14        ad 	sigpending1(l, &bss);
    183   1.3   mycroft 	native_sigset_to_sigset13(&bss, &ess);
    184   1.3   mycroft 	*retval = ess;
    185   1.1    kleink 	return (0);
    186   1.3   mycroft }
    187   1.3   mycroft 
    188   1.3   mycroft int
    189  1.17       dsl compat_13_sys_sigsuspend(struct lwp *l, const struct compat_13_sys_sigsuspend_args *uap, register_t *retval)
    190   1.3   mycroft {
    191  1.17       dsl 	/* {
    192   1.3   mycroft 		syscallarg(sigset13_t) mask;
    193  1.17       dsl 	} */
    194   1.3   mycroft 	sigset13_t ess;
    195   1.3   mycroft 	sigset_t bss;
    196   1.3   mycroft 
    197   1.3   mycroft 	ess = SCARG(uap, mask);
    198   1.3   mycroft 	native_sigset13_to_sigset(&ess, &bss);
    199  1.14        ad 	return (sigsuspend1(l, &bss));
    200   1.1    kleink }
    201  1.21  pgoyette 
    202  1.21  pgoyette int
    203  1.21  pgoyette kern_sig_13_init(void)
    204  1.21  pgoyette {
    205  1.21  pgoyette 
    206  1.21  pgoyette 	return syscall_establish(NULL, kern_sig_13_syscalls);
    207  1.21  pgoyette }
    208  1.21  pgoyette 
    209  1.21  pgoyette int
    210  1.21  pgoyette kern_sig_13_fini(void)
    211  1.21  pgoyette {
    212  1.21  pgoyette 
    213  1.21  pgoyette 	return syscall_disestablish(NULL, kern_sig_13_syscalls);
    214  1.21  pgoyette }
    215