Deleted Added
full compact
linux_ipc.c (122088) linux_ipc.c (133816)
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ipc.c 122088 2003-11-05 01:53:10Z fjoe $");
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_ipc.c 133816 2004-08-16 07:28:16Z tjr $");
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/syscallsubr.h>
35#include <sys/sysproto.h>
36#include <sys/proc.h>
37#include <sys/limits.h>
38#include <sys/msg.h>
39#include <sys/sem.h>
40#include <sys/shm.h>
41
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/syscallsubr.h>
35#include <sys/sysproto.h>
36#include <sys/proc.h>
37#include <sys/limits.h>
38#include <sys/msg.h>
39#include <sys/sem.h>
40#include <sys/shm.h>
41
42#include "opt_compat.h"
43
44#if !COMPAT_LINUX32
42#include <machine/../linux/linux.h>
43#include <machine/../linux/linux_proto.h>
44#include <machine/../linux/linux_ipc64.h>
45#include <machine/../linux/linux.h>
46#include <machine/../linux/linux_proto.h>
47#include <machine/../linux/linux_ipc64.h>
48#else
49#include <machine/../linux32/linux.h>
50#include <machine/../linux32/linux32_proto.h>
51#include <machine/../linux32/linux32_ipc64.h>
52#endif
45#include <compat/linux/linux_ipc.h>
46#include <compat/linux/linux_util.h>
47
48struct l_seminfo {
49 l_int semmap;
50 l_int semmni;
51 l_int semmns;
52 l_int semmnu;

--- 75 unchanged lines hidden (view full) ---

128 lpp->cuid = bpp->cuid;
129 lpp->cgid = bpp->cgid;
130 lpp->mode = bpp->mode;
131 lpp->seq = bpp->seq;
132}
133
134struct l_msqid_ds {
135 struct l_ipc_perm msg_perm;
53#include <compat/linux/linux_ipc.h>
54#include <compat/linux/linux_util.h>
55
56struct l_seminfo {
57 l_int semmap;
58 l_int semmni;
59 l_int semmns;
60 l_int semmnu;

--- 75 unchanged lines hidden (view full) ---

136 lpp->cuid = bpp->cuid;
137 lpp->cgid = bpp->cgid;
138 lpp->mode = bpp->mode;
139 lpp->seq = bpp->seq;
140}
141
142struct l_msqid_ds {
143 struct l_ipc_perm msg_perm;
136 struct l_msg *msg_first; /* first message on queue,unused */
137 struct l_msg *msg_last; /* last message in queue,unused */
144 l_uintptr_t msg_first; /* first message on queue,unused */
145 l_uintptr_t msg_last; /* last message in queue,unused */
138 l_time_t msg_stime; /* last msgsnd time */
139 l_time_t msg_rtime; /* last msgrcv time */
140 l_time_t msg_ctime; /* last change time */
141 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
142 l_ulong msg_lqbytes; /* ditto */
143 l_ushort msg_cbytes; /* current number of bytes on queue */
144 l_ushort msg_qnum; /* number of messages in queue */
145 l_ushort msg_qbytes; /* max number of bytes on queue */
146 l_pid_t msg_lspid; /* pid of last msgsnd */
147 l_pid_t msg_lrpid; /* last receive pid */
146 l_time_t msg_stime; /* last msgsnd time */
147 l_time_t msg_rtime; /* last msgrcv time */
148 l_time_t msg_ctime; /* last change time */
149 l_ulong msg_lcbytes; /* Reuse junk fields for 32 bit */
150 l_ulong msg_lqbytes; /* ditto */
151 l_ushort msg_cbytes; /* current number of bytes on queue */
152 l_ushort msg_qnum; /* number of messages in queue */
153 l_ushort msg_qbytes; /* max number of bytes on queue */
154 l_pid_t msg_lspid; /* pid of last msgsnd */
155 l_pid_t msg_lrpid; /* last receive pid */
148};
156}
157#if __amd64__ && COMPAT_LINUX32
158__packed
159#endif
160;
149
150struct l_semid_ds {
151 struct l_ipc_perm sem_perm;
152 l_time_t sem_otime;
153 l_time_t sem_ctime;
161
162struct l_semid_ds {
163 struct l_ipc_perm sem_perm;
164 l_time_t sem_otime;
165 l_time_t sem_ctime;
154 void *sem_base;
155 void *sem_pending;
156 void *sem_pending_last;
157 void *undo;
166 l_uintptr_t sem_base;
167 l_uintptr_t sem_pending;
168 l_uintptr_t sem_pending_last;
169 l_uintptr_t undo;
158 l_ushort sem_nsems;
170 l_ushort sem_nsems;
159};
171}
172#if __amd64__ && COMPAT_LINUX32
173__packed
174#endif
175;
160
161struct l_shmid_ds {
162 struct l_ipc_perm shm_perm;
163 l_int shm_segsz;
164 l_time_t shm_atime;
165 l_time_t shm_dtime;
166 l_time_t shm_ctime;
167 l_ushort shm_cpid;
168 l_ushort shm_lpid;
169 l_short shm_nattch;
170 l_ushort private1;
176
177struct l_shmid_ds {
178 struct l_ipc_perm shm_perm;
179 l_int shm_segsz;
180 l_time_t shm_atime;
181 l_time_t shm_dtime;
182 l_time_t shm_ctime;
183 l_ushort shm_cpid;
184 l_ushort shm_lpid;
185 l_short shm_nattch;
186 l_ushort private1;
171 void *private2;
172 void *private3;
187 l_uintptr_t private2;
188 l_uintptr_t private3;
173};
174
175static void
176linux_to_bsd_semid_ds(struct l_semid_ds *lsp, struct semid_ds *bsp)
177{
178 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
179 bsp->sem_otime = lsp->sem_otime;
180 bsp->sem_ctime = lsp->sem_ctime;
181 bsp->sem_nsems = lsp->sem_nsems;
189};
190
191static void
192linux_to_bsd_semid_ds(struct l_semid_ds *lsp, struct semid_ds *bsp)
193{
194 linux_to_bsd_ipc_perm(&lsp->sem_perm, &bsp->sem_perm);
195 bsp->sem_otime = lsp->sem_otime;
196 bsp->sem_ctime = lsp->sem_ctime;
197 bsp->sem_nsems = lsp->sem_nsems;
182 bsp->sem_base = lsp->sem_base;
198 bsp->sem_base = PTRIN(lsp->sem_base);
183}
184
185static void
186bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid_ds *lsp)
187{
188 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
189 lsp->sem_otime = bsp->sem_otime;
190 lsp->sem_ctime = bsp->sem_ctime;
191 lsp->sem_nsems = bsp->sem_nsems;
199}
200
201static void
202bsd_to_linux_semid_ds(struct semid_ds *bsp, struct l_semid_ds *lsp)
203{
204 bsd_to_linux_ipc_perm(&bsp->sem_perm, &lsp->sem_perm);
205 lsp->sem_otime = bsp->sem_otime;
206 lsp->sem_ctime = bsp->sem_ctime;
207 lsp->sem_nsems = bsp->sem_nsems;
192 lsp->sem_base = bsp->sem_base;
208 lsp->sem_base = PTROUT(bsp->sem_base);
193}
194
195static void
196linux_to_bsd_shmid_ds(struct l_shmid_ds *lsp, struct shmid_ds *bsp)
197{
198 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
199 bsp->shm_segsz = lsp->shm_segsz;
200 bsp->shm_lpid = lsp->shm_lpid;
201 bsp->shm_cpid = lsp->shm_cpid;
202 bsp->shm_nattch = lsp->shm_nattch;
203 bsp->shm_atime = lsp->shm_atime;
204 bsp->shm_dtime = lsp->shm_dtime;
205 bsp->shm_ctime = lsp->shm_ctime;
209}
210
211static void
212linux_to_bsd_shmid_ds(struct l_shmid_ds *lsp, struct shmid_ds *bsp)
213{
214 linux_to_bsd_ipc_perm(&lsp->shm_perm, &bsp->shm_perm);
215 bsp->shm_segsz = lsp->shm_segsz;
216 bsp->shm_lpid = lsp->shm_lpid;
217 bsp->shm_cpid = lsp->shm_cpid;
218 bsp->shm_nattch = lsp->shm_nattch;
219 bsp->shm_atime = lsp->shm_atime;
220 bsp->shm_dtime = lsp->shm_dtime;
221 bsp->shm_ctime = lsp->shm_ctime;
206 bsp->shm_internal = lsp->private3; /* this goes (yet) SOS */
222 /* this goes (yet) SOS */
223 bsp->shm_internal = PTRIN(lsp->private3);
207}
208
209static void
210bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid_ds *lsp)
211{
212 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
213 lsp->shm_segsz = bsp->shm_segsz;
214 lsp->shm_lpid = bsp->shm_lpid;
215 lsp->shm_cpid = bsp->shm_cpid;
216 lsp->shm_nattch = bsp->shm_nattch;
217 lsp->shm_atime = bsp->shm_atime;
218 lsp->shm_dtime = bsp->shm_dtime;
219 lsp->shm_ctime = bsp->shm_ctime;
224}
225
226static void
227bsd_to_linux_shmid_ds(struct shmid_ds *bsp, struct l_shmid_ds *lsp)
228{
229 bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->shm_perm);
230 lsp->shm_segsz = bsp->shm_segsz;
231 lsp->shm_lpid = bsp->shm_lpid;
232 lsp->shm_cpid = bsp->shm_cpid;
233 lsp->shm_nattch = bsp->shm_nattch;
234 lsp->shm_atime = bsp->shm_atime;
235 lsp->shm_dtime = bsp->shm_dtime;
236 lsp->shm_ctime = bsp->shm_ctime;
220 lsp->private3 = bsp->shm_internal; /* this goes (yet) SOS */
237 /* this goes (yet) SOS */
238 lsp->private3 = PTROUT(bsp->shm_internal);
221}
222
223static void
224linux_to_bsd_msqid_ds(struct l_msqid_ds *lsp, struct msqid_ds *bsp)
225{
226 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
227 bsp->msg_cbytes = lsp->msg_cbytes;
228 bsp->msg_qnum = lsp->msg_qnum;

--- 213 unchanged lines hidden (view full) ---

442{
443 struct semop_args /* {
444 int semid;
445 struct sembuf *sops;
446 int nsops;
447 } */ bsd_args;
448
449 bsd_args.semid = args->semid;
239}
240
241static void
242linux_to_bsd_msqid_ds(struct l_msqid_ds *lsp, struct msqid_ds *bsp)
243{
244 linux_to_bsd_ipc_perm(&lsp->msg_perm, &bsp->msg_perm);
245 bsp->msg_cbytes = lsp->msg_cbytes;
246 bsp->msg_qnum = lsp->msg_qnum;

--- 213 unchanged lines hidden (view full) ---

460{
461 struct semop_args /* {
462 int semid;
463 struct sembuf *sops;
464 int nsops;
465 } */ bsd_args;
466
467 bsd_args.semid = args->semid;
450 bsd_args.sops = (struct sembuf *)args->tsops;
468 bsd_args.sops = (struct sembuf *)PTRIN(args->tsops);
451 bsd_args.nsops = args->nsops;
452 return semop(td, &bsd_args);
453}
454
455int
456linux_semget(struct thread *td, struct linux_semget_args *args)
457{
458 struct semget_args /* {

--- 52 unchanged lines hidden (view full) ---

511 bsd_args.cmd = GETZCNT;
512 break;
513 case LINUX_SETVAL:
514 bsd_args.cmd = SETVAL;
515 break;
516 case LINUX_IPC_SET:
517 bsd_args.cmd = IPC_SET;
518 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
469 bsd_args.nsops = args->nsops;
470 return semop(td, &bsd_args);
471}
472
473int
474linux_semget(struct thread *td, struct linux_semget_args *args)
475{
476 struct semget_args /* {

--- 52 unchanged lines hidden (view full) ---

529 bsd_args.cmd = GETZCNT;
530 break;
531 case LINUX_SETVAL:
532 bsd_args.cmd = SETVAL;
533 break;
534 case LINUX_IPC_SET:
535 bsd_args.cmd = IPC_SET;
536 error = linux_semid_pullup(args->cmd & LINUX_IPC_64,
519 &linux_semid, (caddr_t)args->arg.buf);
537 &linux_semid, (caddr_t)PTRIN(args->arg.buf));
520 if (error)
521 return (error);
522 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds));
523 linux_to_bsd_semid_ds(&linux_semid, unptr->buf);
524 return __semctl(td, &bsd_args);
525 case LINUX_IPC_STAT:
526 case LINUX_SEM_STAT:
527 if((args->cmd & ~LINUX_IPC_64) == LINUX_IPC_STAT)
528 bsd_args.cmd = IPC_STAT;
529 else
530 bsd_args.cmd = SEM_STAT;
531 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds));
532 error = __semctl(td, &bsd_args);
533 if (error)
534 return error;
535 td->td_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid,
536 unptr->buf->sem_perm);
537 bsd_to_linux_semid_ds(unptr->buf, &linux_semid);
538 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
538 if (error)
539 return (error);
540 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds));
541 linux_to_bsd_semid_ds(&linux_semid, unptr->buf);
542 return __semctl(td, &bsd_args);
543 case LINUX_IPC_STAT:
544 case LINUX_SEM_STAT:
545 if((args->cmd & ~LINUX_IPC_64) == LINUX_IPC_STAT)
546 bsd_args.cmd = IPC_STAT;
547 else
548 bsd_args.cmd = SEM_STAT;
549 unptr->buf = stackgap_alloc(&sg, sizeof(struct semid_ds));
550 error = __semctl(td, &bsd_args);
551 if (error)
552 return error;
553 td->td_retval[0] = IXSEQ_TO_IPCID(bsd_args.semid,
554 unptr->buf->sem_perm);
555 bsd_to_linux_semid_ds(unptr->buf, &linux_semid);
556 return (linux_semid_pushdown(args->cmd & LINUX_IPC_64,
539 &linux_semid, (caddr_t)args->arg.buf));
557 &linux_semid, (caddr_t)PTRIN(args->arg.buf)));
540 case LINUX_IPC_INFO:
541 case LINUX_SEM_INFO:
542 bcopy(&seminfo, &linux_seminfo, sizeof(linux_seminfo) );
543/* XXX BSD equivalent?
544#define used_semids 10
545#define used_sems 10
546 linux_seminfo.semusz = used_semids;
547 linux_seminfo.semaem = used_sems;
548*/
558 case LINUX_IPC_INFO:
559 case LINUX_SEM_INFO:
560 bcopy(&seminfo, &linux_seminfo, sizeof(linux_seminfo) );
561/* XXX BSD equivalent?
562#define used_semids 10
563#define used_sems 10
564 linux_seminfo.semusz = used_semids;
565 linux_seminfo.semaem = used_sems;
566*/
549 error = copyout(&linux_seminfo, args->arg.buf,
550 sizeof(linux_seminfo));
567 error = copyout(&linux_seminfo,
568 PTRIN(args->arg.buf), sizeof(linux_seminfo));
551 if (error)
552 return error;
553 td->td_retval[0] = seminfo.semmni;
554 return 0; /* No need for __semctl call */
555 case LINUX_GETALL:
556 /* FALLTHROUGH */
557 case LINUX_SETALL:
558 /* FALLTHROUGH */

--- 11 unchanged lines hidden (view full) ---

570 struct msgsnd_args /* {
571 int msqid;
572 void *msgp;
573 size_t msgsz;
574 int msgflg;
575 } */ bsd_args;
576
577 bsd_args.msqid = args->msqid;
569 if (error)
570 return error;
571 td->td_retval[0] = seminfo.semmni;
572 return 0; /* No need for __semctl call */
573 case LINUX_GETALL:
574 /* FALLTHROUGH */
575 case LINUX_SETALL:
576 /* FALLTHROUGH */

--- 11 unchanged lines hidden (view full) ---

588 struct msgsnd_args /* {
589 int msqid;
590 void *msgp;
591 size_t msgsz;
592 int msgflg;
593 } */ bsd_args;
594
595 bsd_args.msqid = args->msqid;
578 bsd_args.msgp = args->msgp;
596 bsd_args.msgp = PTRIN(args->msgp);
579 bsd_args.msgsz = args->msgsz;
580 bsd_args.msgflg = args->msgflg;
581 return msgsnd(td, &bsd_args);
582}
583
584int
585linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
586{
587 struct msgrcv_args /* {
588 int msqid;
589 void *msgp;
590 size_t msgsz;
591 long msgtyp;
592 int msgflg;
593 } */ bsd_args;
594
595 bsd_args.msqid = args->msqid;
597 bsd_args.msgsz = args->msgsz;
598 bsd_args.msgflg = args->msgflg;
599 return msgsnd(td, &bsd_args);
600}
601
602int
603linux_msgrcv(struct thread *td, struct linux_msgrcv_args *args)
604{
605 struct msgrcv_args /* {
606 int msqid;
607 void *msgp;
608 size_t msgsz;
609 long msgtyp;
610 int msgflg;
611 } */ bsd_args;
612
613 bsd_args.msqid = args->msqid;
596 bsd_args.msgp = args->msgp;
614 bsd_args.msgp = PTRIN(args->msgp);
597 bsd_args.msgsz = args->msgsz;
598 bsd_args.msgtyp = args->msgtyp;
599 bsd_args.msgflg = args->msgflg;
600 return msgrcv(td, &bsd_args);
601}
602
603int
604linux_msgget(struct thread *td, struct linux_msgget_args *args)

--- 16 unchanged lines hidden (view full) ---

621 int cmd;
622 struct msqid_ds *buf;
623 } */ bsd_args;
624 int error;
625 struct l_msqid_ds linux_msqid;
626 caddr_t sg = stackgap_init();
627
628 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
615 bsd_args.msgsz = args->msgsz;
616 bsd_args.msgtyp = args->msgtyp;
617 bsd_args.msgflg = args->msgflg;
618 return msgrcv(td, &bsd_args);
619}
620
621int
622linux_msgget(struct thread *td, struct linux_msgget_args *args)

