Home | History | Annotate | Line # | Download | only in common
kern_ipc_10.c revision 1.12.2.1
      1 /*	$NetBSD: kern_ipc_10.c,v 1.12.2.1 2001/03/05 22:49:19 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 "opt_sysv.h"
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/lwp.h>
     39 #include <sys/proc.h>
     40 #include <sys/sem.h>
     41 #include <sys/malloc.h>
     42 
     43 #include <sys/mount.h>
     44 #include <sys/syscallargs.h>
     45 
     46 #include <compat/common/compat_util.h>
     47 
     48 #ifdef SYSVSEM
     49 int
     50 compat_10_sys_semsys(l, v, retval)
     51 	struct lwp *l;
     52 	void *v;
     53 	register_t *retval;
     54 {
     55 	struct compat_10_sys_semsys_args /* {
     56 		syscallarg(int) which;
     57 		syscallarg(int) a2;
     58 		syscallarg(int) a3;
     59 		syscallarg(int) a4;
     60 		syscallarg(int) a5;
     61 	} */ *uap = v;
     62 	struct compat_14_sys___semctl_args /* {
     63 		syscallarg(int) semid;
     64 		syscallarg(int) semnum;
     65 		syscallarg(int) cmd;
     66 		syscallarg(union __semun *) arg;
     67 	} */ __semctl_args;
     68 	struct sys_semget_args /* {
     69 		syscallarg(key_t) key;
     70 		syscallarg(int) nsems;
     71 		syscallarg(int) semflg;
     72 	} */ semget_args;
     73 	struct sys_semop_args /* {
     74 		syscallarg(int) semid;
     75 		syscallarg(struct sembuf *) sops;
     76 		syscallarg(u_int) nsops;
     77 	} */ semop_args;
     78 	struct sys_semconfig_args /* {
     79 		syscallarg(int) flag;
     80 	} */ semconfig_args;
     81 	struct proc *p = l->l_proc;
     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(l, &__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(l, &semget_args, retval));
    100 
    101 	case 2:						/* semop() */
    102 		SCARG(&semop_args, semid) = SCARG(uap, a2);
    103 		SCARG(&semop_args, sops) =
    104 		    (struct sembuf *)(u_long)SCARG(uap, a3);
    105 		SCARG(&semop_args, nsops) = SCARG(uap, a4);
    106 		return (sys_semop(l, &semop_args, retval));
    107 
    108 	case 3:						/* semconfig() */
    109 		SCARG(&semconfig_args, flag) = SCARG(uap, a2);
    110 		return (sys_semconfig(l, &semconfig_args, retval));
    111 
    112 	default:
    113 		return (EINVAL);
    114 	}
    115 }
    116 #endif
    117 
    118 #ifdef SYSVSHM
    119 int
    120 compat_10_sys_shmsys(l, v, retval)
    121 	struct lwp *l;
    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 compat_14_sys_shmctl_args /* {
    137 		syscallarg(int) shmid;
    138 		syscallarg(int) cmd;
    139 		syscallarg(struct shmid14_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) =
    154 		    (void *)(u_long)SCARG(uap, a3);
    155 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    156 		return (sys_shmat(l, &shmat_args, retval));
    157 
    158 	case 1:						/* shmctl() */
    159 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    160 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    161 		SCARG(&shmctl_args, buf) =
    162 		    (struct shmid_ds14 *)(u_long)SCARG(uap, a4);
    163 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    164 
    165 	case 2:						/* shmdt() */
    166 		SCARG(&shmdt_args, shmaddr) =
    167 		    (void *)(u_long)SCARG(uap, a2);
    168 		return (sys_shmdt(l, &shmdt_args, retval));
    169 
    170 	case 3:						/* shmget() */
    171 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    172 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    173 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4);
    174 		return (sys_shmget(l, &shmget_args, retval));
    175 
    176 	default:
    177 		return (EINVAL);
    178 	}
    179 }
    180 #endif
    181 
    182 #ifdef SYSVMSG
    183 int
    184 compat_10_sys_msgsys(l, v, retval)
    185 	struct lwp *l;
    186 	void *v;
    187 	register_t *retval;
    188 {
    189 	struct compat_10_sys_msgsys_args /* {
    190 		syscallarg(int) which;
    191 		syscallarg(int) a2;
    192 		syscallarg(int) a3;
    193 		syscallarg(int) a4;
    194 		syscallarg(int) a5;
    195 		syscallarg(int) a6;
    196 	} */ *uap = v;
    197 	struct compat_14_sys_msgctl_args /* {
    198 		syscallarg(int) msqid;
    199 		syscallarg(int) cmd;
    200 		syscallarg(struct msqid14_ds *) buf;
    201 	} */ msgctl_args;
    202 	struct sys_msgget_args /* {
    203 		syscallarg(key_t) key;
    204 		syscallarg(int) msgflg;
    205 	} */ msgget_args;
    206 	struct sys_msgsnd_args /* {
    207 		syscallarg(int) msqid;
    208 		syscallarg(void *) msgp;
    209 		syscallarg(size_t) msgsz;
    210 		syscallarg(int) msgflg;
    211 	} */ msgsnd_args;
    212 	struct sys_msgrcv_args /* {
    213 		syscallarg(int) msqid;
    214 		syscallarg(void *) msgp;
    215 		syscallarg(size_t) msgsz;
    216 		syscallarg(long) msgtyp;
    217 		syscallarg(int) msgflg;
    218 	} */ msgrcv_args;
    219 
    220 	switch (SCARG(uap, which)) {
    221 	case 0:					/* msgctl()*/
    222 		SCARG(&msgctl_args, msqid) = SCARG(uap, a2);
    223 		SCARG(&msgctl_args, cmd) = SCARG(uap, a3);
    224 		SCARG(&msgctl_args, buf) =
    225 		    (struct msqid_ds14 *)(u_long)SCARG(uap, a4);
    226 		return (compat_14_sys_msgctl(l, &msgctl_args, retval));
    227 
    228 	case 1:					/* msgget() */
    229 		SCARG(&msgget_args, key) = SCARG(uap, a2);
    230 		SCARG(&msgget_args, msgflg) = SCARG(uap, a3);
    231 		return (sys_msgget(l, &msgget_args, retval));
    232 
    233 	case 2:					/* msgsnd() */
    234 		SCARG(&msgsnd_args, msqid) = SCARG(uap, a2);
    235 		SCARG(&msgsnd_args, msgp) =
    236 		    (void *)(u_long)SCARG(uap, a3);
    237 		SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4);
    238 		SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5);
    239 		return (sys_msgsnd(l, &msgsnd_args, retval));
    240 
    241 	case 3:					/* msgrcv() */
    242 		SCARG(&msgrcv_args, msqid) = SCARG(uap, a2);
    243 		SCARG(&msgrcv_args, msgp) =
    244 		    (void *)(u_long)SCARG(uap, a3);
    245 		SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4);
    246 		SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5);
    247 		SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6);
    248 		return (sys_msgrcv(l, &msgrcv_args, retval));
    249 
    250 	default:
    251 		return (EINVAL);
    252 	}
    253 }
    254 #endif
    255