2003-01-18 11:02:46 +03:00
|
|
|
/* $NetBSD: linux_ipc.c,v 1.28 2003/01/18 08:02:53 thorpej Exp $ */
|
1998-10-01 07:27:38 +04:00
|
|
|
|
|
|
|
/*-
|
1998-10-04 04:02:23 +04:00
|
|
|
* Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
|
1998-10-01 07:27:38 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
1998-10-04 04:02:23 +04:00
|
|
|
* by Frank van der Linden and Eric Haszlakiewicz.
|
1998-10-01 07:27:38 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1995-03-01 02:24:35 +03:00
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-18 11:02:46 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: linux_ipc.c,v 1.28 2003/01/18 08:02:53 thorpej Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
2001-05-30 15:37:21 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1999-01-03 08:18:01 +03:00
|
|
|
#include "opt_sysv.h"
|
2000-12-01 21:16:54 +03:00
|
|
|
#endif
|
1999-01-03 08:18:01 +03:00
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/shm.h>
|
1995-08-16 01:14:32 +04:00
|
|
|
#include <sys/sem.h>
|
1995-03-01 02:24:35 +03:00
|
|
|
#include <sys/msg.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
2003-01-18 11:02:46 +03:00
|
|
|
#include <sys/sa.h>
|
1995-03-01 02:24:35 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
1998-10-04 00:17:36 +04:00
|
|
|
#include <compat/linux/common/linux_types.h>
|
|
|
|
#include <compat/linux/common/linux_signal.h>
|
|
|
|
#include <compat/linux/common/linux_util.h>
|
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
#include <compat/linux/linux_syscallargs.h>
|
1998-10-01 07:27:38 +04:00
|
|
|
#include <compat/linux/linux_syscall.h>
|
1998-10-04 00:17:36 +04:00
|
|
|
|
|
|
|
#include <compat/linux/common/linux_ipc.h>
|
|
|
|
#include <compat/linux/common/linux_msg.h>
|
|
|
|
#include <compat/linux/common/linux_shm.h>
|
|
|
|
#include <compat/linux/common/linux_sem.h>
|
|
|
|
#include <compat/linux/common/linux_ipccall.h>
|
1995-03-01 02:24:35 +03:00
|
|
|
|
|
|
|
/*
|
1998-10-01 07:27:38 +04:00
|
|
|
* Note: Not all linux architechtures have explicit versions
|
|
|
|
* of the SYSV* syscalls. On the ones that don't
|
|
|
|
* we pretend that they are defined anyway. *_args and
|
|
|
|
* prototypes are defined in individual headers;
|
|
|
|
* syscalls.master lists those syscalls as NOARGS.
|
1995-03-01 02:24:35 +03:00
|
|
|
*
|
1998-10-01 07:27:38 +04:00
|
|
|
* The functions in multiarch are the ones that just need
|
|
|
|
* the arguments shuffled around and then use the
|
|
|
|
* normal NetBSD syscall.
|
|
|
|
*
|
|
|
|
* Function in multiarch:
|
|
|
|
* linux_sys_ipc : linux_ipccall.c
|
|
|
|
* liunx_semop : linux_ipccall.c
|
|
|
|
* linux_semget : linux_ipccall.c
|
|
|
|
* linux_msgsnd : linux_ipccall.c
|
|
|
|
* linux_msgrcv : linux_ipccall.c
|
|
|
|
* linux_msgget : linux_ipccall.c
|
|
|
|
* linux_shmdt : linux_ipccall.c
|
|
|
|
* linux_shmget : linux_ipccall.c
|
1995-03-01 02:24:35 +03:00
|
|
|
*/
|
|
|
|
|
1996-11-15 12:51:25 +03:00
|
|
|
#if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
|
1995-03-01 02:24:35 +03:00
|
|
|
/*
|
|
|
|
* Convert between Linux and NetBSD ipc_perm structures. Only the
|
|
|
|
* order of the fields is different.
|
|
|
|
*/
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-03-01 02:24:35 +03:00
|
|
|
linux_to_bsd_ipc_perm(lpp, bpp)
|
|
|
|
struct linux_ipc_perm *lpp;
|
|
|
|
struct ipc_perm *bpp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1999-08-25 08:52:06 +04:00
|
|
|
bpp->_key = lpp->l_key;
|
1995-03-01 02:24:35 +03:00
|
|
|
bpp->uid = lpp->l_uid;
|
|
|
|
bpp->gid = lpp->l_gid;
|
|
|
|
bpp->cuid = lpp->l_cuid;
|
|
|
|
bpp->cgid = lpp->l_cgid;
|
|
|
|
bpp->mode = lpp->l_mode;
|
1999-08-25 08:52:06 +04:00
|
|
|
bpp->_seq = lpp->l_seq;
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-03-01 02:24:35 +03:00
|
|
|
bsd_to_linux_ipc_perm(bpp, lpp)
|
|
|
|
struct ipc_perm *bpp;
|
|
|
|
struct linux_ipc_perm *lpp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1999-08-25 08:52:06 +04:00
|
|
|
lpp->l_key = bpp->_key;
|
1995-03-01 02:24:35 +03:00
|
|
|
lpp->l_uid = bpp->uid;
|
|
|
|
lpp->l_gid = bpp->gid;
|
|
|
|
lpp->l_cuid = bpp->cuid;
|
|
|
|
lpp->l_cgid = bpp->cgid;
|
|
|
|
lpp->l_mode = bpp->mode;
|
1999-08-25 08:52:06 +04:00
|
|
|
lpp->l_seq = bpp->_seq;
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
1996-11-15 12:51:25 +03:00
|
|
|
#endif
|
1995-03-01 02:24:35 +03:00
|
|
|
|
|
|
|
#ifdef SYSVSEM
|
|
|
|
/*
|
1995-08-16 01:14:32 +04:00
|
|
|
* Semaphore operations. Most constants and structures are the same on
|
|
|
|
* both systems. Only semctl() needs some extra work.
|
1995-03-01 02:24:35 +03:00
|
|
|
*/
|
1995-08-16 01:14:32 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert between Linux and NetBSD semid_ds structures.
|
|
|
|
*/
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-08-16 01:14:32 +04:00
|
|
|
bsd_to_linux_semid_ds(bs, ls)
|
|
|
|
struct semid_ds *bs;
|
|
|
|
struct linux_semid_ds *ls;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
bsd_to_linux_ipc_perm(&bs->sem_perm, &ls->l_sem_perm);
|
|
|
|
ls->l_sem_otime = bs->sem_otime;
|
|
|
|
ls->l_sem_ctime = bs->sem_ctime;
|
|
|
|
ls->l_sem_nsems = bs->sem_nsems;
|
1999-08-25 08:52:06 +04:00
|
|
|
ls->l_sem_base = bs->_sem_base;
|
1995-08-16 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-08-16 01:14:32 +04:00
|
|
|
linux_to_bsd_semid_ds(ls, bs)
|
|
|
|
struct linux_semid_ds *ls;
|
|
|
|
struct semid_ds *bs;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
linux_to_bsd_ipc_perm(&ls->l_sem_perm, &bs->sem_perm);
|
|
|
|
bs->sem_otime = ls->l_sem_otime;
|
|
|
|
bs->sem_ctime = ls->l_sem_ctime;
|
|
|
|
bs->sem_nsems = ls->l_sem_nsems;
|
1999-08-25 08:52:06 +04:00
|
|
|
bs->_sem_base = ls->l_sem_base;
|
1995-08-16 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-08-25 08:52:06 +04:00
|
|
|
* Most of this can be handled by directly passing the arguments on; we
|
|
|
|
* just need to frob the `cmd' and convert the semid_ds and semun.
|
1995-08-16 01:14:32 +04:00
|
|
|
*/
|
1995-03-01 02:24:35 +03:00
|
|
|
int
|
2003-01-18 11:02:46 +03:00
|
|
|
linux_sys_semctl(l, v, retval)
|
|
|
|
struct lwp *l;
|
1998-10-01 07:27:38 +04:00
|
|
|
void *v;
|
1995-03-01 02:24:35 +03:00
|
|
|
register_t *retval;
|
|
|
|
{
|
1998-10-01 07:27:38 +04:00
|
|
|
struct linux_sys_semctl_args /* {
|
|
|
|
syscallarg(int) semid;
|
|
|
|
syscallarg(int) semnum;
|
|
|
|
syscallarg(int) cmd;
|
|
|
|
syscallarg(union linux_semun) arg;
|
|
|
|
} */ *uap = v;
|
2003-01-18 11:02:46 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1999-08-25 08:52:06 +04:00
|
|
|
struct semid_ds sembuf;
|
|
|
|
struct linux_semid_ds lsembuf;
|
|
|
|
union __semun semun;
|
|
|
|
int cmd, error;
|
|
|
|
void *pass_arg = NULL;
|
1995-08-16 01:14:32 +04:00
|
|
|
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = SCARG(uap, cmd);
|
|
|
|
|
|
|
|
switch (cmd) {
|
1998-01-22 19:33:57 +03:00
|
|
|
case LINUX_IPC_SET:
|
1999-08-25 08:52:06 +04:00
|
|
|
pass_arg = &sembuf;
|
|
|
|
cmd = IPC_SET;
|
1998-10-01 07:27:38 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
|
|
|
case LINUX_IPC_STAT:
|
|
|
|
pass_arg = &sembuf;
|
|
|
|
cmd = IPC_STAT;
|
|
|
|
break;
|
|
|
|
|
1998-01-22 19:33:57 +03:00
|
|
|
case LINUX_IPC_RMID:
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = IPC_RMID;
|
1998-01-22 19:33:57 +03:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
case LINUX_GETVAL:
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = GETVAL;
|
1995-08-16 01:14:32 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
case LINUX_GETPID:
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = GETPID;
|
1995-08-16 01:14:32 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
case LINUX_GETNCNT:
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = GETNCNT;
|
1995-08-16 01:14:32 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
case LINUX_GETZCNT:
|
1999-08-25 08:52:06 +04:00
|
|
|
cmd = GETZCNT;
|
1999-05-27 17:30:40 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1999-05-27 17:30:40 +04:00
|
|
|
case LINUX_GETALL:
|
1999-08-25 08:52:06 +04:00
|
|
|
pass_arg = &semun;
|
|
|
|
semun.array = SCARG(uap, arg).l_array;
|
|
|
|
cmd = GETALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LINUX_SETVAL:
|
|
|
|
pass_arg = &semun;
|
|
|
|
semun.val = SCARG(uap, arg).l_val;
|
|
|
|
cmd = SETVAL;
|
1999-05-27 17:30:40 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1999-05-27 17:30:40 +04:00
|
|
|
case LINUX_SETALL:
|
1999-08-25 08:52:06 +04:00
|
|
|
pass_arg = &semun;
|
|
|
|
semun.array = SCARG(uap, arg).l_array;
|
|
|
|
cmd = SETALL;
|
1995-08-16 01:14:32 +04:00
|
|
|
break;
|
1999-08-25 08:52:06 +04:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
default:
|
1999-08-25 08:52:06 +04:00
|
|
|
return (EINVAL);
|
1995-08-16 01:14:32 +04:00
|
|
|
}
|
1999-08-25 08:52:06 +04:00
|
|
|
|
|
|
|
if (cmd == IPC_SET) {
|
|
|
|
error = copyin(SCARG(uap, arg).l_buf, &lsembuf,
|
|
|
|
sizeof(lsembuf));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
linux_to_bsd_semid_ds(&lsembuf, &sembuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = semctl1(p, SCARG(uap, semid), SCARG(uap, semnum), cmd,
|
|
|
|
pass_arg, retval);
|
|
|
|
|
|
|
|
if (error == 0 && cmd == IPC_STAT) {
|
|
|
|
bsd_to_linux_semid_ds(&sembuf, &lsembuf);
|
|
|
|
error = copyout(&lsembuf, SCARG(uap, arg).l_buf,
|
|
|
|
sizeof(lsembuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
#endif /* SYSVSEM */
|
|
|
|
|
|
|
|
#ifdef SYSVMSG
|
1995-08-16 01:14:32 +04:00
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-08-16 01:14:32 +04:00
|
|
|
linux_to_bsd_msqid_ds(lmp, bmp)
|
|
|
|
struct linux_msqid_ds *lmp;
|
|
|
|
struct msqid_ds *bmp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm);
|
1999-08-25 08:52:06 +04:00
|
|
|
bmp->_msg_first = lmp->l_msg_first;
|
|
|
|
bmp->_msg_last = lmp->l_msg_last;
|
|
|
|
bmp->_msg_cbytes = lmp->l_msg_cbytes;
|
1995-08-16 01:14:32 +04:00
|
|
|
bmp->msg_qnum = lmp->l_msg_qnum;
|
|
|
|
bmp->msg_qbytes = lmp->l_msg_qbytes;
|
|
|
|
bmp->msg_lspid = lmp->l_msg_lspid;
|
|
|
|
bmp->msg_lrpid = lmp->l_msg_lrpid;
|
|
|
|
bmp->msg_stime = lmp->l_msg_stime;
|
|
|
|
bmp->msg_rtime = lmp->l_msg_rtime;
|
|
|
|
bmp->msg_ctime = lmp->l_msg_ctime;
|
|
|
|
}
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-08-16 01:14:32 +04:00
|
|
|
bsd_to_linux_msqid_ds(bmp, lmp)
|
|
|
|
struct msqid_ds *bmp;
|
|
|
|
struct linux_msqid_ds *lmp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-08-16 01:14:32 +04:00
|
|
|
bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm);
|
1999-08-25 08:52:06 +04:00
|
|
|
lmp->l_msg_first = bmp->_msg_first;
|
|
|
|
lmp->l_msg_last = bmp->_msg_last;
|
|
|
|
lmp->l_msg_cbytes = bmp->_msg_cbytes;
|
1995-08-16 01:14:32 +04:00
|
|
|
lmp->l_msg_qnum = bmp->msg_qnum;
|
|
|
|
lmp->l_msg_qbytes = bmp->msg_qbytes;
|
|
|
|
lmp->l_msg_lspid = bmp->msg_lspid;
|
|
|
|
lmp->l_msg_lrpid = bmp->msg_lrpid;
|
|
|
|
lmp->l_msg_stime = bmp->msg_stime;
|
|
|
|
lmp->l_msg_rtime = bmp->msg_rtime;
|
|
|
|
lmp->l_msg_ctime = bmp->msg_ctime;
|
|
|
|
}
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
int
|
2003-01-18 11:02:46 +03:00
|
|
|
linux_sys_msgctl(l, v, retval)
|
|
|
|
struct lwp *l;
|
1998-10-01 07:27:38 +04:00
|
|
|
void *v;
|
1995-03-01 02:24:35 +03:00
|
|
|
register_t *retval;
|
|
|
|
{
|
1998-10-01 07:27:38 +04:00
|
|
|
struct linux_sys_msgctl_args /* {
|
|
|
|
syscallarg(int) msqid;
|
|
|
|
syscallarg(int) cmd;
|
|
|
|
syscallarg(struct linux_msqid_ds *) buf;
|
|
|
|
} */ *uap = v;
|
2003-01-18 11:02:46 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1998-01-22 19:33:57 +03:00
|
|
|
caddr_t sg;
|
1999-08-25 08:52:06 +04:00
|
|
|
struct sys___msgctl13_args nua;
|
1998-01-22 19:33:57 +03:00
|
|
|
struct msqid_ds *bmp, bm;
|
1995-08-16 01:14:32 +04:00
|
|
|
struct linux_msqid_ds lm;
|
|
|
|
int error;
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
SCARG(&nua, msqid) = SCARG(uap, msqid);
|
|
|
|
switch (SCARG(uap, cmd)) {
|
1995-08-16 01:14:32 +04:00
|
|
|
case LINUX_IPC_STAT:
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
bmp = stackgap_alloc(p, &sg, sizeof (struct msqid_ds));
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = IPC_STAT;
|
|
|
|
SCARG(&nua, buf) = bmp;
|
2003-01-18 11:02:46 +03:00
|
|
|
if ((error = sys___msgctl13(l, &nua, retval)))
|
1995-08-16 01:14:32 +04:00
|
|
|
return error;
|
1998-01-22 19:33:57 +03:00
|
|
|
if ((error = copyin(bmp, &bm, sizeof bm)))
|
1995-08-16 01:14:32 +04:00
|
|
|
return error;
|
|
|
|
bsd_to_linux_msqid_ds(&bm, &lm);
|
1998-10-01 07:27:38 +04:00
|
|
|
return copyout(&lm, SCARG(uap, buf), sizeof lm);
|
1998-01-22 19:33:57 +03:00
|
|
|
case LINUX_IPC_SET:
|
1998-10-01 07:27:38 +04:00
|
|
|
if ((error = copyin(SCARG(uap, buf), &lm, sizeof lm)))
|
1998-01-22 19:33:57 +03:00
|
|
|
return error;
|
|
|
|
linux_to_bsd_msqid_ds(&lm, &bm);
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
bmp = stackgap_alloc(p, &sg, sizeof bm);
|
1998-01-22 19:33:57 +03:00
|
|
|
if ((error = copyout(&bm, bmp, sizeof bm)))
|
|
|
|
return error;
|
|
|
|
SCARG(&nua, cmd) = IPC_SET;
|
|
|
|
SCARG(&nua, buf) = bmp;
|
1998-10-01 07:27:38 +04:00
|
|
|
break;
|
1998-01-22 19:33:57 +03:00
|
|
|
case LINUX_IPC_RMID:
|
|
|
|
SCARG(&nua, cmd) = IPC_RMID;
|
|
|
|
SCARG(&nua, buf) = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
1995-08-16 01:14:32 +04:00
|
|
|
}
|
2003-01-18 11:02:46 +03:00
|
|
|
return sys___msgctl13(l, &nua, retval);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
#endif /* SYSVMSG */
|
|
|
|
|
|
|
|
#ifdef SYSVSHM
|
|
|
|
/*
|
|
|
|
* shmat(2). Very straightforward, except that Linux passes a pointer
|
|
|
|
* in which the return value is to be passed. This is subsequently
|
|
|
|
* handled by libc, apparently.
|
|
|
|
*/
|
1998-10-01 07:27:38 +04:00
|
|
|
int
|
2003-01-18 11:02:46 +03:00
|
|
|
linux_sys_shmat(l, v, retval)
|
|
|
|
struct lwp *l;
|
1998-10-01 07:27:38 +04:00
|
|
|
void *v;
|
1995-03-01 02:24:35 +03:00
|
|
|
register_t *retval;
|
|
|
|
{
|
1998-10-01 07:27:38 +04:00
|
|
|
struct linux_sys_shmat_args /* {
|
|
|
|
syscallarg(int) shmid;
|
|
|
|
syscallarg(void *) shmaddr;
|
|
|
|
syscallarg(int) shmflg;
|
|
|
|
syscallarg(u_long *) raddr;
|
|
|
|
} */ *uap = v;
|
2003-01-18 11:02:46 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1995-03-01 02:24:35 +03:00
|
|
|
int error;
|
2002-04-03 15:54:37 +04:00
|
|
|
vaddr_t attach_va;
|
|
|
|
u_long raddr;
|
1995-03-01 02:24:35 +03:00
|
|
|
|
2002-04-03 15:54:37 +04:00
|
|
|
if ((error = shmat1(p, SCARG(uap, shmid), SCARG(uap, shmaddr),
|
|
|
|
SCARG(uap, shmflg), &attach_va, 1)))
|
1995-03-01 02:24:35 +03:00
|
|
|
return error;
|
|
|
|
|
2002-04-03 15:54:37 +04:00
|
|
|
raddr = (u_long)attach_va;
|
|
|
|
|
|
|
|
if ((error = copyout(&raddr, (caddr_t) SCARG(uap, raddr),
|
1995-03-01 02:24:35 +03:00
|
|
|
sizeof retval[0])))
|
|
|
|
return error;
|
1998-10-01 07:27:38 +04:00
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
retval[0] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert between Linux and NetBSD shmid_ds structures.
|
|
|
|
* The order of the fields is once again the difference, and
|
|
|
|
* we also need a place to store the internal data pointer
|
|
|
|
* in, which is unfortunately stored in this structure.
|
|
|
|
*
|
|
|
|
* We abuse a Linux internal field for that.
|
|
|
|
*/
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-03-01 02:24:35 +03:00
|
|
|
linux_to_bsd_shmid_ds(lsp, bsp)
|
|
|
|
struct linux_shmid_ds *lsp;
|
|
|
|
struct shmid_ds *bsp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
|
|
|
|
bsp->shm_segsz = lsp->l_shm_segsz;
|
|
|
|
bsp->shm_lpid = lsp->l_shm_lpid;
|
|
|
|
bsp->shm_cpid = lsp->l_shm_cpid;
|
|
|
|
bsp->shm_nattch = lsp->l_shm_nattch;
|
|
|
|
bsp->shm_atime = lsp->l_shm_atime;
|
|
|
|
bsp->shm_dtime = lsp->l_shm_dtime;
|
|
|
|
bsp->shm_ctime = lsp->l_shm_ctime;
|
1999-08-25 08:52:06 +04:00
|
|
|
bsp->_shm_internal = lsp->l_private2; /* XXX Oh well. */
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
void
|
1995-03-01 02:24:35 +03:00
|
|
|
bsd_to_linux_shmid_ds(bsp, lsp)
|
|
|
|
struct shmid_ds *bsp;
|
|
|
|
struct linux_shmid_ds *lsp;
|
|
|
|
{
|
1995-10-07 09:25:19 +03:00
|
|
|
|
1995-03-01 02:24:35 +03:00
|
|
|
bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
|
|
|
|
lsp->l_shm_segsz = bsp->shm_segsz;
|
|
|
|
lsp->l_shm_lpid = bsp->shm_lpid;
|
|
|
|
lsp->l_shm_cpid = bsp->shm_cpid;
|
|
|
|
lsp->l_shm_nattch = bsp->shm_nattch;
|
|
|
|
lsp->l_shm_atime = bsp->shm_atime;
|
|
|
|
lsp->l_shm_dtime = bsp->shm_dtime;
|
|
|
|
lsp->l_shm_ctime = bsp->shm_ctime;
|
1999-08-25 08:52:06 +04:00
|
|
|
lsp->l_private2 = bsp->_shm_internal; /* XXX */
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* shmctl. Not implemented (for now): IPC_INFO, SHM_INFO, SHM_STAT
|
|
|
|
* SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
|
|
|
|
* by NetBSD itself.
|
|
|
|
*
|
|
|
|
* The usual structure conversion and massaging is done.
|
|
|
|
*/
|
1998-10-01 07:27:38 +04:00
|
|
|
int
|
2003-01-18 11:02:46 +03:00
|
|
|
linux_sys_shmctl(l, v, retval)
|
|
|
|
struct lwp *l;
|
1998-10-01 07:27:38 +04:00
|
|
|
void *v;
|
1995-03-01 02:24:35 +03:00
|
|
|
register_t *retval;
|
|
|
|
{
|
1998-10-01 07:27:38 +04:00
|
|
|
struct linux_sys_shmctl_args /* {
|
|
|
|
syscallarg(int) shmid;
|
|
|
|
syscallarg(int) cmd;
|
|
|
|
syscallarg(struct linux_shmid_ds *) buf;
|
|
|
|
} */ *uap = v;
|
2003-01-18 11:02:46 +03:00
|
|
|
struct proc *p = l->l_proc;
|
1995-03-01 02:24:35 +03:00
|
|
|
caddr_t sg;
|
1999-08-25 08:52:06 +04:00
|
|
|
struct sys___shmctl13_args nua;
|
1995-03-01 02:24:35 +03:00
|
|
|
struct shmid_ds *bsp, bs;
|
1998-01-22 19:33:57 +03:00
|
|
|
struct linux_shmid_ds ls;
|
|
|
|
int error;
|
1995-03-01 02:24:35 +03:00
|
|
|
|
1998-10-01 07:27:38 +04:00
|
|
|
SCARG(&nua, shmid) = SCARG(uap, shmid);
|
|
|
|
switch (SCARG(uap, cmd)) {
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_IPC_STAT:
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
bsp = stackgap_alloc(p, &sg, sizeof(struct shmid_ds));
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = IPC_STAT;
|
|
|
|
SCARG(&nua, buf) = bsp;
|
2003-01-18 11:02:46 +03:00
|
|
|
if ((error = sys___shmctl13(l, &nua, retval)))
|
1995-03-01 02:24:35 +03:00
|
|
|
return error;
|
1998-10-01 07:27:38 +04:00
|
|
|
if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
|
1995-03-01 02:24:35 +03:00
|
|
|
return error;
|
1998-01-22 19:33:57 +03:00
|
|
|
bsd_to_linux_shmid_ds(&bs, &ls);
|
1998-10-01 07:27:38 +04:00
|
|
|
return copyout(&ls, SCARG(uap, buf), sizeof ls);
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_IPC_SET:
|
1998-10-01 07:27:38 +04:00
|
|
|
if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
|
1995-03-01 02:24:35 +03:00
|
|
|
return error;
|
1998-01-22 19:33:57 +03:00
|
|
|
linux_to_bsd_shmid_ds(&ls, &bs);
|
2002-03-16 23:43:48 +03:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
bsp = stackgap_alloc(p, &sg, sizeof bs);
|
1998-01-22 19:33:57 +03:00
|
|
|
if ((error = copyout(&bs, bsp, sizeof bs)))
|
1995-03-01 02:24:35 +03:00
|
|
|
return error;
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = IPC_SET;
|
|
|
|
SCARG(&nua, buf) = bsp;
|
1998-10-01 07:27:38 +04:00
|
|
|
break;
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_IPC_RMID:
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = IPC_RMID;
|
|
|
|
SCARG(&nua, buf) = NULL;
|
|
|
|
break;
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_SHM_LOCK:
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = SHM_LOCK;
|
|
|
|
SCARG(&nua, buf) = NULL;
|
|
|
|
break;
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_SHM_UNLOCK:
|
1998-01-22 19:33:57 +03:00
|
|
|
SCARG(&nua, cmd) = SHM_UNLOCK;
|
|
|
|
SCARG(&nua, buf) = NULL;
|
|
|
|
break;
|
1995-03-01 02:24:35 +03:00
|
|
|
case LINUX_IPC_INFO:
|
|
|
|
case LINUX_SHM_STAT:
|
|
|
|
case LINUX_SHM_INFO:
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2003-01-18 11:02:46 +03:00
|
|
|
return sys___shmctl13(l, &nua, retval);
|
1995-03-01 02:24:35 +03:00
|
|
|
}
|
|
|
|
#endif /* SYSVSHM */
|