[BACK]Return to svr4_32_ipc.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / compat / svr4_32

File: [cvs.NetBSD.org] / src / sys / compat / svr4_32 / Attic / svr4_32_ipc.c (download)

Revision 1.20, Mon Apr 28 20:23:46 2008 UTC (15 years, 11 months ago) by martin
Branch: MAIN
CVS Tags: yamt-pf42-base4, yamt-pf42-base3, yamt-pf42-base2, yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, yamt-nfs-mp-base9, yamt-nfs-mp-base8, yamt-nfs-mp-base7, yamt-nfs-mp-base6, yamt-nfs-mp-base5, yamt-nfs-mp-base4, yamt-nfs-mp-base3, yamt-nfs-mp-base2, yamt-nfs-mp-base11, yamt-nfs-mp-base10, wrstuden-revivesa-base-4, wrstuden-revivesa-base-3, wrstuden-revivesa-base-2, wrstuden-revivesa-base-1, wrstuden-revivesa-base, uebayasi-xip-base4, uebayasi-xip-base3, uebayasi-xip-base2, uebayasi-xip-base1, uebayasi-xip-base, uebayasi-xip, tls-maxphys-base-20171202, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, simonb-wapbl-nbase, simonb-wapbl-base, simonb-wapbl, rmind-uvmplock-nbase, rmind-uvmplock-base, rmind-uvmplock, rmind-smpnet-nbase, rmind-smpnet-base, rmind-smpnet, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-base, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, perseant-stdc-iso10646-base, perseant-stdc-iso10646, nick-nhusb-base-20170825, nick-nhusb-base-20170204, nick-nhusb-base-20161204, nick-nhusb-base-20161004, nick-nhusb-base-20160907, nick-nhusb-base-20160529, nick-nhusb-base-20160422, nick-nhusb-base-20160319, nick-nhusb-base-20151226, nick-nhusb-base-20150921, nick-nhusb-base-20150606, nick-nhusb-base-20150406, nick-nhusb-base, nick-nhusb, nick-hppapmap-base4, nick-hppapmap-base3, nick-hppapmap-base2, nick-hppapmap-base, nick-hppapmap, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, mjf-devfs2-base, matt-premerge-20091211, matt-nb8-mediatek-base, matt-nb8-mediatek, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, localcount-20160914, khorben-n900, jymxensuspend-base, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, jruoho-x86intr-base, jruoho-x86intr, jmcneill-usbmp-pre-base2, jmcneill-usbmp-base9, jmcneill-usbmp-base8, jmcneill-usbmp-base7, jmcneill-usbmp-base6, jmcneill-usbmp-base5, jmcneill-usbmp-base4, jmcneill-usbmp-base3, jmcneill-usbmp-base2, jmcneill-usbmp-base10, jmcneill-usbmp-base, jmcneill-usbmp, jmcneill-audiomp3-base, jmcneill-audiomp3, jdolecek-ncq-base, jdolecek-ncq, hpcarm-cleanup-nbase, haad-nbase2, haad-dm-base2, haad-dm-base1, haad-dm-base, haad-dm, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver, ad-audiomp2-base, ad-audiomp2
Branch point for: wrstuden-revivesa, phil-wifi, pgoyette-compat
Changes since 1.19: +2 -9 lines

Remove clause 3 and 4 from TNF licenses

/*	$NetBSD: svr4_32_ipc.c,v 1.20 2008/04/28 20:23:46 martin Exp $	*/

