netbsd32_ipc.c revision 1.20 1 1.20 simonb /* $NetBSD: netbsd32_ipc.c,v 1.20 2021/01/19 03:20:13 simonb Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.1 mrg * Copyright (c) 1998, 2001 Matthew R. Green
5 1.1 mrg * All rights reserved.
6 1.1 mrg *
7 1.1 mrg * Redistribution and use in source and binary forms, with or without
8 1.1 mrg * modification, are permitted provided that the following conditions
9 1.1 mrg * are met:
10 1.1 mrg * 1. Redistributions of source code must retain the above copyright
11 1.1 mrg * notice, this list of conditions and the following disclaimer.
12 1.1 mrg * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mrg * notice, this list of conditions and the following disclaimer in the
14 1.1 mrg * documentation and/or other materials provided with the distribution.
15 1.1 mrg *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg */
28 1.3 lukem
29 1.3 lukem #include <sys/cdefs.h>
30 1.20 simonb __KERNEL_RCSID(0, "$NetBSD: netbsd32_ipc.c,v 1.20 2021/01/19 03:20:13 simonb Exp $");
31 1.1 mrg
32 1.2 mrg #if defined(_KERNEL_OPT)
33 1.1 mrg #include "opt_sysv.h"
34 1.1 mrg #endif
35 1.1 mrg
36 1.1 mrg #include <sys/param.h>
37 1.1 mrg #include <sys/systm.h>
38 1.1 mrg #include <sys/ipc.h>
39 1.1 mrg #include <sys/msg.h>
40 1.1 mrg #include <sys/sem.h>
41 1.1 mrg #include <sys/shm.h>
42 1.1 mrg #include <sys/mount.h>
43 1.18 pgoyette #include <sys/module.h>
44 1.6 christos #include <sys/dirent.h>
45 1.18 pgoyette #include <sys/syscallvar.h>
46 1.1 mrg
47 1.1 mrg #include <sys/syscallargs.h>
48 1.1 mrg #include <sys/proc.h>
49 1.1 mrg
50 1.1 mrg #include <compat/netbsd32/netbsd32.h>
51 1.18 pgoyette #include <compat/netbsd32/netbsd32_syscall.h>
52 1.1 mrg #include <compat/netbsd32/netbsd32_syscallargs.h>
53 1.1 mrg #include <compat/netbsd32/netbsd32_conv.h>
54 1.1 mrg
55 1.18 pgoyette #define _PKG_ENTRY(name) \
56 1.18 pgoyette { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
57 1.18 pgoyette
58 1.18 pgoyette #define _PKG_ENTRY2(code, name) \
59 1.18 pgoyette { NETBSD32_SYS_ ## code, 0, (sy_call_t *)name }
60 1.18 pgoyette
61 1.18 pgoyette static const struct syscall_package compat_sysvipc_syscalls[] = {
62 1.18 pgoyette #if defined(SYSVSEM)
63 1.18 pgoyette _PKG_ENTRY(netbsd32_____semctl50),
64 1.18 pgoyette _PKG_ENTRY(netbsd32_semget),
65 1.18 pgoyette _PKG_ENTRY(netbsd32_semop),
66 1.18 pgoyette _PKG_ENTRY(netbsd32_semconfig),
67 1.18 pgoyette #endif /* SYSVSEM */
68 1.18 pgoyette
69 1.18 pgoyette #if defined(SYSVSHM)
70 1.18 pgoyette _PKG_ENTRY(netbsd32_shmat),
71 1.18 pgoyette _PKG_ENTRY(netbsd32___shmctl50),
72 1.18 pgoyette _PKG_ENTRY(netbsd32_shmdt),
73 1.18 pgoyette _PKG_ENTRY(netbsd32_shmget),
74 1.18 pgoyette #endif /* SYSVSHM */
75 1.18 pgoyette
76 1.18 pgoyette #if defined(SYSVMSG)
77 1.18 pgoyette _PKG_ENTRY(netbsd32___msgctl50),
78 1.18 pgoyette _PKG_ENTRY(netbsd32_msgget),
79 1.18 pgoyette _PKG_ENTRY(netbsd32_msgsnd),
80 1.18 pgoyette _PKG_ENTRY(netbsd32_msgrcv),
81 1.18 pgoyette #endif /* SYSVMSG */
82 1.18 pgoyette { 0, 0, NULL }
83 1.18 pgoyette };
84 1.18 pgoyette
85 1.19 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc,
86 1.19 pgoyette "compat_netbsd32,sysv_ipc");
87 1.18 pgoyette
88 1.18 pgoyette static int
89 1.18 pgoyette compat_netbsd32_sysvipc_modcmd(modcmd_t cmd, void *arg)
90 1.18 pgoyette {
91 1.18 pgoyette int error;
92 1.18 pgoyette
93 1.18 pgoyette switch (cmd) {
94 1.18 pgoyette case MODULE_CMD_INIT:
95 1.18 pgoyette error = syscall_establish(&emul_netbsd32,
96 1.18 pgoyette compat_sysvipc_syscalls);
97 1.18 pgoyette break;
98 1.18 pgoyette case MODULE_CMD_FINI:
99 1.18 pgoyette error = syscall_disestablish(&emul_netbsd32,
100 1.18 pgoyette compat_sysvipc_syscalls);
101 1.18 pgoyette break;
102 1.18 pgoyette default:
103 1.18 pgoyette error = ENOTTY;
104 1.18 pgoyette break;
105 1.18 pgoyette }
106 1.18 pgoyette return error;
107 1.18 pgoyette }
108 1.18 pgoyette
109 1.18 pgoyette
110 1.1 mrg #if defined(SYSVSEM)
111 1.12 dsl
112 1.1 mrg int
113 1.16 christos netbsd32_____semctl50(struct lwp *l, const struct netbsd32_____semctl50_args *uap, register_t *retval)
114 1.12 dsl {
115 1.14 dsl /* {
116 1.1 mrg syscallarg(int) semid;
117 1.1 mrg syscallarg(int) semnum;
118 1.1 mrg syscallarg(int) cmd;
119 1.8 cube syscallarg(netbsd32_semunp_t) arg;
120 1.14 dsl } */
121 1.8 cube struct semid_ds sembuf;
122 1.8 cube struct netbsd32_semid_ds sembuf32;
123 1.8 cube int cmd, error;
124 1.8 cube void *pass_arg;
125 1.8 cube union __semun karg;
126 1.8 cube union netbsd32_semun karg32;
127 1.1 mrg
128 1.8 cube cmd = SCARG(uap, cmd);
129 1.1 mrg
130 1.1 mrg switch (cmd) {
131 1.1 mrg case IPC_SET:
132 1.1 mrg case IPC_STAT:
133 1.8 cube pass_arg = &sembuf;
134 1.1 mrg break;
135 1.1 mrg
136 1.8 cube case GETALL:
137 1.8 cube case SETVAL:
138 1.8 cube case SETALL:
139 1.8 cube pass_arg = &karg;
140 1.1 mrg break;
141 1.8 cube default:
142 1.8 cube pass_arg = NULL;
143 1.1 mrg break;
144 1.8 cube }
145 1.1 mrg
146 1.8 cube if (pass_arg) {
147 1.16 christos error = copyin(SCARG_P32(uap, arg), &karg32, sizeof(karg32));
148 1.16 christos if (error)
149 1.16 christos return error;
150 1.8 cube if (pass_arg == &karg) {
151 1.8 cube switch (cmd) {
152 1.8 cube case GETALL:
153 1.8 cube case SETALL:
154 1.8 cube karg.array = NETBSD32PTR64(karg32.array);
155 1.8 cube break;
156 1.8 cube case SETVAL:
157 1.8 cube karg.val = karg32.val;
158 1.1 mrg break;
159 1.8 cube }
160 1.8 cube }
161 1.8 cube if (cmd == IPC_SET) {
162 1.8 cube error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32,
163 1.8 cube sizeof(sembuf32));
164 1.8 cube if (error)
165 1.20 simonb return error;
166 1.8 cube netbsd32_to_semid_ds(&sembuf32, &sembuf);
167 1.1 mrg }
168 1.8 cube }
169 1.1 mrg
170 1.9 ad error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
171 1.8 cube pass_arg, retval);
172 1.1 mrg
173 1.8 cube if (error == 0 && cmd == IPC_STAT) {
174 1.8 cube netbsd32_from_semid_ds(&sembuf, &sembuf32);
175 1.8 cube error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf),
176 1.8 cube sizeof(sembuf32));
177 1.1 mrg }
178 1.1 mrg
179 1.20 simonb return error;
180 1.1 mrg }
181 1.1 mrg
182 1.1 mrg int
183 1.14 dsl netbsd32_semget(struct lwp *l, const struct netbsd32_semget_args *uap, register_t *retval)
184 1.1 mrg {
185 1.14 dsl /* {
186 1.1 mrg syscallarg(netbsd32_key_t) key;
187 1.1 mrg syscallarg(int) nsems;
188 1.1 mrg syscallarg(int) semflg;
189 1.14 dsl } */
190 1.1 mrg struct sys_semget_args ua;
191 1.1 mrg
192 1.1 mrg NETBSD32TOX_UAP(key, key_t);
193 1.1 mrg NETBSD32TO64_UAP(nsems);
194 1.1 mrg NETBSD32TO64_UAP(semflg);
195 1.20 simonb return sys_semget(l, &ua, retval);
196 1.1 mrg }
197 1.1 mrg
198 1.1 mrg int
199 1.14 dsl netbsd32_semop(struct lwp *l, const struct netbsd32_semop_args *uap, register_t *retval)
200 1.1 mrg {
201 1.14 dsl /* {
202 1.1 mrg syscallarg(int) semid;
203 1.1 mrg syscallarg(netbsd32_sembufp_t) sops;
204 1.1 mrg syscallarg(netbsd32_size_t) nsops;
205 1.14 dsl } */
206 1.1 mrg struct sys_semop_args ua;
207 1.1 mrg
208 1.1 mrg NETBSD32TO64_UAP(semid);
209 1.1 mrg NETBSD32TOP_UAP(sops, struct sembuf);
210 1.1 mrg NETBSD32TOX_UAP(nsops, size_t);
211 1.20 simonb return sys_semop(l, &ua, retval);
212 1.1 mrg }
213 1.1 mrg
214 1.1 mrg int
215 1.14 dsl netbsd32_semconfig(struct lwp *l, const struct netbsd32_semconfig_args *uap, register_t *retval)
216 1.1 mrg {
217 1.14 dsl /* {
218 1.1 mrg syscallarg(int) flag;
219 1.14 dsl } */
220 1.1 mrg struct sys_semconfig_args ua;
221 1.1 mrg
222 1.1 mrg NETBSD32TO64_UAP(flag);
223 1.20 simonb return sys_semconfig(l, &ua, retval);
224 1.1 mrg }
225 1.1 mrg #endif /* SYSVSEM */
226 1.1 mrg
227 1.1 mrg #if defined(SYSVMSG)
228 1.1 mrg
229 1.1 mrg int
230 1.16 christos netbsd32___msgctl50(struct lwp *l, const struct netbsd32___msgctl50_args *uap,
231 1.16 christos register_t *retval)
232 1.1 mrg {
233 1.14 dsl /* {
234 1.1 mrg syscallarg(int) msqid;
235 1.1 mrg syscallarg(int) cmd;
236 1.1 mrg syscallarg(netbsd32_msqid_dsp_t) buf;
237 1.14 dsl } */
238 1.1 mrg struct msqid_ds ds;
239 1.8 cube struct netbsd32_msqid_ds ds32;
240 1.8 cube int error, cmd;
241 1.8 cube
242 1.8 cube cmd = SCARG(uap, cmd);
243 1.8 cube if (cmd == IPC_SET) {
244 1.11 dsl error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
245 1.8 cube if (error)
246 1.8 cube return error;
247 1.8 cube netbsd32_to_msqid_ds(&ds32, &ds);
248 1.8 cube }
249 1.8 cube
250 1.9 ad error = msgctl1(l, SCARG(uap, msqid), cmd,
251 1.8 cube (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
252 1.8 cube
253 1.8 cube if (error == 0 && cmd == IPC_STAT) {
254 1.8 cube netbsd32_from_msqid_ds(&ds, &ds32);
255 1.11 dsl error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
256 1.8 cube }
257 1.1 mrg
258 1.8 cube return error;
259 1.1 mrg }
260 1.1 mrg
261 1.1 mrg int
262 1.14 dsl netbsd32_msgget(struct lwp *l, const struct netbsd32_msgget_args *uap, register_t *retval)
263 1.1 mrg {
264 1.14 dsl /* {
265 1.1 mrg syscallarg(netbsd32_key_t) key;
266 1.1 mrg syscallarg(int) msgflg;
267 1.14 dsl } */
268 1.1 mrg struct sys_msgget_args ua;
269 1.1 mrg
270 1.1 mrg NETBSD32TOX_UAP(key, key_t);
271 1.1 mrg NETBSD32TO64_UAP(msgflg);
272 1.8 cube return sys_msgget(l, &ua, retval);
273 1.8 cube }
274 1.8 cube
275 1.8 cube static int
276 1.8 cube netbsd32_msgsnd_fetch_type(const void *src, void *dst, size_t size)
277 1.8 cube {
278 1.8 cube netbsd32_long l32;
279 1.8 cube long *l = dst;
280 1.8 cube int error;
281 1.8 cube
282 1.8 cube KASSERT(size == sizeof(netbsd32_long));
283 1.8 cube
284 1.8 cube error = copyin(src, &l32, sizeof(l32));
285 1.8 cube if (!error)
286 1.8 cube *l = l32;
287 1.8 cube return error;
288 1.1 mrg }
289 1.1 mrg
290 1.1 mrg int
291 1.14 dsl netbsd32_msgsnd(struct lwp *l, const struct netbsd32_msgsnd_args *uap, register_t *retval)
292 1.1 mrg {
293 1.14 dsl /* {
294 1.1 mrg syscallarg(int) msqid;
295 1.1 mrg syscallarg(const netbsd32_voidp) msgp;
296 1.1 mrg syscallarg(netbsd32_size_t) msgsz;
297 1.1 mrg syscallarg(int) msgflg;
298 1.14 dsl } */
299 1.1 mrg
300 1.9 ad return msgsnd1(l, SCARG(uap, msqid),
301 1.11 dsl SCARG_P32(uap, msgp), SCARG(uap, msgsz),
302 1.8 cube SCARG(uap, msgflg), sizeof(netbsd32_long),
303 1.8 cube netbsd32_msgsnd_fetch_type);
304 1.8 cube }
305 1.8 cube
306 1.8 cube static int
307 1.8 cube netbsd32_msgrcv_put_type(const void *src, void *dst, size_t size)
308 1.8 cube {
309 1.8 cube netbsd32_long l32;
310 1.8 cube const long *l = src;
311 1.8 cube
312 1.8 cube KASSERT(size == sizeof(netbsd32_long));
313 1.8 cube
314 1.8 cube l32 = (netbsd32_long)(*l);
315 1.8 cube return copyout(&l32, dst, sizeof(l32));
316 1.1 mrg }
317 1.1 mrg
318 1.1 mrg int
319 1.14 dsl netbsd32_msgrcv(struct lwp *l, const struct netbsd32_msgrcv_args *uap, register_t *retval)
320 1.1 mrg {
321 1.14 dsl /* {
322 1.1 mrg syscallarg(int) msqid;
323 1.1 mrg syscallarg(netbsd32_voidp) msgp;
324 1.1 mrg syscallarg(netbsd32_size_t) msgsz;
325 1.1 mrg syscallarg(netbsd32_long) msgtyp;
326 1.1 mrg syscallarg(int) msgflg;
327 1.14 dsl } */
328 1.1 mrg
329 1.9 ad return msgrcv1(l, SCARG(uap, msqid),
330 1.11 dsl SCARG_P32(uap, msgp), SCARG(uap, msgsz),
331 1.8 cube SCARG(uap, msgtyp), SCARG(uap, msgflg), sizeof(netbsd32_long),
332 1.8 cube netbsd32_msgrcv_put_type, retval);
333 1.1 mrg }
334 1.1 mrg #endif /* SYSVMSG */
335 1.1 mrg
336 1.1 mrg #if defined(SYSVSHM)
337 1.1 mrg
338 1.1 mrg int
339 1.14 dsl netbsd32_shmat(struct lwp *l, const struct netbsd32_shmat_args *uap, register_t *retval)
340 1.1 mrg {
341 1.14 dsl /* {
342 1.1 mrg syscallarg(int) shmid;
343 1.1 mrg syscallarg(const netbsd32_voidp) shmaddr;
344 1.1 mrg syscallarg(int) shmflg;
345 1.14 dsl } */
346 1.1 mrg struct sys_shmat_args ua;
347 1.1 mrg
348 1.1 mrg NETBSD32TO64_UAP(shmid);
349 1.1 mrg NETBSD32TOP_UAP(shmaddr, void);
350 1.1 mrg NETBSD32TO64_UAP(shmflg);
351 1.8 cube return sys_shmat(l, &ua, retval);
352 1.1 mrg }
353 1.1 mrg
354 1.1 mrg int
355 1.16 christos netbsd32___shmctl50(struct lwp *l, const struct netbsd32___shmctl50_args *uap,
356 1.16 christos register_t *retval)
357 1.1 mrg {
358 1.14 dsl /* {
359 1.1 mrg syscallarg(int) shmid;
360 1.1 mrg syscallarg(int) cmd;
361 1.1 mrg syscallarg(netbsd32_shmid_dsp_t) buf;
362 1.14 dsl } */
363 1.1 mrg struct shmid_ds ds;
364 1.8 cube struct netbsd32_shmid_ds ds32;
365 1.8 cube int error, cmd;
366 1.8 cube
367 1.8 cube cmd = SCARG(uap, cmd);
368 1.8 cube if (cmd == IPC_SET) {
369 1.11 dsl error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
370 1.8 cube if (error)
371 1.8 cube return error;
372 1.8 cube netbsd32_to_shmid_ds(&ds32, &ds);
373 1.8 cube }
374 1.8 cube
375 1.9 ad error = shmctl1(l, SCARG(uap, shmid), cmd,
376 1.8 cube (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
377 1.8 cube
378 1.8 cube if (error == 0 && cmd == IPC_STAT) {
379 1.8 cube netbsd32_from_shmid_ds(&ds, &ds32);
380 1.11 dsl error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
381 1.8 cube }
382 1.1 mrg
383 1.8 cube return error;
384 1.1 mrg }
385 1.1 mrg
386 1.1 mrg int
387 1.14 dsl netbsd32_shmdt(struct lwp *l, const struct netbsd32_shmdt_args *uap, register_t *retval)
388 1.1 mrg {
389 1.14 dsl /* {
390 1.1 mrg syscallarg(const netbsd32_voidp) shmaddr;
391 1.14 dsl } */
392 1.1 mrg struct sys_shmdt_args ua;
393 1.1 mrg
394 1.1 mrg NETBSD32TOP_UAP(shmaddr, const char);
395 1.20 simonb return sys_shmdt(l, &ua, retval);
396 1.1 mrg }
397 1.1 mrg
398 1.1 mrg int
399 1.14 dsl netbsd32_shmget(struct lwp *l, const struct netbsd32_shmget_args *uap, register_t *retval)
400 1.1 mrg {
401 1.14 dsl /* {
402 1.1 mrg syscallarg(netbsd32_key_t) key;
403 1.1 mrg syscallarg(netbsd32_size_t) size;
404 1.1 mrg syscallarg(int) shmflg;
405 1.14 dsl } */
406 1.1 mrg struct sys_shmget_args ua;
407 1.1 mrg
408 1.17 njoly NETBSD32TOX_UAP(key, key_t);
409 1.17 njoly NETBSD32TOX_UAP(size, size_t);
410 1.1 mrg NETBSD32TO64_UAP(shmflg);
411 1.20 simonb return sys_shmget(l, &ua, retval);
412 1.1 mrg }
413 1.1 mrg #endif /* SYSVSHM */
414