1139799Simp/*-
211397Sswallace * Copyright (c) 1995 Scott Bartram
311397Sswallace * Copyright (c) 1995 Steven Wallace
43584Ssos * All rights reserved.
53584Ssos *
63584Ssos * Redistribution and use in source and binary forms, with or without
73584Ssos * modification, are permitted provided that the following conditions
83584Ssos * are met:
93584Ssos * 1. Redistributions of source code must retain the above copyright
1011397Sswallace *    notice, this list of conditions and the following disclaimer.
1111397Sswallace * 2. The name of the author may not be used to endorse or promote products
1211397Sswallace *    derived from this software without specific prior written permission
133584Ssos *
143584Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
153584Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
163584Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
173584Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
183584Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
193584Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
203584Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
213584Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223584Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
233584Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
243584Ssos */
2513226Swollman
26115684Sobrien#include <sys/cdefs.h>
27115684Sobrien__FBSDID("$FreeBSD$");
28115684Sobrien
293584Ssos#include <sys/param.h>
303584Ssos#include <sys/systm.h>
31194942Srwatson#include <sys/limits.h>
3211397Sswallace#include <sys/msg.h>
3311397Sswallace#include <sys/sem.h>
3411397Sswallace#include <sys/shm.h>
35160189Sjhb#include <sys/syscallsubr.h>
3611397Sswallace#include <sys/sysproto.h>
373584Ssos
3811397Sswallace#include <i386/ibcs2/ibcs2_types.h>
3911397Sswallace#include <i386/ibcs2/ibcs2_signal.h>
4011397Sswallace#include <i386/ibcs2/ibcs2_proto.h>
4111397Sswallace#include <i386/ibcs2/ibcs2_util.h>
4211397Sswallace#include <i386/ibcs2/ibcs2_ipc.h>
4311397Sswallace
4411397Sswallace#define IBCS2_IPC_RMID	0
4511397Sswallace#define IBCS2_IPC_SET	1
4611397Sswallace#define IBCS2_IPC_STAT	2
4720601Sswallace#define IBCS2_SETVAL	8
4811397Sswallace
4911397Sswallace
5020601Sswallace
5192761Salfredstatic void cvt_msqid2imsqid(struct msqid_ds *, struct ibcs2_msqid_ds *);
5292761Salfredstatic void cvt_imsqid2msqid(struct ibcs2_msqid_ds *, struct msqid_ds *);
5316322Sgpalmer#ifdef unused
5492761Salfredstatic void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
5592761Salfredstatic void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
5616322Sgpalmer#endif
5792761Salfredstatic void cvt_semid2isemid(struct semid_ds *, struct ibcs2_semid_ds *);
5892761Salfredstatic void cvt_isemid2semid(struct ibcs2_semid_ds *, struct semid_ds *);
5992761Salfredstatic void cvt_shmid2ishmid(struct shmid_ds *, struct ibcs2_shmid_ds *);
6092761Salfredstatic void cvt_ishmid2shmid(struct ibcs2_shmid_ds *, struct shmid_ds *);
6192761Salfredstatic void cvt_perm2iperm(struct ipc_perm *, struct ibcs2_ipc_perm *);
6292761Salfredstatic void cvt_iperm2perm(struct ibcs2_ipc_perm *, struct ipc_perm *);
6311397Sswallace
6411397Sswallace
6511397Sswallace/*
6611397Sswallace * iBCS2 msgsys call
6711397Sswallace */
6811397Sswallace
6911397Sswallacestatic void
7011397Sswallacecvt_msqid2imsqid(bp, ibp)
7111397Sswallacestruct msqid_ds *bp;
7211397Sswallacestruct ibcs2_msqid_ds *ibp;
7311397Sswallace{
7443744Sguido	cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
7511397Sswallace	ibp->msg_first = bp->msg_first;
7611397Sswallace	ibp->msg_last = bp->msg_last;
7711397Sswallace	ibp->msg_cbytes = (u_short)bp->msg_cbytes;
7811397Sswallace	ibp->msg_qnum = (u_short)bp->msg_qnum;
7911397Sswallace	ibp->msg_qbytes = (u_short)bp->msg_qbytes;
8011397Sswallace	ibp->msg_lspid = (u_short)bp->msg_lspid;
8111397Sswallace	ibp->msg_lrpid = (u_short)bp->msg_lrpid;
8211397Sswallace	ibp->msg_stime = bp->msg_stime;
8311397Sswallace	ibp->msg_rtime = bp->msg_rtime;
8411397Sswallace	ibp->msg_ctime = bp->msg_ctime;
8511397Sswallace	return;
8611397Sswallace}
8711397Sswallace
8811397Sswallacestatic void
8911397Sswallacecvt_imsqid2msqid(ibp, bp)
9011397Sswallacestruct ibcs2_msqid_ds *ibp;
9111397Sswallacestruct msqid_ds *bp;
9211397Sswallace{
9343744Sguido	cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
9411397Sswallace	bp->msg_first = ibp->msg_first;
9511397Sswallace	bp->msg_last = ibp->msg_last;
9611397Sswallace	bp->msg_cbytes = ibp->msg_cbytes;
9711397Sswallace	bp->msg_qnum = ibp->msg_qnum;
9811397Sswallace	bp->msg_qbytes = ibp->msg_qbytes;
9911397Sswallace	bp->msg_lspid = ibp->msg_lspid;
10011397Sswallace	bp->msg_lrpid = ibp->msg_lrpid;
10111397Sswallace	bp->msg_stime = ibp->msg_stime;
10211397Sswallace	bp->msg_rtime = ibp->msg_rtime;
10311397Sswallace	bp->msg_ctime = ibp->msg_ctime;
10411397Sswallace	return;
10511397Sswallace}
10611397Sswallace
107160189Sjhbstruct ibcs2_msgget_args {
108160189Sjhb	int what;
109160189Sjhb	ibcs2_key_t key;
110160189Sjhb	int msgflg;
111160189Sjhb};
112160189Sjhb
113160189Sjhbstatic int
114160189Sjhbibcs2_msgget(struct thread *td, void *v)
115160189Sjhb{
116160189Sjhb	struct ibcs2_msgget_args *uap = v;
117160189Sjhb	struct msgget_args ap;
118160189Sjhb
119160189Sjhb	ap.key = uap->key;
120160189Sjhb	ap.msgflg = uap->msgflg;
121225617Skmacy	return sys_msgget(td, &ap);
122160189Sjhb}
123160189Sjhb
124160189Sjhbstruct ibcs2_msgctl_args {
125160189Sjhb	int what;
126160189Sjhb	int msqid;
127160189Sjhb	int cmd;
128160189Sjhb	struct ibcs2_msqid_ds *buf;
129160189Sjhb};
130160189Sjhb
131160189Sjhbstatic int
132160189Sjhbibcs2_msgctl(struct thread *td, void *v)
133160189Sjhb{
134160189Sjhb	struct ibcs2_msgctl_args *uap = v;
135160189Sjhb	struct ibcs2_msqid_ds is;
136160189Sjhb	struct msqid_ds bs;
137160189Sjhb	int error;
138160189Sjhb
139160189Sjhb	switch (uap->cmd) {
140160189Sjhb	case IBCS2_IPC_STAT:
141160189Sjhb		error = kern_msgctl(td, uap->msqid, IPC_STAT, &bs);
142160189Sjhb		if (!error) {
143160189Sjhb			cvt_msqid2imsqid(&bs, &is);
144160189Sjhb			error = copyout(&is, uap->buf, sizeof(is));
145160189Sjhb		}
146160189Sjhb		return (error);
147160189Sjhb	case IBCS2_IPC_SET:
148160189Sjhb		error = copyin(uap->buf, &is, sizeof(is));
149160189Sjhb		if (error)
150160189Sjhb			return (error);
151160189Sjhb		cvt_imsqid2msqid(&is, &bs);
152160189Sjhb		return (kern_msgctl(td, uap->msqid, IPC_SET, &bs));
153160189Sjhb	case IBCS2_IPC_RMID:
154160189Sjhb		return (kern_msgctl(td, uap->msqid, IPC_RMID, NULL));
155160189Sjhb	}
156160189Sjhb	return (EINVAL);
157160189Sjhb}
158160189Sjhb
159160189Sjhbstruct ibcs2_msgrcv_args {
160160189Sjhb	int what;
161160189Sjhb	int msqid;
162160189Sjhb	void *msgp;
163160189Sjhb	size_t msgsz;
164160189Sjhb	long msgtyp;
165160189Sjhb	int msgflg;
166160189Sjhb};
167160189Sjhb
168160189Sjhbstatic int
169160189Sjhbibcs2_msgrcv(struct thread *td, void *v)
170160189Sjhb{
171160189Sjhb	struct ibcs2_msgrcv_args *uap = v;
172160189Sjhb	struct msgrcv_args ap;
173160189Sjhb
174160189Sjhb	ap.msqid = uap->msqid;
175160189Sjhb	ap.msgp = uap->msgp;
176160189Sjhb	ap.msgsz = uap->msgsz;
177160189Sjhb	ap.msgtyp = uap->msgtyp;
178160189Sjhb	ap.msgflg = uap->msgflg;
179225617Skmacy	return (sys_msgrcv(td, &ap));
180160189Sjhb}
181160189Sjhb
182160189Sjhbstruct ibcs2_msgsnd_args {
183160189Sjhb	int what;
184160189Sjhb	int msqid;
185160189Sjhb	void *msgp;
186160189Sjhb	size_t msgsz;
187160189Sjhb	int msgflg;
188160189Sjhb};
189160189Sjhb
190160189Sjhbstatic int
191160189Sjhbibcs2_msgsnd(struct thread *td, void *v)
192160189Sjhb{
193160189Sjhb	struct ibcs2_msgsnd_args *uap = v;
194160189Sjhb	struct msgsnd_args ap;
195160189Sjhb
196160189Sjhb	ap.msqid = uap->msqid;
197160189Sjhb	ap.msgp = uap->msgp;
198160189Sjhb	ap.msgsz = uap->msgsz;
199160189Sjhb	ap.msgflg = uap->msgflg;
200225617Skmacy	return (sys_msgsnd(td, &ap));
201160189Sjhb}
202160189Sjhb
2033584Ssosint
20483366Sjulianibcs2_msgsys(td, uap)
20583366Sjulian	struct thread *td;
20611397Sswallace	struct ibcs2_msgsys_args *uap;
2073584Ssos{
208107849Salfred	switch (uap->which) {
209160189Sjhb	case 0:
210160189Sjhb		return (ibcs2_msgget(td, uap));
211160189Sjhb	case 1:
212160189Sjhb		return (ibcs2_msgctl(td, uap));
213160189Sjhb	case 2:
214160189Sjhb		return (ibcs2_msgrcv(td, uap));
215160189Sjhb	case 3:
216160189Sjhb		return (ibcs2_msgsnd(td, uap));
21711397Sswallace	default:
218160189Sjhb		return (EINVAL);
21911397Sswallace	}
22011397Sswallace}
22111397Sswallace
22211397Sswallace/*
22311397Sswallace * iBCS2 semsys call
22411397Sswallace */
22516322Sgpalmer#ifdef unused
22611397Sswallacestatic void
22711397Sswallacecvt_sem2isem(bp, ibp)
22811397Sswallacestruct sem *bp;
22911397Sswallacestruct ibcs2_sem *ibp;
23011397Sswallace{
23111397Sswallace	ibp->semval = bp->semval;
23211397Sswallace	ibp->sempid = bp->sempid;
23311397Sswallace	ibp->semncnt = bp->semncnt;
23411397Sswallace	ibp->semzcnt = bp->semzcnt;
23511397Sswallace	return;
2363584Ssos}
2373584Ssos
23811397Sswallacestatic void
23911397Sswallacecvt_isem2sem(ibp, bp)
24011397Sswallacestruct ibcs2_sem *ibp;
24111397Sswallacestruct sem *bp;
24211397Sswallace{
24311397Sswallace	bp->semval = ibp->semval;
24411397Sswallace	bp->sempid = ibp->sempid;
24511397Sswallace	bp->semncnt = ibp->semncnt;
24611397Sswallace	bp->semzcnt = ibp->semzcnt;
24711397Sswallace	return;
24811397Sswallace}
24916322Sgpalmer#endif
25011397Sswallace
25111397Sswallacestatic void
25243744Sguidocvt_iperm2perm(ipp, pp)
25343744Sguidostruct ibcs2_ipc_perm *ipp;
25443744Sguidostruct ipc_perm *pp;
25543744Sguido{
25643744Sguido	pp->uid = ipp->uid;
25743744Sguido	pp->gid = ipp->gid;
25843744Sguido	pp->cuid = ipp->cuid;
25943744Sguido	pp->cgid = ipp->cgid;
26043744Sguido	pp->mode = ipp->mode;
26143744Sguido	pp->seq = ipp->seq;
26243744Sguido	pp->key = ipp->key;
26343744Sguido}
26443744Sguido
26543744Sguidostatic void
26643744Sguidocvt_perm2iperm(pp, ipp)
26743744Sguidostruct ipc_perm *pp;
26843744Sguidostruct ibcs2_ipc_perm *ipp;
26943744Sguido{
27043744Sguido	ipp->uid = pp->uid;
27143744Sguido	ipp->gid = pp->gid;
27243744Sguido	ipp->cuid = pp->cuid;
27343744Sguido	ipp->cgid = pp->cgid;
27443744Sguido	ipp->mode = pp->mode;
27543744Sguido	ipp->seq = pp->seq;
27643744Sguido	ipp->key = pp->key;
27743744Sguido}
27843744Sguido
27943744Sguidostatic void
28011397Sswallacecvt_semid2isemid(bp, ibp)
28111397Sswallacestruct semid_ds *bp;
28211397Sswallacestruct ibcs2_semid_ds *ibp;
28311397Sswallace{
28443744Sguido	cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
28511397Sswallace	ibp->sem_base = (struct ibcs2_sem *)bp->sem_base;
28611397Sswallace	ibp->sem_nsems = bp->sem_nsems;
28711397Sswallace	ibp->sem_otime = bp->sem_otime;
28811397Sswallace	ibp->sem_ctime = bp->sem_ctime;
28911397Sswallace	return;
29011397Sswallace}
29111397Sswallace
29211397Sswallacestatic void
29311397Sswallacecvt_isemid2semid(ibp, bp)
29411397Sswallacestruct ibcs2_semid_ds *ibp;
29511397Sswallacestruct semid_ds *bp;
29611397Sswallace{
29743744Sguido	cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
29811397Sswallace	bp->sem_base = (struct sem *)ibp->sem_base;
29911397Sswallace	bp->sem_nsems = ibp->sem_nsems;
30011397Sswallace	bp->sem_otime = ibp->sem_otime;
30111397Sswallace	bp->sem_ctime = ibp->sem_ctime;
30211397Sswallace	return;
30311397Sswallace}
30411397Sswallace
305160189Sjhbstruct ibcs2_semctl_args {
306160189Sjhb	int what;
307160189Sjhb	int semid;
308160189Sjhb	int semnum;
309160189Sjhb	int cmd;
310160189Sjhb	union semun arg;
311160189Sjhb};
312160189Sjhb
313160189Sjhbstatic int
314160189Sjhbibcs2_semctl(struct thread *td, void *v)
3153584Ssos{
316160189Sjhb	struct ibcs2_semctl_args *uap = v;
317160189Sjhb	struct ibcs2_semid_ds is;
318160189Sjhb	struct semid_ds bs;
319160189Sjhb	union semun semun;
320160189Sjhb	register_t rval;
32111397Sswallace	int error;
32211397Sswallace
323160189Sjhb	switch(uap->cmd) {
324160189Sjhb	case IBCS2_IPC_STAT:
325160189Sjhb		semun.buf = &bs;
326160189Sjhb		error = kern_semctl(td, uap->semid, uap->semnum, IPC_STAT,
327160189Sjhb		    &semun, &rval);
328160189Sjhb		if (error)
329160189Sjhb			return (error);
330160189Sjhb		cvt_semid2isemid(&bs, &is);
331160189Sjhb		error = copyout(&is, uap->arg.buf, sizeof(is));
332160189Sjhb		if (error == 0)
333160189Sjhb			td->td_retval[0] = rval;
334160189Sjhb		return (error);
33511397Sswallace
336160189Sjhb	case IBCS2_IPC_SET:
337160189Sjhb		error = copyin(uap->arg.buf, &is, sizeof(is));
338160189Sjhb		if (error)
339160189Sjhb			return (error);
340160189Sjhb		cvt_isemid2semid(&is, &bs);
341160189Sjhb		semun.buf = &bs;
342160189Sjhb		return (kern_semctl(td, uap->semid, uap->semnum, IPC_SET,
343160189Sjhb		    &semun, td->td_retval));
344160189Sjhb	}
34543744Sguido
346160189Sjhb	return (kern_semctl(td, uap->semid, uap->semnum, uap->cmd, &uap->arg,
347160189Sjhb	    td->td_retval));
348160189Sjhb}
34911397Sswallace
350160189Sjhbstruct ibcs2_semget_args {
351160189Sjhb	int what;
352160189Sjhb	ibcs2_key_t key;
353160189Sjhb	int nsems;
354160189Sjhb	int semflg;
355160189Sjhb};
35620601Sswallace
357160189Sjhbstatic int
358160189Sjhbibcs2_semget(struct thread *td, void *v)
359160189Sjhb{
360160189Sjhb	struct ibcs2_semget_args *uap = v;
361160189Sjhb	struct semget_args ap;
36220601Sswallace
363160189Sjhb	ap.key = uap->key;
364160189Sjhb	ap.nsems = uap->nsems;
365160189Sjhb	ap.semflg = uap->semflg;
366225617Skmacy	return (sys_semget(td, &ap));
367160189Sjhb}
36811397Sswallace
369160189Sjhbstruct ibcs2_semop_args {
370160189Sjhb	int what;
371160189Sjhb	int semid;
372160189Sjhb	struct sembuf *sops;
373160189Sjhb	size_t nsops;
374160189Sjhb};
37511397Sswallace
376160189Sjhbstatic int
377160189Sjhbibcs2_semop(struct thread *td, void *v)
378160189Sjhb{
379160189Sjhb	struct ibcs2_semop_args *uap = v;
380160189Sjhb	struct semop_args ap;
381160189Sjhb
382160189Sjhb	ap.semid = uap->semid;
383160189Sjhb	ap.sops = uap->sops;
384160189Sjhb	ap.nsops = uap->nsops;
385225617Skmacy	return (sys_semop(td, &ap));
386160189Sjhb}
387160189Sjhb
388160189Sjhbint
389160189Sjhbibcs2_semsys(td, uap)
390160189Sjhb	struct thread *td;
391160189Sjhb	struct ibcs2_semsys_args *uap;
392160189Sjhb{
393160189Sjhb
394160189Sjhb	switch (uap->which) {
395160189Sjhb	case 0:
396160189Sjhb		return (ibcs2_semctl(td, uap));
397160189Sjhb	case 1:
398160189Sjhb		return (ibcs2_semget(td, uap));
399160189Sjhb	case 2:
400160189Sjhb		return (ibcs2_semop(td, uap));
40111397Sswallace	}
402160189Sjhb	return (EINVAL);
40311397Sswallace}
40411397Sswallace
40513334Speter
40611397Sswallace/*
40711397Sswallace * iBCS2 shmsys call
40811397Sswallace */
40911397Sswallace
41011397Sswallacestatic void
41111397Sswallacecvt_shmid2ishmid(bp, ibp)
41211397Sswallacestruct shmid_ds *bp;
41311397Sswallacestruct ibcs2_shmid_ds *ibp;
41411397Sswallace{
41543744Sguido	cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
41611397Sswallace	ibp->shm_segsz = bp->shm_segsz;
41711397Sswallace	ibp->shm_lpid = bp->shm_lpid;
41811397Sswallace	ibp->shm_cpid = bp->shm_cpid;
419194910Sjhb	if (bp->shm_nattch > SHRT_MAX)
420194910Sjhb		ibp->shm_nattch = SHRT_MAX;
421194910Sjhb	else
422194910Sjhb		ibp->shm_nattch = bp->shm_nattch;
42311397Sswallace	ibp->shm_cnattch = 0;			/* ignored anyway */
42411397Sswallace	ibp->shm_atime = bp->shm_atime;
42511397Sswallace	ibp->shm_dtime = bp->shm_dtime;
42611397Sswallace	ibp->shm_ctime = bp->shm_ctime;
42711397Sswallace	return;
4283584Ssos}
4293584Ssos
43011397Sswallacestatic void
43111397Sswallacecvt_ishmid2shmid(ibp, bp)
43211397Sswallacestruct ibcs2_shmid_ds *ibp;
43311397Sswallacestruct shmid_ds *bp;
43411397Sswallace{
43543744Sguido	cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
43611397Sswallace	bp->shm_segsz = ibp->shm_segsz;
43711397Sswallace	bp->shm_lpid = ibp->shm_lpid;
43811397Sswallace	bp->shm_cpid = ibp->shm_cpid;
43911397Sswallace	bp->shm_nattch = ibp->shm_nattch;
44011397Sswallace	bp->shm_atime = ibp->shm_atime;
44111397Sswallace	bp->shm_dtime = ibp->shm_dtime;
44211397Sswallace	bp->shm_ctime = ibp->shm_ctime;
44311397Sswallace	return;
44411397Sswallace}
44511397Sswallace
446160189Sjhbstruct ibcs2_shmat_args {
447160189Sjhb	int what;
448160189Sjhb	int shmid;
449160189Sjhb	const void *shmaddr;
450160189Sjhb	int shmflg;
451160189Sjhb};
452160189Sjhb
453160189Sjhbstatic int
454160189Sjhbibcs2_shmat(struct thread *td, void *v)
4553584Ssos{
456160189Sjhb	struct ibcs2_shmat_args *uap = v;
457160189Sjhb	struct shmat_args ap;
458160189Sjhb
459160189Sjhb	ap.shmid = uap->shmid;
460160189Sjhb	ap.shmaddr = uap->shmaddr;
461160189Sjhb	ap.shmflg = uap->shmflg;
462225617Skmacy	return (sys_shmat(td, &ap));
463160189Sjhb}
464160189Sjhb
465160189Sjhbstruct ibcs2_shmctl_args {
466160189Sjhb	int what;
467160189Sjhb	int shmid;
468160189Sjhb	int cmd;
469160189Sjhb	struct ibcs2_shmid_ds *buf;
470160189Sjhb};
471160189Sjhb
472160189Sjhbstatic int
473160189Sjhbibcs2_shmctl(struct thread *td, void *v)
474160189Sjhb{
475160189Sjhb	struct ibcs2_shmctl_args *uap = v;
476160189Sjhb	struct ibcs2_shmid_ds is;
477160189Sjhb	struct shmid_ds bs;
47811397Sswallace	int error;
47911397Sswallace
480160189Sjhb	switch(uap->cmd) {
481160189Sjhb	case IBCS2_IPC_STAT:
482160189Sjhb		error = kern_shmctl(td, uap->shmid, IPC_STAT, &bs, NULL);
483160189Sjhb		if (error)
484160189Sjhb			return (error);
485160189Sjhb		cvt_shmid2ishmid(&bs, &is);
486160189Sjhb		return (copyout(&is, uap->buf, sizeof(is)));
48711397Sswallace
488160189Sjhb	case IBCS2_IPC_SET:
489160189Sjhb		error = copyin(uap->buf, &is, sizeof(is));
490160189Sjhb		if (error)
491160189Sjhb			return (error);
492160189Sjhb		cvt_ishmid2shmid(&is, &bs);
493160189Sjhb		return (kern_shmctl(td, uap->shmid, IPC_SET, &bs, NULL));
49411397Sswallace
495160189Sjhb	case IPC_INFO:
496160189Sjhb	case SHM_INFO:
497160189Sjhb	case SHM_STAT:
498160189Sjhb		/* XXX: */
499160189Sjhb		return (EINVAL);
500160189Sjhb	}
50111397Sswallace
502160189Sjhb	return (kern_shmctl(td, uap->shmid, uap->cmd, NULL, NULL));
503160189Sjhb}
50420601Sswallace
505160189Sjhbstruct ibcs2_shmdt_args {
506160189Sjhb	int what;
507160189Sjhb	const void *shmaddr;
508160189Sjhb};
50911397Sswallace
510160189Sjhbstatic int
511160189Sjhbibcs2_shmdt(struct thread *td, void *v)
512160189Sjhb{
513160189Sjhb	struct ibcs2_shmdt_args *uap = v;
514160189Sjhb	struct shmdt_args ap;
51511397Sswallace
516160189Sjhb	ap.shmaddr = uap->shmaddr;
517225617Skmacy	return (sys_shmdt(td, &ap));
518160189Sjhb}
519160189Sjhb
520160189Sjhbstruct ibcs2_shmget_args {
521160189Sjhb	int what;
522160189Sjhb	ibcs2_key_t key;
523160189Sjhb	size_t size;
524160189Sjhb	int shmflg;
525160189Sjhb};
526160189Sjhb
527160189Sjhbstatic int
528160189Sjhbibcs2_shmget(struct thread *td, void *v)
529160189Sjhb{
530160189Sjhb	struct ibcs2_shmget_args *uap = v;
531160189Sjhb	struct shmget_args ap;
532160189Sjhb
533160189Sjhb	ap.key = uap->key;
534160189Sjhb	ap.size = uap->size;
535160189Sjhb	ap.shmflg = uap->shmflg;
536225617Skmacy	return (sys_shmget(td, &ap));
537160189Sjhb}
538160189Sjhb
539160189Sjhbint
540160189Sjhbibcs2_shmsys(td, uap)
541160189Sjhb	struct thread *td;
542160189Sjhb	struct ibcs2_shmsys_args *uap;
543160189Sjhb{
544160189Sjhb
545160189Sjhb	switch (uap->which) {
546160189Sjhb	case 0:
547160189Sjhb		return (ibcs2_shmat(td, uap));
548160189Sjhb	case 1:
549160189Sjhb		return (ibcs2_shmctl(td, uap));
550160189Sjhb	case 2:
551160189Sjhb		return (ibcs2_shmdt(td, uap));
552160189Sjhb	case 3:
553160189Sjhb		return (ibcs2_shmget(td, uap));
55411397Sswallace	}
555160189Sjhb	return (EINVAL);
55611397Sswallace}
557148541Sjhb
558148541SjhbMODULE_DEPEND(ibcs2, sysvmsg, 1, 1, 1);
559148541SjhbMODULE_DEPEND(ibcs2, sysvsem, 1, 1, 1);
560148541SjhbMODULE_DEPEND(ibcs2, sysvshm, 1, 1, 1);
561