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