netbsd32_ipc.c revision 1.18 1 1.18 pgoyette /* $NetBSD: netbsd32_ipc.c,v 1.18 2015/12/03 10:38:21 pgoyette 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.18 pgoyette __KERNEL_RCSID(0, "$NetBSD: netbsd32_ipc.c,v 1.18 2015/12/03 10:38:21 pgoyette 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 extern struct emul emul_netbsd32;
56 1.18 pgoyette
57 1.18 pgoyette #define _PKG_ENTRY(name) \
58 1.18 pgoyette { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
59 1.18 pgoyette
60 1.18 pgoyette #define _PKG_ENTRY2(code, name) \
61 1.18 pgoyette { NETBSD32_SYS_ ## code, 0, (sy_call_t *)name }
62 1.18 pgoyette
63 1.18 pgoyette static const struct syscall_package compat_sysvipc_syscalls[] = {
64 1.18 pgoyette #if defined(SYSVSEM)
65 1.18 pgoyette _PKG_ENTRY(netbsd32_____semctl50),
66 1.18 pgoyette _PKG_ENTRY(netbsd32_semget),
67 1.18 pgoyette _PKG_ENTRY(netbsd32_semop),
68 1.18 pgoyette _PKG_ENTRY(netbsd32_semconfig),
69 1.18 pgoyette #if defined(COMPAT_10)
70 1.18 pgoyette _PKG_ENTRY2(compat_10_osemsys, compat_10_netbsd32_semsys),
71 1.18 pgoyette #endif
72 1.18 pgoyette #if defined(COMPAT_14)
73 1.18 pgoyette _PKG_ENTRY(compat_14_netbsd32___semctl),
74 1.18 pgoyette #endif
75 1.18 pgoyette #if defined(COMPAT_50)
76 1.18 pgoyette _PKG_ENTRY(compat_50_netbsd32___semctl14),
77 1.18 pgoyette #endif
78 1.18 pgoyette #endif /* SYSVSEM */
79 1.18 pgoyette
80 1.18 pgoyette #if defined(SYSVSHM)
81 1.18 pgoyette _PKG_ENTRY(netbsd32_shmat),
82 1.18 pgoyette _PKG_ENTRY(netbsd32___shmctl50),
83 1.18 pgoyette _PKG_ENTRY(netbsd32_shmdt),
84 1.18 pgoyette _PKG_ENTRY(netbsd32_shmget),
85 1.18 pgoyette #if defined(COMPAT_10)
86 1.18 pgoyette _PKG_ENTRY2(compat_10_oshmsys, compat_10_netbsd32_shmsys),
87 1.18 pgoyette #endif
88 1.18 pgoyette #if defined(COMPAT_14)
89 1.18 pgoyette _PKG_ENTRY(compat_14_netbsd32_shmctl),
90 1.18 pgoyette #endif
91 1.18 pgoyette #if defined(COMPAT_50)
92 1.18 pgoyette _PKG_ENTRY(compat_50_netbsd32___shmctl13),
93 1.18 pgoyette #endif
94 1.18 pgoyette #endif /* SYSVSHM */
95 1.18 pgoyette
96 1.18 pgoyette #if defined(SYSVMSG)
97 1.18 pgoyette _PKG_ENTRY(netbsd32___msgctl50),
98 1.18 pgoyette _PKG_ENTRY(netbsd32_msgget),
99 1.18 pgoyette _PKG_ENTRY(netbsd32_msgsnd),
100 1.18 pgoyette _PKG_ENTRY(netbsd32_msgrcv),
101 1.18 pgoyette #if defined(COMPAT_10)
102 1.18 pgoyette _PKG_ENTRY2(compat_10_omsgsys, compat_10_netbsd32_msgsys),
103 1.18 pgoyette #endif
104 1.18 pgoyette #if defined(COMPAT_14)
105 1.18 pgoyette _PKG_ENTRY(compat_14_netbsd32_msgctl),
106 1.18 pgoyette #endif
107 1.18 pgoyette #if defined(COMPAT_50)
108 1.18 pgoyette _PKG_ENTRY(compat_50_netbsd32___msgctl13),
109 1.18 pgoyette #endif
110 1.18 pgoyette #endif /* SYSVMSG */
111 1.18 pgoyette { 0, 0, NULL }
112 1.18 pgoyette };
113 1.18 pgoyette
114 1.18 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc, "sysv_ipc,compat_netbsd32");
115 1.18 pgoyette
116 1.18 pgoyette static int
117 1.18 pgoyette compat_netbsd32_sysvipc_modcmd(modcmd_t cmd, void *arg)
118 1.18 pgoyette {
119 1.18 pgoyette int error;
120 1.18 pgoyette
121 1.18 pgoyette switch (cmd) {
122 1.18 pgoyette case MODULE_CMD_INIT:
123 1.18 pgoyette error = syscall_establish(&emul_netbsd32,
124 1.18 pgoyette compat_sysvipc_syscalls);
125 1.18 pgoyette break;
126 1.18 pgoyette case MODULE_CMD_FINI:
127 1.18 pgoyette error = syscall_disestablish(&emul_netbsd32,
128 1.18 pgoyette compat_sysvipc_syscalls);
129 1.18 pgoyette break;
130 1.18 pgoyette default:
131 1.18 pgoyette error = ENOTTY;
132 1.18 pgoyette break;
133 1.18 pgoyette }
134 1.18 pgoyette return error;
135 1.18 pgoyette }
136 1.18 pgoyette
137 1.18 pgoyette
138 1.1 mrg #if defined(SYSVSEM)
139 1.12 dsl
140 1.1 mrg int
141 1.16 christos netbsd32_____semctl50(struct lwp *l, const struct netbsd32_____semctl50_args *uap, register_t *retval)
142 1.12 dsl {
143 1.14 dsl /* {
144 1.1 mrg syscallarg(int) semid;
145 1.1 mrg syscallarg(int) semnum;
146 1.1 mrg syscallarg(int) cmd;
147 1.8 cube syscallarg(netbsd32_semunp_t) arg;
148 1.14 dsl } */
149 1.8 cube struct semid_ds sembuf;
150 1.8 cube struct netbsd32_semid_ds sembuf32;
151 1.8 cube int cmd, error;
152 1.8 cube void *pass_arg;
153 1.8 cube union __semun karg;
154 1.8 cube union netbsd32_semun karg32;
155 1.1 mrg
156 1.8 cube cmd = SCARG(uap, cmd);
157 1.1 mrg
158 1.1 mrg switch (cmd) {
159 1.1 mrg case IPC_SET:
160 1.1 mrg case IPC_STAT:
161 1.8 cube pass_arg = &sembuf;
162 1.1 mrg break;
163 1.1 mrg
164 1.8 cube case GETALL:
165 1.8 cube case SETVAL:
166 1.8 cube case SETALL:
167 1.8 cube pass_arg = &karg;
168 1.1 mrg break;
169 1.8 cube default:
170 1.8 cube pass_arg = NULL;
171 1.1 mrg break;
172 1.8 cube }
173 1.1 mrg
174 1.8 cube if (pass_arg) {
175 1.16 christos error = copyin(SCARG_P32(uap, arg), &karg32, sizeof(karg32));
176 1.16 christos if (error)
177 1.16 christos return error;
178 1.8 cube if (pass_arg == &karg) {
179 1.8 cube switch (cmd) {
180 1.8 cube case GETALL:
181 1.8 cube case SETALL:
182 1.8 cube karg.array = NETBSD32PTR64(karg32.array);
183 1.8 cube break;
184 1.8 cube case SETVAL:
185 1.8 cube karg.val = karg32.val;
186 1.1 mrg break;
187 1.8 cube }
188 1.8 cube }
189 1.8 cube if (cmd == IPC_SET) {
190 1.8 cube error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32,
191 1.8 cube sizeof(sembuf32));
192 1.8 cube if (error)
193 1.8 cube return (error);
194 1.8 cube netbsd32_to_semid_ds(&sembuf32, &sembuf);
195 1.1 mrg }
196 1.8 cube }
197 1.1 mrg
198 1.9 ad error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
199 1.8 cube pass_arg, retval);
200 1.1 mrg
201 1.8 cube if (error == 0 && cmd == IPC_STAT) {
202 1.8 cube netbsd32_from_semid_ds(&sembuf, &sembuf32);
203 1.8 cube error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf),
204 1.8 cube sizeof(sembuf32));
205 1.1 mrg }
206 1.1 mrg
207 1.8 cube return (error);
208 1.1 mrg }
209 1.1 mrg
210 1.1 mrg int
211 1.14 dsl netbsd32_semget(struct lwp *l, const struct netbsd32_semget_args *uap, register_t *retval)
212 1.1 mrg {
213 1.14 dsl /* {
214 1.1 mrg syscallarg(netbsd32_key_t) key;
215 1.1 mrg syscallarg(int) nsems;
216 1.1 mrg syscallarg(int) semflg;
217 1.14 dsl } */
218 1.1 mrg struct sys_semget_args ua;
219 1.1 mrg
220 1.1 mrg NETBSD32TOX_UAP(key, key_t);
221 1.1 mrg NETBSD32TO64_UAP(nsems);
222 1.1 mrg NETBSD32TO64_UAP(semflg);
223 1.5 thorpej return (sys_semget(l, &ua, retval));
224 1.1 mrg }
225 1.1 mrg
226 1.1 mrg int
227 1.14 dsl netbsd32_semop(struct lwp *l, const struct netbsd32_semop_args *uap, register_t *retval)
228 1.1 mrg {
229 1.14 dsl /* {
230 1.1 mrg syscallarg(int) semid;
231 1.1 mrg syscallarg(netbsd32_sembufp_t) sops;
232 1.1 mrg syscallarg(netbsd32_size_t) nsops;
233 1.14 dsl } */
234 1.1 mrg struct sys_semop_args ua;
235 1.1 mrg
236 1.1 mrg NETBSD32TO64_UAP(semid);
237 1.1 mrg NETBSD32TOP_UAP(sops, struct sembuf);
238 1.1 mrg NETBSD32TOX_UAP(nsops, size_t);
239 1.5 thorpej return (sys_semop(l, &ua, retval));
240 1.1 mrg }
241 1.1 mrg
242 1.1 mrg int
243 1.14 dsl netbsd32_semconfig(struct lwp *l, const struct netbsd32_semconfig_args *uap, register_t *retval)
244 1.1 mrg {
245 1.14 dsl /* {
246 1.1 mrg syscallarg(int) flag;
247 1.14 dsl } */
248 1.1 mrg struct sys_semconfig_args ua;
249 1.1 mrg
250 1.1 mrg NETBSD32TO64_UAP(flag);
251 1.5 thorpej return (sys_semconfig(l, &ua, retval));
252 1.1 mrg }
253 1.1 mrg #endif /* SYSVSEM */
254 1.1 mrg
255 1.1 mrg #if defined(SYSVMSG)
256 1.1 mrg
257 1.1 mrg int
258 1.16 christos netbsd32___msgctl50(struct lwp *l, const struct netbsd32___msgctl50_args *uap,
259 1.16 christos register_t *retval)
260 1.1 mrg {
261 1.14 dsl /* {
262 1.1 mrg syscallarg(int) msqid;
263 1.1 mrg syscallarg(int) cmd;
264 1.1 mrg syscallarg(netbsd32_msqid_dsp_t) buf;
265 1.14 dsl } */
266 1.1 mrg struct msqid_ds ds;
267 1.8 cube struct netbsd32_msqid_ds ds32;
268 1.8 cube int error, cmd;
269 1.8 cube
270 1.8 cube cmd = SCARG(uap, cmd);
271 1.8 cube if (cmd == IPC_SET) {
272 1.11 dsl error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
273 1.8 cube if (error)
274 1.8 cube return error;
275 1.8 cube netbsd32_to_msqid_ds(&ds32, &ds);
276 1.8 cube }
277 1.8 cube
278 1.9 ad error = msgctl1(l, SCARG(uap, msqid), cmd,
279 1.8 cube (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
280 1.8 cube
281 1.8 cube if (error == 0 && cmd == IPC_STAT) {
282 1.8 cube netbsd32_from_msqid_ds(&ds, &ds32);
283 1.11 dsl error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
284 1.8 cube }
285 1.1 mrg
286 1.8 cube return error;
287 1.1 mrg }
288 1.1 mrg
289 1.1 mrg int
290 1.14 dsl netbsd32_msgget(struct lwp *l, const struct netbsd32_msgget_args *uap, register_t *retval)
291 1.1 mrg {
292 1.14 dsl /* {
293 1.1 mrg syscallarg(netbsd32_key_t) key;
294 1.1 mrg syscallarg(int) msgflg;
295 1.14 dsl } */
296 1.1 mrg struct sys_msgget_args ua;
297 1.1 mrg
298 1.1 mrg NETBSD32TOX_UAP(key, key_t);
299 1.1 mrg NETBSD32TO64_UAP(msgflg);
300 1.8 cube return sys_msgget(l, &ua, retval);
301 1.8 cube }
302 1.8 cube
303 1.8 cube static int
304 1.8 cube netbsd32_msgsnd_fetch_type(const void *src, void *dst, size_t size)
305 1.8 cube {
306 1.8 cube netbsd32_long l32;
307 1.8 cube long *l = dst;
308 1.8 cube int error;
309 1.8 cube
310 1.8 cube KASSERT(size == sizeof(netbsd32_long));
311 1.8 cube
312 1.8 cube error = copyin(src, &l32, sizeof(l32));
313 1.8 cube if (!error)
314 1.8 cube *l = l32;
315 1.8 cube return error;
316 1.1 mrg }
317 1.1 mrg
318 1.1 mrg int
319 1.14 dsl netbsd32_msgsnd(struct lwp *l, const struct netbsd32_msgsnd_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(const netbsd32_voidp) msgp;
324 1.1 mrg syscallarg(netbsd32_size_t) msgsz;
325 1.1 mrg syscallarg(int) msgflg;
326 1.14 dsl } */
327 1.1 mrg
328 1.9 ad return msgsnd1(l, SCARG(uap, msqid),
329 1.11 dsl SCARG_P32(uap, msgp), SCARG(uap, msgsz),
330 1.8 cube SCARG(uap, msgflg), sizeof(netbsd32_long),
331 1.8 cube netbsd32_msgsnd_fetch_type);
332 1.8 cube }
333 1.8 cube
334 1.8 cube static int
335 1.8 cube netbsd32_msgrcv_put_type(const void *src, void *dst, size_t size)
336 1.8 cube {
337 1.8 cube netbsd32_long l32;
338 1.8 cube const long *l = src;
339 1.8 cube
340 1.8 cube KASSERT(size == sizeof(netbsd32_long));
341 1.8 cube
342 1.8 cube l32 = (netbsd32_long)(*l);
343 1.8 cube return copyout(&l32, dst, sizeof(l32));
344 1.1 mrg }
345 1.1 mrg
346 1.1 mrg int
347 1.14 dsl netbsd32_msgrcv(struct lwp *l, const struct netbsd32_msgrcv_args *uap, register_t *retval)
348 1.1 mrg {
349 1.14 dsl /* {
350 1.1 mrg syscallarg(int) msqid;
351 1.1 mrg syscallarg(netbsd32_voidp) msgp;
352 1.1 mrg syscallarg(netbsd32_size_t) msgsz;
353 1.1 mrg syscallarg(netbsd32_long) msgtyp;
354 1.1 mrg syscallarg(int) msgflg;
355 1.14 dsl } */
356 1.1 mrg
357 1.9 ad return msgrcv1(l, SCARG(uap, msqid),
358 1.11 dsl SCARG_P32(uap, msgp), SCARG(uap, msgsz),
359 1.8 cube SCARG(uap, msgtyp), SCARG(uap, msgflg), sizeof(netbsd32_long),
360 1.8 cube netbsd32_msgrcv_put_type, retval);
361 1.1 mrg }
362 1.1 mrg #endif /* SYSVMSG */
363 1.1 mrg
364 1.1 mrg #if defined(SYSVSHM)
365 1.1 mrg
366 1.1 mrg int
367 1.14 dsl netbsd32_shmat(struct lwp *l, const struct netbsd32_shmat_args *uap, register_t *retval)
368 1.1 mrg {
369 1.14 dsl /* {
370 1.1 mrg syscallarg(int) shmid;
371 1.1 mrg syscallarg(const netbsd32_voidp) shmaddr;
372 1.1 mrg syscallarg(int) shmflg;
373 1.14 dsl } */
374 1.1 mrg struct sys_shmat_args ua;
375 1.1 mrg
376 1.1 mrg NETBSD32TO64_UAP(shmid);
377 1.1 mrg NETBSD32TOP_UAP(shmaddr, void);
378 1.1 mrg NETBSD32TO64_UAP(shmflg);
379 1.8 cube return sys_shmat(l, &ua, retval);
380 1.1 mrg }
381 1.1 mrg
382 1.1 mrg int
383 1.16 christos netbsd32___shmctl50(struct lwp *l, const struct netbsd32___shmctl50_args *uap,
384 1.16 christos register_t *retval)
385 1.1 mrg {
386 1.14 dsl /* {
387 1.1 mrg syscallarg(int) shmid;
388 1.1 mrg syscallarg(int) cmd;
389 1.1 mrg syscallarg(netbsd32_shmid_dsp_t) buf;
390 1.14 dsl } */
391 1.1 mrg struct shmid_ds ds;
392 1.8 cube struct netbsd32_shmid_ds ds32;
393 1.8 cube int error, cmd;
394 1.8 cube
395 1.8 cube cmd = SCARG(uap, cmd);
396 1.8 cube if (cmd == IPC_SET) {
397 1.11 dsl error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32));
398 1.8 cube if (error)
399 1.8 cube return error;
400 1.8 cube netbsd32_to_shmid_ds(&ds32, &ds);
401 1.8 cube }
402 1.8 cube
403 1.9 ad error = shmctl1(l, SCARG(uap, shmid), cmd,
404 1.8 cube (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL);
405 1.8 cube
406 1.8 cube if (error == 0 && cmd == IPC_STAT) {
407 1.8 cube netbsd32_from_shmid_ds(&ds, &ds32);
408 1.11 dsl error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32));
409 1.8 cube }
410 1.1 mrg
411 1.8 cube return error;
412 1.1 mrg }
413 1.1 mrg
414 1.1 mrg int
415 1.14 dsl netbsd32_shmdt(struct lwp *l, const struct netbsd32_shmdt_args *uap, register_t *retval)
416 1.1 mrg {
417 1.14 dsl /* {
418 1.1 mrg syscallarg(const netbsd32_voidp) shmaddr;
419 1.14 dsl } */
420 1.1 mrg struct sys_shmdt_args ua;
421 1.1 mrg
422 1.1 mrg NETBSD32TOP_UAP(shmaddr, const char);
423 1.5 thorpej return (sys_shmdt(l, &ua, retval));
424 1.1 mrg }
425 1.1 mrg
426 1.1 mrg int
427 1.14 dsl netbsd32_shmget(struct lwp *l, const struct netbsd32_shmget_args *uap, register_t *retval)
428 1.1 mrg {
429 1.14 dsl /* {
430 1.1 mrg syscallarg(netbsd32_key_t) key;
431 1.1 mrg syscallarg(netbsd32_size_t) size;
432 1.1 mrg syscallarg(int) shmflg;
433 1.14 dsl } */
434 1.1 mrg struct sys_shmget_args ua;
435 1.1 mrg
436 1.17 njoly NETBSD32TOX_UAP(key, key_t);
437 1.17 njoly NETBSD32TOX_UAP(size, size_t);
438 1.1 mrg NETBSD32TO64_UAP(shmflg);
439 1.5 thorpej return (sys_shmget(l, &ua, retval));
440 1.1 mrg }
441 1.1 mrg #endif /* SYSVSHM */
442