linux32_ipccall.c revision 1.4 1 1.4 njoly /* $NetBSD: linux32_ipccall.c,v 1.4 2009/04/27 13:24:18 njoly Exp $ */
2 1.1 njoly
3 1.1 njoly /*
4 1.1 njoly * Copyright (c) 2008 Nicolas Joly
5 1.1 njoly * All rights reserved.
6 1.1 njoly *
7 1.1 njoly * Redistribution and use in source and binary forms, with or without
8 1.1 njoly * modification, are permitted provided that the following conditions
9 1.1 njoly * are met:
10 1.1 njoly * 1. Redistributions of source code must retain the above copyright
11 1.1 njoly * notice, this list of conditions and the following disclaimer.
12 1.1 njoly * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 njoly * notice, this list of conditions and the following disclaimer in the
14 1.1 njoly * documentation and/or other materials provided with the distribution.
15 1.1 njoly *
16 1.1 njoly * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
17 1.1 njoly * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 njoly * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 njoly * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 njoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 njoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 njoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 njoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 njoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 njoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 njoly * POSSIBILITY OF SUCH DAMAGE.
27 1.1 njoly */
28 1.1 njoly
29 1.1 njoly #include <sys/cdefs.h>
30 1.4 njoly __KERNEL_RCSID(0, "$NetBSD: linux32_ipccall.c,v 1.4 2009/04/27 13:24:18 njoly Exp $");
31 1.1 njoly
32 1.1 njoly #if defined(_KERNEL_OPT)
33 1.1 njoly #include "opt_sysv.h"
34 1.1 njoly #endif
35 1.1 njoly
36 1.1 njoly #include <sys/param.h>
37 1.1 njoly #include <sys/vnode.h>
38 1.1 njoly #include <sys/sem.h>
39 1.1 njoly #include <sys/shm.h>
40 1.1 njoly
41 1.1 njoly #include <sys/syscallargs.h>
42 1.1 njoly
43 1.1 njoly #include <compat/netbsd32/netbsd32.h>
44 1.1 njoly
45 1.1 njoly #include <compat/linux32/common/linux32_types.h>
46 1.1 njoly #include <compat/linux32/common/linux32_signal.h>
47 1.1 njoly #include <compat/linux32/linux32_syscallargs.h>
48 1.1 njoly #include <compat/linux32/common/linux32_ipc.h>
49 1.1 njoly #include <compat/linux32/common/linux32_sem.h>
50 1.1 njoly #include <compat/linux32/common/linux32_shm.h>
51 1.1 njoly
52 1.1 njoly #define LINUX32_IPC_semop 1
53 1.1 njoly #define LINUX32_IPC_semget 2
54 1.1 njoly #define LINUX32_IPC_semctl 3
55 1.1 njoly #define LINUX32_IPC_msgsnd 11
56 1.1 njoly #define LINUX32_IPC_msgrcv 12
57 1.1 njoly #define LINUX32_IPC_msgget 13
58 1.1 njoly #define LINUX32_IPC_msgctl 14
59 1.1 njoly #define LINUX32_IPC_shmat 21
60 1.1 njoly #define LINUX32_IPC_shmdt 22
61 1.1 njoly #define LINUX32_IPC_shmget 23
62 1.1 njoly #define LINUX32_IPC_shmctl 24
63 1.1 njoly
64 1.1 njoly #ifdef SYSVSEM
65 1.1 njoly static void
66 1.1 njoly bsd_to_linux32_semid_ds(struct semid_ds *, struct linux32_semid_ds *);
67 1.1 njoly static void
68 1.1 njoly bsd_to_linux32_semid64_ds(struct semid_ds *, struct linux32_semid64_ds *);
69 1.1 njoly static void
70 1.1 njoly linux32_to_bsd_semid_ds(struct linux32_semid_ds *, struct semid_ds *);
71 1.1 njoly static void
72 1.1 njoly linux32_to_bsd_semid64_ds(struct linux32_semid64_ds *, struct semid_ds *);
73 1.1 njoly
74 1.1 njoly static int
75 1.1 njoly linux32_semop(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
76 1.1 njoly static int
77 1.1 njoly linux32_semget(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
78 1.1 njoly static int
79 1.1 njoly linux32_semctl(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
80 1.1 njoly #endif /* SYSVSEM */
81 1.1 njoly
82 1.1 njoly #ifdef SYSVSHM
83 1.1 njoly static void
84 1.1 njoly bsd_to_linux32_shmid_ds(struct shmid_ds *, struct linux32_shmid_ds *);
85 1.1 njoly static void
86 1.1 njoly linux32_to_bsd_shmid_ds(struct linux32_shmid_ds *, struct shmid_ds *);
87 1.1 njoly static void
88 1.1 njoly bsd_to_linux32_shmid64_ds(struct shmid_ds *, struct linux32_shmid64_ds *);
89 1.1 njoly static void
90 1.1 njoly linux32_to_bsd_shmid64_ds(struct linux32_shmid64_ds *, struct shmid_ds *);
91 1.1 njoly
92 1.1 njoly static int
93 1.1 njoly linux32_shmat(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
94 1.1 njoly static int
95 1.1 njoly linux32_shmdt(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
96 1.1 njoly static int
97 1.1 njoly linux32_shmget(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
98 1.1 njoly static int
99 1.1 njoly linux32_shmctl(struct lwp *, const struct linux32_sys_ipc_args *, register_t *);
100 1.1 njoly #endif /* SYSVSHM */
101 1.1 njoly
102 1.1 njoly int
103 1.1 njoly linux32_sys_ipc(struct lwp *l, const struct linux32_sys_ipc_args *uap,
104 1.1 njoly register_t *retval)
105 1.1 njoly {
106 1.1 njoly /* {
107 1.1 njoly syscallarg(int) what;
108 1.1 njoly syscallarg(int) a1;
109 1.1 njoly syscallarg(int) a2;
110 1.1 njoly syscallarg(int) a3;
111 1.1 njoly syscallarg(netbsd32_voidp) ptr;
112 1.1 njoly } */
113 1.1 njoly
114 1.1 njoly switch (SCARG(uap, what)) {
115 1.1 njoly #ifdef SYSVSEM
116 1.1 njoly case LINUX32_IPC_semop:
117 1.1 njoly return linux32_semop(l, uap, retval);;
118 1.1 njoly case LINUX32_IPC_semget:
119 1.1 njoly return linux32_semget(l, uap, retval);
120 1.1 njoly case LINUX32_IPC_semctl:
121 1.1 njoly return linux32_semctl(l, uap, retval);
122 1.1 njoly #endif /* SYSVSEM */
123 1.1 njoly #ifdef SYSVSHM
124 1.1 njoly case LINUX32_IPC_shmat:
125 1.1 njoly return linux32_shmat(l, uap, retval);
126 1.1 njoly case LINUX32_IPC_shmdt:
127 1.1 njoly return linux32_shmdt(l, uap, retval);
128 1.1 njoly case LINUX32_IPC_shmget:
129 1.1 njoly return linux32_shmget(l, uap, retval);
130 1.1 njoly case LINUX32_IPC_shmctl:
131 1.1 njoly return linux32_shmctl(l, uap, retval);
132 1.1 njoly #endif /* SYSVSHM */
133 1.1 njoly default:
134 1.1 njoly return ENOSYS;
135 1.1 njoly }
136 1.1 njoly
137 1.1 njoly }
138 1.1 njoly
139 1.1 njoly static void
140 1.1 njoly bsd_to_linux32_ipc_perm(struct ipc_perm *bpp, struct linux32_ipc_perm *lpp)
141 1.1 njoly {
142 1.1 njoly lpp->l_key = bpp->_key;
143 1.1 njoly lpp->l_uid = bpp->uid;
144 1.1 njoly lpp->l_gid = bpp->gid;
145 1.1 njoly lpp->l_cuid = bpp->cuid;
146 1.1 njoly lpp->l_cgid = bpp->cgid;
147 1.1 njoly lpp->l_mode = bpp->mode;
148 1.1 njoly lpp->l_seq = bpp->_seq;
149 1.1 njoly }
150 1.1 njoly
151 1.1 njoly static void
152 1.1 njoly linux32_to_bsd_ipc_perm(struct linux32_ipc_perm *lpp, struct ipc_perm *bpp)
153 1.1 njoly {
154 1.1 njoly bpp->_key = lpp->l_key;
155 1.1 njoly bpp->uid = lpp->l_uid;
156 1.1 njoly bpp->gid = lpp->l_gid;
157 1.1 njoly bpp->cuid = lpp->l_cuid;
158 1.1 njoly bpp->cgid = lpp->l_cgid;
159 1.1 njoly bpp->mode = lpp->l_mode;
160 1.1 njoly bpp->_seq = lpp->l_seq;
161 1.1 njoly }
162 1.1 njoly
163 1.1 njoly static void
164 1.1 njoly bsd_to_linux32_ipc64_perm(struct ipc_perm *bpp, struct linux32_ipc64_perm *lpp)
165 1.1 njoly {
166 1.1 njoly lpp->l_key = bpp->_key;
167 1.1 njoly lpp->l_uid = bpp->uid;
168 1.1 njoly lpp->l_gid = bpp->gid;
169 1.1 njoly lpp->l_cuid = bpp->cuid;
170 1.1 njoly lpp->l_cgid = bpp->cgid;
171 1.1 njoly lpp->l_mode = bpp->mode;
172 1.1 njoly lpp->l_seq = bpp->_seq;
173 1.1 njoly }
174 1.1 njoly
175 1.1 njoly static void
176 1.1 njoly linux32_to_bsd_ipc64_perm(struct linux32_ipc64_perm *lpp, struct ipc_perm *bpp)
177 1.1 njoly {
178 1.1 njoly bpp->_key = lpp->l_key;
179 1.1 njoly bpp->uid = lpp->l_uid;
180 1.1 njoly bpp->gid = lpp->l_gid;
181 1.1 njoly bpp->cuid = lpp->l_cuid;
182 1.1 njoly bpp->cgid = lpp->l_cgid;
183 1.1 njoly bpp->mode = lpp->l_mode;
184 1.1 njoly bpp->_seq = lpp->l_seq;
185 1.1 njoly }
186 1.1 njoly
187 1.1 njoly #ifdef SYSVSEM
188 1.1 njoly static void
189 1.1 njoly bsd_to_linux32_semid_ds(struct semid_ds *bsp, struct linux32_semid_ds *lsp)
190 1.1 njoly {
191 1.1 njoly bsd_to_linux32_ipc_perm(&bsp->sem_perm, &lsp->l_sem_perm);
192 1.1 njoly lsp->l_sem_otime = bsp->sem_otime;
193 1.1 njoly lsp->l_sem_ctime = bsp->sem_ctime;
194 1.1 njoly lsp->l_sem_nsems = bsp->sem_nsems;
195 1.1 njoly NETBSD32PTR32(lsp->l_sem_base, bsp->_sem_base);
196 1.1 njoly }
197 1.1 njoly
198 1.1 njoly static void
199 1.1 njoly bsd_to_linux32_semid64_ds(struct semid_ds *bsp, struct linux32_semid64_ds *lsp)
200 1.1 njoly {
201 1.1 njoly bsd_to_linux32_ipc64_perm(&bsp->sem_perm, &lsp->l_sem_perm);
202 1.1 njoly lsp->l_sem_otime = bsp->sem_otime;
203 1.1 njoly lsp->l_sem_ctime = bsp->sem_ctime;
204 1.1 njoly lsp->l_sem_nsems = bsp->sem_nsems;
205 1.1 njoly }
206 1.1 njoly
207 1.1 njoly static void
208 1.1 njoly linux32_to_bsd_semid_ds(struct linux32_semid_ds *lsp, struct semid_ds *bsp)
209 1.1 njoly {
210 1.1 njoly linux32_to_bsd_ipc_perm(&lsp->l_sem_perm, &bsp->sem_perm);
211 1.1 njoly bsp->sem_otime = lsp->l_sem_otime;
212 1.1 njoly bsp->sem_ctime = lsp->l_sem_ctime;
213 1.1 njoly bsp->sem_nsems = lsp->l_sem_nsems;
214 1.1 njoly bsp->_sem_base = NETBSD32PTR64(lsp->l_sem_base);
215 1.1 njoly }
216 1.1 njoly
217 1.1 njoly static void
218 1.1 njoly linux32_to_bsd_semid64_ds(struct linux32_semid64_ds *lsp, struct semid_ds *bsp)
219 1.1 njoly {
220 1.1 njoly linux32_to_bsd_ipc64_perm(&lsp->l_sem_perm, &bsp->sem_perm);
221 1.1 njoly bsp->sem_otime = lsp->l_sem_otime;
222 1.1 njoly bsp->sem_ctime = lsp->l_sem_ctime;
223 1.1 njoly bsp->sem_nsems = lsp->l_sem_nsems;
224 1.1 njoly }
225 1.1 njoly
226 1.1 njoly static int
227 1.1 njoly linux32_semop(struct lwp *l, const struct linux32_sys_ipc_args *uap,
228 1.1 njoly register_t *retval)
229 1.1 njoly {
230 1.1 njoly struct sys_semop_args ua;
231 1.1 njoly
232 1.1 njoly SCARG(&ua, semid) = SCARG(uap, a1);
233 1.1 njoly SCARG(&ua, sops) = SCARG_P32(uap, ptr);
234 1.1 njoly SCARG(&ua, nsops) = SCARG(uap, a2);
235 1.1 njoly
236 1.1 njoly return sys_semop(l, &ua, retval);
237 1.1 njoly }
238 1.1 njoly
239 1.1 njoly static int
240 1.1 njoly linux32_semget(struct lwp *l, const struct linux32_sys_ipc_args *uap,
241 1.1 njoly register_t *retval)
242 1.1 njoly {
243 1.1 njoly struct sys_semget_args ua;
244 1.1 njoly
245 1.1 njoly SCARG(&ua, key) = SCARG(uap, a1);
246 1.1 njoly SCARG(&ua, nsems) = SCARG(uap, a2);
247 1.1 njoly SCARG(&ua, semflg) = SCARG(uap, a3);
248 1.1 njoly
249 1.1 njoly return sys_semget(l, &ua, retval);
250 1.1 njoly }
251 1.1 njoly
252 1.1 njoly static int
253 1.1 njoly linux32_semctl(struct lwp *l, const struct linux32_sys_ipc_args *uap,
254 1.1 njoly register_t *retval)
255 1.1 njoly {
256 1.4 njoly int lcmd, cmd, error;
257 1.1 njoly struct semid_ds bs;
258 1.1 njoly struct linux32_semid_ds ls;
259 1.1 njoly struct linux32_semid64_ds ls64;
260 1.1 njoly union linux32_semun lsem;
261 1.1 njoly union __semun bsem;
262 1.1 njoly void *buf = NULL;
263 1.1 njoly
264 1.1 njoly if ((error = copyin(SCARG_P32(uap, ptr), &lsem, sizeof lsem)))
265 1.1 njoly return error;
266 1.1 njoly
267 1.4 njoly lcmd = SCARG(uap, a3);
268 1.4 njoly
269 1.4 njoly switch (lcmd & ~LINUX32_IPC_64) {
270 1.1 njoly case LINUX32_IPC_RMID:
271 1.1 njoly cmd = IPC_RMID;
272 1.1 njoly break;
273 1.1 njoly case LINUX32_IPC_STAT:
274 1.1 njoly cmd = IPC_STAT;
275 1.1 njoly buf = &bs;
276 1.1 njoly break;
277 1.1 njoly case LINUX32_IPC_SET:
278 1.4 njoly if (lcmd & LINUX32_IPC_64) {
279 1.4 njoly error = copyin(NETBSD32PTR64(lsem.l_buf), &ls64,
280 1.4 njoly sizeof ls64);
281 1.4 njoly linux32_to_bsd_semid64_ds(&ls64, &bs);
282 1.4 njoly } else {
283 1.4 njoly error = copyin(NETBSD32PTR64(lsem.l_buf), &ls,
284 1.4 njoly sizeof ls);
285 1.4 njoly linux32_to_bsd_semid_ds(&ls, &bs);
286 1.4 njoly }
287 1.1 njoly if (error)
288 1.1 njoly return error;
289 1.1 njoly cmd = IPC_SET;
290 1.1 njoly buf = &bs;
291 1.1 njoly break;
292 1.1 njoly case LINUX32_GETVAL:
293 1.1 njoly cmd = GETVAL;
294 1.1 njoly break;
295 1.1 njoly case LINUX32_SETVAL:
296 1.1 njoly cmd = SETVAL;
297 1.1 njoly bsem.val = lsem.l_val;
298 1.1 njoly buf = &bsem;
299 1.1 njoly break;
300 1.1 njoly case LINUX32_GETPID:
301 1.1 njoly cmd = GETPID;
302 1.1 njoly break;
303 1.1 njoly case LINUX32_GETNCNT:
304 1.1 njoly cmd = GETNCNT;
305 1.1 njoly break;
306 1.1 njoly case LINUX32_GETZCNT:
307 1.1 njoly cmd = GETZCNT;
308 1.1 njoly break;
309 1.1 njoly case LINUX32_GETALL:
310 1.1 njoly cmd = GETALL;
311 1.1 njoly bsem.array = NETBSD32PTR64(lsem.l_array);
312 1.1 njoly buf = &bsem;
313 1.1 njoly break;
314 1.1 njoly case LINUX32_SETALL:
315 1.1 njoly cmd = SETALL;
316 1.1 njoly bsem.array = NETBSD32PTR64(lsem.l_array);
317 1.1 njoly buf = &bsem;
318 1.1 njoly break;
319 1.1 njoly default:
320 1.1 njoly return EINVAL;
321 1.1 njoly }
322 1.1 njoly
323 1.1 njoly error = semctl1(l, SCARG(uap, a1), SCARG(uap, a2), cmd, buf, retval);
324 1.1 njoly if (error)
325 1.1 njoly return error;
326 1.1 njoly
327 1.4 njoly switch (lcmd) {
328 1.1 njoly case LINUX32_IPC_STAT:
329 1.1 njoly bsd_to_linux32_semid_ds(&bs, &ls);
330 1.1 njoly error = copyout(&ls, NETBSD32PTR64(lsem.l_buf), sizeof ls);
331 1.1 njoly break;
332 1.1 njoly case LINUX32_IPC_STAT|LINUX32_IPC_64:
333 1.1 njoly bsd_to_linux32_semid64_ds(&bs, &ls64);
334 1.1 njoly error = copyout(&ls64, NETBSD32PTR64(lsem.l_buf), sizeof ls64);
335 1.1 njoly break;
336 1.1 njoly default:
337 1.1 njoly break;
338 1.1 njoly }
339 1.1 njoly
340 1.1 njoly return error;
341 1.1 njoly }
342 1.1 njoly #endif /* SYSVSEM */
343 1.1 njoly
344 1.1 njoly #ifdef SYSVSHM
345 1.1 njoly static void
346 1.1 njoly bsd_to_linux32_shmid_ds(struct shmid_ds *bsp, struct linux32_shmid_ds *lsp)
347 1.1 njoly {
348 1.1 njoly bsd_to_linux32_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
349 1.1 njoly lsp->l_shm_segsz = bsp->shm_segsz;
350 1.1 njoly lsp->l_shm_atime = bsp->shm_atime;
351 1.1 njoly lsp->l_shm_dtime = bsp->shm_dtime;
352 1.1 njoly lsp->l_shm_ctime = bsp->shm_ctime;
353 1.1 njoly lsp->l_shm_cpid = bsp->shm_cpid;
354 1.1 njoly lsp->l_shm_lpid = bsp->shm_lpid;
355 1.1 njoly lsp->l_shm_nattch = bsp->shm_nattch;
356 1.1 njoly NETBSD32PTR32(lsp->l_private2, bsp->_shm_internal);
357 1.1 njoly }
358 1.1 njoly
359 1.1 njoly static void
360 1.1 njoly linux32_to_bsd_shmid_ds(struct linux32_shmid_ds *lsp, struct shmid_ds *bsp)
361 1.1 njoly {
362 1.1 njoly linux32_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
363 1.1 njoly bsp->shm_segsz = lsp->l_shm_segsz;
364 1.1 njoly bsp->shm_atime = lsp->l_shm_atime;
365 1.1 njoly bsp->shm_dtime = lsp->l_shm_dtime;
366 1.1 njoly bsp->shm_ctime = lsp->l_shm_ctime;
367 1.1 njoly bsp->shm_cpid = lsp->l_shm_cpid;
368 1.1 njoly bsp->shm_lpid = lsp->l_shm_lpid;
369 1.1 njoly bsp->shm_nattch = lsp->l_shm_nattch;
370 1.1 njoly bsp->_shm_internal = NETBSD32PTR64(lsp->l_private2);
371 1.1 njoly }
372 1.1 njoly
373 1.1 njoly static void
374 1.1 njoly bsd_to_linux32_shmid64_ds(struct shmid_ds *bsp, struct linux32_shmid64_ds *lsp)
375 1.1 njoly {
376 1.1 njoly bsd_to_linux32_ipc64_perm(&bsp->shm_perm, &lsp->l_shm_perm);
377 1.1 njoly lsp->l_shm_segsz = bsp->shm_segsz;
378 1.1 njoly lsp->l_shm_atime = bsp->shm_atime;
379 1.1 njoly lsp->l_shm_dtime = bsp->shm_dtime;
380 1.1 njoly lsp->l_shm_ctime = bsp->shm_ctime;
381 1.1 njoly lsp->l_shm_cpid = bsp->shm_cpid;
382 1.1 njoly lsp->l_shm_lpid = bsp->shm_lpid;
383 1.1 njoly lsp->l_shm_nattch = bsp->shm_nattch;
384 1.1 njoly lsp->l___unused5 = NETBSD32PTR32I(bsp->_shm_internal);
385 1.1 njoly }
386 1.1 njoly
387 1.1 njoly static void
388 1.1 njoly linux32_to_bsd_shmid64_ds(struct linux32_shmid64_ds *lsp, struct shmid_ds *bsp)
389 1.1 njoly {
390 1.1 njoly linux32_to_bsd_ipc64_perm(&lsp->l_shm_perm, &bsp->shm_perm);
391 1.1 njoly bsp->shm_segsz = lsp->l_shm_segsz;
392 1.1 njoly bsp->shm_atime = lsp->l_shm_atime;
393 1.1 njoly bsp->shm_dtime = lsp->l_shm_dtime;
394 1.1 njoly bsp->shm_ctime = lsp->l_shm_ctime;
395 1.1 njoly bsp->shm_cpid = lsp->l_shm_cpid;
396 1.1 njoly bsp->shm_lpid = lsp->l_shm_lpid;
397 1.1 njoly bsp->shm_nattch = lsp->l_shm_nattch;
398 1.1 njoly bsp->_shm_internal = NETBSD32IPTR64(lsp->l___unused5);
399 1.1 njoly }
400 1.1 njoly
401 1.1 njoly static int
402 1.1 njoly linux32_shmat(struct lwp *l, const struct linux32_sys_ipc_args *uap,
403 1.1 njoly register_t *retval)
404 1.1 njoly {
405 1.1 njoly struct sys_shmat_args ua;
406 1.2 scw netbsd32_pointer_t addr32;
407 1.1 njoly int error;
408 1.1 njoly
409 1.1 njoly SCARG(&ua, shmid) = SCARG(uap, a1);
410 1.1 njoly SCARG(&ua, shmaddr) = SCARG_P32(uap, ptr);
411 1.1 njoly SCARG(&ua, shmflg) = SCARG(uap, a2);
412 1.1 njoly
413 1.1 njoly if ((error = sys_shmat(l, &ua, retval)))
414 1.1 njoly return error;
415 1.1 njoly
416 1.2 scw NETBSD32PTR32(addr32, (const void *)(uintptr_t)retval[0]);
417 1.2 scw
418 1.2 scw error = copyout(&addr32, NETBSD32IPTR64(SCARG(uap, a3)), sizeof addr32);
419 1.2 scw if (error == 0)
420 1.2 scw retval[0] = 0;
421 1.1 njoly
422 1.2 scw return error;
423 1.1 njoly }
424 1.1 njoly
425 1.1 njoly static int
426 1.1 njoly linux32_shmdt(struct lwp *l, const struct linux32_sys_ipc_args *uap,
427 1.1 njoly register_t *retval)
428 1.1 njoly {
429 1.1 njoly struct sys_shmdt_args ua;
430 1.1 njoly
431 1.1 njoly SCARG(&ua, shmaddr) = SCARG_P32(uap, ptr);
432 1.1 njoly
433 1.1 njoly return sys_shmdt(l, &ua, retval);
434 1.1 njoly }
435 1.1 njoly
436 1.1 njoly static int
437 1.1 njoly linux32_shmget(struct lwp *l, const struct linux32_sys_ipc_args *uap,
438 1.1 njoly register_t *retval)
439 1.1 njoly {
440 1.1 njoly struct sys_shmget_args ua;
441 1.1 njoly
442 1.1 njoly SCARG(&ua, key) = SCARG(uap, a1);
443 1.1 njoly SCARG(&ua, size) = SCARG(uap, a2);
444 1.1 njoly SCARG(&ua, shmflg) = SCARG(uap, a3) | _SHM_RMLINGER;
445 1.1 njoly
446 1.1 njoly return sys_shmget(l, &ua, retval);
447 1.1 njoly }
448 1.1 njoly
449 1.1 njoly static int
450 1.1 njoly linux32_shmctl(struct lwp *l, const struct linux32_sys_ipc_args *uap,
451 1.1 njoly register_t *retval)
452 1.1 njoly {
453 1.1 njoly int shmid, cmd, error;
454 1.3 njoly struct shmid_ds bs;
455 1.1 njoly struct linux32_shmid_ds ls;
456 1.1 njoly struct linux32_shmid64_ds ls64;
457 1.1 njoly
458 1.1 njoly shmid = SCARG(uap, a1);
459 1.3 njoly cmd = SCARG(uap, a2);
460 1.3 njoly
461 1.3 njoly switch (cmd & ~LINUX32_IPC_64) {
462 1.1 njoly
463 1.1 njoly case LINUX32_SHM_STAT:
464 1.1 njoly return ENOSYS;
465 1.3 njoly
466 1.1 njoly case LINUX32_IPC_STAT:
467 1.3 njoly error = shmctl1(l, shmid, IPC_STAT, &bs);
468 1.3 njoly if (error != 0)
469 1.3 njoly return error;
470 1.3 njoly if (cmd & LINUX32_IPC_64) {
471 1.3 njoly bsd_to_linux32_shmid64_ds(&bs, &ls64);
472 1.3 njoly error = copyout(&ls64, SCARG_P32(uap, ptr), sizeof ls64);
473 1.3 njoly } else {
474 1.3 njoly bsd_to_linux32_shmid_ds(&bs, &ls);
475 1.3 njoly error = copyout(&ls, SCARG_P32(uap, ptr), sizeof ls);
476 1.3 njoly }
477 1.3 njoly return error;
478 1.3 njoly
479 1.1 njoly case LINUX32_IPC_SET:
480 1.3 njoly if (cmd & LINUX32_IPC_64) {
481 1.3 njoly error = copyin(SCARG_P32(uap, ptr), &ls64, sizeof ls64);
482 1.3 njoly linux32_to_bsd_shmid64_ds(&ls64, &bs);
483 1.3 njoly } else {
484 1.3 njoly error = copyin(SCARG_P32(uap, ptr), &ls, sizeof ls);
485 1.3 njoly linux32_to_bsd_shmid_ds(&ls, &bs);
486 1.3 njoly }
487 1.3 njoly if (error != 0)
488 1.1 njoly return error;
489 1.3 njoly return shmctl1(l, shmid, IPC_SET, &bs);
490 1.3 njoly
491 1.3 njoly case LINUX32_IPC_RMID:
492 1.3 njoly return shmctl1(l, shmid, IPC_RMID, NULL);
493 1.3 njoly
494 1.1 njoly case LINUX32_SHM_LOCK:
495 1.3 njoly return shmctl1(l, shmid, SHM_LOCK, NULL);
496 1.3 njoly
497 1.1 njoly case LINUX32_SHM_UNLOCK:
498 1.3 njoly return shmctl1(l, shmid, SHM_UNLOCK, NULL);
499 1.3 njoly
500 1.1 njoly case LINUX32_IPC_INFO:
501 1.1 njoly case LINUX32_SHM_INFO:
502 1.1 njoly return ENOSYS;
503 1.3 njoly
504 1.1 njoly default:
505 1.1 njoly return EINVAL;
506 1.1 njoly }
507 1.1 njoly }
508 1.1 njoly #endif /* SYSVSHM */
509