--- 16 unchanged lines hidden (view full) ---

639 int cmd;
640 struct msqid_ds *buf;
641 } */ bsd_args;
642 int error;
643 struct l_msqid_ds linux_msqid;
644 caddr_t sg = stackgap_init();
645
646 error = linux_msqid_pullup(args->cmd & LINUX_IPC_64,
629 &linux_msqid, (caddr_t)args->buf);
647 &linux_msqid, (caddr_t)PTRIN(args->buf));
630 if (error != 0)
631 return (error);
632 bsd_args.buf = (struct msqid_ds*)stackgap_alloc(&sg,
633 sizeof(struct l_msqid_ds));
634 bsd_args.msqid = args->msqid;
635 bsd_args.cmd = args->cmd & ~LINUX_IPC_64;
636 if (bsd_args.cmd == LINUX_IPC_SET)
637 linux_to_bsd_msqid_ds(&linux_msqid, bsd_args.buf);
638
639 error = msgctl(td, &bsd_args);
640 if (error != 0)
641 if (bsd_args.cmd != LINUX_IPC_RMID || error != EINVAL)
642 return (error);
643
644 if (bsd_args.cmd == LINUX_IPC_STAT) {
645 bsd_to_linux_msqid_ds(bsd_args.buf, &linux_msqid);
646 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
648 if (error != 0)
649 return (error);
650 bsd_args.buf = (struct msqid_ds*)stackgap_alloc(&sg,
651 sizeof(struct l_msqid_ds));
652 bsd_args.msqid = args->msqid;
653 bsd_args.cmd = args->cmd & ~LINUX_IPC_64;
654 if (bsd_args.cmd == LINUX_IPC_SET)
655 linux_to_bsd_msqid_ds(&linux_msqid, bsd_args.buf);
656
657 error = msgctl(td, &bsd_args);
658 if (error != 0)
659 if (bsd_args.cmd != LINUX_IPC_RMID || error != EINVAL)
660 return (error);
661
662 if (bsd_args.cmd == LINUX_IPC_STAT) {
663 bsd_to_linux_msqid_ds(bsd_args.buf, &linux_msqid);
664 return (linux_msqid_pushdown(args->cmd & LINUX_IPC_64,
647 &linux_msqid, (caddr_t)args->buf));
665 &linux_msqid, (caddr_t)PTRIN(args->buf)));
648 }
649
650 return (0);
651}
652
653int
654linux_shmat(struct thread *td, struct linux_shmat_args *args)
655{
656 struct shmat_args /* {
657 int shmid;
658 void *shmaddr;
659 int shmflg;
660 } */ bsd_args;
661 int error;
666 }
667
668 return (0);
669}
670
671int
672linux_shmat(struct thread *td, struct linux_shmat_args *args)
673{
674 struct shmat_args /* {
675 int shmid;
676 void *shmaddr;
677 int shmflg;
678 } */ bsd_args;
679 int error;
680#if defined(__i386__) || (defined(__amd64__) && COMPAT_LINUX32)
681 l_uintptr_t addr;
682#endif
662
663 bsd_args.shmid = args->shmid;
683
684 bsd_args.shmid = args->shmid;
664 bsd_args.shmaddr = args->shmaddr;
685 bsd_args.shmaddr = PTRIN(args->shmaddr);
665 bsd_args.shmflg = args->shmflg;
666 if ((error = shmat(td, &bsd_args)))
667 return error;
686 bsd_args.shmflg = args->shmflg;
687 if ((error = shmat(td, &bsd_args)))
688 return error;
668#ifdef __i386__
669 if ((error = copyout(td->td_retval, args->raddr, sizeof(l_ulong))))
689#if defined(__i386__) || (defined(__amd64__) && COMPAT_LINUX32)
690 addr = td->td_retval[0];
691 if ((error = copyout(&addr, PTRIN(args->raddr), sizeof(addr))))
670 return error;
671 td->td_retval[0] = 0;
672#endif
673 return 0;
674}
675
676int
677linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
678{
679 struct shmdt_args /* {
680 void *shmaddr;
681 } */ bsd_args;
682
692 return error;
693 td->td_retval[0] = 0;
694#endif
695 return 0;
696}
697
698int
699linux_shmdt(struct thread *td, struct linux_shmdt_args *args)
700{
701 struct shmdt_args /* {
702 void *shmaddr;
703 } */ bsd_args;
704
683 bsd_args.shmaddr = args->shmaddr;
705 bsd_args.shmaddr = PTRIN(args->shmaddr);
684 return shmdt(td, &bsd_args);
685}
686
687int
688linux_shmget(struct thread *td, struct linux_shmget_args *args)
689{
690 struct shmget_args /* {
691 key_t key;

--- 26 unchanged lines hidden (view full) ---

718 error = kern_shmctl(td, args->shmid, IPC_INFO,
719 (void *)&bsd_shminfo, &bufsz);
720 if (error)
721 return error;
722
723 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo);
724
725 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
706 return shmdt(td, &bsd_args);
707}
708
709int
710linux_shmget(struct thread *td, struct linux_shmget_args *args)
711{
712 struct shmget_args /* {
713 key_t key;

--- 26 unchanged lines hidden (view full) ---

740 error = kern_shmctl(td, args->shmid, IPC_INFO,
741 (void *)&bsd_shminfo, &bufsz);
742 if (error)
743 return error;
744
745 bsd_to_linux_shminfo(&bsd_shminfo, &linux_shminfo);
746
747 return (linux_shminfo_pushdown(args->cmd & LINUX_IPC_64,
726 &linux_shminfo, (caddr_t)args->buf));
748 &linux_shminfo, (caddr_t)PTRIN(args->buf)));
727 }
728
729 case LINUX_SHM_INFO: {
730 struct shm_info bsd_shm_info;
731
732 /* Perform shmctl wanting removed segments lookup */
733 error = kern_shmctl(td, args->shmid, SHM_INFO,
734 (void *)&bsd_shm_info, &bufsz);
735 if (error)
736 return error;
737
738 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
739
749 }
750
751 case LINUX_SHM_INFO: {
752 struct shm_info bsd_shm_info;
753
754 /* Perform shmctl wanting removed segments lookup */
755 error = kern_shmctl(td, args->shmid, SHM_INFO,
756 (void *)&bsd_shm_info, &bufsz);
757 if (error)
758 return error;
759
760 bsd_to_linux_shm_info(&bsd_shm_info, &linux_shm_info);
761
740 return copyout(&linux_shm_info, (caddr_t)args->buf,
762 return copyout(&linux_shm_info, (caddr_t)PTRIN(args->buf),
741 sizeof(struct l_shm_info));
742 }
743
744 case LINUX_IPC_STAT:
745 /* Perform shmctl wanting removed segments lookup */
746 error = kern_shmctl(td, args->shmid, IPC_STAT,
747 (void *)&bsd_shmid, &bufsz);
748 if (error)
749 return error;
750
751 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid);
752
753 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
763 sizeof(struct l_shm_info));
764 }
765
766 case LINUX_IPC_STAT:
767 /* Perform shmctl wanting removed segments lookup */
768 error = kern_shmctl(td, args->shmid, IPC_STAT,
769 (void *)&bsd_shmid, &bufsz);
770 if (error)
771 return error;
772
773 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid);
774
775 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
754 &linux_shmid, (caddr_t)args->buf));
776 &linux_shmid, (caddr_t)PTRIN(args->buf)));
755
756 case LINUX_SHM_STAT:
757 /* Perform shmctl wanting removed segments lookup */
758 error = kern_shmctl(td, args->shmid, IPC_STAT,
759 (void *)&bsd_shmid, &bufsz);
760 if (error)
761 return error;
762
763 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid);
764
765 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
777
778 case LINUX_SHM_STAT:
779 /* Perform shmctl wanting removed segments lookup */
780 error = kern_shmctl(td, args->shmid, IPC_STAT,
781 (void *)&bsd_shmid, &bufsz);
782 if (error)
783 return error;
784
785 bsd_to_linux_shmid_ds(&bsd_shmid, &linux_shmid);
786
787 return (linux_shmid_pushdown(args->cmd & LINUX_IPC_64,
766 &linux_shmid, (caddr_t)args->buf));
788 &linux_shmid, (caddr_t)PTRIN(args->buf)));
767
768 case LINUX_IPC_SET:
769 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
789
790 case LINUX_IPC_SET:
791 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
770 &linux_shmid, (caddr_t)args->buf);
792 &linux_shmid, (caddr_t)PTRIN(args->buf));
771 if (error)
772 return error;
773
774 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid);
775
776 /* Perform shmctl wanting removed segments lookup */
777 return kern_shmctl(td, args->shmid, IPC_SET,
778 (void *)&bsd_shmid, &bufsz);
779
780 case LINUX_IPC_RMID: {
781 void *buf;
782
793 if (error)
794 return error;
795
796 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid);
797
798 /* Perform shmctl wanting removed segments lookup */
799 return kern_shmctl(td, args->shmid, IPC_SET,
800 (void *)&bsd_shmid, &bufsz);
801
802 case LINUX_IPC_RMID: {
803 void *buf;
804
783 if (args->buf == NULL)
805 if (args->buf == 0)
784 buf = NULL;
785 else {
786 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
806 buf = NULL;
807 else {
808 error = linux_shmid_pullup(args->cmd & LINUX_IPC_64,
787 &linux_shmid, (caddr_t)args->buf);
809 &linux_shmid, (caddr_t)PTRIN(args->buf));
788 if (error)
789 return error;
790 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid);
791 buf = (void *)&bsd_shmid;
792 }
793 return kern_shmctl(td, args->shmid, IPC_RMID, buf, &bufsz);
794 }
795
796 case LINUX_SHM_LOCK:
797 case LINUX_SHM_UNLOCK:
798 default:
799 linux_msg(td, "ipc typ=%d not implemented", args->cmd & ~LINUX_IPC_64);
800 return EINVAL;
801 }
802}
810 if (error)
811 return error;
812 linux_to_bsd_shmid_ds(&linux_shmid, &bsd_shmid);
813 buf = (void *)&bsd_shmid;
814 }
815 return kern_shmctl(td, args->shmid, IPC_RMID, buf, &bufsz);
816 }
817
818 case LINUX_SHM_LOCK:
819 case LINUX_SHM_UNLOCK:
820 default:
821 linux_msg(td, "ipc typ=%d not implemented", args->cmd & ~LINUX_IPC_64);
822 return EINVAL;
823 }
824}