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/limits.h>
39 #include <sys/syscallsubr.h>
40 #include <sys/sysent.h>
41 #include <sys/sysproto.h>
44 #include <machine/../linux32/linux.h>
45 #include <machine/../linux32/linux32_proto.h>
47 #include <machine/../linux/linux.h>
48 #include <machine/../linux/linux_proto.h>
50 #include <compat/linux/linux_ipc.h>
51 #include <compat/linux/linux_ipc64.h>
52 #include <compat/linux/linux_time.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 & (S_IRWXU|S_IRWXG|S_IRWXO);
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));
312 linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
313 linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
314 linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
315 if (linux_msqid.msg_qbytes == 0)
316 linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
318 linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
323 linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
325 struct l_msqid_ds linux_msqid;
328 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
329 return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
331 bzero(&linux_msqid, sizeof(linux_msqid));
332 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
333 &linux_msqid.msg_perm);
337 linux_msqid.msg_stime = linux_msqid64->msg_stime;
338 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
339 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
341 if (linux_msqid64->msg_cbytes > USHRT_MAX)
342 linux_msqid.msg_cbytes = USHRT_MAX;
344 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
345 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
346 if (linux_msqid64->msg_qnum > USHRT_MAX)
347 linux_msqid.msg_qnum = USHRT_MAX;
349 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
350 if (linux_msqid64->msg_qbytes > USHRT_MAX)
351 linux_msqid.msg_qbytes = USHRT_MAX;
353 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
354 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
355 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
356 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
358 /* Linux does not check overflow */
359 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
360 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
361 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
363 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
367 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
369 struct l_semid_ds linux_semid;
372 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
373 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
374 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
378 bzero(linux_semid64, sizeof(*linux_semid64));
379 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
380 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
381 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
386 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
388 struct l_semid_ds linux_semid;
391 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
392 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
394 bzero(&linux_semid, sizeof(linux_semid));
395 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
396 &linux_semid.sem_perm);
400 linux_semid.sem_otime = linux_semid64->sem_otime;
401 linux_semid.sem_ctime = linux_semid64->sem_ctime;
402 linux_semid.sem_nsems = linux_semid64->sem_nsems;
404 /* Linux does not check overflow */
405 if (linux_semid.sem_otime != linux_semid64->sem_otime ||
406 linux_semid.sem_ctime != linux_semid64->sem_ctime ||
407 linux_semid.sem_nsems != linux_semid64->sem_nsems)
409 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
413 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
415 struct l_shmid_ds linux_shmid;
418 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
419 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
421 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
425 bzero(linux_shmid64, sizeof(*linux_shmid64));
426 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
427 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
428 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
433 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
435 struct l_shmid_ds linux_shmid;
438 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
439 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
441 bzero(&linux_shmid, sizeof(linux_shmid));
442 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
443 &linux_shmid.shm_perm);
447 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
448 linux_shmid.shm_atime = linux_shmid64->shm_atime;
449 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
450 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
451 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
452 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
453 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
455 /* Linux does not check overflow */
456 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
457 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
458 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
459 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
460 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
461 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
462 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
464 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
468 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
471 struct l_shminfo linux_shminfo;
473 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
474 return (copyout(linux_shminfo64, uaddr,
475 sizeof(*linux_shminfo64)));
477 bzero(&linux_shminfo, sizeof(linux_shminfo));
478 linux_shminfo.shmmax = linux_shminfo64->shmmax;
479 linux_shminfo.shmmin = linux_shminfo64->shmmin;
480 linux_shminfo.shmmni = linux_shminfo64->shmmni;
481 linux_shminfo.shmseg = linux_shminfo64->shmseg;
482 linux_shminfo.shmall = linux_shminfo64->shmall;
483 return (copyout(&linux_shminfo, uaddr, sizeof(linux_shminfo)));
486 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
488 linux_semtimedop_time64(struct thread *td, struct linux_semtimedop_time64_args *args)
490 struct timespec ts, *tsa;
494 error = linux_get_timespec64(&ts, args->timeout);
501 return (kern_semop(td, args->semid, PTRIN(args->tsops),
504 #endif /* __i386__) || (__amd64__ && COMPAT_LINUX32) */
507 linux_semtimedop(struct thread *td, struct linux_semtimedop_args *args)
509 struct timespec ts, *tsa;
513 error = linux_get_timespec(&ts, args->timeout);
520 return (kern_semop(td, args->semid, PTRIN(args->tsops),
525 linux_semget(struct thread *td, struct linux_semget_args *args)
527 struct semget_args bsd_args = {
529 .nsems = args->nsems,
530 .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 memset(&linux_seminfo, 0, sizeof(linux_seminfo));
549 memset(&linux_semid64, 0, sizeof(linux_semid64));
551 switch (args->cmd & ~LINUX_IPC_64) {
569 semun.val = args->arg.val;
573 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
574 &linux_semid64, PTRIN(args->arg.buf));
577 linux_to_bsd_semid_ds(&linux_semid64, &semid);
579 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
584 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
588 bsd_to_linux_semid_ds(&semid, &linux_semid64);
589 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
590 &linux_semid64, PTRIN(args->arg.buf)));
594 error = kern_semctl(td, args->semid, args->semnum, cmd, &semun,
598 bsd_to_linux_semid_ds(&semid, &linux_semid64);
599 error = linux_semid_pushdown(args->cmd & LINUX_IPC_64,
600 &linux_semid64, PTRIN(args->arg.buf));
602 td->td_retval[0] = rval;
606 bcopy(&seminfo, &linux_seminfo.semmni, sizeof(linux_seminfo) -
607 sizeof(linux_seminfo.semmap) );
609 * Linux does not use the semmap field but populates it with
610 * the defined value from SEMMAP, which really is redefined to
611 * SEMMNS, which they define as SEMMNI * SEMMSL. Try to
612 * simulate this returning our dynamic semmns value.
614 linux_seminfo.semmap = linux_seminfo.semmns;
615 /* XXX BSD equivalent?
616 #define used_semids 10
618 linux_seminfo.semusz = used_semids;
619 linux_seminfo.semaem = used_sems;
621 error = copyout(&linux_seminfo,
622 PTRIN(args->arg.buf), sizeof(linux_seminfo));
626 * TODO: Linux return the last assigned id, not the semmni.
628 td->td_retval[0] = seminfo.semmni;
632 semun.array = PTRIN(args->arg.array);
636 semun.array = PTRIN(args->arg.array);
639 linux_msg(td, "ipc type %d is not implemented",
640 args->cmd & ~LINUX_IPC_64);
643 return (kern_semctl(td, args->semid, args->semnum, cmd, &semun,
648 linux_msgsnd(struct thread *td, struct linux_msgsnd_args *args)
655 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
657 msgp = PTRIN(args->msgp);
658 if ((error = copyin(msgp, &lmtype, sizeof(lmtype))) != 0)
660 mtype = (long)lmtype;
661 return (kern_msgsnd(td, args->msqid,
662 (const char *)msgp + sizeof(lmtype),
663 args->msgsz, args->msgflg, mtype));
667 linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
674 if ((l_long)args->msgsz < 0 || args->msgsz > (l_long)msginfo.msgmax)
676 msgp = PTRIN(args->msgp);
677 if ((error = kern_msgrcv(td, args->msqid,
678 (char *)msgp + sizeof(lmtype), args->msgsz,
679 args->msgtyp, args->msgflg, &mtype)) != 0)
681 lmtype = (l_long)mtype;
682 return (copyout(&lmtype, msgp, sizeof(lmtype)));
686 linux_msgget(struct thread *td, struct linux_msgget_args *args)
688 struct msgget_args bsd_args = {
690 .msgflg = args->msgflg
693 return (sys_msgget(td, &bsd_args));
697 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
700 struct l_msqid64_ds linux_msqid64;
701 struct msqid_ds bsd_msqid;
703 memset(&linux_msqid64, 0, sizeof(linux_msqid64));
705 bsd_cmd = args->cmd & ~LINUX_IPC_64;
708 case LINUX_MSG_INFO: {
709 struct l_msginfo linux_msginfo;
711 memset(&linux_msginfo, 0, sizeof(linux_msginfo));
713 * XXX MSG_INFO uses the same data structure but returns different
714 * dynamic counters in msgpool, msgmap, and msgtql fields.
716 linux_msginfo.msgpool = (long)msginfo.msgmni *
717 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
718 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
719 linux_msginfo.msgmax = msginfo.msgmax;
720 linux_msginfo.msgmnb = msginfo.msgmnb;
721 linux_msginfo.msgmni = msginfo.msgmni;
722 linux_msginfo.msgssz = msginfo.msgssz;
723 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
724 linux_msginfo.msgseg = msginfo.msgseg;
725 error = copyout(&linux_msginfo, PTRIN(args->buf),
726 sizeof(linux_msginfo));
728 td->td_retval[0] = msginfo.msgmni; /* XXX */
734 * TODO: implement this
735 * case LINUX_MSG_STAT:
742 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
743 &linux_msqid64, PTRIN(args->buf));
746 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
758 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
760 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
762 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
766 if (bsd_cmd == LINUX_IPC_STAT) {
767 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
768 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
769 &linux_msqid64, PTRIN(args->buf)));
776 linux_shmat(struct thread *td, struct linux_shmat_args *args)
778 struct shmat_args bsd_args = {
779 .shmid = args->shmid,
780 .shmaddr = PTRIN(args->shmaddr),
781 .shmflg = args->shmflg
784 return (sys_shmat(td, &bsd_args));
788 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
790 struct shmdt_args bsd_args = {
791 .shmaddr = PTRIN(args->shmaddr)
794 return (sys_shmdt(td, &bsd_args));
798 linux_shmget(struct thread *td, struct linux_shmget_args *args)
800 struct shmget_args bsd_args = {
803 .shmflg = args->shmflg
806 return (sys_shmget(td, &bsd_args));
810 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
812 struct l_shmid64_ds linux_shmid64;
813 struct l_shminfo64 linux_shminfo64;
814 struct l_shm_info linux_shm_info;
815 struct shmid_ds bsd_shmid;
818 memset(&linux_shm_info, 0, sizeof(linux_shm_info));
819 memset(&linux_shmid64, 0, sizeof(linux_shmid64));
820 memset(&linux_shminfo64, 0, sizeof(linux_shminfo64));
822 switch (args->cmd & ~LINUX_IPC_64) {
823 case LINUX_IPC_INFO: {
824 struct shminfo bsd_shminfo;
826 /* Perform shmctl wanting removed segments lookup */
827 error = kern_shmctl(td, args->shmid, IPC_INFO,
828 (void *)&bsd_shminfo, NULL);
832 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
834 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
835 &linux_shminfo64, PTRIN(args->buf)));
838 case LINUX_SHM_INFO: {
839 struct shm_info bsd_shm_info;
841 /* Perform shmctl wanting removed segments lookup */
842 error = kern_shmctl(td, args->shmid, SHM_INFO,
843 (void *)&bsd_shm_info, NULL);
847 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
849 return (copyout(&linux_shm_info, PTRIN(args->buf),
850 sizeof(struct l_shm_info)));
854 /* Perform shmctl wanting removed segments lookup */
855 error = kern_shmctl(td, args->shmid, IPC_STAT,
856 (void *)&bsd_shmid, NULL);
860 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
862 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
863 &linux_shmid64, PTRIN(args->buf)));
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 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
879 &linux_shmid64, PTRIN(args->buf));
883 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
885 /* Perform shmctl wanting removed segments lookup */
886 return (kern_shmctl(td, args->shmid, IPC_SET,
887 (void *)&bsd_shmid, NULL));
889 case LINUX_IPC_RMID: {
895 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
896 &linux_shmid64, PTRIN(args->buf));
899 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
900 buf = (void *)&bsd_shmid;
902 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
907 case LINUX_SHM_UNLOCK:
910 linux_msg(td, "ipc type %d not implemented",
911 args->cmd & ~LINUX_IPC_64);
916 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
917 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
918 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);