Home | History | Annotate | Line # | Download | only in common
kern_ipc_10.c revision 1.17.16.4
      1  1.17.16.4      yamt /*	$NetBSD: kern_ipc_10.c,v 1.17.16.4 2008/01/21 09:40:43 yamt Exp $	*/
      2        1.1  christos 
      3        1.1  christos /*
      4        1.7   mycroft  * Copyright (c) 1994 Adam Glass and Charles M. Hannum.  All rights reserved.
      5        1.1  christos  *
      6        1.1  christos  * Redistribution and use in source and binary forms, with or without
      7        1.1  christos  * modification, are permitted provided that the following conditions
      8        1.1  christos  * are met:
      9        1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10        1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11        1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13        1.1  christos  *    documentation and/or other materials provided with the distribution.
     14        1.1  christos  * 3. All advertising materials mentioning features or use of this software
     15        1.1  christos  *    must display the following acknowledgement:
     16        1.7   mycroft  *	This product includes software developed by Adam Glass and Charles M.
     17        1.1  christos  *	Hannum.
     18        1.1  christos  * 4. The names of the authors may not be used to endorse or promote products
     19        1.1  christos  *    derived from this software without specific prior written permission.
     20        1.1  christos  *
     21        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
     22        1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23        1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24        1.1  christos  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     25        1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26        1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27        1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28        1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29        1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30        1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31        1.1  christos  */
     32       1.13     lukem 
     33       1.13     lukem #include <sys/cdefs.h>
     34  1.17.16.4      yamt __KERNEL_RCSID(0, "$NetBSD: kern_ipc_10.c,v 1.17.16.4 2008/01/21 09:40:43 yamt Exp $");
     35        1.8      tron 
     36        1.8      tron #include "opt_sysv.h"
     37        1.1  christos 
     38        1.1  christos #include <sys/param.h>
     39        1.1  christos #include <sys/systm.h>
     40        1.1  christos #include <sys/kernel.h>
     41        1.1  christos #include <sys/proc.h>
     42        1.1  christos #include <sys/sem.h>
     43        1.1  christos 
     44        1.1  christos #include <sys/mount.h>
     45        1.1  christos #include <sys/syscallargs.h>
     46        1.1  christos 
     47        1.6    scottb #include <compat/common/compat_util.h>
     48  1.17.16.1      yamt #include <compat/sys/shm.h>
     49  1.17.16.3      yamt #include <compat/sys/sem.h>
     50        1.1  christos 
     51       1.15       scw #if defined(SYSVSEM) && !defined(_LP64)
     52        1.1  christos int
     53  1.17.16.4      yamt compat_10_sys_semsys(struct lwp *l, const struct compat_10_sys_semsys_args *uap, register_t *retval)
     54        1.3   thorpej {
     55  1.17.16.4      yamt 	/* {
     56        1.1  christos 		syscallarg(int) which;
     57        1.1  christos 		syscallarg(int) a2;
     58        1.1  christos 		syscallarg(int) a3;
     59        1.1  christos 		syscallarg(int) a4;
     60        1.1  christos 		syscallarg(int) a5;
     61  1.17.16.4      yamt 	} */
     62        1.4   mycroft 	struct sys_semget_args /* {
     63        1.1  christos 		syscallarg(key_t) key;
     64        1.1  christos 		syscallarg(int) nsems;
     65        1.1  christos 		syscallarg(int) semflg;
     66        1.1  christos 	} */ semget_args;
     67        1.4   mycroft 	struct sys_semop_args /* {
     68        1.1  christos 		syscallarg(int) semid;
     69        1.1  christos 		syscallarg(struct sembuf *) sops;
     70        1.1  christos 		syscallarg(u_int) nsops;
     71        1.1  christos 	} */ semop_args;
     72        1.4   mycroft 	struct sys_semconfig_args /* {
     73        1.1  christos 		syscallarg(int) flag;
     74        1.1  christos 	} */ semconfig_args;
     75  1.17.16.3      yamt 	struct semid_ds sembuf;
     76  1.17.16.3      yamt 	struct semid_ds14 osembuf;
     77  1.17.16.3      yamt 	void *pass_arg;
     78  1.17.16.4      yamt 	int a5 = SCARG(uap, a5);
     79  1.17.16.3      yamt 	int error;
     80        1.1  christos 
     81        1.1  christos 	switch (SCARG(uap, which)) {
     82        1.1  christos 	case 0:						/* __semctl() */
     83  1.17.16.3      yamt #define	semctl_semid	SCARG(uap, a2)
     84  1.17.16.3      yamt #define	semctl_semnum	SCARG(uap, a3)
     85  1.17.16.3      yamt #define	semctl_cmd	SCARG(uap, a4)
     86  1.17.16.4      yamt #define	semctl_arg	((union __semun *)&a5)
     87  1.17.16.3      yamt 		pass_arg = get_semctl_arg(semctl_cmd, &sembuf, semctl_arg);
     88  1.17.16.3      yamt 		if (semctl_cmd == IPC_SET) {
     89  1.17.16.3      yamt 			error = copyin(semctl_arg->buf, &osembuf, sizeof osembuf);
     90  1.17.16.3      yamt 			if (error != 0)
     91  1.17.16.3      yamt 				return error;
     92  1.17.16.3      yamt 			semid_ds14_to_native(&osembuf, &sembuf);
     93  1.17.16.3      yamt 		}
     94  1.17.16.3      yamt 		error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
     95  1.17.16.3      yamt 		    pass_arg, retval);
     96  1.17.16.3      yamt 		if (error == 0 && semctl_cmd == IPC_STAT) {
     97  1.17.16.3      yamt 			native_to_semid_ds14(&sembuf, &osembuf);
     98  1.17.16.3      yamt 			error = copyout(&osembuf, semctl_arg->buf, sizeof(osembuf));
     99  1.17.16.3      yamt 		}
    100  1.17.16.3      yamt 		return error;
    101  1.17.16.3      yamt #undef	semctl_semid
    102  1.17.16.3      yamt #undef	semctl_semnum
    103  1.17.16.3      yamt #undef	semctl_cmd
    104  1.17.16.3      yamt #undef	semctl_arg
    105        1.1  christos 
    106        1.1  christos 	case 1:						/* semget() */
    107        1.1  christos 		SCARG(&semget_args, key) = SCARG(uap, a2);
    108        1.1  christos 		SCARG(&semget_args, nsems) = SCARG(uap, a3);
    109        1.1  christos 		SCARG(&semget_args, semflg) = SCARG(uap, a4);
    110       1.16   thorpej 		return (sys_semget(l, &semget_args, retval));
    111        1.1  christos 
    112        1.1  christos 	case 2:						/* semop() */
    113        1.1  christos 		SCARG(&semop_args, semid) = SCARG(uap, a2);
    114       1.12       mrg 		SCARG(&semop_args, sops) =
    115       1.12       mrg 		    (struct sembuf *)(u_long)SCARG(uap, a3);
    116        1.1  christos 		SCARG(&semop_args, nsops) = SCARG(uap, a4);
    117       1.16   thorpej 		return (sys_semop(l, &semop_args, retval));
    118        1.1  christos 
    119        1.1  christos 	case 3:						/* semconfig() */
    120        1.1  christos 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
    121       1.16   thorpej 		return (sys_semconfig(l, &semconfig_args, retval));
    122        1.1  christos 
    123        1.1  christos 	default:
    124        1.1  christos 		return (EINVAL);
    125        1.1  christos 	}
    126        1.1  christos }
    127        1.2   mycroft #endif
    128        1.1  christos 
    129       1.15       scw #if defined(SYSVSHM) && !defined(_LP64)
    130        1.1  christos int
    131  1.17.16.4      yamt compat_10_sys_shmsys(struct lwp *l, const struct compat_10_sys_shmsys_args *uap, register_t *retval)
    132        1.3   thorpej {
    133  1.17.16.4      yamt 	/* {
    134        1.1  christos 		syscallarg(int) which;
    135        1.1  christos 		syscallarg(int) a2;
    136        1.1  christos 		syscallarg(int) a3;
    137        1.1  christos 		syscallarg(int) a4;
    138  1.17.16.4      yamt 	} */
    139        1.4   mycroft 	struct sys_shmat_args /* {
    140        1.1  christos 		syscallarg(int) shmid;
    141        1.1  christos 		syscallarg(void *) shmaddr;
    142        1.1  christos 		syscallarg(int) shmflg;
    143        1.1  christos 	} */ shmat_args;
    144        1.9   thorpej 	struct compat_14_sys_shmctl_args /* {
    145        1.1  christos 		syscallarg(int) shmid;
    146        1.1  christos 		syscallarg(int) cmd;
    147        1.9   thorpej 		syscallarg(struct shmid14_ds *) buf;
    148        1.1  christos 	} */ shmctl_args;
    149        1.4   mycroft 	struct sys_shmdt_args /* {
    150        1.1  christos 		syscallarg(void *) shmaddr;
    151        1.1  christos 	} */ shmdt_args;
    152        1.4   mycroft 	struct sys_shmget_args /* {
    153        1.1  christos 		syscallarg(key_t) key;
    154        1.1  christos 		syscallarg(int) size;
    155        1.1  christos 		syscallarg(int) shmflg;
    156        1.1  christos 	} */ shmget_args;
    157        1.1  christos 
    158        1.1  christos 	switch (SCARG(uap, which)) {
    159        1.1  christos 	case 0:						/* shmat() */
    160        1.1  christos 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    161       1.12       mrg 		SCARG(&shmat_args, shmaddr) =
    162       1.12       mrg 		    (void *)(u_long)SCARG(uap, a3);
    163        1.1  christos 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    164       1.16   thorpej 		return (sys_shmat(l, &shmat_args, retval));
    165        1.1  christos 
    166        1.1  christos 	case 1:						/* shmctl() */
    167        1.1  christos 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    168        1.1  christos 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    169       1.12       mrg 		SCARG(&shmctl_args, buf) =
    170       1.12       mrg 		    (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
    171       1.16   thorpej 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    172        1.1  christos 
    173        1.1  christos 	case 2:						/* shmdt() */
    174       1.12       mrg 		SCARG(&shmdt_args, shmaddr) =
    175       1.12       mrg 		    (void *)(u_long)SCARG(uap, a2);
    176       1.16   thorpej 		return (sys_shmdt(l, &shmdt_args, retval));
    177        1.1  christos 
    178        1.1  christos 	case 3:						/* shmget() */
    179        1.1  christos 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    180        1.1  christos 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    181        1.1  christos 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    182       1.16   thorpej 		return (sys_shmget(l, &shmget_args, retval));
    183        1.1  christos 
    184        1.1  christos 	default:
    185        1.1  christos 		return (EINVAL);
    186        1.1  christos 	}
    187        1.1  christos }
    188        1.2   mycroft #endif
    189        1.1  christos 
    190       1.15       scw #if defined(SYSVMSG) && !defined(_LP64)
    191        1.1  christos int
    192  1.17.16.4      yamt compat_10_sys_msgsys(struct lwp *l, const struct compat_10_sys_msgsys_args *uap, register_t *retval)
    193        1.3   thorpej {
    194  1.17.16.4      yamt 	/* {
    195        1.1  christos 		syscallarg(int) which;
    196        1.1  christos 		syscallarg(int) a2;
    197        1.1  christos 		syscallarg(int) a3;
    198        1.1  christos 		syscallarg(int) a4;
    199        1.1  christos 		syscallarg(int) a5;
    200        1.1  christos 		syscallarg(int) a6;
    201  1.17.16.4      yamt 	} */
    202        1.9   thorpej 	struct compat_14_sys_msgctl_args /* {
    203        1.1  christos 		syscallarg(int) msqid;
    204        1.1  christos 		syscallarg(int) cmd;
    205        1.9   thorpej 		syscallarg(struct msqid14_ds *) buf;
    206        1.1  christos 	} */ msgctl_args;
    207        1.4   mycroft 	struct sys_msgget_args /* {
    208        1.1  christos 		syscallarg(key_t) key;
    209        1.1  christos 		syscallarg(int) msgflg;
    210        1.1  christos 	} */ msgget_args;
    211        1.4   mycroft 	struct sys_msgsnd_args /* {
    212        1.1  christos 		syscallarg(int) msqid;
    213        1.1  christos 		syscallarg(void *) msgp;
    214        1.1  christos 		syscallarg(size_t) msgsz;
    215        1.1  christos 		syscallarg(int) msgflg;
    216        1.1  christos 	} */ msgsnd_args;
    217        1.4   mycroft 	struct sys_msgrcv_args /* {
    218        1.1  christos 		syscallarg(int) msqid;
    219        1.1  christos 		syscallarg(void *) msgp;
    220        1.1  christos 		syscallarg(size_t) msgsz;
    221        1.1  christos 		syscallarg(long) msgtyp;
    222        1.1  christos 		syscallarg(int) msgflg;
    223        1.1  christos 	} */ msgrcv_args;
    224        1.1  christos 
    225        1.1  christos 	switch (SCARG(uap, which)) {
    226        1.1  christos 	case 0:					/* msgctl()*/
    227        1.1  christos 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    228        1.1  christos 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    229        1.1  christos 		SCARG(&msgctl_args, buf) =
    230       1.12       mrg 		    (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
    231       1.16   thorpej 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    232        1.1  christos 
    233        1.1  christos 	case 1:					/* msgget() */
    234        1.1  christos 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    235        1.1  christos 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    236       1.16   thorpej 		return (sys_msgget(l, &msgget_args, retval));
    237        1.1  christos 
    238        1.1  christos 	case 2:					/* msgsnd() */
    239        1.1  christos 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    240       1.12       mrg 		SCARG(&msgsnd_args, msgp) =
    241       1.12       mrg 		    (void *)(u_long)SCARG(uap, a3);
    242        1.1  christos 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    243        1.1  christos 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    244       1.16   thorpej 		return (sys_msgsnd(l, &msgsnd_args, retval));
    245        1.1  christos 
    246        1.1  christos 	case 3:					/* msgrcv() */
    247        1.1  christos 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    248       1.12       mrg 		SCARG(&msgrcv_args, msgp) =
    249       1.12       mrg 		    (void *)(u_long)SCARG(uap, a3);
    250        1.1  christos 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    251        1.1  christos 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    252        1.1  christos 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    253       1.16   thorpej 		return (sys_msgrcv(l, &msgrcv_args, retval));
    254        1.1  christos 
    255        1.1  christos 	default:
    256        1.1  christos 		return (EINVAL);
    257        1.1  christos 	}
    258        1.1  christos }
    259        1.2   mycroft #endif
    260