1 /* $NetBSD: linux_ipc.c,v 1.53 2009/04/23 17:40:57 njoly Exp $ */ 2 3 /*- 4 * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Frank van der Linden and Eric Haszlakiewicz. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.53 2009/04/23 17:40:57 njoly Exp $"); 34 35 #if defined(_KERNEL_OPT) 36 #include "opt_sysv.h" 37 #endif 38 39 #include <sys/param.h> 40 #include <sys/shm.h> 41 #include <sys/sem.h> 42 #include <sys/msg.h> 43 #include <sys/proc.h> 44 #include <sys/systm.h> 45 #include <sys/vnode.h> 46 47 #include <sys/mount.h> 48 #include <sys/syscallargs.h> 49 50 #include <compat/linux/common/linux_types.h> 51 #include <compat/linux/common/linux_signal.h> 52 #include <compat/linux/common/linux_util.h> 53 #include <compat/linux/common/linux_ipc.h> 54 #include <compat/linux/common/linux_msg.h> 55 #include <compat/linux/common/linux_shm.h> 56 #include <compat/linux/common/linux_sem.h> 57 58 #include <compat/linux/linux_syscallargs.h> 59 #include <compat/linux/linux_syscall.h> 60 61 #include <compat/linux/common/linux_ipccall.h> 62 #include <compat/linux/common/linux_machdep.h> 63 64 /* 65 * Note: Not all linux architechtures have explicit versions 66 * of the SYSV* syscalls. On the ones that don't 67 * we pretend that they are defined anyway. *_args and 68 * prototypes are defined in individual headers; 69 * syscalls.master lists those syscalls as NOARGS. 70 * 71 * The functions in multiarch are the ones that just need 72 * the arguments shuffled around and then use the 73 * normal NetBSD syscall. 74 * 75 * Function in multiarch: 76 * linux_sys_ipc : linux_ipccall.c 77 * liunx_semop : linux_ipccall.c 78 * linux_semget : linux_ipccall.c 79 * linux_msgsnd : linux_ipccall.c 80 * linux_msgrcv : linux_ipccall.c 81 * linux_msgget : linux_ipccall.c 82 * linux_shmdt : linux_ipccall.c 83 * linux_shmget : linux_ipccall.c 84 */ 85 86 #if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG) 87 /* 88 * Convert between Linux and NetBSD ipc_perm structures. Only the 89 * order of the fields is different. 90 */ 91 void 92 linux_to_bsd_ipc_perm(struct linux_ipc_perm *lpp, struct ipc_perm *bpp) 93 { 94 95 bpp->_key = lpp->l_key; 96 bpp->uid = lpp->l_uid; 97 bpp->gid = lpp->l_gid; 98 bpp->cuid = lpp->l_cuid; 99 bpp->cgid = lpp->l_cgid; 100 bpp->mode = lpp->l_mode; 101 bpp->_seq = lpp->l_seq; 102 } 103 104 void 105 linux_to_bsd_ipc64_perm(struct linux_ipc64_perm *lpp, struct ipc_perm *bpp) 106 { 107 bpp->_key = lpp->l_key; 108 bpp->uid = lpp->l_uid; 109 bpp->gid = lpp->l_gid; 110 bpp->cuid = lpp->l_cuid; 111 bpp->cgid = lpp->l_cgid; 112 bpp->mode = lpp->l_mode; 113 bpp->_seq = lpp->l_seq; 114 } 115 116 void 117 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct linux_ipc_perm *lpp) 118 { 119 120 lpp->l_key = bpp->_key; 121 lpp->l_uid = bpp->uid; 122 lpp->l_gid = bpp->gid; 123 lpp->l_cuid = bpp->cuid; 124 lpp->l_cgid = bpp->cgid; 125 lpp->l_mode = bpp->mode; 126 lpp->l_seq = bpp->_seq; 127 } 128 129 void 130 bsd_to_linux_ipc64_perm(struct ipc_perm *bpp, struct linux_ipc64_perm *lpp) 131 { 132 lpp->l_key = bpp->_key; 133 lpp->l_uid = bpp->uid; 134 lpp->l_gid = bpp->gid; 135 lpp->l_cuid = bpp->cuid; 136 lpp->l_cgid = bpp->cgid; 137 lpp->l_mode = bpp->mode; 138 lpp->l_seq = bpp->_seq; 139 } 140 141 #endif 142 143 #ifdef SYSVSEM 144 /* 145 * Semaphore operations. Most constants and structures are the same on 146 * both systems. Only semctl() needs some extra work. 147 */ 148 149 /* 150 * Convert between Linux and NetBSD semid_ds structures. 151 */ 152 void 153 bsd_to_linux_semid_ds(struct semid_ds *bs, struct linux_semid_ds *ls) 154 { 155 bsd_to_linux_ipc_perm(&bs->sem_perm, &ls->l_sem_perm); 156 ls->l_sem_otime = bs->sem_otime; 157 ls->l_sem_ctime = bs->sem_ctime; 158 ls->l_sem_nsems = bs->sem_nsems; 159 ls->l_sem_base = bs->_sem_base; 160 } 161 162 void 163 bsd_to_linux_semid64_ds(struct semid_ds *bs, struct linux_semid64_ds *ls) 164 { 165 bsd_to_linux_ipc64_perm(&bs->sem_perm, &ls->l_sem_perm); 166 ls->l_sem_otime = bs->sem_otime; 167 ls->l_sem_ctime = bs->sem_ctime; 168 ls->l_sem_nsems = bs->sem_nsems; 169 } 170 171 void 172 linux_to_bsd_semid_ds(struct linux_semid_ds *ls, struct semid_ds *bs) 173 { 174 linux_to_bsd_ipc_perm(&ls->l_sem_perm, &bs->sem_perm); 175 bs->sem_otime = ls->l_sem_otime; 176 bs->sem_ctime = ls->l_sem_ctime; 177 bs->sem_nsems = ls->l_sem_nsems; 178 bs->_sem_base = ls->l_sem_base; 179 } 180 181 void 182 linux_to_bsd_semid64_ds(struct linux_semid64_ds *ls, struct semid_ds *bs) 183 { 184 linux_to_bsd_ipc64_perm(&ls->l_sem_perm, &bs->sem_perm); 185 bs->sem_otime = ls->l_sem_otime; 186 bs->sem_ctime = ls->l_sem_ctime; 187 bs->sem_nsems = ls->l_sem_nsems; 188 } 189 190 /* 191 * Most of this can be handled by directly passing the arguments on; we 192 * just need to frob the `cmd' and convert the semid_ds and semun. 193 */ 194 int 195 linux_sys_semctl(struct lwp *l, const struct linux_sys_semctl_args *uap, register_t *retval) 196 { 197 /* { 198 syscallarg(int) semid; 199 syscallarg(int) semnum; 200 syscallarg(int) cmd; 201 syscallarg(union linux_semun) arg; 202 } */ 203 struct semid_ds sembuf; 204 struct linux_semid_ds lsembuf; 205 struct linux_semid64_ds lsembuf64; 206 union __semun semun; 207 int cmd, lcmd, error; 208 void *pass_arg = NULL; 209 210 lcmd = SCARG(uap, cmd); 211 #ifdef LINUX_IPC_FORCE64 212 lcmd |= LINUX_IPC_64; 213 #endif 214 215 switch (lcmd & ~LINUX_IPC_64) { 216 case LINUX_IPC_SET: 217 if (lcmd & LINUX_IPC_64) { 218 error = copyin(SCARG(uap, arg).l_buf, &lsembuf64, 219 sizeof(lsembuf64)); 220 linux_to_bsd_semid64_ds(&lsembuf64, &sembuf); 221 } else { 222 error = copyin(SCARG(uap, arg).l_buf, &lsembuf, 223 sizeof(lsembuf)); 224 linux_to_bsd_semid_ds(&lsembuf, &sembuf); 225 } 226 if (error) 227 return (error); 228 pass_arg = &sembuf; 229 cmd = IPC_SET; 230 break; 231 232 case LINUX_IPC_STAT: 233 pass_arg = &sembuf; 234 cmd = IPC_STAT; 235 break; 236 237 case LINUX_IPC_RMID: 238 cmd = IPC_RMID; 239 break; 240 241 case LINUX_GETVAL: 242 cmd = GETVAL; 243 break; 244 245 case LINUX_GETPID: 246 cmd = GETPID; 247 break; 248 249 case LINUX_GETNCNT: 250 cmd = GETNCNT; 251 break; 252 253 case LINUX_GETZCNT: 254 cmd = GETZCNT; 255 break; 256 257 case LINUX_GETALL: 258 pass_arg = &semun; 259 semun.array = SCARG(uap, arg).l_array; 260 cmd = GETALL; 261 break; 262 263 case LINUX_SETVAL: 264 pass_arg = &semun; 265 semun.val = SCARG(uap, arg).l_val; 266 cmd = SETVAL; 267 break; 268 269 case LINUX_SETALL: 270 pass_arg = &semun; 271 semun.array = SCARG(uap, arg).l_array; 272 cmd = SETALL; 273 break; 274 275 default: 276 return (EINVAL); 277 } 278 279 error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd, 280 pass_arg, retval); 281 if (error) 282 return error; 283 284 switch (lcmd) { 285 case LINUX_IPC_STAT: 286 bsd_to_linux_semid_ds(&sembuf, &lsembuf); 287 error = copyout(&lsembuf, SCARG(uap, arg).l_buf, 288 sizeof(lsembuf)); 289 break; 290 case LINUX_IPC_STAT | LINUX_IPC_64: 291 bsd_to_linux_semid64_ds(&sembuf, &lsembuf64); 292 error = copyout(&lsembuf64, SCARG(uap, arg).l_buf, 293 sizeof(lsembuf64)); 294 break; 295 default: 296 break; 297 } 298 299 return (error); 300 } 301 #endif /* SYSVSEM */ 302 303 #ifdef SYSVMSG 304 305 void 306 linux_to_bsd_msqid_ds(struct linux_msqid_ds *lmp, struct msqid_ds *bmp) 307 { 308 309 linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm); 310 bmp->_msg_first = lmp->l_msg_first; 311 bmp->_msg_last = lmp->l_msg_last; 312 bmp->_msg_cbytes = lmp->l_msg_cbytes; 313 bmp->msg_qnum = lmp->l_msg_qnum; 314 bmp->msg_qbytes = lmp->l_msg_qbytes; 315 bmp->msg_lspid = lmp->l_msg_lspid; 316 bmp->msg_lrpid = lmp->l_msg_lrpid; 317 bmp->msg_stime = lmp->l_msg_stime; 318 bmp->msg_rtime = lmp->l_msg_rtime; 319 bmp->msg_ctime = lmp->l_msg_ctime; 320 } 321 322 void 323 linux_to_bsd_msqid64_ds(struct linux_msqid64_ds *lmp, struct msqid_ds *bmp) 324 { 325 linux_to_bsd_ipc64_perm(&lmp->l_msg_perm, &bmp->msg_perm); 326 bmp->msg_stime = lmp->l_msg_stime; 327 bmp->msg_rtime = lmp->l_msg_rtime; 328 bmp->msg_ctime = lmp->l_msg_ctime; 329 bmp->_msg_cbytes = lmp->l_msg_cbytes; 330 bmp->msg_qnum = lmp->l_msg_qnum; 331 bmp->msg_qbytes = lmp->l_msg_qbytes; 332 bmp->msg_lspid = lmp->l_msg_lspid; 333 bmp->msg_lrpid = lmp->l_msg_lrpid; 334 } 335 336 void 337 bsd_to_linux_msqid_ds(struct msqid_ds *bmp, struct linux_msqid_ds *lmp) 338 { 339 340 bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm); 341 lmp->l_msg_first = bmp->_msg_first; 342 lmp->l_msg_last = bmp->_msg_last; 343 lmp->l_msg_cbytes = bmp->_msg_cbytes; 344 lmp->l_msg_qnum = bmp->msg_qnum; 345 lmp->l_msg_qbytes = bmp->msg_qbytes; 346 lmp->l_msg_lspid = bmp->msg_lspid; 347 lmp->l_msg_lrpid = bmp->msg_lrpid; 348 lmp->l_msg_stime = bmp->msg_stime; 349 lmp->l_msg_rtime = bmp->msg_rtime; 350 lmp->l_msg_ctime = bmp->msg_ctime; 351 } 352 353 void 354 bsd_to_linux_msqid64_ds(struct msqid_ds *bmp, struct linux_msqid64_ds *lmp) 355 { 356 bsd_to_linux_ipc64_perm(&bmp->msg_perm, &lmp->l_msg_perm); 357 lmp->l_msg_stime = bmp->msg_stime; 358 lmp->l_msg_rtime = bmp->msg_rtime; 359 lmp->l_msg_ctime = bmp->msg_ctime; 360 lmp->l_msg_cbytes = bmp->_msg_cbytes; 361 lmp->l_msg_qnum = bmp->msg_qnum; 362 lmp->l_msg_qbytes = bmp->msg_qbytes; 363 lmp->l_msg_lspid = bmp->msg_lspid; 364 lmp->l_msg_lrpid = bmp->msg_lrpid; 365 } 366 367 int 368 linux_sys_msgctl(struct lwp *l, const struct linux_sys_msgctl_args *uap, register_t *retval) 369 { 370 /* { 371 syscallarg(int) msqid; 372 syscallarg(int) cmd; 373 syscallarg(struct linux_msqid_ds *) buf; 374 } */ 375 struct msqid_ds bm, *bmp = NULL; 376 struct linux_msqid_ds lm; 377 struct linux_msqid64_ds lm64; 378 int cmd, lcmd, error; 379 380 lcmd = SCARG(uap, cmd); 381 #ifdef LINUX_IPC_FORCE64 382 lcmd |= LINUX_IPC_64; 383 #endif 384 385 switch (lcmd & ~LINUX_IPC_64) { 386 case LINUX_IPC_STAT: 387 cmd = IPC_STAT; 388 bmp = &bm; 389 break; 390 case LINUX_IPC_SET: 391 if (lcmd & LINUX_IPC_64) { 392 error = copyin(SCARG(uap, buf), &lm64, sizeof lm64); 393 linux_to_bsd_msqid64_ds(&lm64, &bm); 394 } else { 395 error = copyin(SCARG(uap, buf), &lm, sizeof lm); 396 linux_to_bsd_msqid_ds(&lm, &bm); 397 } 398 if (error) 399 return error; 400 cmd = IPC_SET; 401 bmp = &bm; 402 break; 403 case LINUX_IPC_RMID: 404 cmd = IPC_RMID; 405 break; 406 default: 407 return EINVAL; 408 } 409 410 if ((error = msgctl1(l, SCARG(uap, msqid), cmd, bmp))) 411 return error; 412 413 switch (lcmd) { 414 case LINUX_IPC_STAT: 415 bsd_to_linux_msqid_ds(&bm, &lm); 416 error = copyout(&lm, SCARG(uap, buf), sizeof lm); 417 break; 418 case LINUX_IPC_STAT|LINUX_IPC_64: 419 bsd_to_linux_msqid64_ds(&bm, &lm64); 420 error = copyout(&lm64, SCARG(uap, buf), sizeof lm64); 421 break; 422 default: 423 break; 424 } 425 426 return error; 427 } 428 #endif /* SYSVMSG */ 429 430 #ifdef SYSVSHM 431 /* 432 * shmget(2). Just make sure the Linux-compatible shmat() semantics 433 * is enabled for the segment, so that shmat() succeeds even when 434 * the segment would be removed. 435 */ 436 int 437 linux_sys_shmget(struct lwp *l, const struct linux_sys_shmget_args *uap, register_t *retval) 438 { 439 /* { 440 syscallarg(key_t) key; 441 syscallarg(size_t) size; 442 syscallarg(int) shmflg; 443 } */ 444 struct sys_shmget_args bsd_ua; 445 446 SCARG(&bsd_ua, key) = SCARG(uap, key); 447 SCARG(&bsd_ua, size) = SCARG(uap, size); 448 SCARG(&bsd_ua, shmflg) = SCARG(uap, shmflg) | _SHM_RMLINGER; 449 450 return sys_shmget(l, &bsd_ua, retval); 451 } 452 453 /* 454 * shmat(2). Very straightforward, except that Linux passes a pointer 455 * in which the return value is to be passed. This is subsequently 456 * handled by libc, apparently. 457 */ 458 #ifndef __amd64__ 459 int 460 linux_sys_shmat(struct lwp *l, const struct linux_sys_shmat_args *uap, register_t *retval) 461 { 462 /* { 463 syscallarg(int) shmid; 464 syscallarg(void *) shmaddr; 465 syscallarg(int) shmflg; 466 syscallarg(u_long *) raddr; 467 } */ 468 int error; 469 470 if ((error = sys_shmat(l, (const void *)uap, retval))) 471 return error; 472 473 if ((error = copyout(&retval[0], SCARG(uap, raddr), sizeof retval[0]))) 474 return error; 475 476 retval[0] = 0; 477 return 0; 478 } 479 #endif /* __amd64__ */ 480 481 /* 482 * Convert between Linux and NetBSD shmid_ds structures. 483 * The order of the fields is once again the difference, and 484 * we also need a place to store the internal data pointer 485 * in, which is unfortunately stored in this structure. 486 * 487 * We abuse a Linux internal field for that. 488 */ 489 void 490 linux_to_bsd_shmid_ds(struct linux_shmid_ds *lsp, struct shmid_ds *bsp) 491 { 492 493 linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm); 494 bsp->shm_segsz = lsp->l_shm_segsz; 495 bsp->shm_lpid = lsp->l_shm_lpid; 496 bsp->shm_cpid = lsp->l_shm_cpid; 497 bsp->shm_nattch = lsp->l_shm_nattch; 498 bsp->shm_atime = lsp->l_shm_atime; 499 bsp->shm_dtime = lsp->l_shm_dtime; 500 bsp->shm_ctime = lsp->l_shm_ctime; 501 bsp->_shm_internal = lsp->l_private2; /* XXX Oh well. */ 502 } 503 504 void 505 linux_to_bsd_shmid64_ds(struct linux_shmid64_ds *lsp, struct shmid_ds *bsp) 506 { 507 508 linux_to_bsd_ipc64_perm(&lsp->l_shm_perm, &bsp->shm_perm); 509 bsp->shm_segsz = lsp->l_shm_segsz; 510 bsp->shm_lpid = lsp->l_shm_lpid; 511 bsp->shm_cpid = lsp->l_shm_cpid; 512 bsp->shm_nattch = lsp->l_shm_nattch; 513 bsp->shm_atime = lsp->l_shm_atime; 514 bsp->shm_dtime = lsp->l_shm_dtime; 515 bsp->shm_ctime = lsp->l_shm_ctime; 516 bsp->_shm_internal = (void*)lsp->l___unused5; /* XXX Oh well. */ 517 } 518 519 void 520 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct linux_shmid_ds *lsp) 521 { 522 523 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm); 524 lsp->l_shm_segsz = bsp->shm_segsz; 525 lsp->l_shm_lpid = bsp->shm_lpid; 526 lsp->l_shm_cpid = bsp->shm_cpid; 527 lsp->l_shm_nattch = bsp->shm_nattch; 528 lsp->l_shm_atime = bsp->shm_atime; 529 lsp->l_shm_dtime = bsp->shm_dtime; 530 lsp->l_shm_ctime = bsp->shm_ctime; 531 lsp->l_private2 = bsp->_shm_internal; /* XXX */ 532 } 533 534 void 535 bsd_to_linux_shmid64_ds(struct shmid_ds *bsp, struct linux_shmid64_ds *lsp) 536 { 537 bsd_to_linux_ipc64_perm(&bsp->shm_perm, &lsp->l_shm_perm); 538 lsp->l_shm_segsz = bsp->shm_segsz; 539 lsp->l_shm_lpid = bsp->shm_lpid; 540 lsp->l_shm_cpid = bsp->shm_cpid; 541 lsp->l_shm_nattch = bsp->shm_nattch; 542 lsp->l_shm_atime = bsp->shm_atime; 543 lsp->l_shm_dtime = bsp->shm_dtime; 544 lsp->l_shm_ctime = bsp->shm_ctime; 545 lsp->l___unused5 = (u_long)bsp->_shm_internal; /* XXX */ 546 } 547 548 /* 549 * shmctl. 550 * 551 * The usual structure conversion and massaging is done. 552 */ 553 int 554 linux_sys_shmctl(struct lwp *l, const struct linux_sys_shmctl_args *uap, register_t *retval) 555 { 556 /* { 557 syscallarg(int) shmid; 558 syscallarg(int) cmd; 559 syscallarg(struct linux_shmid_ds *) buf; 560 } */ 561 struct shmid_ds bs; 562 struct linux_shmid_ds ls; 563 struct linux_shmid64_ds ls64; 564 struct linux_shminfo64 lsi64; 565 struct linux_shm_info lsi; 566 int error, i, cmd, shmid; 567 568 shmid = SCARG(uap, shmid); 569 cmd = SCARG(uap, cmd); 570 #ifdef LINUX_IPC_FORCE64 571 cmd |= LINUX_IPC_64; 572 #endif 573 574 switch (cmd & ~LINUX_IPC_64) { 575 case LINUX_SHM_STAT: 576 shmid = IXSEQ_TO_IPCID(shmid, shmsegs[shmid].shm_perm); 577 retval[0] = shmid; 578 /*FALLTHROUGH*/ 579 580 case LINUX_IPC_STAT: 581 error = shmctl1(l, shmid, IPC_STAT, &bs); 582 if (error != 0) 583 return error; 584 if (cmd & LINUX_IPC_64) { 585 bsd_to_linux_shmid64_ds(&bs, &ls64); 586 error = copyout(&ls64, SCARG(uap, buf), sizeof ls64); 587 } else { 588 bsd_to_linux_shmid_ds(&bs, &ls); 589 error = copyout(&ls, SCARG(uap, buf), sizeof ls); 590 } 591 return error; 592 593 case LINUX_IPC_SET: 594 if (cmd & LINUX_IPC_64) { 595 error = copyin(SCARG(uap, buf), &ls64, sizeof ls64); 596 linux_to_bsd_shmid64_ds(&ls64, &bs); 597 } else { 598 error = copyin(SCARG(uap, buf), &ls, sizeof ls); 599 linux_to_bsd_shmid_ds(&ls, &bs); 600 } 601 if (error != 0) 602 return error; 603 return shmctl1(l, shmid, IPC_SET, &bs); 604 605 case LINUX_IPC_RMID: 606 return shmctl1(l, shmid, IPC_RMID, NULL); 607 608 case LINUX_SHM_LOCK: 609 return shmctl1(l, shmid, SHM_LOCK, NULL); 610 611 case LINUX_SHM_UNLOCK: 612 return shmctl1(l, shmid, SHM_UNLOCK, NULL); 613 614 case LINUX_IPC_INFO: 615 memset(&lsi64, 0, sizeof lsi64); 616 lsi64.l_shmmax = shminfo.shmmax; 617 lsi64.l_shmmin = shminfo.shmmin; 618 lsi64.l_shmmni = shminfo.shmmni; 619 lsi64.l_shmseg = shminfo.shmseg; 620 lsi64.l_shmall = shminfo.shmall; 621 for (i = shminfo.shmmni - 1; i > 0; i--) 622 if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED) 623 break; 624 retval[0] = i; 625 return copyout(&lsi64, SCARG(uap, buf), sizeof lsi64); 626 627 case LINUX_SHM_INFO: 628 (void)memset(&lsi, 0, sizeof lsi); 629 lsi.l_used_ids = shm_nused; 630 for (i = 0; i < shminfo.shmmni; i++) 631 if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED) 632 lsi.l_shm_tot += 633 round_page(shmsegs[i].shm_segsz) / 634 uvmexp.pagesize; 635 lsi.l_shm_rss = 0; 636 lsi.l_shm_swp = 0; 637 lsi.l_swap_attempts = 0; 638 lsi.l_swap_successes = 0; 639 for (i = shminfo.shmmni - 1; i > 0; i--) 640 if (shmsegs[i].shm_perm.mode & SHMSEG_ALLOCATED) 641 break; 642 retval[0] = i; 643 return copyout(&lsi, SCARG(uap, buf), sizeof lsi); 644 645 default: 646 #ifdef DEBUG 647 printf("linux_sys_shmctl cmd %d\n", SCARG(uap, cmd)); 648 #endif 649 return EINVAL; 650 } 651 } 652 #endif /* SYSVSHM */ 653