/*-
 * Copyright (c) 1995 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Christos Zoulas.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_32_ipc.c,v 1.20 2008/04/28 20:23:46 martin Exp $");

#if defined(_KERNEL_OPT)
#include "opt_sysv.h"
#endif

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/proc.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/systm.h>
#include <sys/stat.h>

#include <sys/mount.h>
#include <sys/syscallargs.h>

#include <compat/svr4_32/svr4_32_types.h>
#include <compat/svr4_32/svr4_32_signal.h>
#include <compat/svr4_32/svr4_32_lwp.h>
#include <compat/svr4_32/svr4_32_ucontext.h>
#include <compat/svr4_32/svr4_32_syscallargs.h>
#include <compat/svr4_32/svr4_32_util.h>
#include <compat/svr4_32/svr4_32_ipc.h>

#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)
static void svr4_32_to_bsd_ipc_perm(const struct svr4_32_ipc_perm *,
				      struct ipc_perm *);
static void bsd_to_svr4_32_ipc_perm(const struct ipc_perm *,
				      struct svr4_32_ipc_perm *);
#endif

#ifdef SYSVSEM
static void bsd_to_svr4_32_semid_ds(const struct semid_ds *,
				      struct svr4_32_semid_ds *);
static void svr4_32_to_bsd_semid_ds(const struct svr4_32_semid_ds *,
				      struct semid_ds *);
#endif

#ifdef SYSVMSG
static void bsd_to_svr4_32_msqid_ds(const struct msqid_ds *,
				      struct svr4_32_msqid_ds *);
static void svr4_32_to_bsd_msqid_ds(const struct svr4_32_msqid_ds *,
				      struct msqid_ds *);
#endif

#ifdef SYSVSHM
static void bsd_to_svr4_32_shmid_ds(const struct shmid_ds *,
				      struct svr4_32_shmid_ds *);
static void svr4_32_to_bsd_shmid_ds(const struct svr4_32_shmid_ds *,
				      struct shmid_ds *);
#endif

#if defined(SYSVMSG) || defined(SYSVSHM) || defined(SYSVSEM)

static void
svr4_32_to_bsd_ipc_perm(const struct svr4_32_ipc_perm *spp, struct ipc_perm *bpp)
{
	bpp->_key = spp->key;
	bpp->uid = spp->uid;
	bpp->gid = spp->gid;
	bpp->cuid = spp->cuid;
	bpp->cgid = spp->cgid;
	bpp->mode = spp->mode;
	bpp->_seq = spp->seq;
}

static void
bsd_to_svr4_32_ipc_perm(const struct ipc_perm *bpp, struct svr4_32_ipc_perm *spp)
{
	spp->key = bpp->_key;
	spp->uid = bpp->uid;
	spp->gid = bpp->gid;
	spp->cuid = bpp->cuid;
	spp->cgid = bpp->cgid;
	spp->mode = bpp->mode;
	spp->seq = bpp->_seq;
}
#endif

#ifdef SYSVSEM
static void
bsd_to_svr4_32_semid_ds(const struct semid_ds *bds, struct svr4_32_semid_ds *sds)
{
	bsd_to_svr4_32_ipc_perm(&bds->sem_perm, &sds->sem_perm);
	NETBSD32PTR32(sds->sem_base, bds->_sem_base);
	sds->sem_nsems = bds->sem_nsems;
	sds->sem_otime = bds->sem_otime;
	sds->sem_ctime = bds->sem_ctime;
}

static void
svr4_32_to_bsd_semid_ds(const struct svr4_32_semid_ds *sds, struct semid_ds *bds)
{
	svr4_32_to_bsd_ipc_perm(&sds->sem_perm, &bds->sem_perm);
	bds->_sem_base = NETBSD32PTR64(sds->sem_base);
	bds->sem_nsems = sds->sem_nsems;
	bds->sem_otime = sds->sem_otime;
	bds->sem_ctime = sds->sem_ctime;
}

struct svr4_32_sys_semctl_args {
	syscallarg(int) what;
	syscallarg(int) semid;
	syscallarg(int) semnum;
	syscallarg(int) cmd;
	syscallarg(union netbsd32_semun) arg;
};

static int
svr4_32_semctl(struct lwp *l, const struct svr4_32_sys_semctl_args *uap, register_t *retval)
{
	struct semid_ds sembuf;
	struct svr4_32_semid_ds ssembuf;
	int cmd, error;
	void *pass_arg = NULL;
	union netbsd32_semun arg;

	cmd = SCARG(uap, cmd);

	switch (cmd) {
	case SVR4_IPC_SET:
		pass_arg = &sembuf;
		cmd = IPC_SET;
		break;

	case SVR4_IPC_STAT:
		pass_arg = &sembuf;
		cmd = IPC_STAT;
		break;

	case SVR4_IPC_RMID:
		cmd = IPC_RMID;
		break;

	case SVR4_SEM_GETVAL:
		cmd = GETVAL;
		break;

	case SVR4_SEM_GETPID:
		cmd = GETPID;
		break;

	case SVR4_SEM_GETNCNT:
		cmd = GETNCNT;
		break;

	case SVR4_SEM_GETZCNT:
		cmd = GETZCNT;
		break;

	case SVR4_SEM_GETALL:
		arg = SCARG(uap, arg);
		pass_arg = &arg;
		cmd = GETALL;
		break;

	case SVR4_SEM_SETVAL:
		arg = SCARG(uap, arg);
		pass_arg = &arg;
		cmd = SETVAL;
		break;

	case SVR4_SEM_SETALL:
		arg = SCARG(uap, arg);
		pass_arg = &arg;
		cmd = SETALL;
		break;

	default:
		return (EINVAL);
	}

	if (cmd == IPC_SET) {
		error = copyin(NETBSD32PTR64(SCARG(uap, arg).buf),
			       &ssembuf, sizeof(ssembuf));
		if (error)
			return (error);
		svr4_32_to_bsd_semid_ds(&ssembuf, &sembuf);
	}

	error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
	    pass_arg, retval);

	if (error == 0 && cmd == IPC_STAT) {
		bsd_to_svr4_32_semid_ds(&sembuf, &ssembuf);
		error = copyout(&ssembuf, NETBSD32PTR64(SCARG(uap, arg).buf),
				sizeof(ssembuf));
	}

	return (error);
}

struct svr4_32_sys_semget_args {
	syscallarg(int) what;
	syscallarg(svr4_key_t) key;
	syscallarg(int) nsems;
	syscallarg(int) semflg;
};

static int
svr4_32_semget(struct lwp *l, const struct svr4_32_sys_semget_args *uap, register_t *retval)
{
	struct sys_semget_args ap;

	SCARG(&ap, key) = SCARG(uap, key);
	SCARG(&ap, nsems) = SCARG(uap, nsems);
	SCARG(&ap, semflg) = SCARG(uap, semflg);

	return sys_semget(l, &ap, retval);
}

struct svr4_32_sys_semop_args {
	syscallarg(int) what;
	syscallarg(int) semid;
	syscallarg(svr4_32_sembufp) sops;
	syscallarg(u_int) nsops;
};

static int
svr4_32_semop(struct lwp *l, const struct svr4_32_sys_semop_args *uap, register_t *retval)
{
	struct sys_semop_args ap;

	SCARG(&ap, semid) = SCARG(uap, semid);
	/* These are the same */
	SCARG(&ap, sops) = SCARG_P32(uap, sops);
	SCARG(&ap, nsops) = SCARG(uap, nsops);

	return sys_semop(l, &ap, retval);
}

