Mon Apr 27 13:24:18 2009 UTC ()
Add IPC_64 support to all semctl(2) commands, following corresponding
compat linux change.


(njoly)
diff -r1.3 -r1.4 src/sys/compat/linux32/common/linux32_ipccall.c

cvs diff -r1.3 -r1.4 src/sys/compat/linux32/common/linux32_ipccall.c (expand / switch to unified diff)

--- src/sys/compat/linux32/common/linux32_ipccall.c 2009/02/18 14:40:14 1.3
+++ src/sys/compat/linux32/common/linux32_ipccall.c 2009/04/27 13:24:18 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: linux32_ipccall.c,v 1.3 2009/02/18 14:40:14 njoly Exp $ */ 1/* $NetBSD: linux32_ipccall.c,v 1.4 2009/04/27 13:24:18 njoly Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 Nicolas Joly 4 * Copyright (c) 2008 Nicolas Joly
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: linux32_ipccall.c,v 1.3 2009/02/18 14:40:14 njoly Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: linux32_ipccall.c,v 1.4 2009/04/27 13:24:18 njoly Exp $");
31 31
32#if defined(_KERNEL_OPT) 32#if defined(_KERNEL_OPT)
33#include "opt_sysv.h" 33#include "opt_sysv.h"
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/vnode.h> 37#include <sys/vnode.h>
38#include <sys/sem.h> 38#include <sys/sem.h>
39#include <sys/shm.h> 39#include <sys/shm.h>
40 40
41#include <sys/syscallargs.h> 41#include <sys/syscallargs.h>
42 42
43#include <compat/netbsd32/netbsd32.h> 43#include <compat/netbsd32/netbsd32.h>
@@ -243,59 +243,59 @@ linux32_semget(struct lwp *l, const stru @@ -243,59 +243,59 @@ linux32_semget(struct lwp *l, const stru
243 struct sys_semget_args ua; 243 struct sys_semget_args ua;
244 244
245 SCARG(&ua, key) = SCARG(uap, a1); 245 SCARG(&ua, key) = SCARG(uap, a1);
246 SCARG(&ua, nsems) = SCARG(uap, a2); 246 SCARG(&ua, nsems) = SCARG(uap, a2);
247 SCARG(&ua, semflg) = SCARG(uap, a3); 247 SCARG(&ua, semflg) = SCARG(uap, a3);
248 248
249 return sys_semget(l, &ua, retval); 249 return sys_semget(l, &ua, retval);
250} 250}
251 251
252static int 252static int
253linux32_semctl(struct lwp *l, const struct linux32_sys_ipc_args *uap, 253linux32_semctl(struct lwp *l, const struct linux32_sys_ipc_args *uap,
254 register_t *retval) 254 register_t *retval)
255{ 255{
256 int cmd, error; 256 int lcmd, cmd, error;
257 struct semid_ds bs; 257 struct semid_ds bs;
258 struct linux32_semid_ds ls; 258 struct linux32_semid_ds ls;
259 struct linux32_semid64_ds ls64; 259 struct linux32_semid64_ds ls64;
260 union linux32_semun lsem; 260 union linux32_semun lsem;
261 union __semun bsem; 261 union __semun bsem;
262 void *buf = NULL; 262 void *buf = NULL;
263 263
264 if ((error = copyin(SCARG_P32(uap, ptr), &lsem, sizeof lsem))) 264 if ((error = copyin(SCARG_P32(uap, ptr), &lsem, sizeof lsem)))
265 return error; 265 return error;
266 266
267 switch (SCARG(uap, a3)) { 267 lcmd = SCARG(uap, a3);
 268
 269 switch (lcmd & ~LINUX32_IPC_64) {
268 case LINUX32_IPC_RMID: 270 case LINUX32_IPC_RMID:
269 cmd = IPC_RMID; 271 cmd = IPC_RMID;
270 break; 272 break;
271 case LINUX32_IPC_STAT: 273 case LINUX32_IPC_STAT:
272 case LINUX32_IPC_STAT|LINUX32_IPC_64: 
273 cmd = IPC_STAT; 274 cmd = IPC_STAT;
274 buf = &bs; 275 buf = &bs;
275 break; 276 break;
276 case LINUX32_IPC_SET: 277 case LINUX32_IPC_SET:
277 error = copyin(NETBSD32PTR64(lsem.l_buf), &ls, sizeof ls); 278 if (lcmd & LINUX32_IPC_64) {
278 if (error) 279 error = copyin(NETBSD32PTR64(lsem.l_buf), &ls64,
279 return error; 280 sizeof ls64);
280 linux32_to_bsd_semid_ds(&ls, &bs); 281 linux32_to_bsd_semid64_ds(&ls64, &bs);
281 cmd = IPC_SET; 282 } else {
282 buf = &bs; 283 error = copyin(NETBSD32PTR64(lsem.l_buf), &ls,
283 break; 284 sizeof ls);
284 case LINUX32_IPC_SET|LINUX32_IPC_64: 285 linux32_to_bsd_semid_ds(&ls, &bs);
285 error = copyin(NETBSD32PTR64(lsem.l_buf), &ls64, sizeof ls64); 286 }
286 if (error) 287 if (error)
287 return error; 288 return error;
288 linux32_to_bsd_semid64_ds(&ls64, &bs); 
289 cmd = IPC_SET; 289 cmd = IPC_SET;
290 buf = &bs; 290 buf = &bs;
291 break; 291 break;
292 case LINUX32_GETVAL: 292 case LINUX32_GETVAL:
293 cmd = GETVAL; 293 cmd = GETVAL;
294 break; 294 break;
295 case LINUX32_SETVAL: 295 case LINUX32_SETVAL:
296 cmd = SETVAL; 296 cmd = SETVAL;
297 bsem.val = lsem.l_val; 297 bsem.val = lsem.l_val;
298 buf = &bsem; 298 buf = &bsem;
299 break; 299 break;
300 case LINUX32_GETPID: 300 case LINUX32_GETPID:
301 cmd = GETPID; 301 cmd = GETPID;
@@ -314,27 +314,27 @@ linux32_semctl(struct lwp *l, const stru @@ -314,27 +314,27 @@ linux32_semctl(struct lwp *l, const stru
314 case LINUX32_SETALL: 314 case LINUX32_SETALL:
315 cmd = SETALL; 315 cmd = SETALL;
316 bsem.array = NETBSD32PTR64(lsem.l_array); 316 bsem.array = NETBSD32PTR64(lsem.l_array);
317 buf = &bsem; 317 buf = &bsem;
318 break; 318 break;
319 default: 319 default:
320 return EINVAL; 320 return EINVAL;
321 } 321 }
322 322
323 error = semctl1(l, SCARG(uap, a1), SCARG(uap, a2), cmd, buf, retval); 323 error = semctl1(l, SCARG(uap, a1), SCARG(uap, a2), cmd, buf, retval);
324 if (error) 324 if (error)
325 return error; 325 return error;
326 326
327 switch (SCARG(uap, a3)) { 327 switch (lcmd) {
328 case LINUX32_IPC_STAT: 328 case LINUX32_IPC_STAT:
329 bsd_to_linux32_semid_ds(&bs, &ls); 329 bsd_to_linux32_semid_ds(&bs, &ls);
330 error = copyout(&ls, NETBSD32PTR64(lsem.l_buf), sizeof ls); 330 error = copyout(&ls, NETBSD32PTR64(lsem.l_buf), sizeof ls);
331 break; 331 break;
332 case LINUX32_IPC_STAT|LINUX32_IPC_64: 332 case LINUX32_IPC_STAT|LINUX32_IPC_64:
333 bsd_to_linux32_semid64_ds(&bs, &ls64); 333 bsd_to_linux32_semid64_ds(&bs, &ls64);
334 error = copyout(&ls64, NETBSD32PTR64(lsem.l_buf), sizeof ls64); 334 error = copyout(&ls64, NETBSD32PTR64(lsem.l_buf), sizeof ls64);
335 break; 335 break;
336 default: 336 default:
337 break; 337 break;
338 } 338 }
339 339
340 return error; 340 return error;