2 * SPDX-License-Identifier: BSD-3-Clause
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 * in this position and unchanged.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/syscallsubr.h>
37 #include <sys/sysproto.h>
39 #include <sys/limits.h>
45 #include "opt_compat.h"
48 #include <machine/../linux32/linux.h>
49 #include <machine/../linux32/linux32_proto.h>
51 #include <machine/../linux/linux.h>
52 #include <machine/../linux/linux_proto.h>
54 #include <compat/linux/linux_ipc.h>
55 #include <compat/linux/linux_ipc64.h>
56 #include <compat/linux/linux_util.h>
94 l_ulong shm_tot; /* total allocated shm */
95 l_ulong shm_rss; /* total resident shm */
96 l_ulong shm_swp; /* total swapped shm */
97 l_ulong swap_attempts;
98 l_ulong swap_successes;
113 bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo64 *lpp)
116 lpp->shmmax = bpp->shmmax;
117 lpp->shmmin = bpp->shmmin;
118 lpp->shmmni = bpp->shmmni;
119 lpp->shmseg = bpp->shmseg;
120 lpp->shmall = bpp->shmall;
124 bsd_to_linux_shm_info( struct shm_info *bpp, struct l_shm_info *lpp)
127 lpp->used_ids = bpp->used_ids;
128 lpp->shm_tot = bpp->shm_tot;
129 lpp->shm_rss = bpp->shm_rss;
130 lpp->shm_swp = bpp->shm_swp;
131 lpp->swap_attempts = bpp->swap_attempts;
132 lpp->swap_successes = bpp->swap_successes;
136 linux_to_bsd_ipc_perm(struct l_ipc64_perm *lpp, struct ipc_perm *bpp)
142 bpp->cuid = lpp->cuid;
143 bpp->cgid = lpp->cgid;
144 bpp->mode = lpp->mode;
149 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc64_perm *lpp)
155 lpp->cuid = bpp->cuid;
156 lpp->cgid = bpp->cgid;
157 lpp->mode = bpp->mode & (S_IRWXU|S_IRWXG|S_IRWXO);
162 struct l_ipc_perm msg_perm;
163 l_uintptr_t msg_first; /* first message on queue,unused */
164 l_uintptr_t msg_last; /* last message in queue,unused */
165 l_time_t msg_stime; /* last msgsnd time */
166 l_time_t msg_rtime; /* last msgrcv time */
167 l_time_t msg_ctime; /* last change time */
168 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
169 l_ulong msg_lqbytes; /* ditto */
170 l_ushort msg_cbytes; /* current number of bytes on queue */
171 l_ushort msg_qnum; /* number of messages in queue */
172 l_ushort msg_qbytes; /* max number of bytes on queue */
173 l_pid_t msg_lspid; /* pid of last msgsnd */
174 l_pid_t msg_lrpid; /* last receive pid */
178 struct l_ipc_perm sem_perm;
181 l_uintptr_t sem_base;
182 l_uintptr_t sem_pending;
183 l_uintptr_t sem_pending_last;
189 struct l_ipc_perm shm_perm;
198 l_uintptr_t private2;
199 l_uintptr_t private3;
203 linux_to_bsd_semid_ds(struct l_semid64_ds *lsp, struct semid_ds *bsp)
206 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
207 bsp->sem_otime = lsp->sem_otime;
208 bsp->sem_ctime = lsp->sem_ctime;
209 bsp->sem_nsems = lsp->sem_nsems;
213 bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid64_ds *lsp)
216 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
217 lsp->sem_otime = bsp->sem_otime;
218 lsp->sem_ctime = bsp->sem_ctime;
219 lsp->sem_nsems = bsp->sem_nsems;
223 linux_to_bsd_shmid_ds(struct l_shmid64_ds *lsp, struct shmid_ds *bsp)
226 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
227 bsp->shm_segsz = lsp->shm_segsz;
228 bsp->shm_lpid = lsp->shm_lpid;
229 bsp->shm_cpid = lsp->shm_cpid;
230 bsp->shm_nattch = lsp->shm_nattch;
231 bsp->shm_atime = lsp->shm_atime;
232 bsp->shm_dtime = lsp->shm_dtime;
233 bsp->shm_ctime = lsp->shm_ctime;
237 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid64_ds *lsp)
240 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
241 lsp->shm_segsz = bsp->shm_segsz;
242 lsp->shm_lpid = bsp->shm_lpid;
243 lsp->shm_cpid = bsp->shm_cpid;
244 lsp->shm_nattch = bsp->shm_nattch;
245 lsp->shm_atime = bsp->shm_atime;
246 lsp->shm_dtime = bsp->shm_dtime;
247 lsp->shm_ctime = bsp->shm_ctime;
251 linux_to_bsd_msqid_ds(struct l_msqid64_ds *lsp, struct msqid_ds *bsp)
254 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
255 bsp->msg_cbytes = lsp->msg_cbytes;
256 bsp->msg_qnum = lsp->msg_qnum;
257 bsp->msg_qbytes = lsp->msg_qbytes;
258 bsp->msg_lspid = lsp->msg_lspid;
259 bsp->msg_lrpid = lsp->msg_lrpid;
260 bsp->msg_stime = lsp->msg_stime;
261 bsp->msg_rtime = lsp->msg_rtime;
262 bsp->msg_ctime = lsp->msg_ctime;
266 bsd_to_linux_msqid_ds(struct msqid_ds *bsp, struct l_msqid64_ds *lsp)
269 bsd_to_linux_ipc_perm(&bsp->msg_perm, &lsp->msg_perm);
270 lsp->msg_cbytes = bsp->msg_cbytes;
271 lsp->msg_qnum = bsp->msg_qnum;
272 lsp->msg_qbytes = bsp->msg_qbytes;
273 lsp->msg_lspid = bsp->msg_lspid;
274 lsp->msg_lrpid = bsp->msg_lrpid;
275 lsp->msg_stime = bsp->msg_stime;
276 lsp->msg_rtime = bsp->msg_rtime;
277 lsp->msg_ctime = bsp->msg_ctime;
281 linux_ipc64_perm_to_ipc_perm(struct l_ipc64_perm *in, struct l_ipc_perm *out)
287 out->cuid = in->cuid;
288 out->cgid = in->cgid;
289 out->mode = in->mode;
292 /* Linux does not check overflow */
293 if (out->uid != in->uid || out->gid != in->gid ||
294 out->cuid != in->cuid || out->cgid != in->cgid ||
295 out->mode != in->mode)
302 linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
304 struct l_msqid_ds linux_msqid;
307 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
308 return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
310 error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
314 bzero(linux_msqid64, sizeof(*linux_msqid64));
316 linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
317 linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
318 linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
319 if (linux_msqid.msg_qbytes == 0)
320 linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
322 linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
328 linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
330 struct l_msqid_ds linux_msqid;
333 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
334 return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
336 bzero(&linux_msqid, sizeof(linux_msqid));
338 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
339 &linux_msqid.msg_perm);
343 linux_msqid.msg_stime = linux_msqid64->msg_stime;
344 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
345 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
347 if (linux_msqid64->msg_cbytes > USHRT_MAX)
348 linux_msqid.msg_cbytes = USHRT_MAX;
350 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
351 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
352 if (linux_msqid64->msg_qnum > USHRT_MAX)
353 linux_msqid.msg_qnum = USHRT_MAX;
355 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
356 if (linux_msqid64->msg_qbytes > USHRT_MAX)
357 linux_msqid.msg_qbytes = USHRT_MAX;
359 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
360 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
361 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
362 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
364 /* Linux does not check overflow */
365 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
366 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
367 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
370 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
375 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
377 struct l_semid_ds linux_semid;
380 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
381 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
383 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
387 bzero(linux_semid64, sizeof(*linux_semid64));
389 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
390 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
391 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
397 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
399 struct l_semid_ds linux_semid;
402 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
403 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
405 bzero(&linux_semid, sizeof(linux_semid));
407 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
408 &linux_semid.sem_perm);
412 linux_semid.sem_otime = linux_semid64->sem_otime;
413 linux_semid.sem_ctime = linux_semid64->sem_ctime;
414 linux_semid.sem_nsems = linux_semid64->sem_nsems;
416 /* Linux does not check overflow */
417 if (linux_semid.sem_otime != linux_semid64->sem_otime ||
418 linux_semid.sem_ctime != linux_semid64->sem_ctime ||
419 linux_semid.sem_nsems != linux_semid64->sem_nsems)
422 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
427 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
429 struct l_shmid_ds linux_shmid;
432 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
433 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
435 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
439 bzero(linux_shmid64, sizeof(*linux_shmid64));
441 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
442 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
443 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
449 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
451 struct l_shmid_ds linux_shmid;
454 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
455 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
457 bzero(&linux_shmid, sizeof(linux_shmid));
459 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
460 &linux_shmid.shm_perm);
464 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
465 linux_shmid.shm_atime = linux_shmid64->shm_atime;
466 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
467 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
468 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
469 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
470 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
472 /* Linux does not check overflow */
473 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
474 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
475 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
476 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
477 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
478 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
479 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
482 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
487 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
490 struct l_shminfo linux_shminfo;
492 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
493 return (copyout(linux_shminfo64, uaddr,
494 sizeof(*linux_shminfo64)));
496 bzero(&linux_shminfo, sizeof(linux_shminfo));
498 linux_shminfo.shmmax = linux_shminfo64->shmmax;
499 linux_shminfo.shmmin = linux_shminfo64->shmmin;
500 linux_shminfo.shmmni = linux_shminfo64->shmmni;
501 linux_shminfo.shmseg = linux_shminfo64->shmseg;
502 linux_shminfo.shmall = linux_shminfo64->shmall;
504 return (copyout(&linux_shminfo, uaddr,
505 sizeof(linux_shminfo)));
510 linux_semop(struct thread *td, struct linux_semop_args *args)
512 struct semop_args /* {
518 if (args->nsops < 1 || args->semid < 0)
520 bsd_args.semid = args->semid;
521 bsd_args.sops = PTRIN(args->tsops);
522 bsd_args.nsops = args->nsops;
523 return (sys_semop(td, &bsd_args));
527 linux_semget(struct thread *td, struct linux_semget_args *args)
529 struct semget_args /* {
537 bsd_args.key = args->key;
538 bsd_args.nsems = args->nsems;
539 bsd_args.semflg = args->semflg;
540 return (sys_semget(td, &bsd_args));
544 linux_semctl(struct thread *td, struct linux_semctl_args *args)
546 struct l_semid64_ds linux_semid64;
547 struct l_seminfo linux_seminfo;
548 struct semid_ds semid;
553 switch (args->cmd & ~LINUX_IPC_64) {
571 semun.val = args->arg.val;
575 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
576 &linux_semid64, PTRIN(args->arg.buf));
579 linux_to_bsd_semid_ds(&linux_semid64, &semid);
581 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
586 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
590 bsd_to_linux_semid_ds(&semid, &linux_semid64);
591 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
592 &linux_semid64, PTRIN(args->arg.buf)));
596 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
600 bsd_to_linux_semid_ds(&semid, &linux_semid64);
601 error = linux_semid_pushdown(args->cmd & LINUX_IPC_64,
602 &linux_semid64, PTRIN(args->arg.buf));
604 td->td_retval[0] = rval;
608 bcopy(&seminfo, &linux_seminfo.semmni, sizeof(linux_seminfo) -
609 sizeof(linux_seminfo.semmap) );
611 * Linux does not use the semmap field but populates it with
612 * the defined value from SEMMAP, which really is redefined to
613 * SEMMNS, which they define as SEMMNI * SEMMSL. Try to
614 * simulate this returning our dynamic semmns value.
616 linux_seminfo.semmap = linux_seminfo.semmns;
617 /* XXX BSD equivalent?
618 #define used_semids 10
620 linux_seminfo.semusz = used_semids;
621 linux_seminfo.semaem = used_sems;
623 error = copyout(&linux_seminfo,
624 PTRIN(args->arg.buf), sizeof(linux_seminfo));
628 * TODO: Linux return the last assigned id, not the semmni.
630 td->td_retval[0] = seminfo.semmni;
634 semun.array = PTRIN(args->arg.array);
638 semun.array = PTRIN(args->arg.array);
641 linux_msg(td, "ipc type %d is not implemented",
642 args->cmd & ~LINUX_IPC_64);
645 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
650 linux_msgsnd(struct thread *td, struct linux_msgsnd_args *args)
657 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
659 msgp = PTRIN(args->msgp);
660 if ((error = copyin(msgp, &lmtype, sizeof(lmtype))) != 0)
662 mtype = (long)lmtype;
663 return (kern_msgsnd(td, args->msqid,
664 (const char *)msgp + sizeof(lmtype),
665 args->msgsz, args->msgflg, mtype));
669 linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
676 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
678 msgp = PTRIN(args->msgp);
679 if ((error = kern_msgrcv(td, args->msqid,
680 (char *)msgp + sizeof(lmtype), args->msgsz,
681 args->msgtyp, args->msgflg, &mtype)) != 0)
683 lmtype = (l_long)mtype;
684 return (copyout(&lmtype, msgp, sizeof(lmtype)));
688 linux_msgget(struct thread *td, struct linux_msgget_args *args)
690 struct msgget_args /* {
695 bsd_args.key = args->key;
696 bsd_args.msgflg = args->msgflg;
697 return (sys_msgget(td, &bsd_args));
701 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
704 struct l_msqid64_ds linux_msqid64;
705 struct msqid_ds bsd_msqid;
707 bsd_cmd = args->cmd & ~LINUX_IPC_64;
710 case LINUX_MSG_INFO: {
711 struct l_msginfo linux_msginfo;
714 * XXX MSG_INFO uses the same data structure but returns different
715 * dynamic counters in msgpool, msgmap, and msgtql fields.
717 linux_msginfo.msgpool = (long)msginfo.msgmni *
718 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
719 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
720 linux_msginfo.msgmax = msginfo.msgmax;
721 linux_msginfo.msgmnb = msginfo.msgmnb;
722 linux_msginfo.msgmni = msginfo.msgmni;
723 linux_msginfo.msgssz = msginfo.msgssz;
724 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
725 linux_msginfo.msgseg = msginfo.msgseg;
726 error = copyout(&linux_msginfo, PTRIN(args->buf),
727 sizeof(linux_msginfo));
729 td->td_retval[0] = msginfo.msgmni; /* XXX */
735 * TODO: implement this
736 * case LINUX_MSG_STAT:
743 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
744 &linux_msqid64, PTRIN(args->buf));
747 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
759 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
761 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
763 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
767 if (bsd_cmd == LINUX_IPC_STAT) {
768 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
769 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
770 &linux_msqid64, PTRIN(args->buf)));
777 linux_shmat(struct thread *td, struct linux_shmat_args *args)
779 struct shmat_args /* {
785 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
789 bsd_args.shmid = args->shmid;
790 bsd_args.shmaddr = PTRIN(args->shmaddr);
791 bsd_args.shmflg = args->shmflg;
792 if ((error = sys_shmat(td, &bsd_args)))
794 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
795 addr = td->td_retval[0];
796 if ((error = copyout(&addr, PTRIN(args->raddr), sizeof(addr))))
798 td->td_retval[0] = 0;
804 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
806 struct shmdt_args /* {
810 bsd_args.shmaddr = PTRIN(args->shmaddr);
811 return (sys_shmdt(td, &bsd_args));
815 linux_shmget(struct thread *td, struct linux_shmget_args *args)
817 struct shmget_args /* {
823 bsd_args.key = args->key;
824 bsd_args.size = args->size;
825 bsd_args.shmflg = args->shmflg;
826 return (sys_shmget(td, &bsd_args));
830 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
832 struct l_shmid64_ds linux_shmid64;
833 struct l_shminfo64 linux_shminfo64;
834 struct l_shm_info linux_shm_info;
835 struct shmid_ds bsd_shmid;
838 switch (args->cmd & ~LINUX_IPC_64) {
840 case LINUX_IPC_INFO: {
841 struct shminfo bsd_shminfo;
843 /* Perform shmctl wanting removed segments lookup */
844 error = kern_shmctl(td, args->shmid, IPC_INFO,
845 (void *)&bsd_shminfo, NULL);
849 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
851 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
852 &linux_shminfo64, PTRIN(args->buf)));
855 case LINUX_SHM_INFO: {
856 struct shm_info bsd_shm_info;
858 /* Perform shmctl wanting removed segments lookup */
859 error = kern_shmctl(td, args->shmid, SHM_INFO,
860 (void *)&bsd_shm_info, NULL);
864 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
866 return (copyout(&linux_shm_info, PTRIN(args->buf),
867 sizeof(struct l_shm_info)));
871 /* Perform shmctl wanting removed segments lookup */
872 error = kern_shmctl(td, args->shmid, IPC_STAT,
873 (void *)&bsd_shmid, NULL);
877 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
879 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
880 &linux_shmid64, PTRIN(args->buf)));
883 /* Perform shmctl wanting removed segments lookup */
884 error = kern_shmctl(td, args->shmid, IPC_STAT,
885 (void *)&bsd_shmid, NULL);
889 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
891 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
892 &linux_shmid64, PTRIN(args->buf)));
895 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
896 &linux_shmid64, PTRIN(args->buf));
900 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
902 /* Perform shmctl wanting removed segments lookup */
903 return (kern_shmctl(td, args->shmid, IPC_SET,
904 (void *)&bsd_shmid, NULL));
906 case LINUX_IPC_RMID: {
912 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
913 &linux_shmid64, PTRIN(args->buf));
916 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
917 buf = (void *)&bsd_shmid;
919 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
924 case LINUX_SHM_UNLOCK:
927 linux_msg(td, "ipc type %d not implemented",
928 args->cmd & ~LINUX_IPC_64);
933 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
934 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
935 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);