int
svr4_32_sys_semsys(struct lwp *l, const struct svr4_32_sys_semsys_args *uap, register_t *retval)
{

	DPRINTF(("svr4_32_semsys(%d)\n", SCARG(uap, what)));

	switch (SCARG(uap, what)) {
	case SVR4_semctl:
		return svr4_32_semctl(l, (const void *)uap, retval);
	case SVR4_semget:
		return svr4_32_semget(l, (const void *)uap, retval);
	case SVR4_semop:
		return svr4_32_semop(l, (const void *)uap, retval);
	default:
		return EINVAL;
	}
}
#endif

#ifdef SYSVMSG
static void
bsd_to_svr4_32_msqid_ds(const struct msqid_ds *bds, struct svr4_32_msqid_ds *sds)
{
	bsd_to_svr4_32_ipc_perm(&bds->msg_perm, &sds->msg_perm);
	NETBSD32PTR32(sds->msg_first, bds->_msg_first);
	NETBSD32PTR32(sds->msg_last, bds->_msg_last);
	sds->msg_cbytes = bds->_msg_cbytes;
	sds->msg_qnum = bds->msg_qnum;
	sds->msg_qbytes = bds->msg_qbytes;
	sds->msg_lspid = bds->msg_lspid;
	sds->msg_lrpid = bds->msg_lrpid;
	sds->msg_stime = bds->msg_stime;
	sds->msg_rtime = bds->msg_rtime;
	sds->msg_ctime = bds->msg_ctime;

#if 0
	/* XXX What to put here? */
	sds->msg_cv = 0;
	sds->msg_qnum_cv = 0;
#endif
}

