1 /*	$NetBSD: netbsd32_compat_13.c,v 1.28 2021/01/19 03:20:13 simonb 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.28 2021/01/19 03:20:13 simonb 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 int
compat_13_netbsd32_sigaltstack13(struct lwp * l,const struct compat_13_netbsd32_sigaltstack13_args * uap,register_t * retval)53 compat_13_netbsd32_sigaltstack13(struct lwp *l, const struct compat_13_netbsd32_sigaltstack13_args *uap, register_t *retval)
54 {
55 	compat_sigaltstack(uap, netbsd32_sigaltstack13, SS_ONSTACK, SS_DISABLE);
56 }
57 
58 
59 int
compat_13_netbsd32_sigprocmask(struct lwp * l,const struct compat_13_netbsd32_sigprocmask_args * uap,register_t * retval)60 compat_13_netbsd32_sigprocmask(struct lwp *l, const struct compat_13_netbsd32_sigprocmask_args *uap, register_t *retval)
61 {
62 	/* {
63 		syscallarg(int) how;
64 		syscallarg(int) mask;
65 	} */
66 	sigset13_t ness, oess;
67 	sigset_t nbss, obss;
68 	struct proc *p = l->l_proc;
69 	int error;
70 
71 	ness = SCARG(uap, mask);
72 	native_sigset13_to_sigset(&ness, &nbss);
73 	mutex_enter(p->p_lock);
74 	error = sigprocmask1(l, SCARG(uap, how), &nbss, &obss);
75 	mutex_exit(p->p_lock);
76 	if (error)
77 		return error;
78 	native_sigset_to_sigset13(&obss, &oess);
79 	*retval = oess;
80 	return 0;
81 }
82 
83 int
compat_13_netbsd32_sigsuspend(struct lwp * l,const struct compat_13_netbsd32_sigsuspend_args * uap,register_t * retval)84 compat_13_netbsd32_sigsuspend(struct lwp *l, const struct compat_13_netbsd32_sigsuspend_args *uap, register_t *retval)
85 {
86 	/* {
87 		syscallarg(sigset13_t) mask;
88 	} */
89 	sigset13_t ess;
90 	sigset_t bss;
91 
92 	ess = SCARG(uap, mask);
93 	native_sigset13_to_sigset(&ess, &bss);
94 	return sigsuspend1(l, &bss);
95 }
96 
97 static struct syscall_package compat_netbsd32_13_syscalls[] = {
98 	{ NETBSD32_SYS_compat_13_netbsd32_sigaltstack13, 0,
99 	    (sy_call_t *)compat_13_netbsd32_sigaltstack13 },
100 	{ NETBSD32_SYS_compat_13_sigprocmask13, 0,
101 	    (sy_call_t *)compat_13_netbsd32_sigprocmask },
102 	{ NETBSD32_SYS_compat_13_sigsuspend13, 0,
103 	    (sy_call_t *)compat_13_netbsd32_sigsuspend },
104 	{ 0, 0, NULL }
105 };
106 
107 MODULE(MODULE_CLASS_EXEC, compat_netbsd32_13, "compat_13,compat_netbsd32_16");
108 
109 static int
compat_netbsd32_13_modcmd(modcmd_t cmd,void * arg)110 compat_netbsd32_13_modcmd(modcmd_t cmd, void *arg)
111 {
112 
113 	switch (cmd) {
114 	case MODULE_CMD_INIT:
115 		netbsd32_machdep_md_13_init();
116 		return syscall_establish(&emul_netbsd32,
117 		    compat_netbsd32_13_syscalls);
118 
119 	case MODULE_CMD_FINI:
120 		netbsd32_machdep_md_13_fini();
121 		return syscall_disestablish(&emul_netbsd32,
122 		    compat_netbsd32_13_syscalls);
123 
124 	default:
125 		return ENOTTY;
126 	}
127 }
128