netbsd32_compat_10_sysv.c revision 1.2.4.2 1 1.2.4.2 christos /* $NetBSD: netbsd32_compat_10_sysv.c,v 1.2.4.2 2019/06/10 22:07:01 christos Exp $ */
2 1.2.4.2 christos
3 1.2.4.2 christos /*
4 1.2.4.2 christos * Copyright (c) 1994 Adam Glass and Charles M. Hannum. All rights reserved.
5 1.2.4.2 christos *
6 1.2.4.2 christos * Redistribution and use in source and binary forms, with or without
7 1.2.4.2 christos * modification, are permitted provided that the following conditions
8 1.2.4.2 christos * are met:
9 1.2.4.2 christos * 1. Redistributions of source code must retain the above copyright
10 1.2.4.2 christos * notice, this list of conditions and the following disclaimer.
11 1.2.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
12 1.2.4.2 christos * notice, this list of conditions and the following disclaimer in the
13 1.2.4.2 christos * documentation and/or other materials provided with the distribution.
14 1.2.4.2 christos * 3. All advertising materials mentioning features or use of this software
15 1.2.4.2 christos * must display the following acknowledgement:
16 1.2.4.2 christos * This product includes software developed by Adam Glass and Charles M.
17 1.2.4.2 christos * Hannum.
18 1.2.4.2 christos * 4. The names of the authors may not be used to endorse or promote products
19 1.2.4.2 christos * derived from this software without specific prior written permission.
20 1.2.4.2 christos *
21 1.2.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
22 1.2.4.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.2.4.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.2.4.2 christos * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.2.4.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.2.4.2 christos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.2.4.2 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.2.4.2 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.2.4.2 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.2.4.2 christos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.2.4.2 christos */
32 1.2.4.2 christos
33 1.2.4.2 christos #include <sys/cdefs.h>
34 1.2.4.2 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_10_sysv.c,v 1.2.4.2 2019/06/10 22:07:01 christos Exp $");
35 1.2.4.2 christos
36 1.2.4.2 christos #ifdef _KERNEL_OPT
37 1.2.4.2 christos #include "opt_sysv.h"
38 1.2.4.2 christos #include "opt_compat_netbsd.h"
39 1.2.4.2 christos #endif
40 1.2.4.2 christos
41 1.2.4.2 christos #include <sys/param.h>
42 1.2.4.2 christos #include <sys/systm.h>
43 1.2.4.2 christos #include <sys/module.h>
44 1.2.4.2 christos #include <sys/kernel.h>
45 1.2.4.2 christos #include <sys/proc.h>
46 1.2.4.2 christos #include <sys/sem.h>
47 1.2.4.2 christos
48 1.2.4.2 christos #include <sys/mount.h>
49 1.2.4.2 christos #include <sys/syscallargs.h>
50 1.2.4.2 christos #include <sys/syscallvar.h>
51 1.2.4.2 christos
52 1.2.4.2 christos #include <compat/netbsd32/netbsd32.h>
53 1.2.4.2 christos #include <compat/netbsd32/netbsd32_syscall.h>
54 1.2.4.2 christos #include <compat/netbsd32/netbsd32_syscallargs.h>
55 1.2.4.2 christos #include <compat/sys/shm.h>
56 1.2.4.2 christos
57 1.2.4.2 christos #if defined(COMPAT_10)
58 1.2.4.2 christos
59 1.2.4.2 christos #if defined(SYSVSEM)
60 1.2.4.2 christos int
61 1.2.4.2 christos compat_10_netbsd32_semsys(struct lwp *l, const struct compat_10_netbsd32_semsys_args *uap, register_t *retval)
62 1.2.4.2 christos {
63 1.2.4.2 christos /* {
64 1.2.4.2 christos syscallarg(int) which;
65 1.2.4.2 christos syscallarg(int) a2;
66 1.2.4.2 christos syscallarg(int) a3;
67 1.2.4.2 christos syscallarg(int) a4;
68 1.2.4.2 christos syscallarg(int) a5;
69 1.2.4.2 christos } */
70 1.2.4.2 christos struct compat_50_netbsd32___semctl14_args /* {
71 1.2.4.2 christos syscallarg(int) semid;
72 1.2.4.2 christos syscallarg(int) semnum;
73 1.2.4.2 christos syscallarg(int) cmd;
74 1.2.4.2 christos syscallarg(union semun *) arg;
75 1.2.4.2 christos } */ __semctl_args;
76 1.2.4.2 christos struct sys_semget_args /* {
77 1.2.4.2 christos syscallarg(key_t) key;
78 1.2.4.2 christos syscallarg(int) nsems;
79 1.2.4.2 christos syscallarg(int) semflg;
80 1.2.4.2 christos } */ semget_args;
81 1.2.4.2 christos struct sys_semop_args /* {
82 1.2.4.2 christos syscallarg(int) semid;
83 1.2.4.2 christos syscallarg(struct sembuf *) sops;
84 1.2.4.2 christos syscallarg(u_int) nsops;
85 1.2.4.2 christos } */ semop_args;
86 1.2.4.2 christos struct sys_semconfig_args /* {
87 1.2.4.2 christos syscallarg(int) flag;
88 1.2.4.2 christos } */ semconfig_args;
89 1.2.4.2 christos int a5;
90 1.2.4.2 christos
91 1.2.4.2 christos switch (SCARG(uap, which)) {
92 1.2.4.2 christos case 0: /* __semctl() */
93 1.2.4.2 christos SCARG(&__semctl_args, semid) = SCARG(uap, a2);
94 1.2.4.2 christos SCARG(&__semctl_args, semnum) = SCARG(uap, a3);
95 1.2.4.2 christos SCARG(&__semctl_args, cmd) = SCARG(uap, a4);
96 1.2.4.2 christos a5 = SCARG(uap, a5);
97 1.2.4.2 christos return do_netbsd32___semctl14(l, &__semctl_args, retval, &a5);
98 1.2.4.2 christos
99 1.2.4.2 christos case 1: /* semget() */
100 1.2.4.2 christos SCARG(&semget_args, key) = SCARG(uap, a2);
101 1.2.4.2 christos SCARG(&semget_args, nsems) = SCARG(uap, a3);
102 1.2.4.2 christos SCARG(&semget_args, semflg) = SCARG(uap, a4);
103 1.2.4.2 christos return (sys_semget(l, &semget_args, retval));
104 1.2.4.2 christos
105 1.2.4.2 christos case 2: /* semop() */
106 1.2.4.2 christos SCARG(&semop_args, semid) = SCARG(uap, a2);
107 1.2.4.2 christos SCARG(&semop_args, sops) = NETBSD32IPTR64(SCARG(uap, a3));
108 1.2.4.2 christos SCARG(&semop_args, nsops) = SCARG(uap, a4);
109 1.2.4.2 christos return (sys_semop(l, &semop_args, retval));
110 1.2.4.2 christos
111 1.2.4.2 christos case 3: /* semconfig() */
112 1.2.4.2 christos SCARG(&semconfig_args, flag) = SCARG(uap, a2);
113 1.2.4.2 christos return (sys_semconfig(l, &semconfig_args, retval));
114 1.2.4.2 christos
115 1.2.4.2 christos default:
116 1.2.4.2 christos return (EINVAL);
117 1.2.4.2 christos }
118 1.2.4.2 christos }
119 1.2.4.2 christos #endif
120 1.2.4.2 christos
121 1.2.4.2 christos #if defined(SYSVSHM)
122 1.2.4.2 christos int
123 1.2.4.2 christos compat_10_netbsd32_shmsys(struct lwp *l, const struct compat_10_netbsd32_shmsys_args *uap, register_t *retval)
124 1.2.4.2 christos {
125 1.2.4.2 christos /* {
126 1.2.4.2 christos syscallarg(int) which;
127 1.2.4.2 christos syscallarg(int) a2;
128 1.2.4.2 christos syscallarg(int) a3;
129 1.2.4.2 christos syscallarg(int) a4;
130 1.2.4.2 christos } */
131 1.2.4.2 christos struct sys_shmat_args /* {
132 1.2.4.2 christos syscallarg(int) shmid;
133 1.2.4.2 christos syscallarg(void *) shmaddr;
134 1.2.4.2 christos syscallarg(int) shmflg;
135 1.2.4.2 christos } */ shmat_args;
136 1.2.4.2 christos struct compat_14_sys_shmctl_args /* {
137 1.2.4.2 christos syscallarg(int) shmid;
138 1.2.4.2 christos syscallarg(int) cmd;
139 1.2.4.2 christos syscallarg(struct shmid_ds50 *) buf;
140 1.2.4.2 christos } */ shmctl_args;
141 1.2.4.2 christos struct sys_shmdt_args /* {
142 1.2.4.2 christos syscallarg(void *) shmaddr;
143 1.2.4.2 christos } */ shmdt_args;
144 1.2.4.2 christos struct sys_shmget_args /* {
145 1.2.4.2 christos syscallarg(key_t) key;
146 1.2.4.2 christos syscallarg(int) size;
147 1.2.4.2 christos syscallarg(int) shmflg;
148 1.2.4.2 christos } */ shmget_args;
149 1.2.4.2 christos
150 1.2.4.2 christos switch (SCARG(uap, which)) {
151 1.2.4.2 christos case 0: /* shmat() */
152 1.2.4.2 christos SCARG(&shmat_args, shmid) = SCARG(uap, a2);
153 1.2.4.2 christos SCARG(&shmat_args, shmaddr) = NETBSD32IPTR64(SCARG(uap, a3));
154 1.2.4.2 christos SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
155 1.2.4.2 christos return (sys_shmat(l, &shmat_args, retval));
156 1.2.4.2 christos
157 1.2.4.2 christos case 1: /* shmctl() */
158 1.2.4.2 christos SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
159 1.2.4.2 christos SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
160 1.2.4.2 christos SCARG(&shmctl_args, buf) = NETBSD32IPTR64(SCARG(uap, a4));
161 1.2.4.2 christos return (compat_14_sys_shmctl(l, &shmctl_args, retval));
162 1.2.4.2 christos
163 1.2.4.2 christos case 2: /* shmdt() */
164 1.2.4.2 christos SCARG(&shmdt_args, shmaddr) = NETBSD32IPTR64(SCARG(uap, a2));
165 1.2.4.2 christos return (sys_shmdt(l, &shmdt_args, retval));
166 1.2.4.2 christos
167 1.2.4.2 christos case 3: /* shmget() */
168 1.2.4.2 christos SCARG(&shmget_args, key) = SCARG(uap, a2);
169 1.2.4.2 christos SCARG(&shmget_args, size) = SCARG(uap, a3);
170 1.2.4.2 christos SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
171 1.2.4.2 christos return (sys_shmget(l, &shmget_args, retval));
172 1.2.4.2 christos
173 1.2.4.2 christos default:
174 1.2.4.2 christos return (EINVAL);
175 1.2.4.2 christos }
176 1.2.4.2 christos }
177 1.2.4.2 christos #endif
178 1.2.4.2 christos
179 1.2.4.2 christos #if defined(SYSVMSG)
180 1.2.4.2 christos int
181 1.2.4.2 christos compat_10_netbsd32_msgsys(struct lwp *l, const struct compat_10_netbsd32_msgsys_args *uap, register_t *retval)
182 1.2.4.2 christos {
183 1.2.4.2 christos /* {
184 1.2.4.2 christos syscallarg(int) which;
185 1.2.4.2 christos syscallarg(int) a2;
186 1.2.4.2 christos syscallarg(int) a3;
187 1.2.4.2 christos syscallarg(int) a4;
188 1.2.4.2 christos syscallarg(int) a5;
189 1.2.4.2 christos syscallarg(int) a6;
190 1.2.4.2 christos } */
191 1.2.4.2 christos struct compat_14_sys_msgctl_args /* {
192 1.2.4.2 christos syscallarg(int) msqid;
193 1.2.4.2 christos syscallarg(int) cmd;
194 1.2.4.2 christos syscallarg(struct msqid_ds *) buf;
195 1.2.4.2 christos } */ msgctl_args;
196 1.2.4.2 christos struct sys_msgget_args /* {
197 1.2.4.2 christos syscallarg(key_t) key;
198 1.2.4.2 christos syscallarg(int) msgflg;
199 1.2.4.2 christos } */ msgget_args;
200 1.2.4.2 christos struct sys_msgsnd_args /* {
201 1.2.4.2 christos syscallarg(int) msqid;
202 1.2.4.2 christos syscallarg(void *) msgp;
203 1.2.4.2 christos syscallarg(size_t) msgsz;
204 1.2.4.2 christos syscallarg(int) msgflg;
205 1.2.4.2 christos } */ msgsnd_args;
206 1.2.4.2 christos struct sys_msgrcv_args /* {
207 1.2.4.2 christos syscallarg(int) msqid;
208 1.2.4.2 christos syscallarg(void *) msgp;
209 1.2.4.2 christos syscallarg(size_t) msgsz;
210 1.2.4.2 christos syscallarg(long) msgtyp;
211 1.2.4.2 christos syscallarg(int) msgflg;
212 1.2.4.2 christos } */ msgrcv_args;
213 1.2.4.2 christos
214 1.2.4.2 christos switch (SCARG(uap, which)) {
215 1.2.4.2 christos case 0: /* msgctl()*/
216 1.2.4.2 christos SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
217 1.2.4.2 christos SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
218 1.2.4.2 christos SCARG(&msgctl_args, buf) = NETBSD32IPTR64(SCARG(uap, a4));
219 1.2.4.2 christos return (compat_14_sys_msgctl(l, &msgctl_args, retval));
220 1.2.4.2 christos
221 1.2.4.2 christos case 1: /* msgget() */
222 1.2.4.2 christos SCARG(&msgget_args, key) = SCARG(uap, a2);
223 1.2.4.2 christos SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
224 1.2.4.2 christos return (sys_msgget(l, &msgget_args, retval));
225 1.2.4.2 christos
226 1.2.4.2 christos case 2: /* msgsnd() */
227 1.2.4.2 christos SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
228 1.2.4.2 christos SCARG(&msgsnd_args, msgp) = NETBSD32IPTR64(SCARG(uap, a3));
229 1.2.4.2 christos SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
230 1.2.4.2 christos SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
231 1.2.4.2 christos return (sys_msgsnd(l, &msgsnd_args, retval));
232 1.2.4.2 christos
233 1.2.4.2 christos case 3: /* msgrcv() */
234 1.2.4.2 christos SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
235 1.2.4.2 christos SCARG(&msgrcv_args, msgp) = NETBSD32IPTR64(SCARG(uap, a3));
236 1.2.4.2 christos SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
237 1.2.4.2 christos SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
238 1.2.4.2 christos SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
239 1.2.4.2 christos return (sys_msgrcv(l, &msgrcv_args, retval));
240 1.2.4.2 christos
241 1.2.4.2 christos default:
242 1.2.4.2 christos return (EINVAL);
243 1.2.4.2 christos }
244 1.2.4.2 christos }
245 1.2.4.2 christos #endif
246 1.2.4.2 christos
247 1.2.4.2 christos #define _PKG_ENTRY(name) \
248 1.2.4.2 christos { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
249 1.2.4.2 christos
250 1.2.4.2 christos #define _PKG_ENTRY2(code, name) \
251 1.2.4.2 christos { NETBSD32_SYS_ ## code, 0, (sy_call_t *)name }
252 1.2.4.2 christos
253 1.2.4.2 christos static const struct syscall_package compat_sysvipc_10_syscalls[] = {
254 1.2.4.2 christos #if defined(SYSVSEM)
255 1.2.4.2 christos _PKG_ENTRY2(compat_10_osemsys, compat_10_netbsd32_semsys),
256 1.2.4.2 christos #endif
257 1.2.4.2 christos #if defined(SYSVSHM)
258 1.2.4.2 christos _PKG_ENTRY2(compat_10_oshmsys, compat_10_netbsd32_shmsys),
259 1.2.4.2 christos #endif
260 1.2.4.2 christos #if defined(SYSVMSG)
261 1.2.4.2 christos _PKG_ENTRY2(compat_10_omsgsys, compat_10_netbsd32_msgsys),
262 1.2.4.2 christos #endif
263 1.2.4.2 christos { 0, 0, NULL }
264 1.2.4.2 christos };
265 1.2.4.2 christos
266 1.2.4.2 christos #define REQ1 "sysv_ipc,compat_sysv_10,"
267 1.2.4.2 christos #define REQ2 "compat_netbsd32,compat_netbsd32_sysvipc,"
268 1.2.4.2 christos #define REQ3 "compat_netbsd32_sysvipc_14,compat_netbsd32_sysvipc_50"
269 1.2.4.2 christos
270 1.2.4.2 christos MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_10, REQ1 REQ2 REQ3 );
271 1.2.4.2 christos
272 1.2.4.2 christos static int
273 1.2.4.2 christos compat_netbsd32_sysvipc_10_modcmd(modcmd_t cmd, void *arg)
274 1.2.4.2 christos {
275 1.2.4.2 christos
276 1.2.4.2 christos switch (cmd) {
277 1.2.4.2 christos case MODULE_CMD_INIT:
278 1.2.4.2 christos return syscall_establish(&emul_netbsd32,
279 1.2.4.2 christos compat_sysvipc_10_syscalls);
280 1.2.4.2 christos
281 1.2.4.2 christos case MODULE_CMD_FINI:
282 1.2.4.2 christos return syscall_disestablish(&emul_netbsd32,
283 1.2.4.2 christos compat_sysvipc_10_syscalls);
284 1.2.4.2 christos
285 1.2.4.2 christos default:
286 1.2.4.2 christos return ENOTTY;
287 1.2.4.2 christos }
288 1.2.4.2 christos }
289 1.2.4.2 christos
290 1.2.4.2 christos #endif /* COMPAT_10 */
291