static void
svr4_32_to_bsd_msqid_ds(const struct svr4_32_msqid_ds *sds, struct msqid_ds *bds)
{
	svr4_32_to_bsd_ipc_perm(&sds->msg_perm, &bds->msg_perm);
	bds->_msg_first = NETBSD32PTR64(sds->msg_first);
	bds->_msg_last = NETBSD32PTR64(sds->msg_last);
	bds->_msg_cbytes = sds->msg_cbytes;
	bds->msg_qnum = sds->msg_qnum;
	bds->msg_qbytes = sds->msg_qbytes;
	bds->msg_lspid = sds->msg_lspid;
	bds->msg_lrpid = sds->msg_lrpid;
	bds->msg_stime = sds->msg_stime;
	bds->msg_rtime = sds->msg_rtime;
	bds->msg_ctime = sds->msg_ctime;

#if 0
	XXX sds->msg_cv
	XXX sds->msg_qnum_cv
#endif
}

struct svr4_32_sys_msgsnd_args {
	syscallarg(int) what;
	syscallarg(int) msqid;
	syscallarg(netbsd32_voidp) msgp;
	syscallarg(netbsd32_size_t) msgsz;
	syscallarg(int) msgflg;
};

static int
svr4_32_msgsnd(struct lwp *l, const struct svr4_32_sys_msgsnd_args *uap, register_t *retval)
{
	struct sys_msgsnd_args ap;

	SCARG(&ap, msqid) = SCARG(uap, msqid);
	SCARG(&ap, msgp) = SCARG_P32(uap, msgp);
	SCARG(&ap, msgsz) = SCARG(uap, msgsz);
	SCARG(&ap, msgflg) = SCARG(uap, msgflg);

	return sys_msgsnd(l, &ap, retval);
}

struct svr4_32_sys_msgrcv_args {
	syscallarg(int) what;
	syscallarg(int) msqid;
	syscallarg(netbsd32_voidp) msgp;
	syscallarg(netbsd32_size_t) msgsz;
	syscallarg(netbsd32_long) msgtyp;
	syscallarg(int) msgflg;
};

static int
svr4_32_msgrcv(struct lwp *l, const struct svr4_32_sys_msgrcv_args *uap, register_t *retval)
{
	struct sys_msgrcv_args ap;

	SCARG(&ap, msqid) = SCARG(uap, msqid);
	SCARG(&ap, msgp) = SCARG_P32(uap, msgp);
	SCARG(&ap, msgsz) = SCARG(uap, msgsz);
	SCARG(&ap, msgtyp) = SCARG(uap, msgtyp);
	SCARG(&ap, msgflg) = SCARG(uap, msgflg);

	return sys_msgrcv(l, &ap, retval);
}

struct svr4_32_sys_msgget_args {
	syscallarg(int) what;
	syscallarg(svr4_key_t) key;
	syscallarg(int) msgflg;
};

static int
svr4_32_msgget(struct lwp *l, const struct svr4_32_sys_msgget_args *uap, register_t *retval)
{
	struct sys_msgget_args ap;

	SCARG(&ap, key) = SCARG(uap, key);
	SCARG(&ap, msgflg) = SCARG(uap, msgflg);

	return sys_msgget(l, &ap, retval);
}

