Home | History | Annotate | Line # | Download | only in common
kern_ipc_10.c revision 1.17.16.3
      1 /*	$NetBSD: kern_ipc_10.c,v 1.17.16.3 2007/09/03 14:31:51 yamt 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.17.16.3 2007/09/03 14:31:51 yamt Exp $");
     35 
     36 #include "opt_sysv.h"
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/kernel.h>
     41 #include <sys/proc.h>
     42 #include <sys/sem.h>
     43 
     44 #include <sys/mount.h>
     45 #include <sys/syscallargs.h>
     46 
     47 #include <compat/common/compat_util.h>
     48 #include <compat/sys/shm.h>
     49 #include <compat/sys/sem.h>
     50 
     51 #if defined(SYSVSEM) && !defined(_LP64)
     52 int
     53 compat_10_sys_semsys(l, v, retval)
     54 	struct lwp *l;
     55 	void *v;
     56 	register_t *retval;
     57 {
     58 	struct compat_10_sys_semsys_args /* {
     59 		syscallarg(int) which;
     60 		syscallarg(int) a2;
     61 		syscallarg(int) a3;
     62 		syscallarg(int) a4;
     63 		syscallarg(int) a5;
     64 	} */ *uap = v;
     65 	struct sys_semget_args /* {
     66 		syscallarg(key_t) key;
     67 		syscallarg(int) nsems;
     68 		syscallarg(int) semflg;
     69 	} */ semget_args;
     70 	struct sys_semop_args /* {
     71 		syscallarg(int) semid;
     72 		syscallarg(struct sembuf *) sops;
     73 		syscallarg(u_int) nsops;
     74 	} */ semop_args;
     75 	struct sys_semconfig_args /* {
     76 		syscallarg(int) flag;
     77 	} */ semconfig_args;
     78 	struct semid_ds sembuf;
     79 	struct semid_ds14 osembuf;
     80 	void *pass_arg;
     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 *)&SCARG(uap, 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(l, v, retval)
    134 	struct lwp *l;
    135 	void *v;
    136 	register_t *retval;
    137 {
    138 	struct compat_10_sys_shmsys_args /* {
    139 		syscallarg(int) which;
    140 		syscallarg(int) a2;
    141 		syscallarg(int) a3;
    142 		syscallarg(int) a4;
    143 	} */ *uap = v;
    144 	struct sys_shmat_args /* {
    145 		syscallarg(int) shmid;
    146 		syscallarg(void *) shmaddr;
    147 		syscallarg(int) shmflg;
    148 	} */ shmat_args;
    149 	struct compat_14_sys_shmctl_args /* {
    150 		syscallarg(int) shmid;
    151 		syscallarg(int) cmd;
    152 		syscallarg(struct shmid14_ds *) buf;
    153 	} */ shmctl_args;
    154 	struct sys_shmdt_args /* {
    155 		syscallarg(void *) shmaddr;
    156 	} */ shmdt_args;
    157 	struct sys_shmget_args /* {
    158 		syscallarg(key_t) key;
    159 		syscallarg(int) size;
    160 		syscallarg(int) shmflg;
    161 	} */ shmget_args;
    162 
    163 	switch (SCARG(uap, which)) {
    164 	case 0:						/* shmat() */
    165 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    166 		SCARG(&shmat_args, shmaddr) =
    167 		    (void *)(u_long)SCARG(uap, a3);
    168 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    169 		return (sys_shmat(l, &shmat_args, retval));
    170 
    171 	case 1:						/* shmctl() */
    172 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    173 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    174 		SCARG(&shmctl_args, buf) =
    175 		    (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
    176 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    177 
    178 	case 2:						/* shmdt() */
    179 		SCARG(&shmdt_args, shmaddr) =
    180 		    (void *)(u_long)SCARG(uap, a2);
    181 		return (sys_shmdt(l, &shmdt_args, retval));
    182 
    183 	case 3:						/* shmget() */
    184 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    185 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    186 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    187 		return (sys_shmget(l, &shmget_args, retval));
    188 
    189 	default:
    190 		return (EINVAL);
    191 	}
    192 }
    193 #endif
    194 
    195 #if defined(SYSVMSG) && !defined(_LP64)
    196 int
    197 compat_10_sys_msgsys(l, v, retval)
    198 	struct lwp *l;
    199 	void *v;
    200 	register_t *retval;
    201 {
    202 	struct compat_10_sys_msgsys_args /* {
    203 		syscallarg(int) which;
    204 		syscallarg(int) a2;
    205 		syscallarg(int) a3;
    206 		syscallarg(int) a4;
    207 		syscallarg(int) a5;
    208 		syscallarg(int) a6;
    209 	} */ *uap = v;
    210 	struct compat_14_sys_msgctl_args /* {
    211 		syscallarg(int) msqid;
    212 		syscallarg(int) cmd;
    213 		syscallarg(struct msqid14_ds *) buf;
    214 	} */ msgctl_args;
    215 	struct sys_msgget_args /* {
    216 		syscallarg(key_t) key;
    217 		syscallarg(int) msgflg;
    218 	} */ msgget_args;
    219 	struct sys_msgsnd_args /* {
    220 		syscallarg(int) msqid;
    221 		syscallarg(void *) msgp;
    222 		syscallarg(size_t) msgsz;
    223 		syscallarg(int) msgflg;
    224 	} */ msgsnd_args;
    225 	struct sys_msgrcv_args /* {
    226 		syscallarg(int) msqid;
    227 		syscallarg(void *) msgp;
    228 		syscallarg(size_t) msgsz;
    229 		syscallarg(long) msgtyp;
    230 		syscallarg(int) msgflg;
    231 	} */ msgrcv_args;
    232 
    233 	switch (SCARG(uap, which)) {
    234 	case 0:					/* msgctl()*/
    235 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    236 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    237 		SCARG(&msgctl_args, buf) =
    238 		    (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
    239 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    240 
    241 	case 1:					/* msgget() */
    242 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    243 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    244 		return (sys_msgget(l, &msgget_args, retval));
    245 
    246 	case 2:					/* msgsnd() */
    247 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    248 		SCARG(&msgsnd_args, msgp) =
    249 		    (void *)(u_long)SCARG(uap, a3);
    250 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    251 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    252 		return (sys_msgsnd(l, &msgsnd_args, retval));
    253 
    254 	case 3:					/* msgrcv() */
    255 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    256 		SCARG(&msgrcv_args, msgp) =
    257 		    (void *)(u_long)SCARG(uap, a3);
    258 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    259 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    260 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    261 		return (sys_msgrcv(l, &msgrcv_args, retval));
    262 
    263 	default:
    264 		return (EINVAL);
    265 	}
    266 }
    267 #endif
    268