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