Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_compat_13.c revision 1.26.28.5
      1 /*	$NetBSD: netbsd32_compat_13.c,v 1.26.28.5 2018/09/11 05:00:42 pgoyette Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_13.c,v 1.26.28.5 2018/09/11 05:00:42 pgoyette Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/module.h>
     35 #include <sys/mount.h>
     36 #include <sys/proc.h>
     37 #include <sys/signal.h>
     38 #include <sys/signalvar.h>
     39 #include <sys/syscallargs.h>
     40 #include <sys/syscallvar.h>
     41 
     42 #include <compat/netbsd32/netbsd32.h>
     43 #include <compat/netbsd32/netbsd32_syscall.h>
     44 #include <compat/netbsd32/netbsd32_syscallargs.h>
     45 
     46 #include <compat/sys/stat.h>
     47 #include <compat/sys/signal.h>
     48 #include <compat/sys/signalvar.h>
     49 
     50 #include <compat/common/compat_sigaltstack.h>
     51 
     52 extern struct emul emul_netbsd32;
     53 
     54 int
     55 compat_13_netbsd32_sigaltstack13(struct lwp *l, const struct compat_13_netbsd32_sigaltstack13_args *uap, register_t *retval)
     56 {
     57 	compat_sigaltstack(uap, netbsd32_sigaltstack13, SS_ONSTACK, SS_DISABLE);
     58 }
     59 
     60 
     61 int
     62 compat_13_netbsd32_sigprocmask(struct lwp *l, const struct compat_13_netbsd32_sigprocmask_args *uap, register_t *retval)
     63 {
     64 	/* {
     65 		syscallarg(int) how;
     66 		syscallarg(int) mask;
     67 	} */
     68 	sigset13_t ness, oess;
     69 	sigset_t nbss, obss;
     70 	struct proc *p = l->l_proc;
     71 	int error;
     72 
     73 	ness = SCARG(uap, mask);
     74 	native_sigset13_to_sigset(&ness, &nbss);
     75 	mutex_enter(p->p_lock);
     76 	error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
     77 	mutex_exit(p->p_lock);
     78 	if (error)
     79 		return (error);
     80 	native_sigset_to_sigset13(&obss, &oess);
     81 	*retval = oess;
     82 	return (0);
     83 }
     84 
     85 int
     86 compat_13_netbsd32_sigsuspend(struct lwp *l, const struct compat_13_netbsd32_sigsuspend_args *uap, register_t *retval)
     87 {
     88 	/* {
     89 		syscallarg(sigset13_t) mask;
     90 	} */
     91 	sigset13_t ess;
     92 	sigset_t bss;
     93 
     94 	ess = SCARG(uap, mask);
     95 	native_sigset13_to_sigset(&ess, &bss);
     96 	return (sigsuspend1(l, &bss));
     97 }
     98 
     99 static struct syscall_package compat_netbsd32_13_syscalls[] = {
    100 	{ NETBSD32_SYS_compat_13_netbsd32_sigaltstack13, 0,
    101 	    (sy_call_t *)compat_13_netbsd32_sigaltstack13 },
    102 	{ NETBSD32_SYS_compat_13_sigprocmask13, 0,
    103 	    (sy_call_t *)compat_13_netbsd32_sigprocmask },
    104 	{ NETBSD32_SYS_compat_13_sigsuspend13, 0,
    105 	    (sy_call_t *)compat_13_netbsd32_sigsuspend },
    106 	{ 0, 0, NULL }
    107 };
    108 
    109 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_13, "compat_netbsd32,compat_13");
    110 
    111 static int
    112 compat_netbsd32_13_modcmd(modcmd_t cmd, void *arg)
    113 {
    114 
    115 	switch (cmd) {
    116 	case MODULE_CMD_INIT:
    117 		return syscall_establish(&emul_netbsd32,
    118 		    compat_netbsd32_13_syscalls);
    119 
    120 	case MODULE_CMD_FINI:
    121 		return syscall_disestablish(&emul_netbsd32,
    122 		    compat_netbsd32_13_syscalls);
    123 
    124 	default:
    125 		return ENOTTY;
    126 	}
    127 }
    128