linux_ipc.c revision 1.5 1 1.5 mycroft /* $NetBSD: linux_ipc.c,v 1.5 1995/08/14 01:27:52 mycroft Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*
4 1.1 fvdl * Copyright (c) 1995 Frank van der Linden
5 1.1 fvdl * All rights reserved.
6 1.1 fvdl *
7 1.1 fvdl * Redistribution and use in source and binary forms, with or without
8 1.1 fvdl * modification, are permitted provided that the following conditions
9 1.1 fvdl * are met:
10 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
11 1.1 fvdl * notice, this list of conditions and the following disclaimer.
12 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
14 1.1 fvdl * documentation and/or other materials provided with the distribution.
15 1.1 fvdl * 3. All advertising materials mentioning features or use of this software
16 1.1 fvdl * must display the following acknowledgement:
17 1.1 fvdl * This product includes software developed for the NetBSD Project
18 1.1 fvdl * by Frank van der Linden
19 1.1 fvdl * 4. The name of the author may not be used to endorse or promote products
20 1.1 fvdl * derived from this software without specific prior written permission
21 1.1 fvdl *
22 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 fvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 fvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 fvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 fvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 fvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 fvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 fvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 fvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 fvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 fvdl */
33 1.1 fvdl
34 1.1 fvdl #include <sys/types.h>
35 1.1 fvdl #include <sys/param.h>
36 1.1 fvdl #include <sys/kernel.h>
37 1.1 fvdl #include <sys/shm.h>
38 1.1 fvdl #include <sys/msg.h>
39 1.1 fvdl #include <sys/proc.h>
40 1.1 fvdl #include <sys/uio.h>
41 1.1 fvdl #include <sys/time.h>
42 1.1 fvdl #include <sys/malloc.h>
43 1.1 fvdl #include <sys/mman.h>
44 1.1 fvdl #include <sys/systm.h>
45 1.1 fvdl #include <sys/stat.h>
46 1.1 fvdl
47 1.1 fvdl #include <sys/mount.h>
48 1.1 fvdl #include <sys/syscallargs.h>
49 1.1 fvdl
50 1.1 fvdl #include <compat/linux/linux_types.h>
51 1.5 mycroft #include <compat/linux/linux_signal.h>
52 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
53 1.1 fvdl #include <compat/linux/linux_util.h>
54 1.1 fvdl #include <compat/linux/linux_ipc.h>
55 1.1 fvdl #include <compat/linux/linux_msg.h>
56 1.1 fvdl #include <compat/linux/linux_shm.h>
57 1.1 fvdl #include <compat/linux/linux_ipccall.h>
58 1.1 fvdl
59 1.1 fvdl /*
60 1.1 fvdl * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
61 1.1 fvdl * The main difference is, that Linux handles it all via one
62 1.1 fvdl * system call, which has the usual maximum amount of 5 arguments.
63 1.1 fvdl * This results in a kludge for calls that take 6 of them.
64 1.1 fvdl *
65 1.1 fvdl * The SYSVXXXX options have to be enabled to get the appropriate
66 1.1 fvdl * functions to work.
67 1.1 fvdl */
68 1.1 fvdl
69 1.1 fvdl #ifdef SYSVSEM
70 1.1 fvdl static int linux_semop __P((struct proc *, struct linux_ipc_args *,
71 1.1 fvdl register_t *));
72 1.1 fvdl static int linux_semget __P((struct proc *, struct linux_ipc_args *,
73 1.1 fvdl register_t *));
74 1.1 fvdl static int linux_semctl __P((struct proc *, struct linux_ipc_args *,
75 1.1 fvdl register_t *));
76 1.1 fvdl #endif
77 1.1 fvdl
78 1.1 fvdl #ifdef SYSVMSG
79 1.1 fvdl static int linux_msgsnd __P((struct proc *, struct linux_ipc_args *,
80 1.1 fvdl register_t *));
81 1.1 fvdl static int linux_msgrcv __P((struct proc *, struct linux_ipc_args *,
82 1.1 fvdl register_t *));
83 1.1 fvdl static int linux_msgop __P((struct proc *, struct linux_ipc_args *,
84 1.1 fvdl register_t *));
85 1.1 fvdl static int linux_msgctl __P((struct proc *, struct linux_ipc_args *,
86 1.1 fvdl register_t *));
87 1.1 fvdl #endif
88 1.1 fvdl
89 1.1 fvdl #ifdef SYSVSHM
90 1.1 fvdl static int linux_shmat __P((struct proc *, struct linux_ipc_args *,
91 1.1 fvdl register_t *));
92 1.1 fvdl static int linux_shmdt __P((struct proc *, struct linux_ipc_args *,
93 1.1 fvdl register_t *));
94 1.1 fvdl static int linux_shmget __P((struct proc *, struct linux_ipc_args *,
95 1.1 fvdl register_t *));
96 1.1 fvdl static int linux_shmctl __P((struct proc *, struct linux_ipc_args *,
97 1.1 fvdl register_t *));
98 1.1 fvdl #endif
99 1.1 fvdl
100 1.1 fvdl
101 1.1 fvdl int
102 1.1 fvdl linux_ipc(p, uap, retval)
103 1.1 fvdl struct proc *p;
104 1.1 fvdl struct linux_ipc_args /* {
105 1.1 fvdl syscallarg(int) what;
106 1.1 fvdl syscallarg(int) a1;
107 1.1 fvdl syscallarg(int) a2;
108 1.1 fvdl syscallarg(int) a3;
109 1.1 fvdl syscallarg(caddr_t) ptr;
110 1.1 fvdl } */ *uap;
111 1.1 fvdl register_t *retval;
112 1.1 fvdl {
113 1.1 fvdl int what, error;
114 1.1 fvdl
115 1.1 fvdl switch (SCARG(uap, what)) {
116 1.1 fvdl #ifdef SYSVSEM
117 1.1 fvdl case LINUX_SYS_semop:
118 1.1 fvdl return linux_semop(p, uap, retval);
119 1.1 fvdl case LINUX_SYS_semget:
120 1.1 fvdl return linux_semget(p, uap, retval);
121 1.1 fvdl case LINUX_SYS_semctl:
122 1.1 fvdl return linux_semctl(p, uap, retval);
123 1.1 fvdl #endif
124 1.1 fvdl #ifdef SYSVMSG
125 1.1 fvdl case LINUX_SYS_msgsnd:
126 1.1 fvdl return linux_msgsnd(p, uap, retval);
127 1.1 fvdl case LINUX_SYS_msgrcv:
128 1.1 fvdl return linux_msgrcv(p, uap, retval);
129 1.1 fvdl case LINUX_SYS_msgget:
130 1.1 fvdl return linux_msgget(p, uap, retval);
131 1.1 fvdl case LINUX_SYS_msgctl:
132 1.1 fvdl return linux_msgctl(p, uap, retval);
133 1.1 fvdl #endif
134 1.1 fvdl #ifdef SYSVSHM
135 1.1 fvdl case LINUX_SYS_shmat:
136 1.1 fvdl return linux_shmat(p, uap, retval);
137 1.1 fvdl case LINUX_SYS_shmdt:
138 1.1 fvdl return linux_shmdt(p, uap, retval);
139 1.1 fvdl case LINUX_SYS_shmget:
140 1.1 fvdl return linux_shmget(p, uap, retval);
141 1.1 fvdl case LINUX_SYS_shmctl:
142 1.1 fvdl return linux_shmctl(p, uap, retval);
143 1.1 fvdl #endif
144 1.1 fvdl default:
145 1.1 fvdl return ENOSYS;
146 1.1 fvdl }
147 1.1 fvdl }
148 1.1 fvdl
149 1.1 fvdl /*
150 1.1 fvdl * Convert between Linux and NetBSD ipc_perm structures. Only the
151 1.1 fvdl * order of the fields is different.
152 1.1 fvdl */
153 1.1 fvdl static void
154 1.1 fvdl linux_to_bsd_ipc_perm(lpp, bpp)
155 1.1 fvdl struct linux_ipc_perm *lpp;
156 1.1 fvdl struct ipc_perm *bpp;
157 1.1 fvdl {
158 1.1 fvdl bpp->key = lpp->l_key;
159 1.1 fvdl bpp->uid = lpp->l_uid;
160 1.1 fvdl bpp->gid = lpp->l_gid;
161 1.1 fvdl bpp->cuid = lpp->l_cuid;
162 1.1 fvdl bpp->cgid = lpp->l_cgid;
163 1.1 fvdl bpp->mode = lpp->l_mode;
164 1.1 fvdl bpp->seq = lpp->l_seq;
165 1.1 fvdl }
166 1.1 fvdl
167 1.1 fvdl
168 1.1 fvdl static void
169 1.1 fvdl bsd_to_linux_ipc_perm(bpp, lpp)
170 1.1 fvdl struct ipc_perm *bpp;
171 1.1 fvdl struct linux_ipc_perm *lpp;
172 1.1 fvdl {
173 1.1 fvdl lpp->l_key = bpp->key;
174 1.1 fvdl lpp->l_uid = bpp->uid;
175 1.1 fvdl lpp->l_gid = bpp->gid;
176 1.1 fvdl lpp->l_cuid = bpp->cuid;
177 1.1 fvdl lpp->l_cgid = bpp->cgid;
178 1.1 fvdl lpp->l_mode = bpp->mode;
179 1.1 fvdl lpp->l_seq = bpp->seq;
180 1.1 fvdl }
181 1.1 fvdl
182 1.1 fvdl #ifdef SYSVSEM
183 1.1 fvdl /*
184 1.1 fvdl * Semaphore operations: not implemented yet.
185 1.1 fvdl */
186 1.1 fvdl int
187 1.1 fvdl linux_semop(p, uap, retval)
188 1.1 fvdl struct proc *p;
189 1.1 fvdl struct linux_ipc_args /* {
190 1.1 fvdl syscallarg(int) what;
191 1.1 fvdl syscallarg(int) a1;
192 1.1 fvdl syscallarg(int) a2;
193 1.1 fvdl syscallarg(int) a3;
194 1.1 fvdl syscallarg(caddr_t) ptr;
195 1.1 fvdl } */ *uap;
196 1.1 fvdl register_t *retval;
197 1.1 fvdl {
198 1.1 fvdl return ENOSYS;
199 1.1 fvdl }
200 1.1 fvdl
201 1.1 fvdl int
202 1.1 fvdl linux_semget(p, uap, retval)
203 1.1 fvdl struct proc *p;
204 1.1 fvdl struct linux_ipc_args /* {
205 1.1 fvdl syscallarg(int) what;
206 1.1 fvdl syscallarg(int) a1;
207 1.1 fvdl syscallarg(int) a2;
208 1.1 fvdl syscallarg(int) a3;
209 1.1 fvdl syscallarg(caddr_t) ptr;
210 1.1 fvdl } */ *uap;
211 1.1 fvdl register_t *retval;
212 1.1 fvdl {
213 1.1 fvdl return ENOSYS;
214 1.1 fvdl }
215 1.1 fvdl
216 1.1 fvdl int
217 1.1 fvdl linux_semctl(p, uap, retval)
218 1.1 fvdl struct proc *p;
219 1.1 fvdl struct linux_ipc_args /* {
220 1.1 fvdl syscallarg(int) what;
221 1.1 fvdl syscallarg(int) a1;
222 1.1 fvdl syscallarg(int) a2;
223 1.1 fvdl syscallarg(int) a3;
224 1.1 fvdl syscallarg(caddr_t) ptr;
225 1.1 fvdl } */ *uap;
226 1.1 fvdl register_t *retval;
227 1.1 fvdl {
228 1.1 fvdl return ENOSYS;
229 1.1 fvdl }
230 1.1 fvdl #endif /* SYSVSEM */
231 1.1 fvdl
232 1.1 fvdl #ifdef SYSVMSG
233 1.1 fvdl /*
234 1.1 fvdl * Msg functions: not implemented yet.
235 1.1 fvdl */
236 1.1 fvdl int
237 1.1 fvdl linux_msgsnd(p, uap, retval)
238 1.1 fvdl struct proc *p;
239 1.1 fvdl struct linux_ipc_args /* {
240 1.1 fvdl syscallarg(int) what;
241 1.1 fvdl syscallarg(int) a1;
242 1.1 fvdl syscallarg(int) a2;
243 1.1 fvdl syscallarg(int) a3;
244 1.1 fvdl syscallarg(caddr_t) ptr;
245 1.1 fvdl } */ *uap;
246 1.1 fvdl register_t *retval;
247 1.1 fvdl {
248 1.1 fvdl return ENOSYS;
249 1.1 fvdl }
250 1.1 fvdl
251 1.1 fvdl int
252 1.1 fvdl linux_msgrcv(p, uap, retval)
253 1.1 fvdl struct proc *p;
254 1.1 fvdl struct linux_ipc_args /* {
255 1.1 fvdl syscallarg(int) what;
256 1.1 fvdl syscallarg(int) a1;
257 1.1 fvdl syscallarg(int) a2;
258 1.1 fvdl syscallarg(int) a3;
259 1.1 fvdl syscallarg(caddr_t) ptr;
260 1.1 fvdl } */ *uap;
261 1.1 fvdl register_t *retval;
262 1.1 fvdl {
263 1.1 fvdl return ENOSYS;
264 1.1 fvdl }
265 1.1 fvdl
266 1.1 fvdl int
267 1.1 fvdl linux_msgget(p, uap, retval)
268 1.1 fvdl struct proc *p;
269 1.1 fvdl struct linux_ipc_args /* {
270 1.1 fvdl syscallarg(int) what;
271 1.1 fvdl syscallarg(int) a1;
272 1.1 fvdl syscallarg(int) a2;
273 1.1 fvdl syscallarg(int) a3;
274 1.1 fvdl syscallarg(caddr_t) ptr;
275 1.1 fvdl } */ *uap;
276 1.1 fvdl register_t *retval;
277 1.1 fvdl {
278 1.1 fvdl return ENOSYS;
279 1.1 fvdl }
280 1.1 fvdl
281 1.1 fvdl int
282 1.1 fvdl linux_msgctl(p, uap, retval)
283 1.1 fvdl struct proc *p;
284 1.1 fvdl struct linux_ipc_args /* {
285 1.1 fvdl syscallarg(int) what;
286 1.1 fvdl syscallarg(int) a1;
287 1.1 fvdl syscallarg(int) a2;
288 1.1 fvdl syscallarg(int) a3;
289 1.1 fvdl syscallarg(caddr_t) ptr;
290 1.1 fvdl } */ *uap;
291 1.1 fvdl register_t *retval;
292 1.1 fvdl {
293 1.1 fvdl return ENOSYS;
294 1.1 fvdl }
295 1.1 fvdl #endif /* SYSVMSG */
296 1.1 fvdl
297 1.1 fvdl #ifdef SYSVSHM
298 1.1 fvdl /*
299 1.1 fvdl * shmat(2). Very straightforward, except that Linux passes a pointer
300 1.1 fvdl * in which the return value is to be passed. This is subsequently
301 1.1 fvdl * handled by libc, apparently.
302 1.1 fvdl */
303 1.1 fvdl int
304 1.1 fvdl linux_shmat(p, uap, retval)
305 1.1 fvdl struct proc *p;
306 1.1 fvdl struct linux_ipc_args /* {
307 1.1 fvdl syscallarg(int) what;
308 1.1 fvdl syscallarg(int) a1;
309 1.1 fvdl syscallarg(int) a2;
310 1.1 fvdl syscallarg(int) a3;
311 1.1 fvdl syscallarg(caddr_t) ptr;
312 1.1 fvdl } */ *uap;
313 1.1 fvdl register_t *retval;
314 1.1 fvdl {
315 1.1 fvdl struct shmat_args bsa;
316 1.1 fvdl int error;
317 1.1 fvdl
318 1.1 fvdl SCARG(&bsa, shmid) = SCARG(uap, a1);
319 1.1 fvdl SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
320 1.1 fvdl SCARG(&bsa, shmflg) = SCARG(uap, a2);
321 1.1 fvdl
322 1.1 fvdl if ((error = shmat(p, &bsa, retval)))
323 1.1 fvdl return error;
324 1.1 fvdl
325 1.1 fvdl if ((error = copyout(&retval[0], (caddr_t) SCARG(uap, a3),
326 1.1 fvdl sizeof retval[0])))
327 1.1 fvdl return error;
328 1.1 fvdl
329 1.1 fvdl retval[0] = 0;
330 1.1 fvdl
331 1.1 fvdl return 0;
332 1.1 fvdl }
333 1.1 fvdl
334 1.1 fvdl /*
335 1.1 fvdl * shmdt(): this could have been mapped directly, if it wasn't for
336 1.1 fvdl * the extra indirection by the linux_ipc system call.
337 1.1 fvdl */
338 1.1 fvdl int
339 1.1 fvdl linux_shmdt(p, uap, retval)
340 1.1 fvdl struct proc *p;
341 1.1 fvdl struct linux_ipc_args /* {
342 1.1 fvdl syscallarg(int) what;
343 1.1 fvdl syscallarg(int) a1;
344 1.1 fvdl syscallarg(int) a2;
345 1.1 fvdl syscallarg(int) a3;
346 1.1 fvdl syscallarg(caddr_t) ptr;
347 1.1 fvdl } */ *uap;
348 1.1 fvdl register_t *retval;
349 1.1 fvdl {
350 1.1 fvdl struct shmdt_args bsa;
351 1.1 fvdl
352 1.1 fvdl SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
353 1.1 fvdl return shmdt(p, &bsa, retval);
354 1.1 fvdl }
355 1.1 fvdl
356 1.1 fvdl /*
357 1.1 fvdl * Same story as shmdt.
358 1.1 fvdl */
359 1.1 fvdl int
360 1.1 fvdl linux_shmget(p, uap, retval)
361 1.1 fvdl struct proc *p;
362 1.1 fvdl struct linux_ipc_args /* {
363 1.1 fvdl syscallarg(int) what;
364 1.1 fvdl syscallarg(int) a1;
365 1.1 fvdl syscallarg(int) a2;
366 1.1 fvdl syscallarg(int) a3;
367 1.1 fvdl syscallarg(caddr_t) ptr;
368 1.1 fvdl } */ *uap;
369 1.1 fvdl register_t *retval;
370 1.1 fvdl {
371 1.1 fvdl struct shmget_args bsa;
372 1.1 fvdl
373 1.1 fvdl SCARG(&bsa, key) = SCARG(uap, a1);
374 1.1 fvdl SCARG(&bsa, size) = SCARG(uap, a2);
375 1.1 fvdl SCARG(&bsa, shmflg) = SCARG(uap, a3);
376 1.1 fvdl return shmget(p, &bsa, retval);
377 1.1 fvdl }
378 1.1 fvdl
379 1.1 fvdl /*
380 1.1 fvdl * Convert between Linux and NetBSD shmid_ds structures.
381 1.1 fvdl * The order of the fields is once again the difference, and
382 1.1 fvdl * we also need a place to store the internal data pointer
383 1.1 fvdl * in, which is unfortunately stored in this structure.
384 1.1 fvdl *
385 1.1 fvdl * We abuse a Linux internal field for that.
386 1.1 fvdl */
387 1.1 fvdl static void
388 1.1 fvdl linux_to_bsd_shmid_ds(lsp, bsp)
389 1.1 fvdl struct linux_shmid_ds *lsp;
390 1.1 fvdl struct shmid_ds *bsp;
391 1.1 fvdl {
392 1.1 fvdl linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
393 1.1 fvdl bsp->shm_segsz = lsp->l_shm_segsz;
394 1.1 fvdl bsp->shm_lpid = lsp->l_shm_lpid;
395 1.1 fvdl bsp->shm_cpid = lsp->l_shm_cpid;
396 1.1 fvdl bsp->shm_nattch = lsp->l_shm_nattch;
397 1.1 fvdl bsp->shm_atime = lsp->l_shm_atime;
398 1.1 fvdl bsp->shm_dtime = lsp->l_shm_dtime;
399 1.1 fvdl bsp->shm_ctime = lsp->l_shm_ctime;
400 1.1 fvdl bsp->shm_internal = lsp->l_private2; /* XXX Oh well. */
401 1.1 fvdl }
402 1.1 fvdl
403 1.1 fvdl static void
404 1.1 fvdl bsd_to_linux_shmid_ds(bsp, lsp)
405 1.1 fvdl struct shmid_ds *bsp;
406 1.1 fvdl struct linux_shmid_ds *lsp;
407 1.1 fvdl {
408 1.1 fvdl bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
409 1.1 fvdl lsp->l_shm_segsz = bsp->shm_segsz;
410 1.1 fvdl lsp->l_shm_lpid = bsp->shm_lpid;
411 1.1 fvdl lsp->l_shm_cpid = bsp->shm_cpid;
412 1.1 fvdl lsp->l_shm_nattch = bsp->shm_nattch;
413 1.1 fvdl lsp->l_shm_atime = bsp->shm_atime;
414 1.1 fvdl lsp->l_shm_dtime = bsp->shm_dtime;
415 1.1 fvdl lsp->l_shm_ctime = bsp->shm_ctime;
416 1.1 fvdl lsp->l_private2 = bsp->shm_internal; /* XXX */
417 1.1 fvdl }
418 1.1 fvdl
419 1.1 fvdl /*
420 1.1 fvdl * shmctl. Not implemented (for now): IPC_INFO, SHM_INFO, SHM_STAT
421 1.1 fvdl * SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
422 1.1 fvdl * by NetBSD itself.
423 1.1 fvdl *
424 1.1 fvdl * The usual structure conversion and massaging is done.
425 1.1 fvdl */
426 1.1 fvdl int
427 1.1 fvdl linux_shmctl(p, uap, retval)
428 1.1 fvdl struct proc *p;
429 1.1 fvdl struct linux_ipc_args /* {
430 1.1 fvdl syscallarg(int) what;
431 1.1 fvdl syscallarg(int) a1;
432 1.1 fvdl syscallarg(int) a2;
433 1.1 fvdl syscallarg(int) a3;
434 1.1 fvdl syscallarg(caddr_t) ptr;
435 1.1 fvdl } */ *uap;
436 1.1 fvdl register_t *retval;
437 1.1 fvdl {
438 1.1 fvdl int error;
439 1.1 fvdl caddr_t sg;
440 1.1 fvdl struct shmctl_args bsa;
441 1.1 fvdl struct shmid_ds *bsp, bs;
442 1.1 fvdl struct linux_shmid_ds lseg;
443 1.1 fvdl
444 1.1 fvdl switch (SCARG(uap, a2)) {
445 1.1 fvdl case LINUX_IPC_STAT:
446 1.4 christos sg = stackgap_init(p->p_emul);
447 1.1 fvdl bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
448 1.1 fvdl SCARG(&bsa, shmid) = SCARG(uap, a1);
449 1.1 fvdl SCARG(&bsa, cmd) = IPC_STAT;
450 1.1 fvdl SCARG(&bsa, buf) = bsp;
451 1.1 fvdl if ((error = shmctl(p, &bsa, retval)))
452 1.1 fvdl return error;
453 1.1 fvdl if ((error = copyin((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
454 1.1 fvdl return error;
455 1.1 fvdl bsd_to_linux_shmid_ds(&bs, &lseg);
456 1.1 fvdl return copyout((caddr_t) &lseg, SCARG(uap, ptr), sizeof lseg);
457 1.1 fvdl case LINUX_IPC_SET:
458 1.1 fvdl if ((error = copyin(SCARG(uap, ptr), (caddr_t) &lseg,
459 1.1 fvdl sizeof lseg)))
460 1.1 fvdl return error;
461 1.1 fvdl linux_to_bsd_shmid_ds(&lseg, &bs);
462 1.4 christos sg = stackgap_init(p->p_emul);
463 1.1 fvdl bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
464 1.1 fvdl if ((error = copyout((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
465 1.1 fvdl return error;
466 1.1 fvdl SCARG(&bsa, shmid) = SCARG(uap, a1);
467 1.1 fvdl SCARG(&bsa, cmd) = IPC_SET;
468 1.1 fvdl SCARG(&bsa, buf) = bsp;
469 1.1 fvdl return shmctl(p, &bsa, retval);
470 1.1 fvdl case LINUX_IPC_RMID:
471 1.1 fvdl case LINUX_SHM_LOCK:
472 1.1 fvdl case LINUX_SHM_UNLOCK:
473 1.1 fvdl SCARG(&bsa, shmid) = SCARG(uap, a1);
474 1.1 fvdl switch (SCARG(uap, a2)) {
475 1.1 fvdl case LINUX_IPC_RMID:
476 1.1 fvdl SCARG(&bsa, cmd) = IPC_RMID;
477 1.1 fvdl break;
478 1.1 fvdl case LINUX_SHM_LOCK:
479 1.1 fvdl SCARG(&bsa, cmd) = SHM_LOCK;
480 1.1 fvdl break;
481 1.1 fvdl case LINUX_SHM_UNLOCK:
482 1.1 fvdl SCARG(&bsa, cmd) = SHM_UNLOCK;
483 1.1 fvdl break;
484 1.1 fvdl }
485 1.2 fvdl if ((error = copyin(SCARG(uap, ptr), (caddr_t) &lseg,
486 1.2 fvdl sizeof lseg)))
487 1.2 fvdl return error;
488 1.2 fvdl linux_to_bsd_shmid_ds(&lseg, &bs);
489 1.4 christos sg = stackgap_init(p->p_emul);
490 1.2 fvdl bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
491 1.2 fvdl if ((error = copyout((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
492 1.2 fvdl return error;
493 1.2 fvdl SCARG(&bsa, buf) = bsp;
494 1.1 fvdl return shmctl(p, &bsa, retval);
495 1.1 fvdl case LINUX_IPC_INFO:
496 1.1 fvdl case LINUX_SHM_STAT:
497 1.1 fvdl case LINUX_SHM_INFO:
498 1.1 fvdl default:
499 1.1 fvdl return EINVAL;
500 1.1 fvdl }
501 1.1 fvdl }
502 1.1 fvdl #endif /* SYSVSHM */
503