2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1994-1995 Søren Schmidt
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
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>
43 #include "opt_compat.h"
46 #include <machine/../linux32/linux.h>
47 #include <machine/../linux32/linux32_proto.h>
49 #include <machine/../linux/linux.h>
50 #include <machine/../linux/linux_proto.h>
52 #include <compat/linux/linux_ipc.h>
53 #include <compat/linux/linux_ipc64.h>
54 #include <compat/linux/linux_util.h>
92 l_ulong shm_tot; /* total allocated shm */
93 l_ulong shm_rss; /* total resident shm */
94 l_ulong shm_swp; /* total swapped shm */
95 l_ulong swap_attempts;
96 l_ulong swap_successes;
111 bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo64 *lpp)
114 lpp->shmmax = bpp->shmmax;
115 lpp->shmmin = bpp->shmmin;
116 lpp->shmmni = bpp->shmmni;
117 lpp->shmseg = bpp->shmseg;
118 lpp->shmall = bpp->shmall;
122 bsd_to_linux_shm_info( struct shm_info *bpp, struct l_shm_info *lpp)
125 lpp->used_ids = bpp->used_ids;
126 lpp->shm_tot = bpp->shm_tot;
127 lpp->shm_rss = bpp->shm_rss;
128 lpp->shm_swp = bpp->shm_swp;
129 lpp->swap_attempts = bpp->swap_attempts;
130 lpp->swap_successes = bpp->swap_successes;
134 linux_to_bsd_ipc_perm(struct l_ipc64_perm *lpp, struct ipc_perm *bpp)
140 bpp->cuid = lpp->cuid;
141 bpp->cgid = lpp->cgid;
142 bpp->mode = lpp->mode;
147 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc64_perm *lpp)
153 lpp->cuid = bpp->cuid;
154 lpp->cgid = bpp->cgid;
155 lpp->mode = bpp->mode & (S_IRWXU|S_IRWXG|S_IRWXO);
160 struct l_ipc_perm msg_perm;
161 l_uintptr_t msg_first; /* first message on queue,unused */
162 l_uintptr_t msg_last; /* last message in queue,unused */
163 l_time_t msg_stime; /* last msgsnd time */
164 l_time_t msg_rtime; /* last msgrcv time */
165 l_time_t msg_ctime; /* last change time */
166 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
167 l_ulong msg_lqbytes; /* ditto */
168 l_ushort msg_cbytes; /* current number of bytes on queue */
169 l_ushort msg_qnum; /* number of messages in queue */
170 l_ushort msg_qbytes; /* max number of bytes on queue */
171 l_pid_t msg_lspid; /* pid of last msgsnd */
172 l_pid_t msg_lrpid; /* last receive pid */
176 struct l_ipc_perm sem_perm;
179 l_uintptr_t sem_base;
180 l_uintptr_t sem_pending;
181 l_uintptr_t sem_pending_last;
187 struct l_ipc_perm shm_perm;
196 l_uintptr_t private2;
197 l_uintptr_t private3;
201 linux_to_bsd_semid_ds(struct l_semid64_ds *lsp, struct semid_ds *bsp)
204 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
205 bsp->sem_otime = lsp->sem_otime;
206 bsp->sem_ctime = lsp->sem_ctime;
207 bsp->sem_nsems = lsp->sem_nsems;
211 bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid64_ds *lsp)
214 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
215 lsp->sem_otime = bsp->sem_otime;
216 lsp->sem_ctime = bsp->sem_ctime;
217 lsp->sem_nsems = bsp->sem_nsems;
221 linux_to_bsd_shmid_ds(struct l_shmid64_ds *lsp, struct shmid_ds *bsp)
224 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
225 bsp->shm_segsz = lsp->shm_segsz;
226 bsp->shm_lpid = lsp->shm_lpid;
227 bsp->shm_cpid = lsp->shm_cpid;
228 bsp->shm_nattch = lsp->shm_nattch;
229 bsp->shm_atime = lsp->shm_atime;
230 bsp->shm_dtime = lsp->shm_dtime;
231 bsp->shm_ctime = lsp->shm_ctime;
235 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid64_ds *lsp)
238 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
239 lsp->shm_segsz = bsp->shm_segsz;
240 lsp->shm_lpid = bsp->shm_lpid;
241 lsp->shm_cpid = bsp->shm_cpid;
242 lsp->shm_nattch = bsp->shm_nattch;
243 lsp->shm_atime = bsp->shm_atime;
244 lsp->shm_dtime = bsp->shm_dtime;
245 lsp->shm_ctime = bsp->shm_ctime;
249 linux_to_bsd_msqid_ds(struct l_msqid64_ds *lsp, struct msqid_ds *bsp)
252 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
253 bsp->msg_cbytes = lsp->msg_cbytes;
254 bsp->msg_qnum = lsp->msg_qnum;
255 bsp->msg_qbytes = lsp->msg_qbytes;
256 bsp->msg_lspid = lsp->msg_lspid;
257 bsp->msg_lrpid = lsp->msg_lrpid;
258 bsp->msg_stime = lsp->msg_stime;
259 bsp->msg_rtime = lsp->msg_rtime;
260 bsp->msg_ctime = lsp->msg_ctime;
264 bsd_to_linux_msqid_ds(struct msqid_ds *bsp, struct l_msqid64_ds *lsp)
267 bsd_to_linux_ipc_perm(&bsp->msg_perm, &lsp->msg_perm);
268 lsp->msg_cbytes = bsp->msg_cbytes;
269 lsp->msg_qnum = bsp->msg_qnum;
270 lsp->msg_qbytes = bsp->msg_qbytes;
271 lsp->msg_lspid = bsp->msg_lspid;
272 lsp->msg_lrpid = bsp->msg_lrpid;
273 lsp->msg_stime = bsp->msg_stime;
274 lsp->msg_rtime = bsp->msg_rtime;
275 lsp->msg_ctime = bsp->msg_ctime;
279 linux_ipc64_perm_to_ipc_perm(struct l_ipc64_perm *in, struct l_ipc_perm *out)
285 out->cuid = in->cuid;
286 out->cgid = in->cgid;
287 out->mode = in->mode;
290 /* Linux does not check overflow */
291 if (out->uid != in->uid || out->gid != in->gid ||
292 out->cuid != in->cuid || out->cgid != in->cgid ||
293 out->mode != in->mode)
300 linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
302 struct l_msqid_ds linux_msqid;
305 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
306 return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
308 error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
312 bzero(linux_msqid64, sizeof(*linux_msqid64));
314 linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
315 linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
316 linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
317 if (linux_msqid.msg_qbytes == 0)
318 linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
320 linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
326 linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
328 struct l_msqid_ds linux_msqid;
331 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
332 return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
334 bzero(&linux_msqid, sizeof(linux_msqid));
336 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
337 &linux_msqid.msg_perm);
341 linux_msqid.msg_stime = linux_msqid64->msg_stime;
342 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
343 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
345 if (linux_msqid64->msg_cbytes > USHRT_MAX)
346 linux_msqid.msg_cbytes = USHRT_MAX;
348 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
349 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
350 if (linux_msqid64->msg_qnum > USHRT_MAX)
351 linux_msqid.msg_qnum = USHRT_MAX;
353 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
354 if (linux_msqid64->msg_qbytes > USHRT_MAX)
355 linux_msqid.msg_qbytes = USHRT_MAX;
357 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
358 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
359 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
360 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
362 /* Linux does not check overflow */
363 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
364 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
365 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
368 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
373 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
375 struct l_semid_ds linux_semid;
378 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
379 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
381 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
385 bzero(linux_semid64, sizeof(*linux_semid64));
387 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
388 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
389 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
395 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
397 struct l_semid_ds linux_semid;
400 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
401 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
403 bzero(&linux_semid, sizeof(linux_semid));
405 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
406 &linux_semid.sem_perm);
410 linux_semid.sem_otime = linux_semid64->sem_otime;
411 linux_semid.sem_ctime = linux_semid64->sem_ctime;
412 linux_semid.sem_nsems = linux_semid64->sem_nsems;
414 /* Linux does not check overflow */
415 if (linux_semid.sem_otime != linux_semid64->sem_otime ||
416 linux_semid.sem_ctime != linux_semid64->sem_ctime ||
417 linux_semid.sem_nsems != linux_semid64->sem_nsems)
420 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
425 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
427 struct l_shmid_ds linux_shmid;
430 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
431 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
433 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
437 bzero(linux_shmid64, sizeof(*linux_shmid64));
439 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
440 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
441 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
447 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
449 struct l_shmid_ds linux_shmid;
452 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
453 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
455 bzero(&linux_shmid, sizeof(linux_shmid));
457 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
458 &linux_shmid.shm_perm);
462 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
463 linux_shmid.shm_atime = linux_shmid64->shm_atime;
464 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
465 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
466 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
467 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
468 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
470 /* Linux does not check overflow */
471 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
472 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
473 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
474 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
475 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
476 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
477 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
480 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
485 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
488 struct l_shminfo linux_shminfo;
490 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
491 return (copyout(linux_shminfo64, uaddr,
492 sizeof(*linux_shminfo64)));
494 bzero(&linux_shminfo, sizeof(linux_shminfo));
496 linux_shminfo.shmmax = linux_shminfo64->shmmax;
497 linux_shminfo.shmmin = linux_shminfo64->shmmin;
498 linux_shminfo.shmmni = linux_shminfo64->shmmni;
499 linux_shminfo.shmseg = linux_shminfo64->shmseg;
500 linux_shminfo.shmall = linux_shminfo64->shmall;
502 return (copyout(&linux_shminfo, uaddr,
503 sizeof(linux_shminfo)));
508 linux_semop(struct thread *td, struct linux_semop_args *args)
510 struct semop_args /* {
516 if (args->nsops < 1 || args->semid < 0)
518 bsd_args.semid = args->semid;
519 bsd_args.sops = PTRIN(args->tsops);
520 bsd_args.nsops = args->nsops;
521 return (sys_semop(td, &bsd_args));
525 linux_semget(struct thread *td, struct linux_semget_args *args)
527 struct semget_args /* {
535 bsd_args.key = args->key;
536 bsd_args.nsems = args->nsems;
537 bsd_args.semflg = args->semflg;
538 return (sys_semget(td, &bsd_args));
542 linux_semctl(struct thread *td, struct linux_semctl_args *args)
544 struct l_semid64_ds linux_semid64;
545 struct l_seminfo linux_seminfo;
546 struct semid_ds semid;
551 memset(&linux_seminfo, 0, sizeof(linux_seminfo));
552 memset(&linux_semid64, 0, sizeof(linux_semid64));
554 switch (args->cmd & ~LINUX_IPC_64) {
572 semun.val = args->arg.val;
576 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
577 &linux_semid64, PTRIN(args->arg.buf));
580 linux_to_bsd_semid_ds(&linux_semid64, &semid);
582 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
587 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
591 bsd_to_linux_semid_ds(&semid, &linux_semid64);
592 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
593 &linux_semid64, PTRIN(args->arg.buf)));
597 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
601 bsd_to_linux_semid_ds(&semid, &linux_semid64);
602 error = linux_semid_pushdown(args->cmd & LINUX_IPC_64,
603 &linux_semid64, PTRIN(args->arg.buf));
605 td->td_retval[0] = rval;
609 bcopy(&seminfo, &linux_seminfo.semmni, sizeof(linux_seminfo) -
610 sizeof(linux_seminfo.semmap) );
612 * Linux does not use the semmap field but populates it with
613 * the defined value from SEMMAP, which really is redefined to
614 * SEMMNS, which they define as SEMMNI * SEMMSL. Try to
615 * simulate this returning our dynamic semmns value.
617 linux_seminfo.semmap = linux_seminfo.semmns;
618 /* XXX BSD equivalent?
619 #define used_semids 10
621 linux_seminfo.semusz = used_semids;
622 linux_seminfo.semaem = used_sems;
624 error = copyout(&linux_seminfo,
625 PTRIN(args->arg.buf), sizeof(linux_seminfo));
629 * TODO: Linux return the last assigned id, not the semmni.
631 td->td_retval[0] = seminfo.semmni;
635 semun.array = PTRIN(args->arg.array);
639 semun.array = PTRIN(args->arg.array);
642 linux_msg(td, "ipc type %d is not implemented",
643 args->cmd & ~LINUX_IPC_64);
646 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
651 linux_msgsnd(struct thread *td, struct linux_msgsnd_args *args)
658 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
660 msgp = PTRIN(args->msgp);
661 if ((error = copyin(msgp, &lmtype, sizeof(lmtype))) != 0)
663 mtype = (long)lmtype;
664 return (kern_msgsnd(td, args->msqid,
665 (const char *)msgp + sizeof(lmtype),
666 args->msgsz, args->msgflg, mtype));
670 linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
677 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
679 msgp = PTRIN(args->msgp);
680 if ((error = kern_msgrcv(td, args->msqid,
681 (char *)msgp + sizeof(lmtype), args->msgsz,
682 args->msgtyp, args->msgflg, &mtype)) != 0)
684 lmtype = (l_long)mtype;
685 return (copyout(&lmtype, msgp, sizeof(lmtype)));
689 linux_msgget(struct thread *td, struct linux_msgget_args *args)
691 struct msgget_args /* {
696 bsd_args.key = args->key;
697 bsd_args.msgflg = args->msgflg;
698 return (sys_msgget(td, &bsd_args));
702 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
705 struct l_msqid64_ds linux_msqid64;
706 struct msqid_ds bsd_msqid;
708 memset(&linux_msqid64, 0, sizeof(linux_msqid64));
710 bsd_cmd = args->cmd & ~LINUX_IPC_64;
713 case LINUX_MSG_INFO: {
714 struct l_msginfo linux_msginfo;
716 memset(&linux_msginfo, 0, sizeof(linux_msginfo));
718 * XXX MSG_INFO uses the same data structure but returns different
719 * dynamic counters in msgpool, msgmap, and msgtql fields.
721 linux_msginfo.msgpool = (long)msginfo.msgmni *
722 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
723 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
724 linux_msginfo.msgmax = msginfo.msgmax;
725 linux_msginfo.msgmnb = msginfo.msgmnb;
726 linux_msginfo.msgmni = msginfo.msgmni;
727 linux_msginfo.msgssz = msginfo.msgssz;
728 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
729 linux_msginfo.msgseg = msginfo.msgseg;
730 error = copyout(&linux_msginfo, PTRIN(args->buf),
731 sizeof(linux_msginfo));
733 td->td_retval[0] = msginfo.msgmni; /* XXX */
739 * TODO: implement this
740 * case LINUX_MSG_STAT:
747 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
748 &linux_msqid64, PTRIN(args->buf));
751 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
763 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
765 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
767 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
771 if (bsd_cmd == LINUX_IPC_STAT) {
772 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
773 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
774 &linux_msqid64, PTRIN(args->buf)));
781 linux_shmat(struct thread *td, struct linux_shmat_args *args)
783 struct shmat_args /* {
789 bsd_args.shmid = args->shmid;
790 bsd_args.shmaddr = PTRIN(args->shmaddr);
791 bsd_args.shmflg = args->shmflg;
792 return (sys_shmat(td, &bsd_args));
796 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
798 struct shmdt_args /* {
802 bsd_args.shmaddr = PTRIN(args->shmaddr);
803 return (sys_shmdt(td, &bsd_args));
807 linux_shmget(struct thread *td, struct linux_shmget_args *args)
809 struct shmget_args /* {
815 bsd_args.key = args->key;
816 bsd_args.size = args->size;
817 bsd_args.shmflg = args->shmflg;
818 return (sys_shmget(td, &bsd_args));
822 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
824 struct l_shmid64_ds linux_shmid64;
825 struct l_shminfo64 linux_shminfo64;
826 struct l_shm_info linux_shm_info;
827 struct shmid_ds bsd_shmid;
830 memset(&linux_shm_info, 0, sizeof(linux_shm_info));
831 memset(&linux_shmid64, 0, sizeof(linux_shmid64));
832 memset(&linux_shminfo64, 0, sizeof(linux_shminfo64));
834 switch (args->cmd & ~LINUX_IPC_64) {
836 case LINUX_IPC_INFO: {
837 struct shminfo bsd_shminfo;
839 /* Perform shmctl wanting removed segments lookup */
840 error = kern_shmctl(td, args->shmid, IPC_INFO,
841 (void *)&bsd_shminfo, NULL);
845 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
847 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
848 &linux_shminfo64, PTRIN(args->buf)));
851 case LINUX_SHM_INFO: {
852 struct shm_info bsd_shm_info;
854 /* Perform shmctl wanting removed segments lookup */
855 error = kern_shmctl(td, args->shmid, SHM_INFO,
856 (void *)&bsd_shm_info, NULL);
860 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
862 return (copyout(&linux_shm_info, PTRIN(args->buf),
863 sizeof(struct l_shm_info)));
867 /* Perform shmctl wanting removed segments lookup */
868 error = kern_shmctl(td, args->shmid, IPC_STAT,
869 (void *)&bsd_shmid, NULL);
873 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
875 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
876 &linux_shmid64, PTRIN(args->buf)));
879 /* Perform shmctl wanting removed segments lookup */
880 error = kern_shmctl(td, args->shmid, IPC_STAT,
881 (void *)&bsd_shmid, NULL);
885 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
887 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
888 &linux_shmid64, PTRIN(args->buf)));
891 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
892 &linux_shmid64, PTRIN(args->buf));
896 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
898 /* Perform shmctl wanting removed segments lookup */
899 return (kern_shmctl(td, args->shmid, IPC_SET,
900 (void *)&bsd_shmid, NULL));
902 case LINUX_IPC_RMID: {
908 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
909 &linux_shmid64, PTRIN(args->buf));
912 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
913 buf = (void *)&bsd_shmid;
915 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
920 case LINUX_SHM_UNLOCK:
923 linux_msg(td, "ipc type %d not implemented",
924 args->cmd & ~LINUX_IPC_64);
929 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
930 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
931 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);