Home | History | Annotate | Line # | Download | only in common
linux_ipccall.c revision 1.31
      1  1.31    martin /*	$NetBSD: linux_ipccall.c,v 1.31 2008/04/28 20:23:43 martin 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  *
     19  1.14       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.14       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.14       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.14       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.14       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.14       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.14       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.14       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.14       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.14       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.14       erh  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1      fvdl  */
     31  1.21     lukem 
     32  1.21     lukem #include <sys/cdefs.h>
     33  1.31    martin __KERNEL_RCSID(0, "$NetBSD: linux_ipccall.c,v 1.31 2008/04/28 20:23:43 martin Exp $");
     34   1.1      fvdl 
     35  1.20       mrg #if defined(_KERNEL_OPT)
     36  1.19      tron #include "opt_sysv.h"
     37  1.19      tron #endif
     38  1.19      tron 
     39   1.1      fvdl #include <sys/param.h>
     40   1.1      fvdl #include <sys/shm.h>
     41   1.6      fvdl #include <sys/sem.h>
     42   1.1      fvdl #include <sys/msg.h>
     43   1.1      fvdl #include <sys/proc.h>
     44   1.1      fvdl #include <sys/systm.h>
     45   1.1      fvdl 
     46  1.14       erh /* real syscalls */
     47   1.1      fvdl #include <sys/mount.h>
     48   1.1      fvdl #include <sys/syscallargs.h>
     49   1.1      fvdl 
     50  1.14       erh /* sys_ipc + args prototype */
     51  1.15  christos #include <compat/linux/common/linux_types.h>
     52  1.15  christos #include <compat/linux/common/linux_signal.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.14       erh 
     57  1.14       erh /* general ipc defines */
     58  1.15  christos #include <compat/linux/common/linux_ipc.h>
     59  1.14       erh 
     60  1.14       erh /* prototypes for real/normal linux-emul syscalls */
     61  1.15  christos #include <compat/linux/common/linux_msg.h>
     62  1.15  christos #include <compat/linux/common/linux_shm.h>
     63  1.15  christos #include <compat/linux/common/linux_sem.h>
     64  1.14       erh 
     65  1.14       erh /* prototypes for sys_ipc stuff */
     66  1.15  christos #include <compat/linux/common/linux_ipccall.h>
     67   1.1      fvdl 
     68  1.14       erh /* Used on: arm, i386, m68k, mips, ppc, sparc, sparc64 */
     69  1.14       erh /* Not used on: alpha */
     70  1.14       erh 
     71   1.1      fvdl /*
     72   1.1      fvdl  * Stuff to deal with the SysV ipc/shm/semaphore interface in Linux.
     73   1.1      fvdl  * The main difference is, that Linux handles it all via one
     74   1.1      fvdl  * system call, which has the usual maximum amount of 5 arguments.
     75   1.1      fvdl  * This results in a kludge for calls that take 6 of them.
     76   1.1      fvdl  *
     77  1.14       erh  * The SYSV??? options have to be enabled to get the appropriate
     78   1.1      fvdl  * functions to work.
     79   1.1      fvdl  */
     80   1.1      fvdl 
     81   1.1      fvdl int
     82  1.30       dsl linux_sys_ipc(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
     83   1.7   thorpej {
     84  1.30       dsl 	/* {
     85   1.1      fvdl 		syscallarg(int) what;
     86   1.1      fvdl 		syscallarg(int) a1;
     87   1.1      fvdl 		syscallarg(int) a2;
     88   1.1      fvdl 		syscallarg(int) a3;
     89  1.28  christos 		syscallarg(void *) ptr;
     90  1.30       dsl 	} */
     91   1.1      fvdl 
     92   1.1      fvdl 	switch (SCARG(uap, what)) {
     93   1.1      fvdl #ifdef SYSVSEM
     94   1.6      fvdl 	case LINUX_SYS_semop:
     95  1.23   thorpej 		return linux_semop(l, uap, retval);
     96   1.6      fvdl 	case LINUX_SYS_semget:
     97  1.23   thorpej 		return linux_semget(l, uap, retval);
     98  1.14       erh 	case LINUX_SYS_semctl: {
     99  1.14       erh 		struct linux_sys_semctl_args bsa;
    100  1.14       erh 		union linux_semun arg;
    101  1.14       erh 		int error;
    102  1.14       erh 
    103  1.14       erh 		SCARG(&bsa, semid) = SCARG(uap, a1);
    104  1.14       erh 		SCARG(&bsa, semnum) = SCARG(uap, a2);
    105  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a3);
    106  1.14       erh 		/* Convert from (union linux_semun *) to (union linux_semun) */
    107  1.14       erh 		if ((error = copyin(SCARG(uap, ptr), &arg, sizeof arg)))
    108  1.14       erh 			return error;
    109  1.14       erh 		SCARG(&bsa, arg) = arg;
    110  1.14       erh 
    111  1.23   thorpej 		return linux_sys_semctl(l, &bsa, retval);
    112  1.14       erh 	    }
    113   1.1      fvdl #endif
    114   1.1      fvdl #ifdef SYSVMSG
    115   1.6      fvdl 	case LINUX_SYS_msgsnd:
    116  1.23   thorpej 		return linux_msgsnd(l, uap, retval);
    117   1.6      fvdl 	case LINUX_SYS_msgrcv:
    118  1.23   thorpej 		return linux_msgrcv(l, uap, retval);
    119   1.6      fvdl 	case LINUX_SYS_msgget:
    120  1.23   thorpej 		return linux_msgget(l, uap, retval);
    121  1.14       erh 	case LINUX_SYS_msgctl: {
    122  1.14       erh 		struct linux_sys_msgctl_args bsa;
    123  1.14       erh 
    124  1.14       erh 		SCARG(&bsa, msqid) = SCARG(uap, a1);
    125  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a2);
    126  1.14       erh 		SCARG(&bsa, buf) = (struct linux_msqid_ds *)SCARG(uap, ptr);
    127  1.14       erh 
    128  1.23   thorpej 		return linux_sys_msgctl(l, &bsa, retval);
    129  1.14       erh 	    }
    130   1.1      fvdl #endif
    131   1.1      fvdl #ifdef SYSVSHM
    132  1.14       erh 	case LINUX_SYS_shmat: {
    133  1.14       erh 		struct linux_sys_shmat_args bsa;
    134  1.25     perry 
    135  1.14       erh 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    136  1.14       erh 		SCARG(&bsa, shmaddr) = (void *)SCARG(uap, ptr);
    137  1.14       erh 		SCARG(&bsa, shmflg) = SCARG(uap, a2);
    138  1.14       erh 		/* XXX passing pointer inside int here */
    139  1.14       erh 		SCARG(&bsa, raddr) = (u_long *)SCARG(uap, a3);
    140  1.14       erh 
    141  1.23   thorpej 		return linux_sys_shmat(l, &bsa, retval);
    142  1.14       erh 	    }
    143   1.6      fvdl 	case LINUX_SYS_shmdt:
    144  1.23   thorpej 		return linux_shmdt(l, uap, retval);
    145   1.6      fvdl 	case LINUX_SYS_shmget:
    146  1.23   thorpej 		return linux_shmget(l, uap, retval);
    147  1.14       erh 	case LINUX_SYS_shmctl: {
    148  1.14       erh 		struct linux_sys_shmctl_args bsa;
    149  1.14       erh 
    150  1.14       erh 		SCARG(&bsa, shmid) = SCARG(uap, a1);
    151  1.14       erh 		SCARG(&bsa, cmd) = SCARG(uap, a2);
    152  1.14       erh 		SCARG(&bsa, buf) = (struct linux_shmid_ds *)SCARG(uap, ptr);
    153  1.14       erh 
    154  1.23   thorpej 		return linux_sys_shmctl(l, &bsa, retval);
    155  1.14       erh 	    }
    156   1.1      fvdl #endif
    157   1.6      fvdl 	default:
    158   1.6      fvdl 		return ENOSYS;
    159   1.1      fvdl 	}
    160   1.1      fvdl }
    161   1.1      fvdl 
    162   1.1      fvdl #ifdef SYSVSEM
    163  1.14       erh inline int
    164  1.30       dsl linux_semop(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    165  1.30       dsl {
    166  1.30       dsl 	/* {
    167   1.1      fvdl 		syscallarg(int) what;
    168   1.1      fvdl 		syscallarg(int) a1;
    169   1.1      fvdl 		syscallarg(int) a2;
    170   1.1      fvdl 		syscallarg(int) a3;
    171  1.28  christos 		syscallarg(void *) ptr;
    172  1.30       dsl 	} */
    173   1.8   mycroft 	struct sys_semop_args bsa;
    174   1.6      fvdl 
    175   1.6      fvdl 	SCARG(&bsa, semid) = SCARG(uap, a1);
    176   1.6      fvdl 	SCARG(&bsa, sops) = (struct sembuf *)SCARG(uap, ptr);
    177   1.6      fvdl 	SCARG(&bsa, nsops) = SCARG(uap, a2);
    178   1.6      fvdl 
    179  1.23   thorpej 	return sys_semop(l, &bsa, retval);
    180   1.1      fvdl }
    181   1.1      fvdl 
    182  1.14       erh inline int
    183  1.30       dsl linux_semget(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    184  1.30       dsl {
    185  1.30       dsl 	/* {
    186   1.1      fvdl 		syscallarg(int) what;
    187   1.1      fvdl 		syscallarg(int) a1;
    188   1.1      fvdl 		syscallarg(int) a2;
    189   1.1      fvdl 		syscallarg(int) a3;
    190  1.28  christos 		syscallarg(void *) ptr;
    191  1.30       dsl 	} */
    192   1.8   mycroft 	struct sys_semget_args bsa;
    193   1.6      fvdl 
    194   1.6      fvdl 	SCARG(&bsa, key) = (key_t)SCARG(uap, a1);
    195   1.6      fvdl 	SCARG(&bsa, nsems) = SCARG(uap, a2);
    196   1.6      fvdl 	SCARG(&bsa, semflg) = SCARG(uap, a3);
    197   1.6      fvdl 
    198  1.23   thorpej 	return sys_semget(l, &bsa, retval);
    199   1.1      fvdl }
    200   1.1      fvdl 
    201   1.1      fvdl #endif /* SYSVSEM */
    202   1.1      fvdl 
    203   1.1      fvdl #ifdef SYSVMSG
    204   1.6      fvdl 
    205  1.14       erh inline int
    206  1.30       dsl linux_msgsnd(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    207   1.1      fvdl {
    208   1.8   mycroft 	struct sys_msgsnd_args bma;
    209   1.6      fvdl 
    210   1.6      fvdl 	SCARG(&bma, msqid) = SCARG(uap, a1);
    211   1.6      fvdl 	SCARG(&bma, msgp) = SCARG(uap, ptr);
    212   1.6      fvdl 	SCARG(&bma, msgsz) = SCARG(uap, a2);
    213   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a3);
    214   1.6      fvdl 
    215  1.23   thorpej 	return sys_msgsnd(l, &bma, retval);
    216   1.1      fvdl }
    217   1.1      fvdl 
    218  1.14       erh inline int
    219  1.30       dsl linux_msgrcv(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    220   1.1      fvdl {
    221   1.8   mycroft 	struct sys_msgrcv_args bma;
    222   1.6      fvdl 	struct linux_msgrcv_msgarg kluge;
    223   1.6      fvdl 	int error;
    224   1.6      fvdl 
    225   1.6      fvdl 	if ((error = copyin(SCARG(uap, ptr), &kluge, sizeof kluge)))
    226   1.6      fvdl 		return error;
    227   1.6      fvdl 
    228   1.6      fvdl 	SCARG(&bma, msqid) = SCARG(uap, a1);
    229   1.6      fvdl 	SCARG(&bma, msgp) = kluge.msg;
    230   1.6      fvdl 	SCARG(&bma, msgsz) = SCARG(uap, a2);
    231   1.6      fvdl 	SCARG(&bma, msgtyp) = kluge.type;
    232   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a3);
    233   1.8   mycroft 
    234  1.23   thorpej 	return sys_msgrcv(l, &bma, retval);
    235   1.1      fvdl }
    236   1.1      fvdl 
    237  1.14       erh inline int
    238  1.30       dsl linux_msgget(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    239   1.1      fvdl {
    240   1.8   mycroft 	struct sys_msgget_args bma;
    241   1.6      fvdl 
    242   1.6      fvdl 	SCARG(&bma, key) = (key_t)SCARG(uap, a1);
    243   1.6      fvdl 	SCARG(&bma, msgflg) = SCARG(uap, a2);
    244   1.8   mycroft 
    245  1.23   thorpej 	return sys_msgget(l, &bma, retval);
    246   1.1      fvdl }
    247   1.1      fvdl 
    248   1.1      fvdl #endif /* SYSVMSG */
    249   1.1      fvdl 
    250   1.1      fvdl #ifdef SYSVSHM
    251   1.1      fvdl /*
    252   1.1      fvdl  * shmdt(): this could have been mapped directly, if it wasn't for
    253   1.1      fvdl  * the extra indirection by the linux_ipc system call.
    254   1.1      fvdl  */
    255  1.14       erh inline int
    256  1.30       dsl linux_shmdt(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    257   1.1      fvdl {
    258   1.8   mycroft 	struct sys_shmdt_args bsa;
    259   1.1      fvdl 
    260   1.1      fvdl 	SCARG(&bsa, shmaddr) = SCARG(uap, ptr);
    261   1.8   mycroft 
    262  1.23   thorpej 	return sys_shmdt(l, &bsa, retval);
    263   1.1      fvdl }
    264   1.1      fvdl 
    265   1.1      fvdl /*
    266   1.1      fvdl  * Same story as shmdt.
    267   1.1      fvdl  */
    268  1.14       erh inline int
    269  1.30       dsl linux_shmget(struct lwp *l, const struct linux_sys_ipc_args *uap, register_t *retval)
    270   1.1      fvdl {
    271  1.30       dsl 	struct linux_sys_shmget_args bsa;
    272   1.1      fvdl 
    273   1.1      fvdl 	SCARG(&bsa, key) = SCARG(uap, a1);
    274   1.1      fvdl 	SCARG(&bsa, size) = SCARG(uap, a2);
    275   1.1      fvdl 	SCARG(&bsa, shmflg) = SCARG(uap, a3);
    276   1.8   mycroft 
    277  1.24  jdolecek 	return linux_sys_shmget(l, &bsa, retval);
    278   1.1      fvdl }
    279   1.1      fvdl 
    280   1.1      fvdl #endif /* SYSVSHM */
    281