2 * SPDX-License-Identifier: BSD-2-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 * 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/param.h>
30 #include <sys/limits.h>
36 #include <sys/syscallsubr.h>
37 #include <sys/sysent.h>
38 #include <sys/sysproto.h>
41 #include <machine/../linux32/linux.h>
42 #include <machine/../linux32/linux32_proto.h>
44 #include <machine/../linux/linux.h>
45 #include <machine/../linux/linux_proto.h>
47 #include <compat/linux/linux_ipc.h>
48 #include <compat/linux/linux_ipc64.h>
49 #include <compat/linux/linux_time.h>
50 #include <compat/linux/linux_util.h>
88 l_ulong shm_tot; /* total allocated shm */
89 l_ulong shm_rss; /* total resident shm */
90 l_ulong shm_swp; /* total swapped shm */
91 l_ulong swap_attempts;
92 l_ulong swap_successes;
107 bsd_to_linux_shminfo( struct shminfo *bpp, struct l_shminfo64 *lpp)
110 lpp->shmmax = bpp->shmmax;
111 lpp->shmmin = bpp->shmmin;
112 lpp->shmmni = bpp->shmmni;
113 lpp->shmseg = bpp->shmseg;
114 lpp->shmall = bpp->shmall;
118 bsd_to_linux_shm_info( struct shm_info *bpp, struct l_shm_info *lpp)
121 lpp->used_ids = bpp->used_ids;
122 lpp->shm_tot = bpp->shm_tot;
123 lpp->shm_rss = bpp->shm_rss;
124 lpp->shm_swp = bpp->shm_swp;
125 lpp->swap_attempts = bpp->swap_attempts;
126 lpp->swap_successes = bpp->swap_successes;
130 linux_to_bsd_ipc_perm(struct l_ipc64_perm *lpp, struct ipc_perm *bpp)
136 bpp->cuid = lpp->cuid;
137 bpp->cgid = lpp->cgid;
138 bpp->mode = lpp->mode;
143 bsd_to_linux_ipc_perm(struct ipc_perm *bpp, struct l_ipc64_perm *lpp)
149 lpp->cuid = bpp->cuid;
150 lpp->cgid = bpp->cgid;
151 lpp->mode = bpp->mode & (S_IRWXU|S_IRWXG|S_IRWXO);
156 struct l_ipc_perm msg_perm;
157 l_uintptr_t msg_first; /* first message on queue,unused */
158 l_uintptr_t msg_last; /* last message in queue,unused */
159 l_time_t msg_stime; /* last msgsnd time */
160 l_time_t msg_rtime; /* last msgrcv time */
161 l_time_t msg_ctime; /* last change time */
162 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
163 l_ulong msg_lqbytes; /* ditto */
164 l_ushort msg_cbytes; /* current number of bytes on queue */
165 l_ushort msg_qnum; /* number of messages in queue */
166 l_ushort msg_qbytes; /* max number of bytes on queue */
167 l_pid_t msg_lspid; /* pid of last msgsnd */
168 l_pid_t msg_lrpid; /* last receive pid */
172 struct l_ipc_perm sem_perm;
175 l_uintptr_t sem_base;
176 l_uintptr_t sem_pending;
177 l_uintptr_t sem_pending_last;
183 struct l_ipc_perm shm_perm;
192 l_uintptr_t private2;
193 l_uintptr_t private3;
197 linux_to_bsd_semid_ds(struct l_semid64_ds *lsp, struct semid_ds *bsp)
200 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
201 bsp->sem_otime = lsp->sem_otime;
202 bsp->sem_ctime = lsp->sem_ctime;
203 bsp->sem_nsems = lsp->sem_nsems;
207 bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid64_ds *lsp)
210 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
211 lsp->sem_otime = bsp->sem_otime;
212 lsp->sem_ctime = bsp->sem_ctime;
213 lsp->sem_nsems = bsp->sem_nsems;
217 linux_to_bsd_shmid_ds(struct l_shmid64_ds *lsp, struct shmid_ds *bsp)
220 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
221 bsp->shm_segsz = lsp->shm_segsz;
222 bsp->shm_lpid = lsp->shm_lpid;
223 bsp->shm_cpid = lsp->shm_cpid;
224 bsp->shm_nattch = lsp->shm_nattch;
225 bsp->shm_atime = lsp->shm_atime;
226 bsp->shm_dtime = lsp->shm_dtime;
227 bsp->shm_ctime = lsp->shm_ctime;
231 bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid64_ds *lsp)
234 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
235 lsp->shm_segsz = bsp->shm_segsz;
236 lsp->shm_lpid = bsp->shm_lpid;
237 lsp->shm_cpid = bsp->shm_cpid;
238 lsp->shm_nattch = bsp->shm_nattch;
239 lsp->shm_atime = bsp->shm_atime;
240 lsp->shm_dtime = bsp->shm_dtime;
241 lsp->shm_ctime = bsp->shm_ctime;
245 linux_to_bsd_msqid_ds(struct l_msqid64_ds *lsp, struct msqid_ds *bsp)
248 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
249 bsp->msg_cbytes = lsp->msg_cbytes;
250 bsp->msg_qnum = lsp->msg_qnum;
251 bsp->msg_qbytes = lsp->msg_qbytes;
252 bsp->msg_lspid = lsp->msg_lspid;
253 bsp->msg_lrpid = lsp->msg_lrpid;
254 bsp->msg_stime = lsp->msg_stime;
255 bsp->msg_rtime = lsp->msg_rtime;
256 bsp->msg_ctime = lsp->msg_ctime;
260 bsd_to_linux_msqid_ds(struct msqid_ds *bsp, struct l_msqid64_ds *lsp)
263 bsd_to_linux_ipc_perm(&bsp->msg_perm, &lsp->msg_perm);
264 lsp->msg_cbytes = bsp->msg_cbytes;
265 lsp->msg_qnum = bsp->msg_qnum;
266 lsp->msg_qbytes = bsp->msg_qbytes;
267 lsp->msg_lspid = bsp->msg_lspid;
268 lsp->msg_lrpid = bsp->msg_lrpid;
269 lsp->msg_stime = bsp->msg_stime;
270 lsp->msg_rtime = bsp->msg_rtime;
271 lsp->msg_ctime = bsp->msg_ctime;
275 linux_ipc64_perm_to_ipc_perm(struct l_ipc64_perm *in, struct l_ipc_perm *out)
281 out->cuid = in->cuid;
282 out->cgid = in->cgid;
283 out->mode = in->mode;
286 /* Linux does not check overflow */
287 if (out->uid != in->uid || out->gid != in->gid ||
288 out->cuid != in->cuid || out->cgid != in->cgid ||
289 out->mode != in->mode)
296 linux_msqid_pullup(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
298 struct l_msqid_ds linux_msqid;
301 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
302 return (copyin(uaddr, linux_msqid64, sizeof(*linux_msqid64)));
304 error = copyin(uaddr, &linux_msqid, sizeof(linux_msqid));
308 bzero(linux_msqid64, sizeof(*linux_msqid64));
309 linux_msqid64->msg_perm.uid = linux_msqid.msg_perm.uid;
310 linux_msqid64->msg_perm.gid = linux_msqid.msg_perm.gid;
311 linux_msqid64->msg_perm.mode = linux_msqid.msg_perm.mode;
312 if (linux_msqid.msg_qbytes == 0)
313 linux_msqid64->msg_qbytes = linux_msqid.msg_lqbytes;
315 linux_msqid64->msg_qbytes = linux_msqid.msg_qbytes;
320 linux_msqid_pushdown(l_int ver, struct l_msqid64_ds *linux_msqid64, caddr_t uaddr)
322 struct l_msqid_ds linux_msqid;
325 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
326 return (copyout(linux_msqid64, uaddr, sizeof(*linux_msqid64)));
328 bzero(&linux_msqid, sizeof(linux_msqid));
329 error = linux_ipc64_perm_to_ipc_perm(&linux_msqid64->msg_perm,
330 &linux_msqid.msg_perm);
334 linux_msqid.msg_stime = linux_msqid64->msg_stime;
335 linux_msqid.msg_rtime = linux_msqid64->msg_rtime;
336 linux_msqid.msg_ctime = linux_msqid64->msg_ctime;
338 if (linux_msqid64->msg_cbytes > USHRT_MAX)
339 linux_msqid.msg_cbytes = USHRT_MAX;
341 linux_msqid.msg_cbytes = linux_msqid64->msg_cbytes;
342 linux_msqid.msg_lcbytes = linux_msqid64->msg_cbytes;
343 if (linux_msqid64->msg_qnum > USHRT_MAX)
344 linux_msqid.msg_qnum = USHRT_MAX;
346 linux_msqid.msg_qnum = linux_msqid64->msg_qnum;
347 if (linux_msqid64->msg_qbytes > USHRT_MAX)
348 linux_msqid.msg_qbytes = USHRT_MAX;
350 linux_msqid.msg_qbytes = linux_msqid64->msg_qbytes;
351 linux_msqid.msg_lqbytes = linux_msqid64->msg_qbytes;
352 linux_msqid.msg_lspid = linux_msqid64->msg_lspid;
353 linux_msqid.msg_lrpid = linux_msqid64->msg_lrpid;
355 /* Linux does not check overflow */
356 if (linux_msqid.msg_stime != linux_msqid64->msg_stime ||
357 linux_msqid.msg_rtime != linux_msqid64->msg_rtime ||
358 linux_msqid.msg_ctime != linux_msqid64->msg_ctime)
360 return (copyout(&linux_msqid, uaddr, sizeof(linux_msqid)));
364 linux_semid_pullup(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
366 struct l_semid_ds linux_semid;
369 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
370 return (copyin(uaddr, linux_semid64, sizeof(*linux_semid64)));
371 error = copyin(uaddr, &linux_semid, sizeof(linux_semid));
375 bzero(linux_semid64, sizeof(*linux_semid64));
376 linux_semid64->sem_perm.uid = linux_semid.sem_perm.uid;
377 linux_semid64->sem_perm.gid = linux_semid.sem_perm.gid;
378 linux_semid64->sem_perm.mode = linux_semid.sem_perm.mode;
383 linux_semid_pushdown(l_int ver, struct l_semid64_ds *linux_semid64, caddr_t uaddr)
385 struct l_semid_ds linux_semid;
388 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
389 return (copyout(linux_semid64, uaddr, sizeof(*linux_semid64)));
391 bzero(&linux_semid, sizeof(linux_semid));
392 error = linux_ipc64_perm_to_ipc_perm(&linux_semid64->sem_perm,
393 &linux_semid.sem_perm);
397 linux_semid.sem_otime = linux_semid64->sem_otime;
398 linux_semid.sem_ctime = linux_semid64->sem_ctime;
399 linux_semid.sem_nsems = linux_semid64->sem_nsems;
401 /* Linux does not check overflow */
402 if (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 return (copyout(&linux_semid, uaddr, sizeof(linux_semid)));
410 linux_shmid_pullup(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
412 struct l_shmid_ds linux_shmid;
415 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
416 return (copyin(uaddr, linux_shmid64, sizeof(*linux_shmid64)));
418 error = copyin(uaddr, &linux_shmid, sizeof(linux_shmid));
422 bzero(linux_shmid64, sizeof(*linux_shmid64));
423 linux_shmid64->shm_perm.uid = linux_shmid.shm_perm.uid;
424 linux_shmid64->shm_perm.gid = linux_shmid.shm_perm.gid;
425 linux_shmid64->shm_perm.mode = linux_shmid.shm_perm.mode;
430 linux_shmid_pushdown(l_int ver, struct l_shmid64_ds *linux_shmid64, caddr_t uaddr)
432 struct l_shmid_ds linux_shmid;
435 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
436 return (copyout(linux_shmid64, uaddr, sizeof(*linux_shmid64)));
438 bzero(&linux_shmid, sizeof(linux_shmid));
439 error = linux_ipc64_perm_to_ipc_perm(&linux_shmid64->shm_perm,
440 &linux_shmid.shm_perm);
444 linux_shmid.shm_segsz = linux_shmid64->shm_segsz;
445 linux_shmid.shm_atime = linux_shmid64->shm_atime;
446 linux_shmid.shm_dtime = linux_shmid64->shm_dtime;
447 linux_shmid.shm_ctime = linux_shmid64->shm_ctime;
448 linux_shmid.shm_cpid = linux_shmid64->shm_cpid;
449 linux_shmid.shm_lpid = linux_shmid64->shm_lpid;
450 linux_shmid.shm_nattch = linux_shmid64->shm_nattch;
452 /* Linux does not check overflow */
453 if (linux_shmid.shm_segsz != linux_shmid64->shm_segsz ||
454 linux_shmid.shm_atime != linux_shmid64->shm_atime ||
455 linux_shmid.shm_dtime != linux_shmid64->shm_dtime ||
456 linux_shmid.shm_ctime != linux_shmid64->shm_ctime ||
457 linux_shmid.shm_cpid != linux_shmid64->shm_cpid ||
458 linux_shmid.shm_lpid != linux_shmid64->shm_lpid ||
459 linux_shmid.shm_nattch != linux_shmid64->shm_nattch)
461 return (copyout(&linux_shmid, uaddr, sizeof(linux_shmid)));
465 linux_shminfo_pushdown(l_int ver, struct l_shminfo64 *linux_shminfo64,
468 struct l_shminfo linux_shminfo;
470 if (ver == LINUX_IPC_64 || SV_CURPROC_FLAG(SV_LP64))
471 return (copyout(linux_shminfo64, uaddr,
472 sizeof(*linux_shminfo64)));
474 bzero(&linux_shminfo, sizeof(linux_shminfo));
475 linux_shminfo.shmmax = linux_shminfo64->shmmax;
476 linux_shminfo.shmmin = linux_shminfo64->shmmin;
477 linux_shminfo.shmmni = linux_shminfo64->shmmni;
478 linux_shminfo.shmseg = linux_shminfo64->shmseg;
479 linux_shminfo.shmall = linux_shminfo64->shmall;
480 return (copyout(&linux_shminfo, uaddr, sizeof(linux_shminfo)));
483 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
485 linux_semtimedop_time64(struct thread *td, struct linux_semtimedop_time64_args *args)
487 struct timespec ts, *tsa;
491 error = linux_get_timespec64(&ts, args->timeout);
498 return (kern_semop(td, args->semid, PTRIN(args->tsops),
501 #endif /* __i386__) || (__amd64__ && COMPAT_LINUX32) */
504 linux_semtimedop(struct thread *td, struct linux_semtimedop_args *args)
506 struct timespec ts, *tsa;
510 error = linux_get_timespec(&ts, args->timeout);
517 return (kern_semop(td, args->semid, PTRIN(args->tsops),
522 linux_semget(struct thread *td, struct linux_semget_args *args)
524 struct semget_args bsd_args = {
526 .nsems = args->nsems,
527 .semflg = args->semflg
532 return (sys_semget(td, &bsd_args));
536 linux_semctl(struct thread *td, struct linux_semctl_args *args)
538 struct l_semid64_ds linux_semid64;
539 struct l_seminfo linux_seminfo;
540 struct semid_ds semid;
545 memset(&linux_seminfo, 0, sizeof(linux_seminfo));
546 memset(&linux_semid64, 0, sizeof(linux_semid64));
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 bsd_args = {
687 .msgflg = args->msgflg
690 return (sys_msgget(td, &bsd_args));
694 linux_msgctl(struct thread *td, struct linux_msgctl_args *args)
697 struct l_msqid64_ds linux_msqid64;
698 struct msqid_ds bsd_msqid;
700 memset(&linux_msqid64, 0, sizeof(linux_msqid64));
702 bsd_cmd = args->cmd & ~LINUX_IPC_64;
705 case LINUX_MSG_INFO: {
706 struct l_msginfo linux_msginfo;
708 memset(&linux_msginfo, 0, sizeof(linux_msginfo));
710 * XXX MSG_INFO uses the same data structure but returns different
711 * dynamic counters in msgpool, msgmap, and msgtql fields.
713 linux_msginfo.msgpool = (long)msginfo.msgmni *
714 (long)msginfo.msgmnb / 1024L; /* XXX MSG_INFO. */
715 linux_msginfo.msgmap = msginfo.msgmnb; /* XXX MSG_INFO. */
716 linux_msginfo.msgmax = msginfo.msgmax;
717 linux_msginfo.msgmnb = msginfo.msgmnb;
718 linux_msginfo.msgmni = msginfo.msgmni;
719 linux_msginfo.msgssz = msginfo.msgssz;
720 linux_msginfo.msgtql = msginfo.msgtql; /* XXX MSG_INFO. */
721 linux_msginfo.msgseg = msginfo.msgseg;
722 error = copyout(&linux_msginfo, PTRIN(args->buf),
723 sizeof(linux_msginfo));
725 td->td_retval[0] = msginfo.msgmni; /* XXX */
731 * TODO: implement this
732 * case LINUX_MSG_STAT:
739 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
740 &linux_msqid64, PTRIN(args->buf));
743 linux_to_bsd_msqid_ds(&linux_msqid64, &bsd_msqid);
755 error = kern_msgctl(td, args->msqid, bsd_cmd, &bsd_msqid);
757 if (bsd_cmd == LINUX_IPC_RMID && error == EACCES)
759 if (bsd_cmd != LINUX_IPC_RMID || error != EINVAL)
763 if (bsd_cmd == LINUX_IPC_STAT) {
764 bsd_to_linux_msqid_ds(&bsd_msqid, &linux_msqid64);
765 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
766 &linux_msqid64, PTRIN(args->buf)));
773 linux_shmat(struct thread *td, struct linux_shmat_args *args)
775 struct shmat_args bsd_args = {
776 .shmid = args->shmid,
777 .shmaddr = PTRIN(args->shmaddr),
778 .shmflg = args->shmflg
781 return (sys_shmat(td, &bsd_args));
785 linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
787 struct shmdt_args bsd_args = {
788 .shmaddr = PTRIN(args->shmaddr)
791 return (sys_shmdt(td, &bsd_args));
795 linux_shmget(struct thread *td, struct linux_shmget_args *args)
797 struct shmget_args bsd_args = {
800 .shmflg = args->shmflg
803 return (sys_shmget(td, &bsd_args));
807 linux_shmctl(struct thread *td, struct linux_shmctl_args *args)
809 struct l_shmid64_ds linux_shmid64;
810 struct l_shminfo64 linux_shminfo64;
811 struct l_shm_info linux_shm_info;
812 struct shmid_ds bsd_shmid;
815 memset(&linux_shm_info, 0, sizeof(linux_shm_info));
816 memset(&linux_shmid64, 0, sizeof(linux_shmid64));
817 memset(&linux_shminfo64, 0, sizeof(linux_shminfo64));
819 switch (args->cmd & ~LINUX_IPC_64) {
820 case LINUX_IPC_INFO: {
821 struct shminfo bsd_shminfo;
823 /* Perform shmctl wanting removed segments lookup */
824 error = kern_shmctl(td, args->shmid, IPC_INFO,
825 (void *)&bsd_shminfo, NULL);
829 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo64);
831 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
832 &linux_shminfo64, PTRIN(args->buf)));
835 case LINUX_SHM_INFO: {
836 struct shm_info bsd_shm_info;
838 /* Perform shmctl wanting removed segments lookup */
839 error = kern_shmctl(td, args->shmid, SHM_INFO,
840 (void *)&bsd_shm_info, NULL);
844 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
846 return (copyout(&linux_shm_info, PTRIN(args->buf),
847 sizeof(struct l_shm_info)));
851 /* Perform shmctl wanting removed segments lookup */
852 error = kern_shmctl(td, args->shmid, IPC_STAT,
853 (void *)&bsd_shmid, NULL);
857 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
859 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
860 &linux_shmid64, PTRIN(args->buf)));
863 /* Perform shmctl wanting removed segments lookup */
864 error = kern_shmctl(td, args->shmid, IPC_STAT,
865 (void *)&bsd_shmid, NULL);
869 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid64);
871 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
872 &linux_shmid64, PTRIN(args->buf)));
875 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
876 &linux_shmid64, PTRIN(args->buf));
880 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
882 /* Perform shmctl wanting removed segments lookup */
883 return (kern_shmctl(td, args->shmid, IPC_SET,
884 (void *)&bsd_shmid, NULL));
886 case LINUX_IPC_RMID: {
892 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
893 &linux_shmid64, PTRIN(args->buf));
896 linux_to_bsd_shmid_ds(&linux_shmid64, &bsd_shmid);
897 buf = (void *)&bsd_shmid;
899 return (kern_shmctl(td, args->shmid, IPC_RMID, buf, NULL));
904 case LINUX_SHM_UNLOCK:
907 linux_msg(td, "ipc type %d not implemented",
908 args->cmd & ~LINUX_IPC_64);
913 MODULE_DEPEND(linux, sysvmsg, 1, 1, 1);
914 MODULE_DEPEND(linux, sysvsem, 1, 1, 1);
915 MODULE_DEPEND(linux, sysvshm, 1, 1, 1);