struct svr4_32_sys_msgctl_args {
	syscallarg(int) what;
	syscallarg(int) msqid;
	syscallarg(int) cmd;
	syscallarg(svr4_32_msqid_dsp) buf;
};

static int
svr4_32_msgctl(struct lwp *l, const struct svr4_32_sys_msgctl_args *uap, register_t *retval)
{
	struct svr4_32_msqid_ds ss;
	struct msqid_ds bs;
	int error;

	switch (SCARG(uap, cmd)) {
	case SVR4_IPC_STAT:
		error = msgctl1(l, SCARG(uap, msqid), IPC_STAT, &bs);
		if (error == 0) {
			bsd_to_svr4_32_msqid_ds(&bs, &ss);
			error = copyout(&ss, SCARG_P32(uap, buf), sizeof ss);
		}
		return error;

	case SVR4_IPC_SET:
		error = copyin(SCARG_P32(uap, buf), &ss, sizeof ss);
		if (error)
			return error;
		svr4_32_to_bsd_msqid_ds(&ss, &bs);
		return msgctl1(l, SCARG(uap, msqid), IPC_SET, &bs);

	case SVR4_IPC_RMID:
		return msgctl1(l, SCARG(uap, msqid), IPC_RMID, NULL);

	default:
		return EINVAL;
	}
}

int
svr4_32_sys_msgsys(struct lwp *l, const struct svr4_32_sys_msgsys_args *uap, register_t *retval)
{

	DPRINTF(("svr4_32_msgsys(%d)\n", SCARG(uap, what)));

	switch (SCARG(uap, what)) {
	case SVR4_msgsnd:
		return svr4_32_msgsnd(l, (const void *)uap, retval);
	case SVR4_msgrcv:
		return svr4_32_msgrcv(l, (const void *)uap, retval);
	case SVR4_msgget:
		return svr4_32_msgget(l, (const void *)uap, retval);
	case SVR4_msgctl:
		return svr4_32_msgctl(l, (const void *)uap, retval);
	default:
		return EINVAL;
	}
}
#endif

#ifdef SYSVSHM

static void
bsd_to_svr4_32_shmid_ds(const struct shmid_ds *bds, struct svr4_32_shmid_ds *sds)
{
	bsd_to_svr4_32_ipc_perm(&bds->shm_perm, &sds->shm_perm);
	sds->shm_segsz = bds->shm_segsz;
	sds->shm_lkcnt = 0;
	sds->shm_lpid = bds->shm_lpid;
	sds->shm_cpid = bds->shm_cpid;
	NETBSD32PTR32(sds->shm_amp, bds->_shm_internal);
	sds->shm_nattch = bds->shm_nattch;
	sds->shm_cnattch = 0;
	sds->shm_atime = bds->shm_atime;
	sds->shm_pad1 = 0;
	sds->shm_dtime = bds->shm_dtime;
	sds->shm_pad2 = 0;
	sds->shm_ctime = bds->shm_ctime;
	sds->shm_pad3 = 0;
}

static void
svr4_32_to_bsd_shmid_ds(const struct svr4_32_shmid_ds *sds, struct shmid_ds *bds)
{
	svr4_32_to_bsd_ipc_perm(&sds->shm_perm, &bds->shm_perm);
	bds->shm_segsz = sds->shm_segsz;
	bds->shm_lpid = sds->shm_lpid;
	bds->shm_cpid = sds->shm_cpid;
	bds->_shm_internal = NETBSD32PTR64(sds->shm_amp);
	bds->shm_nattch = sds->shm_nattch;
	bds->shm_atime = sds->shm_atime;
	bds->shm_dtime = sds->shm_dtime;
	bds->shm_ctime = sds->shm_ctime;
}

struct svr4_32_sys_shmat_args {
	syscallarg(int) what;
	syscallarg(int) shmid;
	syscallarg(netbsd32_voidp) shmaddr;
	syscallarg(int) shmflg;
};

