Home | History | Annotate | Line # | Download | only in common
linux_ipccall.c revision 1.28
      1  1.28  christos /*	$NetBSD: linux_ipccall.c,v 1.28 2007/03/04 06:01:23 christos Exp $	*/
      2  1.14       erh 
      3  1.14       erh /*-
      4  1.14       erh  * Copyright (c) 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.21     lukem 
     39  1.21     lukem #include <sys/cdefs.h>
     40  1.28  christos __KERNEL_RCSID(0, "$NetBSD: linux_ipccall.c,v 1.28 2007/03/04 06:01:23 christos Exp $");
     41   1.1      fvdl 
     42  1.20       mrg #if defined(_KERNEL_OPT)
     43  1.19      tron #include "opt_sysv.h"
     44  1.19      tron #endif
     45  1.19      tron 
     46   1.1      fvdl #include <sys/param.h>
     47   1.1      fvdl #include <sys/shm.h>
     48   1.6      fvdl #include <sys/sem.h>
     49   1.1      fvdl #include <sys/msg.h>
     50   1.1      fvdl #include <sys/proc.h>
     51   1.1      fvdl #include <sys/systm.h>
     52   1.1      fvdl 
     53  1.14       erh /* real syscalls */
     54   1.1      fvdl #include <sys/mount.h>
     55   1.1      fvdl #include <sys/syscallargs.h>
     56   1.1      fvdl 
     57  1.14       erh /* sys_ipc + args prototype */
     58  1.15  christos #include <compat/linux/common/linux_types.h>
     59  1.15  christos #include <compat/linux/common/linux_signal.h>
     60  1.15  christos 
     61   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     62  1.14       erh #include <compat/linux/linux_syscall.h>
     63  1.14       erh 
     64  1.14       erh /* general ipc defines */
     65  1.15  christos #include <compat/linux/common/linux_ipc.h>
     66  1.14       erh 
     67  1.14       erh /* prototypes for real/normal linux-emul syscalls */
     68  1.15  christos #include <compat/linux/common/linux_msg.h>
     69  1.15  christos #include <compat/linux/common/linux_shm.h>
     70  1.15  christos #include <compat/linux/common/linux_sem.h>
     71  1.14       erh 
     72  1.14       erh /* prototypes for sys_ipc stuff */
     73  1.15  christos #include <compat/linux/common/linux_ipccall.h>
     74   1.1      fvdl 
     75  1.14       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     76  1.14       erh /* Not used on: alpha */
     77  1.14       erh 
     78   1.1      fvdl /*
     79   1.1      fvdl  * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
     80   1.1      fvdl  * The main difference is, that Linux handles it all via one
     81   1.1      fvdl  * system call, which has the usual maximum amount of 5 arguments.
     82   1.1      fvdl  * This results in a kludge for calls that take 6 of them.
     83   1.1      fvdl  *
     84  1.14       erh  * The SYSV??? options have to be enabled to get the appropriate
     85   1.1      fvdl  * functions to work.
     86   1.1      fvdl  */
     87   1.1      fvdl 
     88   1.1      fvdl int
     89  1.23   thorpej linux_sys_ipc(l, v, retval)
     90  1.23   thorpej 	struct lwp *l;
     91   1.7   thorpej 	void *v;
     92   1.7   thorpej 	register_t *retval;
     93   1.7   thorpej {
     94   1.8   mycroft 	struct linux_sys_ipc_args /* {
     95   1.1      fvdl 		syscallarg(int) what;
     96   1.1      fvdl 		syscallarg(int) a1;
     97   1.1      fvdl 		syscallarg(int) a2;
     98   1.1      fvdl 		syscallarg(int) a3;
     99  1.28  christos 		syscallarg(void *) ptr;
    100   1.7   thorpej 	} */ *uap = v;
    101   1.1      fvdl 
    102   1.1      fvdl 	switch (SCARG(uap, what)) {
    103   1.1      fvdl #ifdef SYSVSEM
    104   1.6      fvdl 	case LINUX_SYS_semop:
    105  1.23   thorpej 		return linux_semop(l, uap, retval);
    106   1.6      fvdl 	case LINUX_SYS_semget:
    107  1.23   thorpej 		return linux_semget(l, uap, retval);
    108  1.14       erh 	case LINUX_SYS_semctl: {
    109  1.14       erh 		struct linux_sys_semctl_args bsa;
    110  1.14       erh 		union linux_semun arg;
    111  1.14       erh 		int error;
    112  1.14       erh 
    113  1.14       erh 		SCARG(&bsa, semid) = SCARG(uap, a1);
    114  1.14       erh 		SCARG(&bsa, semnum) = SCARG(uap, a2);
    115  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a3);
    116  1.14       erh 		/* Convert from (union linux_semun *) to (union linux_semun) */
    117  1.14       erh 		if ((error = copyin(SCARG(uap, ptr), &arg, sizeof arg)))
    118  1.14       erh 			return error;
    119  1.14       erh 		SCARG(&bsa, arg) = arg;
    120  1.14       erh 
    121  1.23   thorpej 		return linux_sys_semctl(l, &bsa, retval);
    122  1.14       erh 	    }
    123   1.1      fvdl #endif
    124   1.1      fvdl #ifdef SYSVMSG
    125   1.6      fvdl 	case LINUX_SYS_msgsnd:
    126  1.23   thorpej 		return linux_msgsnd(l, uap, retval);
    127   1.6      fvdl 	case LINUX_SYS_msgrcv:
    128  1.23   thorpej 		return linux_msgrcv(l, uap, retval);
    129   1.6      fvdl 	case LINUX_SYS_msgget:
    130  1.23   thorpej 		return linux_msgget(l, uap, retval);
    131  1.14       erh 	case LINUX_SYS_msgctl: {
    132  1.14       erh 		struct linux_sys_msgctl_args bsa;
    133  1.14       erh 
    134  1.14       erh 		SCARG(&bsa, msqid) = SCARG(uap, a1);
    135  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a2);
    136  1.14       erh 		SCARG(&bsa, buf) = (struct linux_msqid_ds *)SCARG(uap, ptr);
    137  1.14       erh 
    138  1.23   thorpej 		return linux_sys_msgctl(l, &bsa, retval);
    139  1.14       erh 	    }
    140   1.1      fvdl #endif
    141   1.1      fvdl #ifdef SYSVSHM
    142  1.14       erh 	case LINUX_SYS_shmat: {
    143  1.14       erh 		struct linux_sys_shmat_args bsa;
    144  1.25     perry 
    145  1.14       erh 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    146  1.14       erh 		SCARG(&bsa, shmaddr) = (void *)SCARG(uap, ptr);
    147  1.14       erh 		SCARG(&bsa, shmflg) = SCARG(uap, a2);
    148  1.14       erh 		/* XXX passing pointer inside int here */
    149  1.14       erh 		SCARG(&bsa, raddr) = (u_long *)SCARG(uap, a3);
    150  1.14       erh 
    151  1.23   thorpej 		return linux_sys_shmat(l, &bsa, retval);
    152  1.14       erh 	    }
    153   1.6      fvdl 	case LINUX_SYS_shmdt:
    154  1.23   thorpej 		return linux_shmdt(l, uap, retval);
    155   1.6      fvdl 	case LINUX_SYS_shmget:
    156  1.23   thorpej 		return linux_shmget(l, uap, retval);
    157  1.14       erh 	case LINUX_SYS_shmctl: {
    158  1.14       erh 		struct linux_sys_shmctl_args bsa;
    159  1.14       erh 
    160  1.14       erh 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    161  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a2);
    162  1.14       erh 		SCARG(&bsa, buf) = (struct linux_shmid_ds *)SCARG(uap, ptr);
    163  1.14       erh 
    164  1.23   thorpej 		return linux_sys_shmctl(l, &bsa, retval);
    165  1.14       erh 	    }
    166   1.1      fvdl #endif
    167   1.6      fvdl 	default:
    168   1.6      fvdl 		return ENOSYS;
    169   1.1      fvdl 	}
    170   1.1      fvdl }
    171   1.1      fvdl 
    172   1.1      fvdl #ifdef SYSVSEM
    173  1.14       erh inline int
    174  1.23   thorpej linux_semop(l, uap, retval)
    175  1.23   thorpej 	struct lwp *l;
    176   1.8   mycroft 	struct linux_sys_ipc_args /* {
    177   1.1      fvdl 		syscallarg(int) what;
    178   1.1      fvdl 		syscallarg(int) a1;
    179   1.1      fvdl 		syscallarg(int) a2;
    180   1.1      fvdl 		syscallarg(int) a3;
    181  1.28  christos 		syscallarg(void *) ptr;
    182   1.1      fvdl 	} */ *uap;
    183   1.1      fvdl 	register_t *retval;
    184   1.1      fvdl {
    185   1.8   mycroft 	struct sys_semop_args bsa;
    186   1.6      fvdl 
    187   1.6      fvdl 	SCARG(&bsa, semid) = SCARG(uap, a1);
    188   1.6      fvdl 	SCARG(&bsa, sops) = (struct sembuf *)SCARG(uap, ptr);
    189   1.6      fvdl 	SCARG(&bsa, nsops) = SCARG(uap, a2);
    190   1.6      fvdl 
    191  1.23   thorpej 	return sys_semop(l, &bsa, retval);
    192   1.1      fvdl }
    193   1.1      fvdl 
    194  1.14       erh inline int
    195  1.23   thorpej linux_semget(l, uap, retval)
    196  1.23   thorpej 	struct lwp *l;
    197   1.8   mycroft 	struct linux_sys_ipc_args /* {
    198   1.1      fvdl 		syscallarg(int) what;
    199   1.1      fvdl 		syscallarg(int) a1;
    200   1.1      fvdl 		syscallarg(int) a2;
    201   1.1      fvdl 		syscallarg(int) a3;
    202  1.28  christos 		syscallarg(void *) ptr;
    203   1.1      fvdl 	} */ *uap;
    204   1.1      fvdl 	register_t *retval;
    205   1.1      fvdl {
    206   1.8   mycroft 	struct sys_semget_args bsa;
    207   1.6      fvdl 
    208   1.6      fvdl 	SCARG(&bsa, key) = (key_t)SCARG(uap, a1);
    209   1.6      fvdl 	SCARG(&bsa, nsems) = SCARG(uap, a2);
    210   1.6      fvdl 	SCARG(&bsa, semflg) = SCARG(uap, a3);
    211   1.6      fvdl 
    212  1.23   thorpej 	return sys_semget(l, &bsa, retval);
    213   1.1      fvdl }
    214   1.1      fvdl 
    215   1.1      fvdl #endif /* SYSVSEM */
    216   1.1      fvdl 
    217   1.1      fvdl #ifdef SYSVMSG
    218   1.6      fvdl 
    219  1.14       erh inline int
    220  1.23   thorpej linux_msgsnd(l, uap, retval)
    221  1.23   thorpej 	struct lwp *l;
    222   1.8   mycroft 	struct linux_sys_ipc_args /* {
    223   1.1      fvdl 		syscallarg(int) what;
    224   1.1      fvdl 		syscallarg(int) a1;
    225   1.1      fvdl 		syscallarg(int) a2;
    226   1.1      fvdl 		syscallarg(int) a3;
    227  1.28  christos 		syscallarg(void *) ptr;
    228   1.1      fvdl 	} */ *uap;
    229   1.1      fvdl 	register_t *retval;
    230   1.1      fvdl {
    231   1.8   mycroft 	struct sys_msgsnd_args bma;
    232   1.6      fvdl 
    233   1.6      fvdl 	SCARG(&bma, msqid) = SCARG(uap, a1);
    234   1.6      fvdl 	SCARG(&bma, msgp) = SCARG(uap, ptr);
    235   1.6      fvdl 	SCARG(&bma, msgsz) = SCARG(uap, a2);
    236   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a3);
    237   1.6      fvdl 
    238  1.23   thorpej 	return sys_msgsnd(l, &bma, retval);
    239   1.1      fvdl }
    240   1.1      fvdl 
    241  1.14       erh inline int
    242  1.23   thorpej linux_msgrcv(l, uap, retval)
    243  1.23   thorpej 	struct lwp *l;
    244   1.8   mycroft 	struct linux_sys_ipc_args /* {
    245   1.1      fvdl 		syscallarg(int) what;
    246   1.1      fvdl 		syscallarg(int) a1;
    247   1.1      fvdl 		syscallarg(int) a2;
    248   1.1      fvdl 		syscallarg(int) a3;
    249  1.28  christos 		syscallarg(void *) ptr;
    250   1.1      fvdl 	} */ *uap;
    251   1.1      fvdl 	register_t *retval;
    252   1.1      fvdl {
    253   1.8   mycroft 	struct sys_msgrcv_args bma;
    254   1.6      fvdl 	struct linux_msgrcv_msgarg kluge;
    255   1.6      fvdl 	int error;
    256   1.6      fvdl 
    257   1.6      fvdl 	if ((error = copyin(SCARG(uap, ptr), &kluge, sizeof kluge)))
    258   1.6      fvdl 		return error;
    259   1.6      fvdl 
    260   1.6      fvdl 	SCARG(&bma, msqid) = SCARG(uap, a1);
    261   1.6      fvdl 	SCARG(&bma, msgp) = kluge.msg;
    262   1.6      fvdl 	SCARG(&bma, msgsz) = SCARG(uap, a2);
    263   1.6      fvdl 	SCARG(&bma, msgtyp) = kluge.type;
    264   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a3);
    265   1.8   mycroft 
    266  1.23   thorpej 	return sys_msgrcv(l, &bma, retval);
    267   1.1      fvdl }
    268   1.1      fvdl 
    269  1.14       erh inline int
    270  1.23   thorpej linux_msgget(l, uap, retval)
    271  1.23   thorpej 	struct lwp *l;
    272   1.8   mycroft 	struct linux_sys_ipc_args /* {
    273   1.1      fvdl 		syscallarg(int) what;
    274   1.1      fvdl 		syscallarg(int) a1;
    275   1.1      fvdl 		syscallarg(int) a2;
    276   1.1      fvdl 		syscallarg(int) a3;
    277  1.28  christos 		syscallarg(void *) ptr;
    278   1.1      fvdl 	} */ *uap;
    279   1.1      fvdl 	register_t *retval;
    280   1.1      fvdl {
    281   1.8   mycroft 	struct sys_msgget_args bma;
    282   1.6      fvdl 
    283   1.6      fvdl 	SCARG(&bma, key) = (key_t)SCARG(uap, a1);
    284   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a2);
    285   1.8   mycroft 
    286  1.23   thorpej 	return sys_msgget(l, &bma, retval);
    287   1.1      fvdl }
    288   1.1      fvdl 
    289   1.1      fvdl #endif /* SYSVMSG */
    290   1.1      fvdl 
    291   1.1      fvdl #ifdef SYSVSHM
    292   1.1      fvdl /*
    293   1.1      fvdl  * shmdt(): this could have been mapped directly, if it wasn't for
    294   1.1      fvdl  * the extra indirection by the linux_ipc system call.
    295   1.1      fvdl  */
    296  1.14       erh inline int
    297  1.23   thorpej linux_shmdt(l, uap, retval)
    298  1.23   thorpej 	struct lwp *l;
    299   1.8   mycroft 	struct linux_sys_ipc_args /* {
    300   1.1      fvdl 		syscallarg(int) what;
    301   1.1      fvdl 		syscallarg(int) a1;
    302   1.1      fvdl 		syscallarg(int) a2;
    303   1.1      fvdl 		syscallarg(int) a3;
    304  1.28  christos 		syscallarg(void *) ptr;
    305   1.1      fvdl 	} */ *uap;
    306   1.1      fvdl 	register_t *retval;
    307   1.1      fvdl {
    308   1.8   mycroft 	struct sys_shmdt_args bsa;
    309   1.1      fvdl 
    310   1.1      fvdl 	SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
    311   1.8   mycroft 
    312  1.23   thorpej 	return sys_shmdt(l, &bsa, retval);
    313   1.1      fvdl }
    314   1.1      fvdl 
    315   1.1      fvdl /*
    316   1.1      fvdl  * Same story as shmdt.
    317   1.1      fvdl  */
    318  1.14       erh inline int
    319  1.23   thorpej linux_shmget(l, uap, retval)
    320  1.23   thorpej 	struct lwp *l;
    321   1.8   mycroft 	struct linux_sys_ipc_args /* {
    322   1.1      fvdl 		syscallarg(int) what;
    323   1.1      fvdl 		syscallarg(int) a1;
    324   1.1      fvdl 		syscallarg(int) a2;
    325   1.1      fvdl 		syscallarg(int) a3;
    326  1.28  christos 		syscallarg(void *) ptr;
    327   1.1      fvdl 	} */ *uap;
    328   1.1      fvdl 	register_t *retval;
    329   1.1      fvdl {
    330   1.8   mycroft 	struct sys_shmget_args bsa;
    331   1.1      fvdl 
    332   1.1      fvdl 	SCARG(&bsa, key) = SCARG(uap, a1);
    333   1.1      fvdl 	SCARG(&bsa, size) = SCARG(uap, a2);
    334   1.1      fvdl 	SCARG(&bsa, shmflg) = SCARG(uap, a3);
    335   1.8   mycroft 
    336  1.24  jdolecek 	return linux_sys_shmget(l, &bsa, retval);
    337   1.1      fvdl }
    338   1.1      fvdl 
    339   1.1      fvdl #endif /* SYSVSHM */
    340