2007-12-21 02:02:38 +03:00
|
|
|
/* $NetBSD: ibcs2_ipc.c,v 1.27 2007/12/20 23:02:49 dsl Exp $ */
|
1996-05-03 21:05:16 +04:00
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Scott Bartram
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
2000-11-30 00:51:49 +03:00
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-12-21 02:02:38 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ibcs2_ipc.c,v 1.27 2007/12/20 23:02:49 dsl Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
2001-05-30 15:37:21 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-10-20 02:34:49 +04:00
|
|
|
#include "opt_sysv.h"
|
2000-11-30 00:51:49 +03:00
|
|
|
#endif
|
1998-10-20 02:34:49 +04:00
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/reboot.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/times.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/msg.h>
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
|
|
|
#include <compat/ibcs2/ibcs2_types.h>
|
|
|
|
#include <compat/ibcs2/ibcs2_signal.h>
|
|
|
|
#include <compat/ibcs2/ibcs2_syscallargs.h>
|
|
|
|
#include <compat/ibcs2/ibcs2_util.h>
|
|
|
|
|
2005-09-13 05:42:32 +04:00
|
|
|
#include <compat/sys/sem.h>
|
2005-11-10 21:47:53 +03:00
|
|
|
#include <compat/sys/shm.h>
|
2005-11-11 20:10:42 +03:00
|
|
|
#include <compat/sys/msg.h>
|
2005-09-13 05:42:32 +04:00
|
|
|
|
2007-06-17 20:32:51 +04:00
|
|
|
/* Verify that the standard values are correct. */
|
|
|
|
typedef char x[IPC_RMID == 0 && IPC_SET == 1 && IPC_STAT == 2 ? 1 : -1];
|
1995-03-14 18:12:17 +03:00
|
|
|
|
1999-08-25 08:52:06 +04:00
|
|
|
struct ibcs2_ipc_perm {
|
|
|
|
ibcs2_uid_t uid;
|
|
|
|
ibcs2_gid_t gid;
|
|
|
|
ibcs2_uid_t cuid;
|
|
|
|
ibcs2_gid_t cgid;
|
|
|
|
ibcs2_mode_t mode;
|
|
|
|
u_short seq;
|
|
|
|
ibcs2_key_t key;
|
|
|
|
};
|
|
|
|
|
2007-06-17 20:32:51 +04:00
|
|
|
struct ibcs2_msqid_ds {
|
|
|
|
struct ibcs2_ipc_perm msg_perm;
|
|
|
|
struct __msg *msg_first; /* kernel address don't copyout */
|
|
|
|
struct __msg *msg_last; /* kernel address don't copyout */
|
|
|
|
u_short msg_cbytes;
|
|
|
|
u_short msg_qnum;
|
|
|
|
u_short msg_qbytes;
|
|
|
|
u_short msg_lspid;
|
|
|
|
u_short msg_lrpid;
|
|
|
|
ibcs2_time_t msg_stime;
|
|
|
|
ibcs2_time_t msg_rtime;
|
|
|
|
ibcs2_time_t msg_ctime;
|
|
|
|
};
|
1999-08-25 08:52:06 +04:00
|
|
|
|
2007-06-17 20:32:51 +04:00
|
|
|
#if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
|
1999-08-25 08:52:06 +04:00
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_perm2iperm(const struct ipc_perm *bp, struct ibcs2_ipc_perm *ibp)
|
1999-08-25 08:52:06 +04:00
|
|
|
{
|
|
|
|
ibp->cuid = bp->cuid;
|
|
|
|
ibp->cgid = bp->cgid;
|
|
|
|
ibp->uid = bp->uid;
|
|
|
|
ibp->gid = bp->gid;
|
|
|
|
ibp->mode = bp->mode;
|
2007-06-17 20:32:51 +04:00
|
|
|
ibp->seq = bp->_seq;
|
|
|
|
ibp->key = bp->_key;
|
1999-08-25 08:52:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_iperm2perm(const struct ibcs2_ipc_perm *ibp, struct ipc_perm *bp)
|
1999-08-25 08:52:06 +04:00
|
|
|
{
|
|
|
|
bp->cuid = ibp->cuid;
|
|
|
|
bp->cgid = ibp->cgid;
|
|
|
|
bp->uid = ibp->uid;
|
|
|
|
bp->gid = ibp->gid;
|
|
|
|
bp->mode = ibp->mode;
|
2007-06-17 20:32:51 +04:00
|
|
|
bp->_seq = ibp->seq;
|
|
|
|
bp->_key = ibp->key;
|
1999-08-25 08:52:06 +04:00
|
|
|
}
|
|
|
|
#endif /* SYSVMSG || SYSVSEM || SYSVMSG */
|
|
|
|
|
1997-01-18 04:51:41 +03:00
|
|
|
#ifdef SYSVMSG
|
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
/*
|
|
|
|
* iBCS2 msgsys call
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_msqid2imsqid(const struct msqid_ds *bp, struct ibcs2_msqid_ds *ibp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_perm2iperm(&bp->msg_perm, &ibp->msg_perm);
|
2007-06-17 20:32:51 +04:00
|
|
|
ibp->msg_first = NULL;
|
|
|
|
ibp->msg_last = NULL;
|
|
|
|
ibp->msg_cbytes = bp->_msg_cbytes;
|
|
|
|
ibp->msg_qnum = bp->msg_qnum;
|
|
|
|
ibp->msg_qbytes = bp->msg_qbytes;
|
|
|
|
ibp->msg_lspid = bp->msg_lspid;
|
|
|
|
ibp->msg_lrpid = bp->msg_lrpid;
|
1995-03-14 18:12:17 +03:00
|
|
|
ibp->msg_stime = bp->msg_stime;
|
|
|
|
ibp->msg_rtime = bp->msg_rtime;
|
|
|
|
ibp->msg_ctime = bp->msg_ctime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_imsqid2msqid(struct ibcs2_msqid_ds *ibp, struct msqid_ds *bp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_iperm2perm(&ibp->msg_perm, &bp->msg_perm);
|
2007-06-17 20:32:51 +04:00
|
|
|
bp->_msg_first = NULL;
|
|
|
|
bp->_msg_last = NULL;
|
|
|
|
bp->_msg_cbytes = ibp->msg_cbytes;
|
1995-03-14 18:12:17 +03:00
|
|
|
bp->msg_qnum = ibp->msg_qnum;
|
|
|
|
bp->msg_qbytes = ibp->msg_qbytes;
|
|
|
|
bp->msg_lspid = ibp->msg_lspid;
|
|
|
|
bp->msg_lrpid = ibp->msg_lrpid;
|
|
|
|
bp->msg_stime = ibp->msg_stime;
|
|
|
|
bp->msg_rtime = ibp->msg_rtime;
|
|
|
|
bp->msg_ctime = ibp->msg_ctime;
|
|
|
|
}
|
|
|
|
|
2007-12-21 02:02:38 +03:00
|
|
|
static int
|
|
|
|
do_compat_10_sys_msgsys(struct lwp *l, const struct ibcs2_sys_msgsys_args *uap,
|
|
|
|
register_t *retval, int which)
|
|
|
|
{
|
|
|
|
struct compat_10_sys_msgsys_args bsd_ua;
|
|
|
|
|
|
|
|
SCARG(&bsd_ua, which) = which;
|
|
|
|
SCARG(&bsd_ua, a2) = SCARG(uap, a2);
|
|
|
|
SCARG(&bsd_ua, a3) = SCARG(uap, a3);
|
|
|
|
SCARG(&bsd_ua, a4) = SCARG(uap, a4);
|
|
|
|
SCARG(&bsd_ua, a5) = SCARG(uap, a5);
|
|
|
|
SCARG(&bsd_ua, a6) = SCARG(uap, a6);
|
|
|
|
|
|
|
|
return compat_10_sys_msgsys(l, &bsd_ua, retval);
|
|
|
|
}
|
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
ibcs2_sys_msgsys(struct lwp *l, const struct ibcs2_sys_msgsys_args *uap, register_t *retval)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
2007-06-17 20:32:51 +04:00
|
|
|
#ifdef SYSVMSG
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1995-10-07 09:25:19 +03:00
|
|
|
syscallarg(int) which;
|
|
|
|
syscallarg(int) a2;
|
|
|
|
syscallarg(int) a3;
|
|
|
|
syscallarg(int) a4;
|
|
|
|
syscallarg(int) a5;
|
|
|
|
syscallarg(int) a6;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-06-17 20:32:51 +04:00
|
|
|
int error;
|
|
|
|
struct msqid_ds msqbuf;
|
|
|
|
struct ibcs2_msqid_ds msqbuf_ibcs2, *ibp;
|
1995-09-20 02:19:01 +04:00
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
switch (SCARG(uap, which)) {
|
|
|
|
case 0: /* msgget */
|
2007-12-21 02:02:38 +03:00
|
|
|
return do_compat_10_sys_msgsys(l, uap, retval, 1);
|
2007-06-17 20:32:51 +04:00
|
|
|
case 1: /* msgctl */
|
|
|
|
ibp = (void *)SCARG(uap, a4);
|
|
|
|
switch (SCARG(uap, a3)) {
|
|
|
|
case IPC_STAT:
|
|
|
|
error = msgctl1(l, SCARG(uap, a2), IPC_STAT, &msqbuf);
|
|
|
|
if (error == 0) {
|
|
|
|
cvt_msqid2imsqid(&msqbuf, &msqbuf_ibcs2);
|
|
|
|
error = copyout(&msqbuf_ibcs2, ibp,
|
|
|
|
sizeof msqbuf_ibcs2);
|
|
|
|
}
|
1995-03-14 18:12:17 +03:00
|
|
|
return error;
|
2007-06-17 20:32:51 +04:00
|
|
|
case IPC_SET:
|
|
|
|
error = copyin(ibp, &msqbuf_ibcs2, sizeof msqbuf_ibcs2);
|
|
|
|
if (error == 0) {
|
|
|
|
cvt_imsqid2msqid(&msqbuf_ibcs2, &msqbuf);
|
|
|
|
error = msgctl1(l, SCARG(uap, a2),
|
|
|
|
IPC_SET, &msqbuf);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
case IPC_RMID:
|
|
|
|
return msgctl1(l, SCARG(uap, a2), IPC_RMID, NULL);
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
|
|
|
return EINVAL;
|
|
|
|
case 2: /* msgrcv */
|
2007-12-21 02:02:38 +03:00
|
|
|
return do_compat_10_sys_msgsys(l, uap, retval, 3);
|
1995-03-14 18:12:17 +03:00
|
|
|
case 3: /* msgsnd */
|
2007-12-21 02:02:38 +03:00
|
|
|
return do_compat_10_sys_msgsys(l, uap, retval, 2);
|
1995-03-14 18:12:17 +03:00
|
|
|
default:
|
2007-06-17 20:32:51 +04:00
|
|
|
break;
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
2007-06-17 20:32:51 +04:00
|
|
|
#endif
|
|
|
|
return EINVAL;
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
|
|
|
|
1997-01-18 04:51:41 +03:00
|
|
|
#endif /* SYSVMSG */
|
|
|
|
|
|
|
|
#ifdef SYSVSEM
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* iBCS2 semsys call
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ibcs2_semid_ds {
|
1998-03-05 07:36:07 +03:00
|
|
|
struct ibcs2_ipc_perm sem_perm;
|
1995-03-14 18:12:17 +03:00
|
|
|
struct ibcs2_sem *sem_base;
|
|
|
|
u_short sem_nsems;
|
1998-03-05 07:36:07 +03:00
|
|
|
u_short pad1;
|
1995-03-14 18:12:17 +03:00
|
|
|
ibcs2_time_t sem_otime;
|
|
|
|
ibcs2_time_t sem_ctime;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ibcs2_sem {
|
|
|
|
u_short semval;
|
|
|
|
ibcs2_pid_t sempid;
|
|
|
|
u_short semncnt;
|
|
|
|
u_short semzcnt;
|
|
|
|
};
|
|
|
|
|
1996-05-03 21:05:16 +04:00
|
|
|
#ifdef notdef
|
2007-12-04 21:40:07 +03:00
|
|
|
static void cvt_sem2isem(struct sem *, struct ibcs2_sem *);
|
|
|
|
static void cvt_isem2sem(struct ibcs2_sem *, struct sem *);
|
1996-05-03 21:05:16 +04:00
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
static void
|
2007-12-08 21:35:53 +03:00
|
|
|
cvt_sem2isem(struct __sem *bp, struct ibcs2_sem *ibp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
|
|
|
ibp->semval = bp->semval;
|
|
|
|
ibp->sempid = bp->sempid;
|
|
|
|
ibp->semncnt = bp->semncnt;
|
|
|
|
ibp->semzcnt = bp->semzcnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-12-08 21:35:53 +03:00
|
|
|
cvt_isem2sem(struct ibcs2_sem *ibp, struct __sem *bp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
|
|
|
bp->semval = ibp->semval;
|
|
|
|
bp->sempid = ibp->sempid;
|
|
|
|
bp->semncnt = ibp->semncnt;
|
|
|
|
bp->semzcnt = ibp->semzcnt;
|
|
|
|
}
|
1996-05-03 21:05:16 +04:00
|
|
|
#endif
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_semid2isemid(const struct semid_ds *bp, struct ibcs2_semid_ds *ibp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_perm2iperm(&bp->sem_perm, &ibp->sem_perm);
|
2007-06-17 20:32:51 +04:00
|
|
|
ibp->sem_base = (struct ibcs2_sem *)bp->_sem_base;
|
1995-03-14 18:12:17 +03:00
|
|
|
ibp->sem_nsems = bp->sem_nsems;
|
|
|
|
ibp->sem_otime = bp->sem_otime;
|
|
|
|
ibp->sem_ctime = bp->sem_ctime;
|
|
|
|
}
|
|
|
|
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-03-14 18:12:17 +03:00
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_isemid2semid(const struct ibcs2_semid_ds *ibp, struct semid_ds *bp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_iperm2perm(&ibp->sem_perm, &bp->sem_perm);
|
2007-06-17 20:32:51 +04:00
|
|
|
bp->_sem_base = (struct __sem *)ibp->sem_base;
|
1995-03-14 18:12:17 +03:00
|
|
|
bp->sem_nsems = ibp->sem_nsems;
|
|
|
|
bp->sem_otime = ibp->sem_otime;
|
|
|
|
bp->sem_ctime = ibp->sem_ctime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
ibcs2_sys_semsys(struct lwp *l, const struct ibcs2_sys_semsys_args *uap, register_t *retval)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
2007-06-17 20:32:51 +04:00
|
|
|
#ifdef SYSVSEM
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1995-10-07 09:25:19 +03:00
|
|
|
syscallarg(int) which;
|
|
|
|
syscallarg(int) a2;
|
|
|
|
syscallarg(int) a3;
|
|
|
|
syscallarg(int) a4;
|
|
|
|
syscallarg(int) a5;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-06-17 20:32:51 +04:00
|
|
|
struct semid_ds sembuf;
|
|
|
|
struct ibcs2_semid_ds isembuf;
|
|
|
|
void *pass_arg;
|
2007-12-21 02:02:38 +03:00
|
|
|
int a5 = SCARG(uap, a5);
|
1995-03-14 18:12:17 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (SCARG(uap, which)) {
|
|
|
|
case 0: /* semctl */
|
2007-06-17 20:32:51 +04:00
|
|
|
#define semctl_semid SCARG(uap, a2)
|
|
|
|
#define semctl_semnum SCARG(uap, a3)
|
|
|
|
#define semctl_cmd SCARG(uap, a4)
|
2007-12-21 02:02:38 +03:00
|
|
|
#define semctl_arg ((union __semun *)&a5)
|
2007-06-17 20:32:51 +04:00
|
|
|
pass_arg = get_semctl_arg(semctl_cmd, &sembuf, semctl_arg);
|
|
|
|
if (semctl_cmd == IPC_SET) {
|
|
|
|
error = copyin(semctl_arg->buf, &isembuf, sizeof isembuf);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
cvt_isemid2semid(&isembuf, &sembuf);
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
2007-06-17 20:32:51 +04:00
|
|
|
error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
|
|
|
|
pass_arg, retval);
|
|
|
|
if (error == 0 && semctl_cmd == IPC_STAT) {
|
|
|
|
cvt_semid2isemid(&sembuf, &isembuf);
|
|
|
|
error = copyout(&isembuf, semctl_arg->buf, sizeof(isembuf));
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
#undef semctl_semid
|
|
|
|
#undef semctl_semnum
|
|
|
|
#undef semctl_cmd
|
|
|
|
#undef semctl_arg
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
case 1: /* semget */
|
2007-12-21 02:02:38 +03:00
|
|
|
return compat_10_sys_semsys(l, (const void *)uap, retval);
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
case 2: /* semop */
|
2007-12-21 02:02:38 +03:00
|
|
|
return compat_10_sys_semsys(l, (const void *)uap, retval);
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
1995-06-11 19:07:55 +04:00
|
|
|
#endif
|
1995-03-14 18:12:17 +03:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1997-01-18 04:51:41 +03:00
|
|
|
#endif /* SYSVSEM */
|
|
|
|
|
|
|
|
#ifdef SYSVSHM
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* iBCS2 shmsys call
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ibcs2_shmid_ds {
|
1999-08-25 08:52:06 +04:00
|
|
|
struct ibcs2_ipc_perm shm_perm;
|
1995-03-14 18:12:17 +03:00
|
|
|
int shm_segsz;
|
|
|
|
int pad1;
|
|
|
|
char pad2[4];
|
|
|
|
u_short shm_lpid;
|
|
|
|
u_short shm_cpid;
|
|
|
|
u_short shm_nattch;
|
|
|
|
u_short shm_cnattch;
|
|
|
|
ibcs2_time_t shm_atime;
|
|
|
|
ibcs2_time_t shm_dtime;
|
|
|
|
ibcs2_time_t shm_ctime;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_shmid2ishmid(const struct shmid_ds *bp, struct ibcs2_shmid_ds *ibp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_perm2iperm(&bp->shm_perm, &ibp->shm_perm);
|
1995-03-14 18:12:17 +03:00
|
|
|
ibp->shm_segsz = bp->shm_segsz;
|
|
|
|
ibp->shm_lpid = bp->shm_lpid;
|
|
|
|
ibp->shm_cpid = bp->shm_cpid;
|
|
|
|
ibp->shm_nattch = bp->shm_nattch;
|
|
|
|
ibp->shm_cnattch = 0; /* ignored anyway */
|
|
|
|
ibp->shm_atime = bp->shm_atime;
|
|
|
|
ibp->shm_dtime = bp->shm_dtime;
|
|
|
|
ibp->shm_ctime = bp->shm_ctime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-06-17 20:32:51 +04:00
|
|
|
cvt_ishmid2shmid(const struct ibcs2_shmid_ds *ibp, struct shmid_ds *bp)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
1999-08-25 08:52:06 +04:00
|
|
|
cvt_iperm2perm(&ibp->shm_perm, &bp->shm_perm);
|
1995-03-14 18:12:17 +03:00
|
|
|
bp->shm_segsz = ibp->shm_segsz;
|
|
|
|
bp->shm_lpid = ibp->shm_lpid;
|
|
|
|
bp->shm_cpid = ibp->shm_cpid;
|
|
|
|
bp->shm_nattch = ibp->shm_nattch;
|
|
|
|
bp->shm_atime = ibp->shm_atime;
|
|
|
|
bp->shm_dtime = ibp->shm_dtime;
|
|
|
|
bp->shm_ctime = ibp->shm_ctime;
|
2007-06-17 20:32:51 +04:00
|
|
|
bp->_shm_internal = (void *)0; /* ignored anyway */
|
1995-03-14 18:12:17 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
ibcs2_sys_shmsys(struct lwp *l, const struct ibcs2_sys_shmsys_args *uap, register_t *retval)
|
1995-03-14 18:12:17 +03:00
|
|
|
{
|
2007-06-17 20:32:51 +04:00
|
|
|
#ifdef SYSVSHM
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
1995-10-07 09:25:19 +03:00
|
|
|
syscallarg(int) which;
|
|
|
|
syscallarg(int) a2;
|
|
|
|
syscallarg(int) a3;
|
|
|
|
syscallarg(int) a4;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2007-06-17 20:32:51 +04:00
|
|
|
struct shmid_ds shmbuf;
|
|
|
|
struct ibcs2_shmid_ds *isp, ishmbuf;
|
|
|
|
int cmd, error;
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
switch (SCARG(uap, which)) {
|
|
|
|
case 0: /* shmat */
|
2007-12-21 02:02:38 +03:00
|
|
|
break;
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
case 1: /* shmctl */
|
2007-06-17 20:32:51 +04:00
|
|
|
cmd = SCARG(uap, a3);
|
|
|
|
isp = (struct ibcs2_shmid_ds *)SCARG(uap, a4);
|
|
|
|
if (cmd == IPC_SET) {
|
|
|
|
error = copyin(isp, &ishmbuf, sizeof(ishmbuf));
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
cvt_ishmid2shmid(&ishmbuf, &shmbuf);
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
2007-06-17 20:32:51 +04:00
|
|
|
|
|
|
|
error = shmctl1(l, SCARG(uap, a2), cmd,
|
|
|
|
(cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
|
|
|
|
|
|
|
|
if (error == 0 && cmd == IPC_STAT) {
|
|
|
|
cvt_shmid2ishmid(&shmbuf, &ishmbuf);
|
|
|
|
error = copyout(&ishmbuf, isp, sizeof(ishmbuf));
|
|
|
|
}
|
|
|
|
return error;
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
case 2: /* shmdt */
|
2007-12-21 02:02:38 +03:00
|
|
|
break;
|
1995-03-14 18:12:17 +03:00
|
|
|
|
|
|
|
case 3: /* shmget */
|
2007-12-21 02:02:38 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
2007-12-21 02:02:38 +03:00
|
|
|
return compat_10_sys_shmsys(l, (const void *)uap, retval);
|
|
|
|
#else
|
1995-03-14 18:12:17 +03:00
|
|
|
return EINVAL;
|
2007-12-21 02:02:38 +03:00
|
|
|
#endif
|
1995-03-14 18:12:17 +03:00
|
|
|
}
|
1997-01-18 04:51:41 +03:00
|
|
|
|
|
|
|
#endif /* SYSVSHM */
|