linux_ipc.c revision 1.27 1 1.27 fvdl /* $NetBSD: linux_ipc.c,v 1.27 2002/04/03 11:54:37 fvdl Exp $ */
2 1.14 erh
3 1.14 erh /*-
4 1.16 fvdl * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5 1.14 erh * All rights reserved.
6 1.14 erh *
7 1.14 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.16 fvdl * by Frank van der Linden and Eric Haszlakiewicz.
9 1.14 erh *
10 1.14 erh * Redistribution and use in source and binary forms, with or without
11 1.14 erh * modification, are permitted provided that the following conditions
12 1.14 erh * are met:
13 1.14 erh * 1. Redistributions of source code must retain the above copyright
14 1.14 erh * notice, this list of conditions and the following disclaimer.
15 1.14 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.14 erh * notice, this list of conditions and the following disclaimer in the
17 1.14 erh * documentation and/or other materials provided with the distribution.
18 1.14 erh * 3. All advertising materials mentioning features or use of this software
19 1.14 erh * must display the following acknowledgement:
20 1.14 erh * This product includes software developed by the NetBSD
21 1.14 erh * Foundation, Inc. and its contributors.
22 1.14 erh * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.14 erh * contributors may be used to endorse or promote products derived
24 1.14 erh * from this software without specific prior written permission.
25 1.14 erh *
26 1.14 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.14 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.14 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.14 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.14 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.14 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.14 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.14 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.14 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.14 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.14 erh * POSSIBILITY OF SUCH DAMAGE.
37 1.1 fvdl */
38 1.24 lukem
39 1.24 lukem #include <sys/cdefs.h>
40 1.27 fvdl __KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.27 2002/04/03 11:54:37 fvdl Exp $");
41 1.19 erh
42 1.23 mrg #if defined(_KERNEL_OPT)
43 1.19 erh #include "opt_sysv.h"
44 1.22 jdolecek #endif
45 1.1 fvdl
46 1.1 fvdl #include <sys/param.h>
47 1.1 fvdl #include <sys/shm.h>
48 1.6 fvdl #include <sys/sem.h>
49 1.1 fvdl #include <sys/msg.h>
50 1.1 fvdl #include <sys/proc.h>
51 1.1 fvdl #include <sys/systm.h>
52 1.1 fvdl
53 1.1 fvdl #include <sys/mount.h>
54 1.1 fvdl #include <sys/syscallargs.h>
55 1.1 fvdl
56 1.15 christos #include <compat/linux/common/linux_types.h>
57 1.15 christos #include <compat/linux/common/linux_signal.h>
58 1.15 christos #include <compat/linux/common/linux_util.h>
59 1.15 christos
60 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
61 1.14 erh #include <compat/linux/linux_syscall.h>
62 1.15 christos
63 1.15 christos #include <compat/linux/common/linux_ipc.h>
64 1.15 christos #include <compat/linux/common/linux_msg.h>
65 1.15 christos #include <compat/linux/common/linux_shm.h>
66 1.15 christos #include <compat/linux/common/linux_sem.h>
67 1.15 christos #include <compat/linux/common/linux_ipccall.h>
68 1.1 fvdl
69 1.1 fvdl /*
70 1.14 erh * Note: Not all linux architechtures have explicit versions
71 1.14 erh * of the SYSV* syscalls. On the ones that don't
72 1.14 erh * we pretend that they are defined anyway. *_args and
73 1.14 erh * prototypes are defined in individual headers;
74 1.14 erh * syscalls.master lists those syscalls as NOARGS.
75 1.1 fvdl *
76 1.14 erh * The functions in multiarch are the ones that just need
77 1.14 erh * the arguments shuffled around and then use the
78 1.14 erh * normal NetBSD syscall.
79 1.14 erh *
80 1.14 erh * Function in multiarch:
81 1.14 erh * linux_sys_ipc : linux_ipccall.c
82 1.14 erh * liunx_semop : linux_ipccall.c
83 1.14 erh * linux_semget : linux_ipccall.c
84 1.14 erh * linux_msgsnd : linux_ipccall.c
85 1.14 erh * linux_msgrcv : linux_ipccall.c
86 1.14 erh * linux_msgget : linux_ipccall.c
87 1.14 erh * linux_shmdt : linux_ipccall.c
88 1.14 erh * linux_shmget : linux_ipccall.c
89 1.1 fvdl */
90 1.1 fvdl
91 1.11 fvdl #if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
92 1.1 fvdl /*
93 1.1 fvdl * Convert between Linux and NetBSD ipc_perm structures. Only the
94 1.1 fvdl * order of the fields is different.
95 1.1 fvdl */
96 1.14 erh void
97 1.1 fvdl linux_to_bsd_ipc_perm(lpp, bpp)
98 1.1 fvdl struct linux_ipc_perm *lpp;
99 1.1 fvdl struct ipc_perm *bpp;
100 1.1 fvdl {
101 1.8 mycroft
102 1.21 thorpej bpp->_key = lpp->l_key;
103 1.1 fvdl bpp->uid = lpp->l_uid;
104 1.1 fvdl bpp->gid = lpp->l_gid;
105 1.1 fvdl bpp->cuid = lpp->l_cuid;
106 1.1 fvdl bpp->cgid = lpp->l_cgid;
107 1.1 fvdl bpp->mode = lpp->l_mode;
108 1.21 thorpej bpp->_seq = lpp->l_seq;
109 1.1 fvdl }
110 1.1 fvdl
111 1.14 erh void
112 1.1 fvdl bsd_to_linux_ipc_perm(bpp, lpp)
113 1.1 fvdl struct ipc_perm *bpp;
114 1.1 fvdl struct linux_ipc_perm *lpp;
115 1.1 fvdl {
116 1.8 mycroft
117 1.21 thorpej lpp->l_key = bpp->_key;
118 1.1 fvdl lpp->l_uid = bpp->uid;
119 1.1 fvdl lpp->l_gid = bpp->gid;
120 1.1 fvdl lpp->l_cuid = bpp->cuid;
121 1.1 fvdl lpp->l_cgid = bpp->cgid;
122 1.1 fvdl lpp->l_mode = bpp->mode;
123 1.21 thorpej lpp->l_seq = bpp->_seq;
124 1.1 fvdl }
125 1.11 fvdl #endif
126 1.1 fvdl
127 1.1 fvdl #ifdef SYSVSEM
128 1.1 fvdl /*
129 1.6 fvdl * Semaphore operations. Most constants and structures are the same on
130 1.6 fvdl * both systems. Only semctl() needs some extra work.
131 1.1 fvdl */
132 1.6 fvdl
133 1.6 fvdl /*
134 1.6 fvdl * Convert between Linux and NetBSD semid_ds structures.
135 1.6 fvdl */
136 1.14 erh void
137 1.6 fvdl bsd_to_linux_semid_ds(bs, ls)
138 1.6 fvdl struct semid_ds *bs;
139 1.6 fvdl struct linux_semid_ds *ls;
140 1.6 fvdl {
141 1.8 mycroft
142 1.6 fvdl bsd_to_linux_ipc_perm(&bs->sem_perm, &ls->l_sem_perm);
143 1.6 fvdl ls->l_sem_otime = bs->sem_otime;
144 1.6 fvdl ls->l_sem_ctime = bs->sem_ctime;
145 1.6 fvdl ls->l_sem_nsems = bs->sem_nsems;
146 1.21 thorpej ls->l_sem_base = bs->_sem_base;
147 1.6 fvdl }
148 1.6 fvdl
149 1.14 erh void
150 1.6 fvdl linux_to_bsd_semid_ds(ls, bs)
151 1.6 fvdl struct linux_semid_ds *ls;
152 1.6 fvdl struct semid_ds *bs;
153 1.6 fvdl {
154 1.8 mycroft
155 1.6 fvdl linux_to_bsd_ipc_perm(&ls->l_sem_perm, &bs->sem_perm);
156 1.6 fvdl bs->sem_otime = ls->l_sem_otime;
157 1.6 fvdl bs->sem_ctime = ls->l_sem_ctime;
158 1.6 fvdl bs->sem_nsems = ls->l_sem_nsems;
159 1.21 thorpej bs->_sem_base = ls->l_sem_base;
160 1.6 fvdl }
161 1.6 fvdl
162 1.6 fvdl /*
163 1.21 thorpej * Most of this can be handled by directly passing the arguments on; we
164 1.21 thorpej * just need to frob the `cmd' and convert the semid_ds and semun.
165 1.6 fvdl */
166 1.1 fvdl int
167 1.14 erh linux_sys_semctl(p, v, retval)
168 1.1 fvdl struct proc *p;
169 1.14 erh void *v;
170 1.1 fvdl register_t *retval;
171 1.1 fvdl {
172 1.14 erh struct linux_sys_semctl_args /* {
173 1.14 erh syscallarg(int) semid;
174 1.14 erh syscallarg(int) semnum;
175 1.14 erh syscallarg(int) cmd;
176 1.14 erh syscallarg(union linux_semun) arg;
177 1.14 erh } */ *uap = v;
178 1.21 thorpej struct semid_ds sembuf;
179 1.21 thorpej struct linux_semid_ds lsembuf;
180 1.21 thorpej union __semun semun;
181 1.21 thorpej int cmd, error;
182 1.21 thorpej void *pass_arg = NULL;
183 1.21 thorpej
184 1.21 thorpej cmd = SCARG(uap, cmd);
185 1.21 thorpej
186 1.21 thorpej switch (cmd) {
187 1.21 thorpej case LINUX_IPC_SET:
188 1.21 thorpej pass_arg = &sembuf;
189 1.21 thorpej cmd = IPC_SET;
190 1.21 thorpej break;
191 1.6 fvdl
192 1.13 mycroft case LINUX_IPC_STAT:
193 1.21 thorpej pass_arg = &sembuf;
194 1.21 thorpej cmd = IPC_STAT;
195 1.14 erh break;
196 1.21 thorpej
197 1.13 mycroft case LINUX_IPC_RMID:
198 1.21 thorpej cmd = IPC_RMID;
199 1.13 mycroft break;
200 1.21 thorpej
201 1.6 fvdl case LINUX_GETVAL:
202 1.21 thorpej cmd = GETVAL;
203 1.6 fvdl break;
204 1.21 thorpej
205 1.6 fvdl case LINUX_GETPID:
206 1.21 thorpej cmd = GETPID;
207 1.6 fvdl break;
208 1.21 thorpej
209 1.6 fvdl case LINUX_GETNCNT:
210 1.21 thorpej cmd = GETNCNT;
211 1.6 fvdl break;
212 1.21 thorpej
213 1.6 fvdl case LINUX_GETZCNT:
214 1.21 thorpej cmd = GETZCNT;
215 1.6 fvdl break;
216 1.21 thorpej
217 1.21 thorpej case LINUX_GETALL:
218 1.21 thorpej pass_arg = &semun;
219 1.21 thorpej semun.array = SCARG(uap, arg).l_array;
220 1.21 thorpej cmd = GETALL;
221 1.21 thorpej break;
222 1.21 thorpej
223 1.6 fvdl case LINUX_SETVAL:
224 1.21 thorpej pass_arg = &semun;
225 1.21 thorpej semun.val = SCARG(uap, arg).l_val;
226 1.21 thorpej cmd = SETVAL;
227 1.20 tron break;
228 1.21 thorpej
229 1.20 tron case LINUX_SETALL:
230 1.21 thorpej pass_arg = &semun;
231 1.21 thorpej semun.array = SCARG(uap, arg).l_array;
232 1.21 thorpej cmd = SETALL;
233 1.6 fvdl break;
234 1.21 thorpej
235 1.6 fvdl default:
236 1.21 thorpej return (EINVAL);
237 1.21 thorpej }
238 1.21 thorpej
239 1.21 thorpej if (cmd == IPC_SET) {
240 1.21 thorpej error = copyin(SCARG(uap, arg).l_buf, &lsembuf,
241 1.21 thorpej sizeof(lsembuf));
242 1.21 thorpej if (error)
243 1.21 thorpej return (error);
244 1.21 thorpej linux_to_bsd_semid_ds(&lsembuf, &sembuf);
245 1.21 thorpej }
246 1.21 thorpej
247 1.21 thorpej error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum), cmd,
248 1.21 thorpej pass_arg, retval);
249 1.21 thorpej
250 1.21 thorpej if (error == 0 && cmd == IPC_STAT) {
251 1.21 thorpej bsd_to_linux_semid_ds(&sembuf, &lsembuf);
252 1.21 thorpej error = copyout(&lsembuf, SCARG(uap, arg).l_buf,
253 1.21 thorpej sizeof(lsembuf));
254 1.6 fvdl }
255 1.21 thorpej
256 1.21 thorpej return (error);
257 1.1 fvdl }
258 1.1 fvdl #endif /* SYSVSEM */
259 1.1 fvdl
260 1.1 fvdl #ifdef SYSVMSG
261 1.6 fvdl
262 1.14 erh void
263 1.6 fvdl linux_to_bsd_msqid_ds(lmp, bmp)
264 1.6 fvdl struct linux_msqid_ds *lmp;
265 1.6 fvdl struct msqid_ds *bmp;
266 1.6 fvdl {
267 1.8 mycroft
268 1.6 fvdl linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm);
269 1.21 thorpej bmp->_msg_first = lmp->l_msg_first;
270 1.21 thorpej bmp->_msg_last = lmp->l_msg_last;
271 1.21 thorpej bmp->_msg_cbytes = lmp->l_msg_cbytes;
272 1.6 fvdl bmp->msg_qnum = lmp->l_msg_qnum;
273 1.6 fvdl bmp->msg_qbytes = lmp->l_msg_qbytes;
274 1.6 fvdl bmp->msg_lspid = lmp->l_msg_lspid;
275 1.6 fvdl bmp->msg_lrpid = lmp->l_msg_lrpid;
276 1.6 fvdl bmp->msg_stime = lmp->l_msg_stime;
277 1.6 fvdl bmp->msg_rtime = lmp->l_msg_rtime;
278 1.6 fvdl bmp->msg_ctime = lmp->l_msg_ctime;
279 1.6 fvdl }
280 1.6 fvdl
281 1.14 erh void
282 1.6 fvdl bsd_to_linux_msqid_ds(bmp, lmp)
283 1.6 fvdl struct msqid_ds *bmp;
284 1.6 fvdl struct linux_msqid_ds *lmp;
285 1.6 fvdl {
286 1.8 mycroft
287 1.6 fvdl bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm);
288 1.21 thorpej lmp->l_msg_first = bmp->_msg_first;
289 1.21 thorpej lmp->l_msg_last = bmp->_msg_last;
290 1.21 thorpej lmp->l_msg_cbytes = bmp->_msg_cbytes;
291 1.6 fvdl lmp->l_msg_qnum = bmp->msg_qnum;
292 1.6 fvdl lmp->l_msg_qbytes = bmp->msg_qbytes;
293 1.6 fvdl lmp->l_msg_lspid = bmp->msg_lspid;
294 1.6 fvdl lmp->l_msg_lrpid = bmp->msg_lrpid;
295 1.6 fvdl lmp->l_msg_stime = bmp->msg_stime;
296 1.6 fvdl lmp->l_msg_rtime = bmp->msg_rtime;
297 1.6 fvdl lmp->l_msg_ctime = bmp->msg_ctime;
298 1.6 fvdl }
299 1.6 fvdl
300 1.14 erh int
301 1.14 erh linux_sys_msgctl(p, v, retval)
302 1.1 fvdl struct proc *p;
303 1.14 erh void *v;
304 1.1 fvdl register_t *retval;
305 1.1 fvdl {
306 1.14 erh struct linux_sys_msgctl_args /* {
307 1.14 erh syscallarg(int) msqid;
308 1.14 erh syscallarg(int) cmd;
309 1.14 erh syscallarg(struct linux_msqid_ds *) buf;
310 1.14 erh } */ *uap = v;
311 1.13 mycroft caddr_t sg;
312 1.21 thorpej struct sys___msgctl13_args nua;
313 1.13 mycroft struct msqid_ds *bmp, bm;
314 1.6 fvdl struct linux_msqid_ds lm;
315 1.6 fvdl int error;
316 1.6 fvdl
317 1.14 erh SCARG(&nua, msqid) = SCARG(uap, msqid);
318 1.14 erh switch (SCARG(uap, cmd)) {
319 1.13 mycroft case LINUX_IPC_STAT:
320 1.26 christos sg = stackgap_init(p, 0);
321 1.26 christos bmp = stackgap_alloc(p, &sg, sizeof (struct msqid_ds));
322 1.13 mycroft SCARG(&nua, cmd) = IPC_STAT;
323 1.13 mycroft SCARG(&nua, buf) = bmp;
324 1.21 thorpej if ((error = sys___msgctl13(p, &nua, retval)))
325 1.13 mycroft return error;
326 1.13 mycroft if ((error = copyin(bmp, &bm, sizeof bm)))
327 1.13 mycroft return error;
328 1.13 mycroft bsd_to_linux_msqid_ds(&bm, &lm);
329 1.14 erh return copyout(&lm, SCARG(uap, buf), sizeof lm);
330 1.6 fvdl case LINUX_IPC_SET:
331 1.14 erh if ((error = copyin(SCARG(uap, buf), &lm, sizeof lm)))
332 1.6 fvdl return error;
333 1.6 fvdl linux_to_bsd_msqid_ds(&lm, &bm);
334 1.26 christos sg = stackgap_init(p, 0);
335 1.26 christos bmp = stackgap_alloc(p, &sg, sizeof bm);
336 1.13 mycroft if ((error = copyout(&bm, bmp, sizeof bm)))
337 1.6 fvdl return error;
338 1.13 mycroft SCARG(&nua, cmd) = IPC_SET;
339 1.13 mycroft SCARG(&nua, buf) = bmp;
340 1.14 erh break;
341 1.13 mycroft case LINUX_IPC_RMID:
342 1.13 mycroft SCARG(&nua, cmd) = IPC_RMID;
343 1.13 mycroft SCARG(&nua, buf) = NULL;
344 1.13 mycroft break;
345 1.13 mycroft default:
346 1.13 mycroft return EINVAL;
347 1.6 fvdl }
348 1.21 thorpej return sys___msgctl13(p, &nua, retval);
349 1.1 fvdl }
350 1.1 fvdl #endif /* SYSVMSG */
351 1.1 fvdl
352 1.1 fvdl #ifdef SYSVSHM
353 1.1 fvdl /*
354 1.1 fvdl * shmat(2). Very straightforward, except that Linux passes a pointer
355 1.1 fvdl * in which the return value is to be passed. This is subsequently
356 1.1 fvdl * handled by libc, apparently.
357 1.1 fvdl */
358 1.14 erh int
359 1.14 erh linux_sys_shmat(p, v, retval)
360 1.1 fvdl struct proc *p;
361 1.14 erh void *v;
362 1.1 fvdl register_t *retval;
363 1.1 fvdl {
364 1.14 erh struct linux_sys_shmat_args /* {
365 1.14 erh syscallarg(int) shmid;
366 1.14 erh syscallarg(void *) shmaddr;
367 1.14 erh syscallarg(int) shmflg;
368 1.14 erh syscallarg(u_long *) raddr;
369 1.14 erh } */ *uap = v;
370 1.1 fvdl int error;
371 1.27 fvdl vaddr_t attach_va;
372 1.27 fvdl u_long raddr;
373 1.1 fvdl
374 1.27 fvdl if ((error = shmat1(p, SCARG(uap, shmid), SCARG(uap, shmaddr),
375 1.27 fvdl SCARG(uap, shmflg), &attach_va, 1)))
376 1.1 fvdl return error;
377 1.1 fvdl
378 1.27 fvdl raddr = (u_long)attach_va;
379 1.27 fvdl
380 1.27 fvdl if ((error = copyout(&raddr, (caddr_t) SCARG(uap, raddr),
381 1.1 fvdl sizeof retval[0])))
382 1.1 fvdl return error;
383 1.14 erh
384 1.1 fvdl retval[0] = 0;
385 1.1 fvdl return 0;
386 1.1 fvdl }
387 1.1 fvdl
388 1.1 fvdl /*
389 1.1 fvdl * Convert between Linux and NetBSD shmid_ds structures.
390 1.1 fvdl * The order of the fields is once again the difference, and
391 1.1 fvdl * we also need a place to store the internal data pointer
392 1.1 fvdl * in, which is unfortunately stored in this structure.
393 1.1 fvdl *
394 1.1 fvdl * We abuse a Linux internal field for that.
395 1.1 fvdl */
396 1.14 erh void
397 1.1 fvdl linux_to_bsd_shmid_ds(lsp, bsp)
398 1.1 fvdl struct linux_shmid_ds *lsp;
399 1.1 fvdl struct shmid_ds *bsp;
400 1.1 fvdl {
401 1.8 mycroft
402 1.1 fvdl linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
403 1.1 fvdl bsp->shm_segsz = lsp->l_shm_segsz;
404 1.1 fvdl bsp->shm_lpid = lsp->l_shm_lpid;
405 1.1 fvdl bsp->shm_cpid = lsp->l_shm_cpid;
406 1.1 fvdl bsp->shm_nattch = lsp->l_shm_nattch;
407 1.1 fvdl bsp->shm_atime = lsp->l_shm_atime;
408 1.1 fvdl bsp->shm_dtime = lsp->l_shm_dtime;
409 1.1 fvdl bsp->shm_ctime = lsp->l_shm_ctime;
410 1.21 thorpej bsp->_shm_internal = lsp->l_private2; /* XXX Oh well. */
411 1.1 fvdl }
412 1.1 fvdl
413 1.14 erh void
414 1.1 fvdl bsd_to_linux_shmid_ds(bsp, lsp)
415 1.1 fvdl struct shmid_ds *bsp;
416 1.1 fvdl struct linux_shmid_ds *lsp;
417 1.1 fvdl {
418 1.8 mycroft
419 1.1 fvdl bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
420 1.1 fvdl lsp->l_shm_segsz = bsp->shm_segsz;
421 1.1 fvdl lsp->l_shm_lpid = bsp->shm_lpid;
422 1.1 fvdl lsp->l_shm_cpid = bsp->shm_cpid;
423 1.1 fvdl lsp->l_shm_nattch = bsp->shm_nattch;
424 1.1 fvdl lsp->l_shm_atime = bsp->shm_atime;
425 1.1 fvdl lsp->l_shm_dtime = bsp->shm_dtime;
426 1.1 fvdl lsp->l_shm_ctime = bsp->shm_ctime;
427 1.21 thorpej lsp->l_private2 = bsp->_shm_internal; /* XXX */
428 1.1 fvdl }
429 1.1 fvdl
430 1.1 fvdl /*
431 1.1 fvdl * shmctl. Not implemented (for now): IPC_INFO, SHM_INFO, SHM_STAT
432 1.1 fvdl * SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
433 1.1 fvdl * by NetBSD itself.
434 1.1 fvdl *
435 1.1 fvdl * The usual structure conversion and massaging is done.
436 1.1 fvdl */
437 1.14 erh int
438 1.14 erh linux_sys_shmctl(p, v, retval)
439 1.1 fvdl struct proc *p;
440 1.14 erh void *v;
441 1.1 fvdl register_t *retval;
442 1.1 fvdl {
443 1.14 erh struct linux_sys_shmctl_args /* {
444 1.14 erh syscallarg(int) shmid;
445 1.14 erh syscallarg(int) cmd;
446 1.14 erh syscallarg(struct linux_shmid_ds *) buf;
447 1.14 erh } */ *uap = v;
448 1.1 fvdl caddr_t sg;
449 1.21 thorpej struct sys___shmctl13_args nua;
450 1.1 fvdl struct shmid_ds *bsp, bs;
451 1.13 mycroft struct linux_shmid_ds ls;
452 1.13 mycroft int error;
453 1.1 fvdl
454 1.14 erh SCARG(&nua, shmid) = SCARG(uap, shmid);
455 1.14 erh switch (SCARG(uap, cmd)) {
456 1.1 fvdl case LINUX_IPC_STAT:
457 1.26 christos sg = stackgap_init(p, 0);
458 1.26 christos bsp = stackgap_alloc(p, &sg, sizeof(struct shmid_ds));
459 1.13 mycroft SCARG(&nua, cmd) = IPC_STAT;
460 1.13 mycroft SCARG(&nua, buf) = bsp;
461 1.21 thorpej if ((error = sys___shmctl13(p, &nua, retval)))
462 1.1 fvdl return error;
463 1.14 erh if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
464 1.1 fvdl return error;
465 1.13 mycroft bsd_to_linux_shmid_ds(&bs, &ls);
466 1.14 erh return copyout(&ls, SCARG(uap, buf), sizeof ls);
467 1.1 fvdl case LINUX_IPC_SET:
468 1.14 erh if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
469 1.1 fvdl return error;
470 1.13 mycroft linux_to_bsd_shmid_ds(&ls, &bs);
471 1.26 christos sg = stackgap_init(p, 0);
472 1.26 christos bsp = stackgap_alloc(p, &sg, sizeof bs);
473 1.13 mycroft if ((error = copyout(&bs, bsp, sizeof bs)))
474 1.1 fvdl return error;
475 1.13 mycroft SCARG(&nua, cmd) = IPC_SET;
476 1.13 mycroft SCARG(&nua, buf) = bsp;
477 1.14 erh break;
478 1.1 fvdl case LINUX_IPC_RMID:
479 1.13 mycroft SCARG(&nua, cmd) = IPC_RMID;
480 1.13 mycroft SCARG(&nua, buf) = NULL;
481 1.13 mycroft break;
482 1.1 fvdl case LINUX_SHM_LOCK:
483 1.13 mycroft SCARG(&nua, cmd) = SHM_LOCK;
484 1.13 mycroft SCARG(&nua, buf) = NULL;
485 1.13 mycroft break;
486 1.1 fvdl case LINUX_SHM_UNLOCK:
487 1.13 mycroft SCARG(&nua, cmd) = SHM_UNLOCK;
488 1.13 mycroft SCARG(&nua, buf) = NULL;
489 1.13 mycroft break;
490 1.1 fvdl case LINUX_IPC_INFO:
491 1.1 fvdl case LINUX_SHM_STAT:
492 1.1 fvdl case LINUX_SHM_INFO:
493 1.1 fvdl default:
494 1.1 fvdl return EINVAL;
495 1.1 fvdl }
496 1.21 thorpej return sys___shmctl13(p, &nua, retval);
497 1.1 fvdl }
498 1.1 fvdl #endif /* SYSVSHM */
499