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_timer.h>
55 #include <compat/linux/linux_util.h>
93 l_ulong shm_tot; /* total allocated shm */
94 l_ulong shm_rss; /* total resident shm */
95 l_ulong shm_swp; /* total swapped shm */
96 l_ulong swap_attempts;
97 l_ulong swap_successes;
112 bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo64 *lpp)
115 lpp->shmmax = bpp->shmmax;
116 lpp->shmmin = bpp->shmmin;
117 lpp->shmmni = bpp->shmmni;
118 lpp->shmseg = bpp->shmseg;
119 lpp->shmall = bpp->shmall;
123 bsd_to_linux_shm_info( struct shm_info *bpp, struct l_shm_info *lpp)
126 lpp->used_ids = bpp->used_ids;
127 lpp->shm_tot = bpp->shm_tot;
128 lpp->shm_rss = bpp->shm_rss;
129 lpp->shm_swp = bpp->shm_swp;
130 lpp->swap_attempts = bpp->swap_attempts;
131 lpp->swap_successes = bpp->swap_successes;
135 linux_to_bsd_ipc_perm(struct l_ipc64_perm *lpp, struct ipc_perm *bpp)
141 bpp->cuid = lpp->cuid;
142 bpp->cgid = lpp->cgid;
143 bpp->mode = lpp->mode;
148 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc64_perm *lpp)
154 lpp->cuid = bpp->cuid;
155 lpp->cgid = bpp->cgid;
156 lpp->mode = bpp->mode & (S_IRWXU|S_IRWXG|S_IRWXO);
161 struct l_ipc_perm msg_perm;
162 l_uintptr_t msg_first; /* first message on queue,unused */
163 l_uintptr_t msg_last; /* last message in queue,unused */
164 l_time_t msg_stime; /* last msgsnd time */
165 l_time_t msg_rtime; /* last msgrcv time */
166 l_time_t msg_ctime; /* last change time */
167 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
168 l_ulong msg_lqbytes; /* ditto */
169 l_ushort msg_cbytes; /* current number of bytes on queue */
170 l_ushort msg_qnum; /* number of messages in queue */
171 l_ushort msg_qbytes; /* max number of bytes on queue */
172 l_pid_t msg_lspid; /* pid of last msgsnd */
173 l_pid_t msg_lrpid; /* last receive pid */
177 struct l_ipc_perm sem_perm;
180 l_uintptr_t sem_base;
181 l_uintptr_t sem_pending;
182 l_uintptr_t sem_pending_last;
188 struct l_ipc_perm shm_perm;
197 l_uintptr_t private2;
198 l_uintptr_t private3;
202 linux_to_bsd_semid_ds(struct l_semid64_ds *lsp, struct semid_ds *bsp)
205 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
206 bsp->sem_otime = lsp->sem_otime;
207 bsp->sem_ctime = lsp->sem_ctime;
208 bsp->sem_nsems = lsp->sem_nsems;
212 bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid64_ds *lsp)
215 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
216 lsp->sem_otime = bsp->sem_otime;
217 lsp->sem_ctime = bsp->sem_ctime;
218 lsp->sem_nsems = bsp->sem_nsems;
222 linux_to_bsd_shmid_ds(struct l_shmid64_ds *lsp, struct shmid_ds *bsp)
225 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
226 bsp->shm_segsz = lsp->shm_segsz;
227 bsp->shm_lpid = lsp->shm_lpid;
228 bsp->shm_cpid = lsp->shm_cpid;
229 bsp->shm_nattch = lsp->shm_nattch;
230 bsp->shm_atime = lsp->shm_atime;
231 bsp->shm_dtime = lsp->shm_dtime;
232 bsp->shm_ctime = lsp->shm_ctime;
236 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid64_ds *lsp)
239 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
240 lsp->shm_segsz = bsp->shm_segsz;
241 lsp->shm_lpid = bsp->shm_lpid;
242 lsp->shm_cpid = bsp->shm_cpid;
243 lsp->shm_nattch = bsp->shm_nattch;
244 lsp->shm_atime = bsp->shm_atime;
245 lsp->shm_dtime = bsp->shm_dtime;
246 lsp->shm_ctime = bsp->shm_ctime;
250 linux_to_bsd_msqid_ds(struct l_msqid64_ds *lsp, struct msqid_ds *bsp)
253 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
254 bsp->msg_cbytes = lsp->msg_cbytes;
255 bsp->msg_qnum = lsp->msg_qnum;
256 bsp->msg_qbytes = lsp->msg_qbytes;
257 bsp->msg_lspid = lsp->msg_lspid;
258 bsp->msg_lrpid = lsp->msg_lrpid;
259 bsp->msg_stime = lsp->msg_stime;
260 bsp->msg_rtime = lsp->msg_rtime;
261 bsp->msg_ctime = lsp->msg_ctime;
265 bsd_to_linux_msqid_ds(struct msqid_ds *bsp, struct l_msqid64_ds *lsp)
268 bsd_to_linux_ipc_perm(&bsp->msg_perm, &lsp->msg_perm);
269 lsp->msg_cbytes = bsp->msg_cbytes;
270 lsp->msg_qnum = bsp->msg_qnum;
271 lsp->msg_qbytes = bsp->msg_qbytes;
272 lsp->msg_lspid = bsp->msg_lspid;
273 lsp->msg_lrpid = bsp->msg_lrpid;
274 lsp->msg_stime = bsp->msg_stime;
275 lsp->msg_rtime = bsp->msg_rtime;
276 lsp->msg_ctime = bsp->msg_ctime;
280 linux_ipc64_perm_to_ipc_perm(struct l_ipc64_perm *in, struct l_ipc_perm *out)
286 out->cuid = in->cuid;
287 out->cgid = in->cgid;
288 out->mode = in->mode;
291 /* Linux does not check overflow */
292 if (out->uid != in->uid || out->gid != in->gid ||
293 out->cuid != in->cuid || out->cgid != in->cgid ||
294 out->mode != in->mode)
301 linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
303 struct l_msqid_ds linux_msqid;
306 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
307 return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
309 error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
313 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;
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));
334 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
335 &linux_msqid.msg_perm);
339 linux_msqid.msg_stime = linux_msqid64->msg_stime;
340 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
341 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
343 if (linux_msqid64->msg_cbytes > USHRT_MAX)
344 linux_msqid.msg_cbytes = USHRT_MAX;
346 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
347 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
348 if (linux_msqid64->msg_qnum > USHRT_MAX)
349 linux_msqid.msg_qnum = USHRT_MAX;
351 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
352 if (linux_msqid64->msg_qbytes > USHRT_MAX)
353 linux_msqid.msg_qbytes = USHRT_MAX;
355 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
356 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
357 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
358 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
360 /* Linux does not check overflow */
361 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
362 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
363 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
365 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
369 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
371 struct l_semid_ds linux_semid;
374 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
375 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
376 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
380 bzero(linux_semid64, sizeof(*linux_semid64));
381 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
382 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
383 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
388 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
390 struct l_semid_ds linux_semid;
393 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
394 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
396 bzero(&linux_semid, sizeof(linux_semid));
397 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
398 &linux_semid.sem_perm);
402 linux_semid.sem_otime = linux_semid64->sem_otime;
403 linux_semid.sem_ctime = linux_semid64->sem_ctime;
404 linux_semid.sem_nsems = linux_semid64->sem_nsems;
406 /* Linux does not check overflow */
407 if (linux_semid.sem_otime != linux_semid64->sem_otime ||
408 linux_semid.sem_ctime != linux_semid64->sem_ctime ||
409 linux_semid.sem_nsems != linux_semid64->sem_nsems)
411 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
415 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
417 struct l_shmid_ds linux_shmid;
420 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
421 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
423 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
427 bzero(linux_shmid64, sizeof(*linux_shmid64));
428 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
429 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
430 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
435 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
437 struct l_shmid_ds linux_shmid;
440 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
441 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
443 bzero(&linux_shmid, sizeof(linux_shmid));
444 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
445 &linux_shmid.shm_perm);
449 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
450 linux_shmid.shm_atime = linux_shmid64->shm_atime;
451 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
452 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
453 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
454 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
455 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
457 /* Linux does not check overflow */
458 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
459 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
460 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
461 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
462 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
463 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
464 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
466 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
470 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
473 struct l_shminfo linux_shminfo;
475 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
476 return (copyout(linux_shminfo64, uaddr,
477 sizeof(*linux_shminfo64)));
479 bzero(&linux_shminfo, sizeof(linux_shminfo));
480 linux_shminfo.shmmax = linux_shminfo64->shmmax;
481 linux_shminfo.shmmin = linux_shminfo64->shmmin;
482 linux_shminfo.shmmni = linux_shminfo64->shmmni;
483 linux_shminfo.shmseg = linux_shminfo64->shmseg;
484 linux_shminfo.shmall = linux_shminfo64->shmall;
485 return (copyout(&linux_shminfo, uaddr, sizeof(linux_shminfo)));
488 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
490 linux_semtimedop_time64(struct thread *td, struct linux_semtimedop_time64_args *args)
492 struct timespec ts, *tsa;
496 error = linux_get_timespec64(&ts, args->timeout);
503 return (kern_semop(td, args->semid, PTRIN(args->tsops),
506 #endif /* __i386__) || (__amd64__ && COMPAT_LINUX32) */
509 linux_semtimedop(struct thread *td, struct linux_semtimedop_args *args)
511 struct timespec ts, *tsa;
515 error = linux_get_timespec(&ts, args->timeout);
522 return (kern_semop(td, args->semid, PTRIN(args->tsops),
527 linux_semget(struct thread *td, struct linux_semget_args *args)
529 struct semget_args bsd_args = {
531 .nsems = args->nsems,
532 .semflg = args->semflg
537 return (sys_semget(td, &bsd_args));
541 linux_semctl(struct thread *td, struct linux_semctl_args *args)
543 struct l_semid64_ds linux_semid64;
544 struct l_seminfo linux_seminfo;
545 struct semid_ds semid;
550 memset(&linux_seminfo, 0, sizeof(linux_seminfo));
551 memset(&linux_semid64, 0, sizeof(linux_semid64));
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 bsd_args = {
692 .msgflg = args->msgflg
695 return (sys_msgget(td, &bsd_args));
699 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
702 struct l_msqid64_ds linux_msqid64;
703 struct msqid_ds bsd_msqid;
705 memset(&linux_msqid64, 0, sizeof(linux_msqid64));
707 bsd_cmd = args->cmd & ~LINUX_IPC_64;
710 case LINUX_MSG_INFO: {
711 struct l_msginfo linux_msginfo;
713 memset(&linux_msginfo, 0, sizeof(linux_msginfo));
715 * XXX MSG_INFO uses the same data structure but returns different
716 * dynamic counters in msgpool, msgmap, and msgtql fields.
718 linux_msginfo.msgpool = (long)msginfo.msgmni *
719 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
720 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
721 linux_msginfo.msgmax = msginfo.msgmax;
722 linux_msginfo.msgmnb = msginfo.msgmnb;
723 linux_msginfo.msgmni = msginfo.msgmni;
724 linux_msginfo.msgssz = msginfo.msgssz;
725 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
726 linux_msginfo.msgseg = msginfo.msgseg;
727 error = copyout(&linux_msginfo, PTRIN(args->buf),
728 sizeof(linux_msginfo));
730 td->td_retval[0] = msginfo.msgmni; /* XXX */
736 * TODO: implement this
737 * case LINUX_MSG_STAT:
744 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
745 &linux_msqid64, PTRIN(args->buf));
748 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
760 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
762 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
764 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
768 if (bsd_cmd == LINUX_IPC_STAT) {
769 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
770 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
771 &linux_msqid64, PTRIN(args->buf)));
778 linux_shmat(struct thread *td, struct linux_shmat_args *args)
780 struct shmat_args bsd_args = {
781 .shmid = args->shmid,
782 .shmaddr = PTRIN(args->shmaddr),
783 .shmflg = args->shmflg
786 return (sys_shmat(td, &bsd_args));
790 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
792 struct shmdt_args bsd_args = {
793 .shmaddr = PTRIN(args->shmaddr)
796 return (sys_shmdt(td, &bsd_args));
800 linux_shmget(struct thread *td, struct linux_shmget_args *args)
802 struct shmget_args bsd_args = {
805 .shmflg = args->shmflg
808 return (sys_shmget(td, &bsd_args));
812 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
814 struct l_shmid64_ds linux_shmid64;
815 struct l_shminfo64 linux_shminfo64;
816 struct l_shm_info linux_shm_info;
817 struct shmid_ds bsd_shmid;
820 memset(&linux_shm_info, 0, sizeof(linux_shm_info));
821 memset(&linux_shmid64, 0, sizeof(linux_shmid64));
822 memset(&linux_shminfo64, 0, sizeof(linux_shminfo64));
824 switch (args->cmd & ~LINUX_IPC_64) {
825 case LINUX_IPC_INFO: {
826 struct shminfo bsd_shminfo;
828 /* Perform shmctl wanting removed segments lookup */
829 error = kern_shmctl(td, args->shmid, IPC_INFO,
830 (void *)&bsd_shminfo, NULL);
834 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
836 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
837 &linux_shminfo64, PTRIN(args->buf)));
840 case LINUX_SHM_INFO: {
841 struct shm_info bsd_shm_info;
843 /* Perform shmctl wanting removed segments lookup */
844 error = kern_shmctl(td, args->shmid, SHM_INFO,
845 (void *)&bsd_shm_info, NULL);
849 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
851 return (copyout(&linux_shm_info, PTRIN(args->buf),
852 sizeof(struct l_shm_info)));
856 /* Perform shmctl wanting removed segments lookup */
857 error = kern_shmctl(td, args->shmid, IPC_STAT,
858 (void *)&bsd_shmid, NULL);
862 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
864 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
865 &linux_shmid64, PTRIN(args->buf)));
868 /* Perform shmctl wanting removed segments lookup */
869 error = kern_shmctl(td, args->shmid, IPC_STAT,
870 (void *)&bsd_shmid, NULL);
874 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
876 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
877 &linux_shmid64, PTRIN(args->buf)));
880 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
881 &linux_shmid64, PTRIN(args->buf));
885 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
887 /* Perform shmctl wanting removed segments lookup */
888 return (kern_shmctl(td, args->shmid, IPC_SET,
889 (void *)&bsd_shmid, NULL));
891 case LINUX_IPC_RMID: {
897 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
898 &linux_shmid64, PTRIN(args->buf));
901 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
902 buf = (void *)&bsd_shmid;
904 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
909 case LINUX_SHM_UNLOCK:
912 linux_msg(td, "ipc type %d not implemented",
913 args->cmd & ~LINUX_IPC_64);
918 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
919 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
920 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);