2 * Copyright (c) 1994-1995 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/syscallsubr.h>
35 #include <sys/sysproto.h>
37 #include <sys/limits.h>
42 #include "opt_compat.h"
45 #include <machine/../linux32/linux.h>
46 #include <machine/../linux32/linux32_proto.h>
48 #include <machine/../linux/linux.h>
49 #include <machine/../linux/linux_proto.h>
51 #include <compat/linux/linux_ipc.h>
52 #include <compat/linux/linux_ipc64.h>
53 #include <compat/linux/linux_util.h>
91 l_ulong shm_tot; /* total allocated shm */
92 l_ulong shm_rss; /* total resident shm */
93 l_ulong shm_swp; /* total swapped shm */
94 l_ulong swap_attempts;
95 l_ulong swap_successes;
110 bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo64 *lpp)
113 lpp->shmmax = bpp->shmmax;
114 lpp->shmmin = bpp->shmmin;
115 lpp->shmmni = bpp->shmmni;
116 lpp->shmseg = bpp->shmseg;
117 lpp->shmall = bpp->shmall;
121 bsd_to_linux_shm_info( struct shm_info *bpp, struct l_shm_info *lpp)
124 lpp->used_ids = bpp->used_ids;
125 lpp->shm_tot = bpp->shm_tot;
126 lpp->shm_rss = bpp->shm_rss;
127 lpp->shm_swp = bpp->shm_swp;
128 lpp->swap_attempts = bpp->swap_attempts;
129 lpp->swap_successes = bpp->swap_successes;
133 linux_to_bsd_ipc_perm(struct l_ipc64_perm *lpp, struct ipc_perm *bpp)
139 bpp->cuid = lpp->cuid;
140 bpp->cgid = lpp->cgid;
141 bpp->mode = lpp->mode;
146 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc64_perm *lpp)
152 lpp->cuid = bpp->cuid;
153 lpp->cgid = bpp->cgid;
154 lpp->mode = bpp->mode;
159 struct l_ipc_perm msg_perm;
160 l_uintptr_t msg_first; /* first message on queue,unused */
161 l_uintptr_t msg_last; /* last message in queue,unused */
162 l_time_t msg_stime; /* last msgsnd time */
163 l_time_t msg_rtime; /* last msgrcv time */
164 l_time_t msg_ctime; /* last change time */
165 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
166 l_ulong msg_lqbytes; /* ditto */
167 l_ushort msg_cbytes; /* current number of bytes on queue */
168 l_ushort msg_qnum; /* number of messages in queue */
169 l_ushort msg_qbytes; /* max number of bytes on queue */
170 l_pid_t msg_lspid; /* pid of last msgsnd */
171 l_pid_t msg_lrpid; /* last receive pid */
175 struct l_ipc_perm sem_perm;
178 l_uintptr_t sem_base;
179 l_uintptr_t sem_pending;
180 l_uintptr_t sem_pending_last;
186 struct l_ipc_perm shm_perm;
195 l_uintptr_t private2;
196 l_uintptr_t private3;
200 linux_to_bsd_semid_ds(struct l_semid64_ds *lsp, struct semid_ds *bsp)
203 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
204 bsp->sem_otime = lsp->sem_otime;
205 bsp->sem_ctime = lsp->sem_ctime;
206 bsp->sem_nsems = lsp->sem_nsems;
210 bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid64_ds *lsp)
213 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
214 lsp->sem_otime = bsp->sem_otime;
215 lsp->sem_ctime = bsp->sem_ctime;
216 lsp->sem_nsems = bsp->sem_nsems;
220 linux_to_bsd_shmid_ds(struct l_shmid64_ds *lsp, struct shmid_ds *bsp)
223 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
224 bsp->shm_segsz = lsp->shm_segsz;
225 bsp->shm_lpid = lsp->shm_lpid;
226 bsp->shm_cpid = lsp->shm_cpid;
227 bsp->shm_nattch = lsp->shm_nattch;
228 bsp->shm_atime = lsp->shm_atime;
229 bsp->shm_dtime = lsp->shm_dtime;
230 bsp->shm_ctime = lsp->shm_ctime;
234 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid64_ds *lsp)
237 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
238 lsp->shm_segsz = bsp->shm_segsz;
239 lsp->shm_lpid = bsp->shm_lpid;
240 lsp->shm_cpid = bsp->shm_cpid;
241 lsp->shm_nattch = bsp->shm_nattch;
242 lsp->shm_atime = bsp->shm_atime;
243 lsp->shm_dtime = bsp->shm_dtime;
244 lsp->shm_ctime = bsp->shm_ctime;
248 linux_to_bsd_msqid_ds(struct l_msqid64_ds *lsp, struct msqid_ds *bsp)
251 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
252 bsp->msg_cbytes = lsp->msg_cbytes;
253 bsp->msg_qnum = lsp->msg_qnum;
254 bsp->msg_qbytes = lsp->msg_qbytes;
255 bsp->msg_lspid = lsp->msg_lspid;
256 bsp->msg_lrpid = lsp->msg_lrpid;
257 bsp->msg_stime = lsp->msg_stime;
258 bsp->msg_rtime = lsp->msg_rtime;
259 bsp->msg_ctime = lsp->msg_ctime;
263 bsd_to_linux_msqid_ds(struct msqid_ds *bsp, struct l_msqid64_ds *lsp)
266 bsd_to_linux_ipc_perm(&bsp->msg_perm, &lsp->msg_perm);
267 lsp->msg_cbytes = bsp->msg_cbytes;
268 lsp->msg_qnum = bsp->msg_qnum;
269 lsp->msg_qbytes = bsp->msg_qbytes;
270 lsp->msg_lspid = bsp->msg_lspid;
271 lsp->msg_lrpid = bsp->msg_lrpid;
272 lsp->msg_stime = bsp->msg_stime;
273 lsp->msg_rtime = bsp->msg_rtime;
274 lsp->msg_ctime = bsp->msg_ctime;
278 linux_ipc64_perm_to_ipc_perm(struct l_ipc64_perm *in, struct l_ipc_perm *out)
284 out->cuid = in->cuid;
285 out->cgid = in->cgid;
286 out->mode = in->mode;
289 /* Linux does not check overflow */
290 if (out->uid != in->uid || out->gid != in->gid ||
291 out->cuid != in->cuid || out->cgid != in->cgid ||
292 out->mode != in->mode)
299 linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
301 struct l_msqid_ds linux_msqid;
304 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
305 return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
307 error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
311 bzero(linux_msqid64, sizeof(*linux_msqid64));
313 linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
314 linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
315 linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
316 if (linux_msqid.msg_qbytes == 0)
317 linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
319 linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
325 linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
327 struct l_msqid_ds linux_msqid;
330 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
331 return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
333 bzero(&linux_msqid, sizeof(linux_msqid));
335 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
336 &linux_msqid.msg_perm);
340 linux_msqid.msg_stime = linux_msqid64->msg_stime;
341 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
342 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
344 if (linux_msqid64->msg_cbytes > USHRT_MAX)
345 linux_msqid.msg_cbytes = USHRT_MAX;
347 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
348 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
349 if (linux_msqid64->msg_qnum > USHRT_MAX)
350 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
352 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
353 if (linux_msqid64->msg_qbytes > USHRT_MAX)
354 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
356 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
357 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
358 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
359 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
361 /* Linux does not check overflow */
362 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
363 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
364 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
367 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
372 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
374 struct l_semid_ds linux_semid;
377 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
378 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
380 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
384 bzero(linux_semid64, sizeof(*linux_semid64));
386 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
387 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
388 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
394 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
396 struct l_semid_ds linux_semid;
399 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
400 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
402 bzero(&linux_semid, sizeof(linux_semid));
404 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
405 &linux_semid.sem_perm);
409 linux_semid.sem_otime = linux_semid64->sem_otime;
410 linux_semid.sem_ctime = linux_semid64->sem_ctime;
411 linux_semid.sem_nsems = linux_semid64->sem_nsems;
413 /* Linux does not check overflow */
414 if (linux_semid.sem_otime != linux_semid64->sem_otime ||
415 linux_semid.sem_ctime != linux_semid64->sem_ctime ||
416 linux_semid.sem_nsems != linux_semid64->sem_nsems)
419 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
424 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
426 struct l_shmid_ds linux_shmid;
429 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
430 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
432 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
436 bzero(linux_shmid64, sizeof(*linux_shmid64));
438 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
439 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
440 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
446 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
448 struct l_shmid_ds linux_shmid;
451 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
452 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
454 bzero(&linux_shmid, sizeof(linux_shmid));
456 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
457 &linux_shmid.shm_perm);
461 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
462 linux_shmid.shm_atime = linux_shmid64->shm_atime;
463 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
464 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
465 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
466 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
467 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
469 /* Linux does not check overflow */
470 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
471 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
472 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
473 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
474 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
475 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
476 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
479 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
484 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
487 struct l_shminfo linux_shminfo;
489 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
490 return (copyout(linux_shminfo64, uaddr,
491 sizeof(*linux_shminfo64)));
493 bzero(&linux_shminfo, sizeof(linux_shminfo));
495 linux_shminfo.shmmax = linux_shminfo64->shmmax;
496 linux_shminfo.shmmin = linux_shminfo64->shmmin;
497 linux_shminfo.shmmni = linux_shminfo64->shmmni;
498 linux_shminfo.shmseg = linux_shminfo64->shmseg;
499 linux_shminfo.shmall = linux_shminfo64->shmall;
501 return (copyout(&linux_shminfo, uaddr,
502 sizeof(linux_shminfo)));
507 linux_semop(struct thread *td, struct linux_semop_args *args)
509 struct semop_args /* {
515 bsd_args.semid = args->semid;
516 bsd_args.sops = PTRIN(args->tsops);
517 bsd_args.nsops = args->nsops;
518 return (sys_semop(td, &bsd_args));
522 linux_semget(struct thread *td, struct linux_semget_args *args)
524 struct semget_args /* {
532 bsd_args.key = args->key;
533 bsd_args.nsems = args->nsems;
534 bsd_args.semflg = args->semflg;
535 return (sys_semget(td, &bsd_args));
539 linux_semctl(struct thread *td, struct linux_semctl_args *args)
541 struct l_semid64_ds linux_semid64;
542 struct l_seminfo linux_seminfo;
543 struct semid_ds semid;
548 switch (args->cmd & ~LINUX_IPC_64) {
566 semun.val = args->arg.val;
570 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
571 &linux_semid64, PTRIN(args->arg.buf));
574 linux_to_bsd_semid_ds(&linux_semid64, &semid);
576 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
581 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
585 bsd_to_linux_semid_ds(&semid, &linux_semid64);
586 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
587 &linux_semid64, PTRIN(args->arg.buf)));
591 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
595 bsd_to_linux_semid_ds(&semid, &linux_semid64);
596 error = linux_semid_pushdown(args->cmd & LINUX_IPC_64,
597 &linux_semid64, PTRIN(args->arg.buf));
599 td->td_retval[0] = rval;
603 bcopy(&seminfo, &linux_seminfo.semmni, sizeof(linux_seminfo) -
604 sizeof(linux_seminfo.semmap) );
606 * Linux does not use the semmap field but populates it with
607 * the defined value from SEMMAP, which really is redefined to
608 * SEMMNS, which they define as SEMMNI * SEMMSL. Try to
609 * simulate this returning our dynamic semmns value.
611 linux_seminfo.semmap = linux_seminfo.semmns;
612 /* XXX BSD equivalent?
613 #define used_semids 10
615 linux_seminfo.semusz = used_semids;
616 linux_seminfo.semaem = used_sems;
618 error = copyout(&linux_seminfo,
619 PTRIN(args->arg.buf), sizeof(linux_seminfo));
623 * TODO: Linux return the last assigned id, not the semmni.
625 td->td_retval[0] = seminfo.semmni;
629 semun.array = PTRIN(args->arg.array);
633 semun.array = PTRIN(args->arg.array);
636 linux_msg(td, "ipc type %d is not implemented",
637 args->cmd & ~LINUX_IPC_64);
640 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
645 linux_msgsnd(struct thread *td, struct linux_msgsnd_args *args)
652 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
654 msgp = PTRIN(args->msgp);
655 if ((error = copyin(msgp, &lmtype, sizeof(lmtype))) != 0)
657 mtype = (long)lmtype;
658 return (kern_msgsnd(td, args->msqid,
659 (const char *)msgp + sizeof(lmtype),
660 args->msgsz, args->msgflg, mtype));
664 linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
671 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
673 msgp = PTRIN(args->msgp);
674 if ((error = kern_msgrcv(td, args->msqid,
675 (char *)msgp + sizeof(lmtype), args->msgsz,
676 args->msgtyp, args->msgflg, &mtype)) != 0)
678 lmtype = (l_long)mtype;
679 return (copyout(&lmtype, msgp, sizeof(lmtype)));
683 linux_msgget(struct thread *td, struct linux_msgget_args *args)
685 struct msgget_args /* {
690 bsd_args.key = args->key;
691 bsd_args.msgflg = args->msgflg;
692 return (sys_msgget(td, &bsd_args));
696 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
699 struct l_msqid64_ds linux_msqid64;
700 struct msqid_ds bsd_msqid;
702 bsd_cmd = args->cmd & ~LINUX_IPC_64;
705 case LINUX_MSG_INFO: {
706 struct l_msginfo linux_msginfo;
709 * XXX MSG_INFO uses the same data structure but returns different
710 * dynamic counters in msgpool, msgmap, and msgtql fields.
712 linux_msginfo.msgpool = (long)msginfo.msgmni *
713 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
714 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
715 linux_msginfo.msgmax = msginfo.msgmax;
716 linux_msginfo.msgmnb = msginfo.msgmnb;
717 linux_msginfo.msgmni = msginfo.msgmni;
718 linux_msginfo.msgssz = msginfo.msgssz;
719 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
720 linux_msginfo.msgseg = msginfo.msgseg;
721 error = copyout(&linux_msginfo, PTRIN(args->buf),
722 sizeof(linux_msginfo));
724 td->td_retval[0] = msginfo.msgmni; /* XXX */
730 * TODO: implement this
731 * case LINUX_MSG_STAT:
738 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
739 &linux_msqid64, PTRIN(args->buf));
742 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
754 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
756 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
758 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
762 if (bsd_cmd == LINUX_IPC_STAT) {
763 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
764 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
765 &linux_msqid64, PTRIN(args->buf)));
772 linux_shmat(struct thread *td, struct linux_shmat_args *args)
774 struct shmat_args /* {
780 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
784 bsd_args.shmid = args->shmid;
785 bsd_args.shmaddr = PTRIN(args->shmaddr);
786 bsd_args.shmflg = args->shmflg;
787 if ((error = sys_shmat(td, &bsd_args)))
789 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
790 addr = td->td_retval[0];
791 if ((error = copyout(&addr, PTRIN(args->raddr), sizeof(addr))))
793 td->td_retval[0] = 0;
799 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
801 struct shmdt_args /* {
805 bsd_args.shmaddr = PTRIN(args->shmaddr);
806 return (sys_shmdt(td, &bsd_args));
810 linux_shmget(struct thread *td, struct linux_shmget_args *args)
812 struct shmget_args /* {
818 bsd_args.key = args->key;
819 bsd_args.size = args->size;
820 bsd_args.shmflg = args->shmflg;
821 return (sys_shmget(td, &bsd_args));
825 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
827 struct l_shmid64_ds linux_shmid64;
828 struct l_shminfo64 linux_shminfo64;
829 struct l_shm_info linux_shm_info;
830 struct shmid_ds bsd_shmid;
833 switch (args->cmd & ~LINUX_IPC_64) {
835 case LINUX_IPC_INFO: {
836 struct shminfo bsd_shminfo;
838 /* Perform shmctl wanting removed segments lookup */
839 error = kern_shmctl(td, args->shmid, IPC_INFO,
840 (void *)&bsd_shminfo, NULL);
844 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
846 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
847 &linux_shminfo64, PTRIN(args->buf)));
850 case LINUX_SHM_INFO: {
851 struct shm_info bsd_shm_info;
853 /* Perform shmctl wanting removed segments lookup */
854 error = kern_shmctl(td, args->shmid, SHM_INFO,
855 (void *)&bsd_shm_info, NULL);
859 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
861 return (copyout(&linux_shm_info, PTRIN(args->buf),
862 sizeof(struct l_shm_info)));
866 /* Perform shmctl wanting removed segments lookup */
867 error = kern_shmctl(td, args->shmid, IPC_STAT,
868 (void *)&bsd_shmid, NULL);
872 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
874 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
875 &linux_shmid64, PTRIN(args->buf)));
878 /* Perform shmctl wanting removed segments lookup */
879 error = kern_shmctl(td, args->shmid, IPC_STAT,
880 (void *)&bsd_shmid, NULL);
884 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
886 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
887 &linux_shmid64, PTRIN(args->buf)));
890 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
891 &linux_shmid64, PTRIN(args->buf));
895 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
897 /* Perform shmctl wanting removed segments lookup */
898 return (kern_shmctl(td, args->shmid, IPC_SET,
899 (void *)&bsd_shmid, NULL));
901 case LINUX_IPC_RMID: {
907 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
908 &linux_shmid64, PTRIN(args->buf));
911 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
912 buf = (void *)&bsd_shmid;
914 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
919 case LINUX_SHM_UNLOCK:
922 linux_msg(td, "ipc type %d not implemented",
923 args->cmd & ~LINUX_IPC_64);
928 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
929 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
930 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);