static int
svr4_32_shmat(struct lwp *l, const struct svr4_32_sys_shmat_args *uap, register_t *retval)
{
	struct sys_shmat_args ap;

	SCARG(&ap, shmid) = SCARG(uap, shmid);
	SCARG(&ap, shmaddr) = SCARG_P32(uap, shmaddr);
	SCARG(&ap, shmflg) = SCARG(uap, shmflg);

	return sys_shmat(l, &ap, retval);
}

struct svr4_32_sys_shmdt_args {
	syscallarg(int) what;
	syscallarg(netbsd32_voidp) shmaddr;
};

static int
svr4_32_shmdt(struct lwp *l, const struct svr4_32_sys_shmdt_args *uap, register_t *retval)
{
	struct sys_shmdt_args ap;

	SCARG(&ap, shmaddr) = SCARG_P32(uap, shmaddr);

	return sys_shmdt(l, &ap, retval);
}

struct svr4_32_sys_shmget_args {
	syscallarg(int) what;
	syscallarg(netbsd32_key_t) key;
	syscallarg(int) size;
	syscallarg(int) shmflg;
};

static int
svr4_32_shmget(struct lwp *l, const struct svr4_32_sys_shmget_args *uap, register_t *retval)
{
	struct sys_shmget_args ap;

	SCARG(&ap, key) = SCARG(uap, key);
	SCARG(&ap, size) = SCARG(uap, size);
	SCARG(&ap, shmflg) = SCARG(uap, shmflg);

	return sys_shmget(l, &ap, retval);
}

struct svr4_32_sys_shmctl_args {
	syscallarg(int) what;
	syscallarg(int) shmid;
	syscallarg(int) cmd;
	syscallarg(svr4_32_shmid_dsp) buf;
};

static int
svr4_32_shmctl(struct lwp *l, const struct svr4_32_sys_shmctl_args *uap, register_t *retval)
{
	struct shmid_ds bs;
	struct svr4_32_shmid_ds ss;
	int error;

	switch (SCARG(uap, cmd)) {
	case SVR4_IPC_STAT:
		error = shmctl1(l, SCARG(uap, shmid), IPC_STAT, &bs);
		if (error == 0) {
			bsd_to_svr4_32_shmid_ds(&bs, &ss);
			error = copyout(&ss, SCARG_P32(uap, buf), sizeof ss);
		}
		return error;

	case SVR4_IPC_SET:
		error = copyin(SCARG_P32(uap, buf), &ss, sizeof ss);
		if (error)
			return error;
		svr4_32_to_bsd_shmid_ds(&ss, &bs);
		return shmctl1(l, SCARG(uap, shmid), IPC_SET, &bs);

	case SVR4_IPC_RMID:
		return shmctl1(l, SCARG(uap, shmid), IPC_RMID, NULL);

	case SVR4_SHM_LOCK:
		return shmctl1(l, SCARG(uap, shmid), SHM_LOCK, NULL);

	case SVR4_SHM_UNLOCK:
		return shmctl1(l, SCARG(uap, shmid), SHM_UNLOCK, NULL);

	default:
		return EINVAL;
	}
}

int
svr4_32_sys_shmsys(struct lwp *l, const struct svr4_32_sys_shmsys_args *uap, register_t *retval)
{

	DPRINTF(("svr4_32_shmsys(%d)\n", SCARG(uap, what)));

	switch (SCARG(uap, what)) {
	case SVR4_shmat:
		return svr4_32_shmat(l, (const void *)uap, retval);
	case SVR4_shmdt:
		return svr4_32_shmdt(l, (const void *)uap, retval);
	case SVR4_shmget:
		return svr4_32_shmget(l, (const void *)uap, retval);
	case SVR4_shmctl:
		return svr4_32_shmctl(l, (const void *)uap, retval);
	default:
		return ENOSYS;
	}
}
#endif /* SYSVSHM */