Home | History | Annotate | Line # | Download | only in common
linux_ipc.c revision 1.18
      1  1.18       erh /*	$NetBSD: linux_ipc.c,v 1.18 1999/01/03 03:54:45 erh Exp $	*/
      2  1.14       erh 
      3  1.14       erh /*-
      4  1.16      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5  1.14       erh  * All rights reserved.
      6  1.14       erh  *
      7  1.14       erh  * This code is derived from software contributed to The NetBSD Foundation
      8  1.16      fvdl  * by Frank van der Linden and Eric Haszlakiewicz.
      9  1.14       erh  *
     10  1.14       erh  * Redistribution and use in source and binary forms, with or without
     11  1.14       erh  * modification, are permitted provided that the following conditions
     12  1.14       erh  * are met:
     13  1.14       erh  * 1. Redistributions of source code must retain the above copyright
     14  1.14       erh  *    notice, this list of conditions and the following disclaimer.
     15  1.14       erh  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.14       erh  *    notice, this list of conditions and the following disclaimer in the
     17  1.14       erh  *    documentation and/or other materials provided with the distribution.
     18  1.14       erh  * 3. All advertising materials mentioning features or use of this software
     19  1.14       erh  *    must display the following acknowledgement:
     20  1.14       erh  *	This product includes software developed by the NetBSD
     21  1.14       erh  *	Foundation, Inc. and its contributors.
     22  1.14       erh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.14       erh  *    contributors may be used to endorse or promote products derived
     24  1.14       erh  *    from this software without specific prior written permission.
     25  1.14       erh  *
     26  1.14       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.14       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.14       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.14       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.14       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.14       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.14       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.14       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.14       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.14       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.14       erh  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      fvdl  */
     38   1.1      fvdl 
     39   1.1      fvdl #include <sys/types.h>
     40   1.1      fvdl #include <sys/param.h>
     41   1.1      fvdl #include <sys/shm.h>
     42   1.6      fvdl #include <sys/sem.h>
     43   1.1      fvdl #include <sys/msg.h>
     44   1.1      fvdl #include <sys/proc.h>
     45   1.1      fvdl #include <sys/systm.h>
     46   1.1      fvdl 
     47   1.1      fvdl #include <sys/mount.h>
     48   1.1      fvdl #include <sys/syscallargs.h>
     49   1.1      fvdl 
     50  1.15  christos #include <compat/linux/common/linux_types.h>
     51  1.15  christos #include <compat/linux/common/linux_signal.h>
     52  1.15  christos #include <compat/linux/common/linux_util.h>
     53  1.15  christos 
     54   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     55  1.14       erh #include <compat/linux/linux_syscall.h>
     56  1.15  christos 
     57  1.15  christos #include <compat/linux/common/linux_ipc.h>
     58  1.15  christos #include <compat/linux/common/linux_msg.h>
     59  1.15  christos #include <compat/linux/common/linux_shm.h>
     60  1.15  christos #include <compat/linux/common/linux_sem.h>
     61  1.15  christos #include <compat/linux/common/linux_ipccall.h>
     62   1.1      fvdl 
     63   1.1      fvdl /*
     64  1.14       erh  * Note: Not all linux architechtures have explicit versions
     65  1.14       erh  *	of the SYSV* syscalls.  On the ones that don't
     66  1.14       erh  *	we pretend that they are defined anyway.  *_args and
     67  1.14       erh  *	prototypes are defined in individual headers;
     68  1.14       erh  *	syscalls.master lists those syscalls as NOARGS.
     69   1.1      fvdl  *
     70  1.14       erh  *	The functions in multiarch are the ones that just need
     71  1.14       erh  *	the arguments shuffled around and then use the
     72  1.14       erh  *	normal NetBSD syscall.
     73  1.14       erh  *
     74  1.14       erh  * Function in multiarch:
     75  1.14       erh  *	linux_sys_ipc		: linux_ipccall.c
     76  1.14       erh  *	liunx_semop		: linux_ipccall.c
     77  1.14       erh  *	linux_semget		: linux_ipccall.c
     78  1.14       erh  *	linux_msgsnd		: linux_ipccall.c
     79  1.14       erh  *	linux_msgrcv		: linux_ipccall.c
     80  1.14       erh  *	linux_msgget		: linux_ipccall.c
     81  1.14       erh  *	linux_shmdt		: linux_ipccall.c
     82  1.14       erh  *	linux_shmget		: linux_ipccall.c
     83   1.1      fvdl  */
     84   1.1      fvdl 
     85  1.11      fvdl #if defined (SYSVSEM) || defined(SYSVSHM) || defined(SYSVMSG)
     86   1.1      fvdl /*
     87   1.1      fvdl  * Convert between Linux and NetBSD ipc_perm structures. Only the
     88   1.1      fvdl  * order of the fields is different.
     89   1.1      fvdl  */
     90  1.14       erh void
     91   1.1      fvdl linux_to_bsd_ipc_perm(lpp, bpp)
     92   1.1      fvdl 	struct linux_ipc_perm *lpp;
     93   1.1      fvdl 	struct ipc_perm *bpp;
     94   1.1      fvdl {
     95   1.8   mycroft 
     96   1.1      fvdl 	bpp->key = lpp->l_key;
     97   1.1      fvdl 	bpp->uid = lpp->l_uid;
     98   1.1      fvdl 	bpp->gid = lpp->l_gid;
     99   1.1      fvdl 	bpp->cuid = lpp->l_cuid;
    100   1.1      fvdl 	bpp->cgid = lpp->l_cgid;
    101   1.1      fvdl 	bpp->mode = lpp->l_mode;
    102   1.1      fvdl 	bpp->seq = lpp->l_seq;
    103   1.1      fvdl }
    104   1.1      fvdl 
    105  1.14       erh void
    106   1.1      fvdl bsd_to_linux_ipc_perm(bpp, lpp)
    107   1.1      fvdl 	struct ipc_perm *bpp;
    108   1.1      fvdl 	struct linux_ipc_perm *lpp;
    109   1.1      fvdl {
    110   1.8   mycroft 
    111   1.1      fvdl 	lpp->l_key = bpp->key;
    112   1.1      fvdl 	lpp->l_uid = bpp->uid;
    113   1.1      fvdl 	lpp->l_gid = bpp->gid;
    114   1.1      fvdl 	lpp->l_cuid = bpp->cuid;
    115   1.1      fvdl 	lpp->l_cgid = bpp->cgid;
    116   1.1      fvdl 	lpp->l_mode = bpp->mode;
    117   1.1      fvdl 	lpp->l_seq = bpp->seq;
    118   1.1      fvdl }
    119  1.11      fvdl #endif
    120   1.1      fvdl 
    121   1.1      fvdl #ifdef SYSVSEM
    122   1.1      fvdl /*
    123   1.6      fvdl  * Semaphore operations. Most constants and structures are the same on
    124   1.6      fvdl  * both systems. Only semctl() needs some extra work.
    125   1.1      fvdl  */
    126   1.6      fvdl 
    127   1.6      fvdl /*
    128   1.6      fvdl  * Convert between Linux and NetBSD semid_ds structures.
    129   1.6      fvdl  */
    130  1.14       erh void
    131   1.6      fvdl bsd_to_linux_semid_ds(bs, ls)
    132   1.6      fvdl 	struct semid_ds *bs;
    133   1.6      fvdl 	struct linux_semid_ds *ls;
    134   1.6      fvdl {
    135   1.8   mycroft 
    136   1.6      fvdl 	bsd_to_linux_ipc_perm(&bs->sem_perm, &ls->l_sem_perm);
    137   1.6      fvdl 	ls->l_sem_otime = bs->sem_otime;
    138   1.6      fvdl 	ls->l_sem_ctime = bs->sem_ctime;
    139   1.6      fvdl 	ls->l_sem_nsems = bs->sem_nsems;
    140   1.8   mycroft 	ls->l_sem_base = bs->sem_base;
    141   1.6      fvdl }
    142   1.6      fvdl 
    143  1.14       erh void
    144   1.6      fvdl linux_to_bsd_semid_ds(ls, bs)
    145   1.6      fvdl 	struct linux_semid_ds *ls;
    146   1.6      fvdl 	struct semid_ds *bs;
    147   1.6      fvdl {
    148   1.8   mycroft 
    149   1.6      fvdl 	linux_to_bsd_ipc_perm(&ls->l_sem_perm, &bs->sem_perm);
    150   1.6      fvdl 	bs->sem_otime = ls->l_sem_otime;
    151   1.6      fvdl 	bs->sem_ctime = ls->l_sem_ctime;
    152   1.6      fvdl 	bs->sem_nsems = ls->l_sem_nsems;
    153   1.8   mycroft 	bs->sem_base = ls->l_sem_base;
    154   1.6      fvdl }
    155   1.6      fvdl 
    156   1.6      fvdl /*
    157   1.6      fvdl  * Most of this can be handled by directly passing the arguments on,
    158  1.14       erh  * but IPC_* require a lot of copy{in,out} because of the extra indirection
    159  1.14       erh  * (we need to pass a pointer to a union cointaining a pointer to a semid_ds
    160  1.14       erh  * structure.  Linux actually handles this better than we do.)
    161   1.6      fvdl  */
    162   1.1      fvdl int
    163  1.14       erh linux_sys_semctl(p, v, retval)
    164   1.1      fvdl 	struct proc *p;
    165  1.14       erh 	void *v;
    166   1.1      fvdl 	register_t *retval;
    167   1.1      fvdl {
    168  1.14       erh 	struct linux_sys_semctl_args /* {
    169  1.14       erh 		syscallarg(int) semid;
    170  1.14       erh 		syscallarg(int) semnum;
    171  1.14       erh 		syscallarg(int) cmd;
    172  1.14       erh 		syscallarg(union linux_semun) arg;
    173  1.14       erh 	} */ *uap = v;
    174  1.13   mycroft 	caddr_t sg;
    175  1.13   mycroft 	struct sys___semctl_args nua;
    176  1.13   mycroft 	struct semid_ds *bmp, bm;
    177   1.6      fvdl 	struct linux_semid_ds lm;
    178  1.13   mycroft 	union semun *bup;
    179  1.13   mycroft 	int error;
    180   1.6      fvdl 
    181  1.14       erh 	SCARG(&nua, semid) = SCARG(uap, semid);
    182  1.14       erh 	SCARG(&nua, semnum) = SCARG(uap, semnum);
    183  1.14       erh 	switch (SCARG(uap, cmd)) {
    184  1.13   mycroft 	case LINUX_IPC_STAT:
    185  1.13   mycroft 		sg = stackgap_init(p->p_emul);
    186  1.13   mycroft 		bup = stackgap_alloc(&sg, sizeof (union semun));
    187  1.13   mycroft 		bmp = stackgap_alloc(&sg, sizeof (struct semid_ds));
    188  1.13   mycroft 		if ((error = copyout(&bmp, bup, sizeof bmp)))
    189  1.13   mycroft 			return error;
    190  1.13   mycroft 		SCARG(&nua, cmd) = IPC_STAT;
    191  1.13   mycroft 		SCARG(&nua, arg) = bup;
    192  1.13   mycroft 		if ((error = sys___semctl(p, &nua, retval)))
    193  1.13   mycroft 			return error;
    194  1.13   mycroft 		if ((error = copyin(bmp, &bm, sizeof bm)))
    195  1.13   mycroft 			return error;
    196  1.13   mycroft 		bsd_to_linux_semid_ds(&bm, &lm);
    197  1.14       erh 		return copyout(&lm, SCARG(uap, arg).l_buf, sizeof lm);
    198  1.13   mycroft 	case LINUX_IPC_SET:
    199  1.14       erh 		if ((error = copyin(SCARG(uap, arg).l_buf, &lm, sizeof lm)))
    200  1.13   mycroft 			return error;
    201  1.13   mycroft 		linux_to_bsd_semid_ds(&lm, &bm);
    202  1.13   mycroft 		sg = stackgap_init(p->p_emul);
    203  1.13   mycroft 		bup = stackgap_alloc(&sg, sizeof (union semun));
    204  1.13   mycroft 		bmp = stackgap_alloc(&sg, sizeof (struct semid_ds));
    205  1.13   mycroft 		if ((error = copyout(&bm, bmp, sizeof bm)))
    206  1.13   mycroft 			return error;
    207  1.13   mycroft 		if ((error = copyout(&bmp, bup, sizeof bmp)))
    208  1.13   mycroft 			return error;
    209  1.13   mycroft 		SCARG(&nua, cmd) = IPC_SET;
    210  1.13   mycroft 		SCARG(&nua, arg) = bup;
    211  1.14       erh 		break;
    212  1.13   mycroft 	case LINUX_IPC_RMID:
    213  1.13   mycroft 		SCARG(&nua, cmd) = IPC_RMID;
    214  1.13   mycroft 		break;
    215   1.6      fvdl 	case LINUX_GETVAL:
    216  1.13   mycroft 		SCARG(&nua, cmd) = GETVAL;
    217   1.6      fvdl 		break;
    218   1.6      fvdl 	case LINUX_GETPID:
    219  1.13   mycroft 		SCARG(&nua, cmd) = GETPID;
    220   1.6      fvdl 		break;
    221   1.6      fvdl 	case LINUX_GETNCNT:
    222  1.13   mycroft 		SCARG(&nua, cmd) = GETNCNT;
    223   1.6      fvdl 		break;
    224   1.6      fvdl 	case LINUX_GETZCNT:
    225  1.13   mycroft 		SCARG(&nua, cmd) = GETZCNT;
    226   1.6      fvdl 		break;
    227   1.6      fvdl 	case LINUX_SETVAL:
    228  1.13   mycroft 		SCARG(&nua, cmd) = SETVAL;
    229   1.6      fvdl 		break;
    230   1.6      fvdl 	default:
    231   1.6      fvdl 		return EINVAL;
    232   1.6      fvdl 	}
    233  1.13   mycroft 	return sys___semctl(p, &nua, retval);
    234   1.1      fvdl }
    235   1.1      fvdl #endif /* SYSVSEM */
    236   1.1      fvdl 
    237   1.1      fvdl #ifdef SYSVMSG
    238   1.6      fvdl 
    239  1.14       erh void
    240   1.6      fvdl linux_to_bsd_msqid_ds(lmp, bmp)
    241   1.6      fvdl 	struct linux_msqid_ds *lmp;
    242   1.6      fvdl 	struct msqid_ds *bmp;
    243   1.6      fvdl {
    244   1.8   mycroft 
    245   1.6      fvdl 	linux_to_bsd_ipc_perm(&lmp->l_msg_perm, &bmp->msg_perm);
    246   1.6      fvdl 	bmp->msg_first = lmp->l_msg_first;
    247   1.6      fvdl 	bmp->msg_last = lmp->l_msg_last;
    248   1.6      fvdl 	bmp->msg_cbytes = lmp->l_msg_cbytes;
    249   1.6      fvdl 	bmp->msg_qnum = lmp->l_msg_qnum;
    250   1.6      fvdl 	bmp->msg_qbytes = lmp->l_msg_qbytes;
    251   1.6      fvdl 	bmp->msg_lspid = lmp->l_msg_lspid;
    252   1.6      fvdl 	bmp->msg_lrpid = lmp->l_msg_lrpid;
    253   1.6      fvdl 	bmp->msg_stime = lmp->l_msg_stime;
    254   1.6      fvdl 	bmp->msg_rtime = lmp->l_msg_rtime;
    255   1.6      fvdl 	bmp->msg_ctime = lmp->l_msg_ctime;
    256   1.6      fvdl }
    257   1.6      fvdl 
    258  1.14       erh void
    259   1.6      fvdl bsd_to_linux_msqid_ds(bmp, lmp)
    260   1.6      fvdl 	struct msqid_ds *bmp;
    261   1.6      fvdl 	struct linux_msqid_ds *lmp;
    262   1.6      fvdl {
    263   1.8   mycroft 
    264   1.6      fvdl 	bsd_to_linux_ipc_perm(&bmp->msg_perm, &lmp->l_msg_perm);
    265   1.6      fvdl 	lmp->l_msg_first = bmp->msg_first;
    266   1.6      fvdl 	lmp->l_msg_last = bmp->msg_last;
    267   1.6      fvdl 	lmp->l_msg_cbytes = bmp->msg_cbytes;
    268   1.6      fvdl 	lmp->l_msg_qnum = bmp->msg_qnum;
    269   1.6      fvdl 	lmp->l_msg_qbytes = bmp->msg_qbytes;
    270   1.6      fvdl 	lmp->l_msg_lspid = bmp->msg_lspid;
    271   1.6      fvdl 	lmp->l_msg_lrpid = bmp->msg_lrpid;
    272   1.6      fvdl 	lmp->l_msg_stime = bmp->msg_stime;
    273   1.6      fvdl 	lmp->l_msg_rtime = bmp->msg_rtime;
    274   1.6      fvdl 	lmp->l_msg_ctime = bmp->msg_ctime;
    275   1.6      fvdl }
    276   1.6      fvdl 
    277  1.14       erh int
    278  1.14       erh linux_sys_msgctl(p, v, retval)
    279   1.1      fvdl 	struct proc *p;
    280  1.14       erh 	void *v;
    281   1.1      fvdl 	register_t *retval;
    282   1.1      fvdl {
    283  1.14       erh 	struct linux_sys_msgctl_args /* {
    284  1.14       erh 		syscallarg(int) msqid;
    285  1.14       erh 		syscallarg(int) cmd;
    286  1.14       erh 		syscallarg(struct linux_msqid_ds *) buf;
    287  1.14       erh 	} */ *uap = v;
    288  1.13   mycroft 	caddr_t sg;
    289  1.13   mycroft 	struct sys_msgctl_args nua;
    290  1.13   mycroft 	struct msqid_ds *bmp, bm;
    291   1.6      fvdl 	struct linux_msqid_ds lm;
    292   1.6      fvdl 	int error;
    293   1.6      fvdl 
    294  1.14       erh 	SCARG(&nua, msqid) = SCARG(uap, msqid);
    295  1.14       erh 	switch (SCARG(uap, cmd)) {
    296  1.13   mycroft 	case LINUX_IPC_STAT:
    297  1.13   mycroft 		sg = stackgap_init(p->p_emul);
    298  1.13   mycroft 		bmp = stackgap_alloc(&sg, sizeof (struct msqid_ds));
    299  1.13   mycroft 		SCARG(&nua, cmd) = IPC_STAT;
    300  1.13   mycroft 		SCARG(&nua, buf) = bmp;
    301  1.13   mycroft 		if ((error = sys_msgctl(p, &nua, retval)))
    302  1.13   mycroft 			return error;
    303  1.13   mycroft 		if ((error = copyin(bmp, &bm, sizeof bm)))
    304  1.13   mycroft 			return error;
    305  1.13   mycroft 		bsd_to_linux_msqid_ds(&bm, &lm);
    306  1.14       erh 		return copyout(&lm, SCARG(uap, buf), sizeof lm);
    307   1.6      fvdl 	case LINUX_IPC_SET:
    308  1.14       erh 		if ((error = copyin(SCARG(uap, buf), &lm, sizeof lm)))
    309   1.6      fvdl 			return error;
    310   1.6      fvdl 		linux_to_bsd_msqid_ds(&lm, &bm);
    311   1.6      fvdl 		sg = stackgap_init(p->p_emul);
    312  1.13   mycroft 		bmp = stackgap_alloc(&sg, sizeof bm);
    313  1.13   mycroft 		if ((error = copyout(&bm, bmp, sizeof bm)))
    314   1.6      fvdl 			return error;
    315  1.13   mycroft 		SCARG(&nua, cmd) = IPC_SET;
    316  1.13   mycroft 		SCARG(&nua, buf) = bmp;
    317  1.14       erh 		break;
    318  1.13   mycroft 	case LINUX_IPC_RMID:
    319  1.13   mycroft 		SCARG(&nua, cmd) = IPC_RMID;
    320  1.13   mycroft 		SCARG(&nua, buf) = NULL;
    321  1.13   mycroft 		break;
    322  1.13   mycroft 	default:
    323  1.13   mycroft 		return EINVAL;
    324   1.6      fvdl 	}
    325  1.13   mycroft 	return sys_msgctl(p, &nua, retval);
    326   1.1      fvdl }
    327   1.1      fvdl #endif /* SYSVMSG */
    328   1.1      fvdl 
    329   1.1      fvdl #ifdef SYSVSHM
    330   1.1      fvdl /*
    331   1.1      fvdl  * shmat(2). Very straightforward, except that Linux passes a pointer
    332   1.1      fvdl  * in which the return value is to be passed. This is subsequently
    333   1.1      fvdl  * handled by libc, apparently.
    334   1.1      fvdl  */
    335  1.14       erh int
    336  1.14       erh linux_sys_shmat(p, v, retval)
    337   1.1      fvdl 	struct proc *p;
    338  1.14       erh 	void *v;
    339   1.1      fvdl 	register_t *retval;
    340   1.1      fvdl {
    341  1.14       erh 	struct linux_sys_shmat_args /* {
    342  1.14       erh 		syscallarg(int) shmid;
    343  1.14       erh 		syscallarg(void *) shmaddr;
    344  1.14       erh 		syscallarg(int) shmflg;
    345  1.14       erh 		syscallarg(u_long *) raddr;
    346  1.14       erh 	} */ *uap = v;
    347   1.1      fvdl 	int error;
    348   1.1      fvdl 
    349  1.14       erh 	if ((error = sys_shmat(p, uap, retval)))
    350   1.1      fvdl 		return error;
    351   1.1      fvdl 
    352  1.14       erh 	if ((error = copyout(&retval[0], (caddr_t) SCARG(uap, raddr),
    353   1.1      fvdl 	     sizeof retval[0])))
    354   1.1      fvdl 		return error;
    355  1.14       erh 
    356   1.1      fvdl 	retval[0] = 0;
    357   1.1      fvdl 	return 0;
    358   1.1      fvdl }
    359   1.1      fvdl 
    360   1.1      fvdl /*
    361   1.1      fvdl  * Convert between Linux and NetBSD shmid_ds structures.
    362   1.1      fvdl  * The order of the fields is once again the difference, and
    363   1.1      fvdl  * we also need a place to store the internal data pointer
    364   1.1      fvdl  * in, which is unfortunately stored in this structure.
    365   1.1      fvdl  *
    366   1.1      fvdl  * We abuse a Linux internal field for that.
    367   1.1      fvdl  */
    368  1.14       erh void
    369   1.1      fvdl linux_to_bsd_shmid_ds(lsp, bsp)
    370   1.1      fvdl 	struct linux_shmid_ds *lsp;
    371   1.1      fvdl 	struct shmid_ds *bsp;
    372   1.1      fvdl {
    373   1.8   mycroft 
    374   1.1      fvdl 	linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
    375   1.1      fvdl 	bsp->shm_segsz = lsp->l_shm_segsz;
    376   1.1      fvdl 	bsp->shm_lpid = lsp->l_shm_lpid;
    377   1.1      fvdl 	bsp->shm_cpid = lsp->l_shm_cpid;
    378   1.1      fvdl 	bsp->shm_nattch = lsp->l_shm_nattch;
    379   1.1      fvdl 	bsp->shm_atime = lsp->l_shm_atime;
    380   1.1      fvdl 	bsp->shm_dtime = lsp->l_shm_dtime;
    381   1.1      fvdl 	bsp->shm_ctime = lsp->l_shm_ctime;
    382   1.1      fvdl 	bsp->shm_internal = lsp->l_private2;	/* XXX Oh well. */
    383   1.1      fvdl }
    384   1.1      fvdl 
    385  1.14       erh void
    386   1.1      fvdl bsd_to_linux_shmid_ds(bsp, lsp)
    387   1.1      fvdl 	struct shmid_ds *bsp;
    388   1.1      fvdl 	struct linux_shmid_ds *lsp;
    389   1.1      fvdl {
    390   1.8   mycroft 
    391   1.1      fvdl 	bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
    392   1.1      fvdl 	lsp->l_shm_segsz = bsp->shm_segsz;
    393   1.1      fvdl 	lsp->l_shm_lpid = bsp->shm_lpid;
    394   1.1      fvdl 	lsp->l_shm_cpid = bsp->shm_cpid;
    395   1.1      fvdl 	lsp->l_shm_nattch = bsp->shm_nattch;
    396   1.1      fvdl 	lsp->l_shm_atime = bsp->shm_atime;
    397   1.1      fvdl 	lsp->l_shm_dtime = bsp->shm_dtime;
    398   1.1      fvdl 	lsp->l_shm_ctime = bsp->shm_ctime;
    399   1.1      fvdl 	lsp->l_private2 = bsp->shm_internal;	/* XXX */
    400   1.1      fvdl }
    401   1.1      fvdl 
    402   1.1      fvdl /*
    403   1.1      fvdl  * shmctl. Not implemented (for now): IPC_INFO, SHM_INFO, SHM_STAT
    404   1.1      fvdl  * SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
    405   1.1      fvdl  * by NetBSD itself.
    406   1.1      fvdl  *
    407   1.1      fvdl  * The usual structure conversion and massaging is done.
    408   1.1      fvdl  */
    409  1.14       erh int
    410  1.14       erh linux_sys_shmctl(p, v, retval)
    411   1.1      fvdl 	struct proc *p;
    412  1.14       erh 	void *v;
    413   1.1      fvdl 	register_t *retval;
    414   1.1      fvdl {
    415  1.14       erh 	struct linux_sys_shmctl_args /* {
    416  1.14       erh 		syscallarg(int) shmid;
    417  1.14       erh 		syscallarg(int) cmd;
    418  1.14       erh 		syscallarg(struct linux_shmid_ds *) buf;
    419  1.14       erh 	} */ *uap = v;
    420   1.1      fvdl 	caddr_t sg;
    421  1.13   mycroft 	struct sys_shmctl_args nua;
    422   1.1      fvdl 	struct shmid_ds *bsp, bs;
    423  1.13   mycroft 	struct linux_shmid_ds ls;
    424  1.13   mycroft 	int error;
    425   1.1      fvdl 
    426  1.14       erh 	SCARG(&nua, shmid) = SCARG(uap, shmid);
    427  1.14       erh 	switch (SCARG(uap, cmd)) {
    428   1.1      fvdl 	case LINUX_IPC_STAT:
    429   1.4  christos 		sg = stackgap_init(p->p_emul);
    430  1.14       erh 		bsp = stackgap_alloc(&sg, sizeof(struct shmid_ds));
    431  1.13   mycroft 		SCARG(&nua, cmd) = IPC_STAT;
    432  1.13   mycroft 		SCARG(&nua, buf) = bsp;
    433  1.13   mycroft 		if ((error = sys_shmctl(p, &nua, retval)))
    434   1.1      fvdl 			return error;
    435  1.14       erh 		if ((error = copyin(SCARG(&nua, buf), &bs, sizeof bs)))
    436   1.1      fvdl 			return error;
    437  1.13   mycroft 		bsd_to_linux_shmid_ds(&bs, &ls);
    438  1.14       erh 		return copyout(&ls, SCARG(uap, buf), sizeof ls);
    439   1.1      fvdl 	case LINUX_IPC_SET:
    440  1.14       erh 		if ((error = copyin(SCARG(uap, buf), &ls, sizeof ls)))
    441   1.1      fvdl 			return error;
    442  1.13   mycroft 		linux_to_bsd_shmid_ds(&ls, &bs);
    443   1.4  christos 		sg = stackgap_init(p->p_emul);
    444  1.13   mycroft 		bsp = stackgap_alloc(&sg, sizeof bs);
    445  1.13   mycroft 		if ((error = copyout(&bs, bsp, sizeof bs)))
    446   1.1      fvdl 			return error;
    447  1.13   mycroft 		SCARG(&nua, cmd) = IPC_SET;
    448  1.13   mycroft 		SCARG(&nua, buf) = bsp;
    449  1.14       erh 		break;
    450   1.1      fvdl 	case LINUX_IPC_RMID:
    451  1.13   mycroft 		SCARG(&nua, cmd) = IPC_RMID;
    452  1.13   mycroft 		SCARG(&nua, buf) = NULL;
    453  1.13   mycroft 		break;
    454   1.1      fvdl 	case LINUX_SHM_LOCK:
    455  1.13   mycroft 		SCARG(&nua, cmd) = SHM_LOCK;
    456  1.13   mycroft 		SCARG(&nua, buf) = NULL;
    457  1.13   mycroft 		break;
    458   1.1      fvdl 	case LINUX_SHM_UNLOCK:
    459  1.13   mycroft 		SCARG(&nua, cmd) = SHM_UNLOCK;
    460  1.13   mycroft 		SCARG(&nua, buf) = NULL;
    461  1.13   mycroft 		break;
    462   1.1      fvdl 	case LINUX_IPC_INFO:
    463   1.1      fvdl 	case LINUX_SHM_STAT:
    464   1.1      fvdl 	case LINUX_SHM_INFO:
    465   1.1      fvdl 	default:
    466   1.1      fvdl 		return EINVAL;
    467   1.1      fvdl 	}
    468  1.13   mycroft 	return sys_shmctl(p, &nua, retval);
    469   1.1      fvdl }
    470   1.1      fvdl #endif /* SYSVSHM */
    471