Home | History | Annotate | Line # | Download | only in common
linux_ipccall.c revision 1.4
      1  1.4  christos /*	$NetBSD: linux_ipccall.c,v 1.4 1995/06/24 20:20:22 christos Exp $	*/
      2  1.1      fvdl 
      3  1.1      fvdl /*
      4  1.1      fvdl  * Copyright (c) 1995 Frank van der Linden
      5  1.1      fvdl  * All rights reserved.
      6  1.1      fvdl  *
      7  1.1      fvdl  * Redistribution and use in source and binary forms, with or without
      8  1.1      fvdl  * modification, are permitted provided that the following conditions
      9  1.1      fvdl  * are met:
     10  1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     11  1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     12  1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     15  1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     16  1.1      fvdl  *    must display the following acknowledgement:
     17  1.1      fvdl  *      This product includes software developed for the NetBSD Project
     18  1.1      fvdl  *      by Frank van der Linden
     19  1.1      fvdl  * 4. The name of the author may not be used to endorse or promote products
     20  1.1      fvdl  *    derived from this software without specific prior written permission
     21  1.1      fvdl  *
     22  1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1      fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1      fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1      fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1      fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1      fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1      fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1      fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1      fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1      fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1      fvdl  */
     33  1.1      fvdl 
     34  1.1      fvdl #include <sys/types.h>
     35  1.1      fvdl #include <sys/param.h>
     36  1.1      fvdl #include <sys/kernel.h>
     37  1.1      fvdl #include <sys/shm.h>
     38  1.1      fvdl #include <sys/msg.h>
     39  1.1      fvdl #include <sys/proc.h>
     40  1.1      fvdl #include <sys/uio.h>
     41  1.1      fvdl #include <sys/time.h>
     42  1.1      fvdl #include <sys/malloc.h>
     43  1.1      fvdl #include <sys/mman.h>
     44  1.1      fvdl #include <sys/systm.h>
     45  1.1      fvdl #include <sys/stat.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.1      fvdl #include <compat/linux/linux_types.h>
     51  1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     52  1.1      fvdl #include <compat/linux/linux_util.h>
     53  1.1      fvdl #include <compat/linux/linux_ipc.h>
     54  1.1      fvdl #include <compat/linux/linux_msg.h>
     55  1.1      fvdl #include <compat/linux/linux_shm.h>
     56  1.1      fvdl #include <compat/linux/linux_ipccall.h>
     57  1.1      fvdl 
     58  1.1      fvdl /*
     59  1.1      fvdl  * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
     60  1.1      fvdl  * The main difference is, that Linux handles it all via one
     61  1.1      fvdl  * system call, which has the usual maximum amount of 5 arguments.
     62  1.1      fvdl  * This results in a kludge for calls that take 6 of them.
     63  1.1      fvdl  *
     64  1.1      fvdl  * The SYSVXXXX options have to be enabled to get the appropriate
     65  1.1      fvdl  * functions to work.
     66  1.1      fvdl  */
     67  1.1      fvdl 
     68  1.1      fvdl #ifdef SYSVSEM
     69  1.1      fvdl static int linux_semop __P((struct proc *, struct linux_ipc_args *,
     70  1.1      fvdl 				register_t *));
     71  1.1      fvdl static int linux_semget __P((struct proc *, struct linux_ipc_args *,
     72  1.1      fvdl 				register_t *));
     73  1.1      fvdl static int linux_semctl __P((struct proc *, struct linux_ipc_args *,
     74  1.1      fvdl 				register_t *));
     75  1.1      fvdl #endif
     76  1.1      fvdl 
     77  1.1      fvdl #ifdef SYSVMSG
     78  1.1      fvdl static int linux_msgsnd __P((struct proc *, struct linux_ipc_args *,
     79  1.1      fvdl 				register_t *));
     80  1.1      fvdl static int linux_msgrcv __P((struct proc *, struct linux_ipc_args *,
     81  1.1      fvdl 				register_t *));
     82  1.1      fvdl static int linux_msgop __P((struct proc *, struct linux_ipc_args *,
     83  1.1      fvdl 				register_t *));
     84  1.1      fvdl static int linux_msgctl __P((struct proc *, struct linux_ipc_args *,
     85  1.1      fvdl 				register_t *));
     86  1.1      fvdl #endif
     87  1.1      fvdl 
     88  1.1      fvdl #ifdef SYSVSHM
     89  1.1      fvdl static int linux_shmat __P((struct proc *, struct linux_ipc_args *,
     90  1.1      fvdl 				register_t *));
     91  1.1      fvdl static int linux_shmdt __P((struct proc *, struct linux_ipc_args *,
     92  1.1      fvdl 				register_t *));
     93  1.1      fvdl static int linux_shmget __P((struct proc *, struct linux_ipc_args *,
     94  1.1      fvdl 				register_t *));
     95  1.1      fvdl static int linux_shmctl __P((struct proc *, struct linux_ipc_args *,
     96  1.1      fvdl 				register_t *));
     97  1.1      fvdl #endif
     98  1.1      fvdl 
     99  1.1      fvdl 
    100  1.1      fvdl int
    101  1.1      fvdl linux_ipc(p, uap, retval)
    102  1.1      fvdl 	struct proc *p;
    103  1.1      fvdl 	struct linux_ipc_args /* {
    104  1.1      fvdl 		syscallarg(int) what;
    105  1.1      fvdl 		syscallarg(int) a1;
    106  1.1      fvdl 		syscallarg(int) a2;
    107  1.1      fvdl 		syscallarg(int) a3;
    108  1.1      fvdl 		syscallarg(caddr_t) ptr;
    109  1.1      fvdl 	} */ *uap;
    110  1.1      fvdl 	register_t *retval;
    111  1.1      fvdl {
    112  1.1      fvdl 	int what, error;
    113  1.1      fvdl 
    114  1.1      fvdl 	switch (SCARG(uap, what)) {
    115  1.1      fvdl #ifdef SYSVSEM
    116  1.1      fvdl 		case LINUX_SYS_semop:
    117  1.1      fvdl 			return linux_semop(p, uap, retval);
    118  1.1      fvdl 		case LINUX_SYS_semget:
    119  1.1      fvdl 			return linux_semget(p, uap, retval);
    120  1.1      fvdl 		case LINUX_SYS_semctl:
    121  1.1      fvdl 			return linux_semctl(p, uap, retval);
    122  1.1      fvdl #endif
    123  1.1      fvdl #ifdef SYSVMSG
    124  1.1      fvdl 		case LINUX_SYS_msgsnd:
    125  1.1      fvdl 			return linux_msgsnd(p, uap, retval);
    126  1.1      fvdl 		case LINUX_SYS_msgrcv:
    127  1.1      fvdl 			return linux_msgrcv(p, uap, retval);
    128  1.1      fvdl 		case LINUX_SYS_msgget:
    129  1.1      fvdl 			return linux_msgget(p, uap, retval);
    130  1.1      fvdl 		case LINUX_SYS_msgctl:
    131  1.1      fvdl 			return linux_msgctl(p, uap, retval);
    132  1.1      fvdl #endif
    133  1.1      fvdl #ifdef SYSVSHM
    134  1.1      fvdl 		case LINUX_SYS_shmat:
    135  1.1      fvdl 			return linux_shmat(p, uap, retval);
    136  1.1      fvdl 		case LINUX_SYS_shmdt:
    137  1.1      fvdl 			return linux_shmdt(p, uap, retval);
    138  1.1      fvdl 		case LINUX_SYS_shmget:
    139  1.1      fvdl 			return linux_shmget(p, uap, retval);
    140  1.1      fvdl 		case LINUX_SYS_shmctl:
    141  1.1      fvdl 			return linux_shmctl(p, uap, retval);
    142  1.1      fvdl #endif
    143  1.1      fvdl 		default:
    144  1.1      fvdl 			return ENOSYS;
    145  1.1      fvdl 	}
    146  1.1      fvdl }
    147  1.1      fvdl 
    148  1.1      fvdl /*
    149  1.1      fvdl  * Convert between Linux and NetBSD ipc_perm structures. Only the
    150  1.1      fvdl  * order of the fields is different.
    151  1.1      fvdl  */
    152  1.1      fvdl static void
    153  1.1      fvdl linux_to_bsd_ipc_perm(lpp, bpp)
    154  1.1      fvdl 	struct linux_ipc_perm *lpp;
    155  1.1      fvdl 	struct ipc_perm *bpp;
    156  1.1      fvdl {
    157  1.1      fvdl 	bpp->key = lpp->l_key;
    158  1.1      fvdl 	bpp->uid = lpp->l_uid;
    159  1.1      fvdl 	bpp->gid = lpp->l_gid;
    160  1.1      fvdl 	bpp->cuid = lpp->l_cuid;
    161  1.1      fvdl 	bpp->cgid = lpp->l_cgid;
    162  1.1      fvdl 	bpp->mode = lpp->l_mode;
    163  1.1      fvdl 	bpp->seq = lpp->l_seq;
    164  1.1      fvdl }
    165  1.1      fvdl 
    166  1.1      fvdl 
    167  1.1      fvdl static void
    168  1.1      fvdl bsd_to_linux_ipc_perm(bpp, lpp)
    169  1.1      fvdl 	struct ipc_perm *bpp;
    170  1.1      fvdl 	struct linux_ipc_perm *lpp;
    171  1.1      fvdl {
    172  1.1      fvdl 	lpp->l_key = bpp->key;
    173  1.1      fvdl 	lpp->l_uid = bpp->uid;
    174  1.1      fvdl 	lpp->l_gid = bpp->gid;
    175  1.1      fvdl 	lpp->l_cuid = bpp->cuid;
    176  1.1      fvdl 	lpp->l_cgid = bpp->cgid;
    177  1.1      fvdl 	lpp->l_mode = bpp->mode;
    178  1.1      fvdl 	lpp->l_seq = bpp->seq;
    179  1.1      fvdl }
    180  1.1      fvdl 
    181  1.1      fvdl #ifdef SYSVSEM
    182  1.1      fvdl /*
    183  1.1      fvdl  * Semaphore operations: not implemented yet.
    184  1.1      fvdl  */
    185  1.1      fvdl int
    186  1.1      fvdl linux_semop(p, uap, retval)
    187  1.1      fvdl 	struct proc *p;
    188  1.1      fvdl 	struct linux_ipc_args /* {
    189  1.1      fvdl 		syscallarg(int) what;
    190  1.1      fvdl 		syscallarg(int) a1;
    191  1.1      fvdl 		syscallarg(int) a2;
    192  1.1      fvdl 		syscallarg(int) a3;
    193  1.1      fvdl 		syscallarg(caddr_t) ptr;
    194  1.1      fvdl 	} */ *uap;
    195  1.1      fvdl 	register_t *retval;
    196  1.1      fvdl {
    197  1.1      fvdl 	return ENOSYS;
    198  1.1      fvdl }
    199  1.1      fvdl 
    200  1.1      fvdl int
    201  1.1      fvdl linux_semget(p, uap, retval)
    202  1.1      fvdl 	struct proc *p;
    203  1.1      fvdl 	struct linux_ipc_args /* {
    204  1.1      fvdl 		syscallarg(int) what;
    205  1.1      fvdl 		syscallarg(int) a1;
    206  1.1      fvdl 		syscallarg(int) a2;
    207  1.1      fvdl 		syscallarg(int) a3;
    208  1.1      fvdl 		syscallarg(caddr_t) ptr;
    209  1.1      fvdl 	} */ *uap;
    210  1.1      fvdl 	register_t *retval;
    211  1.1      fvdl {
    212  1.1      fvdl 	return ENOSYS;
    213  1.1      fvdl }
    214  1.1      fvdl 
    215  1.1      fvdl int
    216  1.1      fvdl linux_semctl(p, uap, retval)
    217  1.1      fvdl 	struct proc *p;
    218  1.1      fvdl 	struct linux_ipc_args /* {
    219  1.1      fvdl 		syscallarg(int) what;
    220  1.1      fvdl 		syscallarg(int) a1;
    221  1.1      fvdl 		syscallarg(int) a2;
    222  1.1      fvdl 		syscallarg(int) a3;
    223  1.1      fvdl 		syscallarg(caddr_t) ptr;
    224  1.1      fvdl 	} */ *uap;
    225  1.1      fvdl 	register_t *retval;
    226  1.1      fvdl {
    227  1.1      fvdl 	return ENOSYS;
    228  1.1      fvdl }
    229  1.1      fvdl #endif /* SYSVSEM */
    230  1.1      fvdl 
    231  1.1      fvdl #ifdef SYSVMSG
    232  1.1      fvdl /*
    233  1.1      fvdl  * Msg functions: not implemented yet.
    234  1.1      fvdl  */
    235  1.1      fvdl int
    236  1.1      fvdl linux_msgsnd(p, uap, retval)
    237  1.1      fvdl 	struct proc *p;
    238  1.1      fvdl 	struct linux_ipc_args /* {
    239  1.1      fvdl 		syscallarg(int) what;
    240  1.1      fvdl 		syscallarg(int) a1;
    241  1.1      fvdl 		syscallarg(int) a2;
    242  1.1      fvdl 		syscallarg(int) a3;
    243  1.1      fvdl 		syscallarg(caddr_t) ptr;
    244  1.1      fvdl 	} */ *uap;
    245  1.1      fvdl 	register_t *retval;
    246  1.1      fvdl {
    247  1.1      fvdl 	return ENOSYS;
    248  1.1      fvdl }
    249  1.1      fvdl 
    250  1.1      fvdl int
    251  1.1      fvdl linux_msgrcv(p, uap, retval)
    252  1.1      fvdl 	struct proc *p;
    253  1.1      fvdl 	struct linux_ipc_args /* {
    254  1.1      fvdl 		syscallarg(int) what;
    255  1.1      fvdl 		syscallarg(int) a1;
    256  1.1      fvdl 		syscallarg(int) a2;
    257  1.1      fvdl 		syscallarg(int) a3;
    258  1.1      fvdl 		syscallarg(caddr_t) ptr;
    259  1.1      fvdl 	} */ *uap;
    260  1.1      fvdl 	register_t *retval;
    261  1.1      fvdl {
    262  1.1      fvdl 	return ENOSYS;
    263  1.1      fvdl }
    264  1.1      fvdl 
    265  1.1      fvdl int
    266  1.1      fvdl linux_msgget(p, uap, retval)
    267  1.1      fvdl 	struct proc *p;
    268  1.1      fvdl 	struct linux_ipc_args /* {
    269  1.1      fvdl 		syscallarg(int) what;
    270  1.1      fvdl 		syscallarg(int) a1;
    271  1.1      fvdl 		syscallarg(int) a2;
    272  1.1      fvdl 		syscallarg(int) a3;
    273  1.1      fvdl 		syscallarg(caddr_t) ptr;
    274  1.1      fvdl 	} */ *uap;
    275  1.1      fvdl 	register_t *retval;
    276  1.1      fvdl {
    277  1.1      fvdl 	return ENOSYS;
    278  1.1      fvdl }
    279  1.1      fvdl 
    280  1.1      fvdl int
    281  1.1      fvdl linux_msgctl(p, uap, retval)
    282  1.1      fvdl 	struct proc *p;
    283  1.1      fvdl 	struct linux_ipc_args /* {
    284  1.1      fvdl 		syscallarg(int) what;
    285  1.1      fvdl 		syscallarg(int) a1;
    286  1.1      fvdl 		syscallarg(int) a2;
    287  1.1      fvdl 		syscallarg(int) a3;
    288  1.1      fvdl 		syscallarg(caddr_t) ptr;
    289  1.1      fvdl 	} */ *uap;
    290  1.1      fvdl 	register_t *retval;
    291  1.1      fvdl {
    292  1.1      fvdl 	return ENOSYS;
    293  1.1      fvdl }
    294  1.1      fvdl #endif /* SYSVMSG */
    295  1.1      fvdl 
    296  1.1      fvdl #ifdef SYSVSHM
    297  1.1      fvdl /*
    298  1.1      fvdl  * shmat(2). Very straightforward, except that Linux passes a pointer
    299  1.1      fvdl  * in which the return value is to be passed. This is subsequently
    300  1.1      fvdl  * handled by libc, apparently.
    301  1.1      fvdl  */
    302  1.1      fvdl int
    303  1.1      fvdl linux_shmat(p, uap, retval)
    304  1.1      fvdl 	struct proc *p;
    305  1.1      fvdl 	struct linux_ipc_args /* {
    306  1.1      fvdl 		syscallarg(int) what;
    307  1.1      fvdl 		syscallarg(int) a1;
    308  1.1      fvdl 		syscallarg(int) a2;
    309  1.1      fvdl 		syscallarg(int) a3;
    310  1.1      fvdl 		syscallarg(caddr_t) ptr;
    311  1.1      fvdl 	} */ *uap;
    312  1.1      fvdl 	register_t *retval;
    313  1.1      fvdl {
    314  1.1      fvdl 	struct shmat_args bsa;
    315  1.1      fvdl 	int error;
    316  1.1      fvdl 
    317  1.1      fvdl 	SCARG(&bsa, shmid) = SCARG(uap, a1);
    318  1.1      fvdl 	SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
    319  1.1      fvdl 	SCARG(&bsa, shmflg) = SCARG(uap, a2);
    320  1.1      fvdl 
    321  1.1      fvdl 	if ((error = shmat(p, &bsa, retval)))
    322  1.1      fvdl 		return error;
    323  1.1      fvdl 
    324  1.1      fvdl 	if ((error = copyout(&retval[0], (caddr_t) SCARG(uap, a3),
    325  1.1      fvdl 	     sizeof retval[0])))
    326  1.1      fvdl 		return error;
    327  1.1      fvdl 
    328  1.1      fvdl 	retval[0] = 0;
    329  1.1      fvdl 
    330  1.1      fvdl 	return 0;
    331  1.1      fvdl }
    332  1.1      fvdl 
    333  1.1      fvdl /*
    334  1.1      fvdl  * shmdt(): this could have been mapped directly, if it wasn't for
    335  1.1      fvdl  * the extra indirection by the linux_ipc system call.
    336  1.1      fvdl  */
    337  1.1      fvdl int
    338  1.1      fvdl linux_shmdt(p, uap, retval)
    339  1.1      fvdl 	struct proc *p;
    340  1.1      fvdl 	struct linux_ipc_args /* {
    341  1.1      fvdl 		syscallarg(int) what;
    342  1.1      fvdl 		syscallarg(int) a1;
    343  1.1      fvdl 		syscallarg(int) a2;
    344  1.1      fvdl 		syscallarg(int) a3;
    345  1.1      fvdl 		syscallarg(caddr_t) ptr;
    346  1.1      fvdl 	} */ *uap;
    347  1.1      fvdl 	register_t *retval;
    348  1.1      fvdl {
    349  1.1      fvdl 	struct shmdt_args bsa;
    350  1.1      fvdl 
    351  1.1      fvdl 	SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
    352  1.1      fvdl 	return shmdt(p, &bsa, retval);
    353  1.1      fvdl }
    354  1.1      fvdl 
    355  1.1      fvdl /*
    356  1.1      fvdl  * Same story as shmdt.
    357  1.1      fvdl  */
    358  1.1      fvdl int
    359  1.1      fvdl linux_shmget(p, uap, retval)
    360  1.1      fvdl 	struct proc *p;
    361  1.1      fvdl 	struct linux_ipc_args /* {
    362  1.1      fvdl 		syscallarg(int) what;
    363  1.1      fvdl 		syscallarg(int) a1;
    364  1.1      fvdl 		syscallarg(int) a2;
    365  1.1      fvdl 		syscallarg(int) a3;
    366  1.1      fvdl 		syscallarg(caddr_t) ptr;
    367  1.1      fvdl 	} */ *uap;
    368  1.1      fvdl 	register_t *retval;
    369  1.1      fvdl {
    370  1.1      fvdl 	struct shmget_args bsa;
    371  1.1      fvdl 
    372  1.1      fvdl 	SCARG(&bsa, key) = SCARG(uap, a1);
    373  1.1      fvdl 	SCARG(&bsa, size) = SCARG(uap, a2);
    374  1.1      fvdl 	SCARG(&bsa, shmflg) = SCARG(uap, a3);
    375  1.1      fvdl 	return shmget(p, &bsa, retval);
    376  1.1      fvdl }
    377  1.1      fvdl 
    378  1.1      fvdl /*
    379  1.1      fvdl  * Convert between Linux and NetBSD shmid_ds structures.
    380  1.1      fvdl  * The order of the fields is once again the difference, and
    381  1.1      fvdl  * we also need a place to store the internal data pointer
    382  1.1      fvdl  * in, which is unfortunately stored in this structure.
    383  1.1      fvdl  *
    384  1.1      fvdl  * We abuse a Linux internal field for that.
    385  1.1      fvdl  */
    386  1.1      fvdl static void
    387  1.1      fvdl linux_to_bsd_shmid_ds(lsp, bsp)
    388  1.1      fvdl 	struct linux_shmid_ds *lsp;
    389  1.1      fvdl 	struct shmid_ds *bsp;
    390  1.1      fvdl {
    391  1.1      fvdl 	linux_to_bsd_ipc_perm(&lsp->l_shm_perm, &bsp->shm_perm);
    392  1.1      fvdl 	bsp->shm_segsz = lsp->l_shm_segsz;
    393  1.1      fvdl 	bsp->shm_lpid = lsp->l_shm_lpid;
    394  1.1      fvdl 	bsp->shm_cpid = lsp->l_shm_cpid;
    395  1.1      fvdl 	bsp->shm_nattch = lsp->l_shm_nattch;
    396  1.1      fvdl 	bsp->shm_atime = lsp->l_shm_atime;
    397  1.1      fvdl 	bsp->shm_dtime = lsp->l_shm_dtime;
    398  1.1      fvdl 	bsp->shm_ctime = lsp->l_shm_ctime;
    399  1.1      fvdl 	bsp->shm_internal = lsp->l_private2;	/* XXX Oh well. */
    400  1.1      fvdl }
    401  1.1      fvdl 
    402  1.1      fvdl static void
    403  1.1      fvdl bsd_to_linux_shmid_ds(bsp, lsp)
    404  1.1      fvdl 	struct shmid_ds *bsp;
    405  1.1      fvdl 	struct linux_shmid_ds *lsp;
    406  1.1      fvdl {
    407  1.1      fvdl 	bsd_to_linux_ipc_perm(&bsp->shm_perm, &lsp->l_shm_perm);
    408  1.1      fvdl 	lsp->l_shm_segsz = bsp->shm_segsz;
    409  1.1      fvdl 	lsp->l_shm_lpid = bsp->shm_lpid;
    410  1.1      fvdl 	lsp->l_shm_cpid = bsp->shm_cpid;
    411  1.1      fvdl 	lsp->l_shm_nattch = bsp->shm_nattch;
    412  1.1      fvdl 	lsp->l_shm_atime = bsp->shm_atime;
    413  1.1      fvdl 	lsp->l_shm_dtime = bsp->shm_dtime;
    414  1.1      fvdl 	lsp->l_shm_ctime = bsp->shm_ctime;
    415  1.1      fvdl 	lsp->l_private2 = bsp->shm_internal;	/* XXX */
    416  1.1      fvdl }
    417  1.1      fvdl 
    418  1.1      fvdl /*
    419  1.1      fvdl  * shmctl. Not implemented (for now): IPC_INFO, SHM_INFO, SHM_STAT
    420  1.1      fvdl  * SHM_LOCK and SHM_UNLOCK are passed on, but currently not implemented
    421  1.1      fvdl  * by NetBSD itself.
    422  1.1      fvdl  *
    423  1.1      fvdl  * The usual structure conversion and massaging is done.
    424  1.1      fvdl  */
    425  1.1      fvdl int
    426  1.1      fvdl linux_shmctl(p, uap, retval)
    427  1.1      fvdl 	struct proc *p;
    428  1.1      fvdl 	struct linux_ipc_args /* {
    429  1.1      fvdl 		syscallarg(int) what;
    430  1.1      fvdl 		syscallarg(int) a1;
    431  1.1      fvdl 		syscallarg(int) a2;
    432  1.1      fvdl 		syscallarg(int) a3;
    433  1.1      fvdl 		syscallarg(caddr_t) ptr;
    434  1.1      fvdl 	} */ *uap;
    435  1.1      fvdl 	register_t *retval;
    436  1.1      fvdl {
    437  1.1      fvdl 	int error;
    438  1.1      fvdl 	caddr_t sg;
    439  1.1      fvdl 	struct shmctl_args bsa;
    440  1.1      fvdl 	struct shmid_ds *bsp, bs;
    441  1.1      fvdl 	struct linux_shmid_ds lseg;
    442  1.1      fvdl 
    443  1.1      fvdl 	switch (SCARG(uap, a2)) {
    444  1.1      fvdl 	case LINUX_IPC_STAT:
    445  1.4  christos 		sg = stackgap_init(p->p_emul);
    446  1.1      fvdl 		bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
    447  1.1      fvdl 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    448  1.1      fvdl 		SCARG(&bsa, cmd) = IPC_STAT;
    449  1.1      fvdl 		SCARG(&bsa, buf) = bsp;
    450  1.1      fvdl 		if ((error = shmctl(p, &bsa, retval)))
    451  1.1      fvdl 			return error;
    452  1.1      fvdl 		if ((error = copyin((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
    453  1.1      fvdl 			return error;
    454  1.1      fvdl 		bsd_to_linux_shmid_ds(&bs, &lseg);
    455  1.1      fvdl 		return copyout((caddr_t) &lseg, SCARG(uap, ptr), sizeof lseg);
    456  1.1      fvdl 	case LINUX_IPC_SET:
    457  1.1      fvdl 		if ((error = copyin(SCARG(uap, ptr), (caddr_t) &lseg,
    458  1.1      fvdl 		     sizeof lseg)))
    459  1.1      fvdl 			return error;
    460  1.1      fvdl 		linux_to_bsd_shmid_ds(&lseg, &bs);
    461  1.4  christos 		sg = stackgap_init(p->p_emul);
    462  1.1      fvdl 		bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
    463  1.1      fvdl 		if ((error = copyout((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
    464  1.1      fvdl 			return error;
    465  1.1      fvdl 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    466  1.1      fvdl 		SCARG(&bsa, cmd) = IPC_SET;
    467  1.1      fvdl 		SCARG(&bsa, buf) = bsp;
    468  1.1      fvdl 		return shmctl(p, &bsa, retval);
    469  1.1      fvdl 	case LINUX_IPC_RMID:
    470  1.1      fvdl 	case LINUX_SHM_LOCK:
    471  1.1      fvdl 	case LINUX_SHM_UNLOCK:
    472  1.1      fvdl 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    473  1.1      fvdl 		switch (SCARG(uap, a2)) {
    474  1.1      fvdl 		case LINUX_IPC_RMID:
    475  1.1      fvdl 			SCARG(&bsa, cmd) = IPC_RMID;
    476  1.1      fvdl 			break;
    477  1.1      fvdl 		case LINUX_SHM_LOCK:
    478  1.1      fvdl 			SCARG(&bsa, cmd) = SHM_LOCK;
    479  1.1      fvdl 			break;
    480  1.1      fvdl 		case LINUX_SHM_UNLOCK:
    481  1.1      fvdl 			SCARG(&bsa, cmd) = SHM_UNLOCK;
    482  1.1      fvdl 			break;
    483  1.1      fvdl 		}
    484  1.2      fvdl 		if ((error = copyin(SCARG(uap, ptr), (caddr_t) &lseg,
    485  1.2      fvdl 		     sizeof lseg)))
    486  1.2      fvdl 			return error;
    487  1.2      fvdl 		linux_to_bsd_shmid_ds(&lseg, &bs);
    488  1.4  christos 		sg = stackgap_init(p->p_emul);
    489  1.2      fvdl 		bsp = stackgap_alloc(&sg, sizeof (struct shmid_ds));
    490  1.2      fvdl 		if ((error = copyout((caddr_t) &bs, (caddr_t) bsp, sizeof bs)))
    491  1.2      fvdl 			return error;
    492  1.2      fvdl 		SCARG(&bsa, buf) = bsp;
    493  1.1      fvdl 		return shmctl(p, &bsa, retval);
    494  1.1      fvdl 	case LINUX_IPC_INFO:
    495  1.1      fvdl 	case LINUX_SHM_STAT:
    496  1.1      fvdl 	case LINUX_SHM_INFO:
    497  1.1      fvdl 	default:
    498  1.1      fvdl 		return EINVAL;
    499  1.1      fvdl 	}
    500  1.1      fvdl }
    501  1.1      fvdl #endif /* SYSVSHM */
    502