Home | History | Annotate | Line # | Download | only in common
kern_ipc_10.c revision 1.23.8.1
      1 /*	$NetBSD: kern_ipc_10.c,v 1.23.8.1 2008/03/29 20:46:57 christos 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.8.1 2008/03/29 20:46:57 christos 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 #include <sys/shm.h>
     44 
     45 #include <sys/mount.h>
     46 #include <sys/syscallargs.h>
     47 
     48 #include <compat/common/compat_util.h>
     49 #include <compat/sys/shm.h>
     50 #include <compat/sys/sem.h>
     51 
     52 #if defined(SYSVSEM) && !defined(_LP64)
     53 int
     54 compat_10_sys_semsys(struct lwp *l, const struct compat_10_sys_semsys_args *uap, register_t *retval)
     55 {
     56 	/* {
     57 		syscallarg(int) which;
     58 		syscallarg(int) a2;
     59 		syscallarg(int) a3;
     60 		syscallarg(int) a4;
     61 		syscallarg(int) a5;
     62 	} */
     63 	struct sys_semget_args /* {
     64 		syscallarg(key_t) key;
     65 		syscallarg(int) nsems;
     66 		syscallarg(int) semflg;
     67 	} */ semget_args;
     68 	struct sys_semop_args /* {
     69 		syscallarg(int) semid;
     70 		syscallarg(struct sembuf *) sops;
     71 		syscallarg(u_int) nsops;
     72 	} */ semop_args;
     73 	struct sys_semconfig_args /* {
     74 		syscallarg(int) flag;
     75 	} */ semconfig_args;
     76 	struct semid_ds sembuf;
     77 	struct semid_ds14 osembuf;
     78 	void *pass_arg;
     79 	int a5 = SCARG(uap, a5);
     80 	int error;
     81 
     82 	switch (SCARG(uap, which)) {
     83 	case 0:						/* __semctl() */
     84 #define	semctl_semid	SCARG(uap, a2)
     85 #define	semctl_semnum	SCARG(uap, a3)
     86 #define	semctl_cmd	SCARG(uap, a4)
     87 #define	semctl_arg	((union __semun *)&a5)
     88 		pass_arg = get_semctl_arg(semctl_cmd, &sembuf, semctl_arg);
     89 		if (semctl_cmd == IPC_SET) {
     90 			error = copyin(semctl_arg->buf, &osembuf, sizeof osembuf);
     91 			if (error != 0)
     92 				return error;
     93 			semid_ds14_to_native(&osembuf, &sembuf);
     94 		}
     95 		error = semctl1(l, semctl_semid, semctl_semnum, semctl_cmd,
     96 		    pass_arg, retval);
     97 		if (error == 0 && semctl_cmd == IPC_STAT) {
     98 			native_to_semid_ds14(&sembuf, &osembuf);
     99 			error = copyout(&osembuf, semctl_arg->buf, sizeof(osembuf));
    100 		}
    101 		return error;
    102 #undef	semctl_semid
    103 #undef	semctl_semnum
    104 #undef	semctl_cmd
    105 #undef	semctl_arg
    106 
    107 	case 1:						/* semget() */
    108 		SCARG(&semget_args, key) = SCARG(uap, a2);
    109 		SCARG(&semget_args, nsems) = SCARG(uap, a3);
    110 		SCARG(&semget_args, semflg) = SCARG(uap, a4);
    111 		return (sys_semget(l, &semget_args, retval));
    112 
    113 	case 2:						/* semop() */
    114 		SCARG(&semop_args, semid) = SCARG(uap, a2);
    115 		SCARG(&semop_args, sops) =
    116 		    (struct sembuf *)(u_long)SCARG(uap, a3);
    117 		SCARG(&semop_args, nsops) = SCARG(uap, a4);
    118 		return (sys_semop(l, &semop_args, retval));
    119 
    120 	case 3:						/* semconfig() */
    121 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
    122 		return (sys_semconfig(l, &semconfig_args, retval));
    123 
    124 	default:
    125 		return (EINVAL);
    126 	}
    127 }
    128 #endif
    129 
    130 #if defined(SYSVSHM) && !defined(_LP64)
    131 int
    132 compat_10_sys_shmsys(struct lwp *l, const struct compat_10_sys_shmsys_args *uap, register_t *retval)
    133 {
    134 	/* {
    135 		syscallarg(int) which;
    136 		syscallarg(int) a2;
    137 		syscallarg(int) a3;
    138 		syscallarg(int) a4;
    139 	} */
    140 	struct sys_shmat_args /* {
    141 		syscallarg(int) shmid;
    142 		syscallarg(void *) shmaddr;
    143 		syscallarg(int) shmflg;
    144 	} */ shmat_args;
    145 	struct compat_14_sys_shmctl_args /* {
    146 		syscallarg(int) shmid;
    147 		syscallarg(int) cmd;
    148 		syscallarg(struct shmid14_ds *) buf;
    149 	} */ shmctl_args;
    150 	struct sys_shmdt_args /* {
    151 		syscallarg(void *) shmaddr;
    152 	} */ shmdt_args;
    153 	struct sys_shmget_args /* {
    154 		syscallarg(key_t) key;
    155 		syscallarg(int) size;
    156 		syscallarg(int) shmflg;
    157 	} */ shmget_args;
    158 
    159 	switch (SCARG(uap, which)) {
    160 	case 0:						/* shmat() */
    161 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    162 		SCARG(&shmat_args, shmaddr) =
    163 		    (void *)(u_long)SCARG(uap, a3);
    164 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    165 		return (sys_shmat(l, &shmat_args, retval));
    166 
    167 	case 1:						/* shmctl() */
    168 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    169 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    170 		SCARG(&shmctl_args, buf) =
    171 		    (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
    172 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    173 
    174 	case 2:						/* shmdt() */
    175 		SCARG(&shmdt_args, shmaddr) =
    176 		    (void *)(u_long)SCARG(uap, a2);
    177 		return (sys_shmdt(l, &shmdt_args, retval));
    178 
    179 	case 3:						/* shmget() */
    180 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    181 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    182 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    183 		return (sys_shmget(l, &shmget_args, retval));
    184 
    185 	default:
    186 		return (EINVAL);
    187 	}
    188 }
    189 #endif
    190 
    191 #if defined(SYSVMSG) && !defined(_LP64)
    192 int
    193 compat_10_sys_msgsys(struct lwp *l, const struct compat_10_sys_msgsys_args *uap, register_t *retval)
    194 {
    195 	/* {
    196 		syscallarg(int) which;
    197 		syscallarg(int) a2;
    198 		syscallarg(int) a3;
    199 		syscallarg(int) a4;
    200 		syscallarg(int) a5;
    201 		syscallarg(int) a6;
    202 	} */
    203 	struct compat_14_sys_msgctl_args /* {
    204 		syscallarg(int) msqid;
    205 		syscallarg(int) cmd;
    206 		syscallarg(struct msqid14_ds *) buf;
    207 	} */ msgctl_args;
    208 	struct sys_msgget_args /* {
    209 		syscallarg(key_t) key;
    210 		syscallarg(int) msgflg;
    211 	} */ msgget_args;
    212 	struct sys_msgsnd_args /* {
    213 		syscallarg(int) msqid;
    214 		syscallarg(void *) msgp;
    215 		syscallarg(size_t) msgsz;
    216 		syscallarg(int) msgflg;
    217 	} */ msgsnd_args;
    218 	struct sys_msgrcv_args /* {
    219 		syscallarg(int) msqid;
    220 		syscallarg(void *) msgp;
    221 		syscallarg(size_t) msgsz;
    222 		syscallarg(long) msgtyp;
    223 		syscallarg(int) msgflg;
    224 	} */ msgrcv_args;
    225 
    226 	switch (SCARG(uap, which)) {
    227 	case 0:					/* msgctl()*/
    228 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    229 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    230 		SCARG(&msgctl_args, buf) =
    231 		    (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
    232 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    233 
    234 	case 1:					/* msgget() */
    235 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    236 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    237 		return (sys_msgget(l, &msgget_args, retval));
    238 
    239 	case 2:					/* msgsnd() */
    240 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    241 		SCARG(&msgsnd_args, msgp) =
    242 		    (void *)(u_long)SCARG(uap, a3);
    243 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    244 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    245 		return (sys_msgsnd(l, &msgsnd_args, retval));
    246 
    247 	case 3:					/* msgrcv() */
    248 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    249 		SCARG(&msgrcv_args, msgp) =
    250 		    (void *)(u_long)SCARG(uap, a3);
    251 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    252 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    253 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    254 		return (sys_msgrcv(l, &msgrcv_args, retval));
    255 
    256 	default:
    257 		return (EINVAL);
    258 	}
    259 }
    260 #endif
    261