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