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