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