1 /* $NetBSD: kern_ipc_10.c,v 1.9 1999/08/25 04:47:12 thorpej 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 #include <vm/vm_map.h> 49 #include <vm/vm_map.h> 50 #include <vm/vm_kern.h> 51 52 #ifdef SYSVSEM 53 int 54 compat_10_sys_semsys(p, v, retval) 55 struct proc *p; 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 caddr_t sg = stackgap_init(p->p_emul); 86 87 switch (SCARG(uap, which)) { 88 case 0: /* __semctl() */ 89 SCARG(&__semctl_args, semid) = SCARG(uap, a2); 90 SCARG(&__semctl_args, semnum) = SCARG(uap, a3); 91 SCARG(&__semctl_args, cmd) = SCARG(uap, a4); 92 SCARG(&__semctl_args, arg) = stackgap_alloc(&sg, 93 sizeof(union semun *)); 94 copyout(&SCARG(uap, a5), SCARG(&__semctl_args, arg), 95 sizeof(union __semun)); 96 return (compat_14_sys___semctl(p, &__semctl_args, retval)); 97 98 case 1: /* semget() */ 99 SCARG(&semget_args, key) = SCARG(uap, a2); 100 SCARG(&semget_args, nsems) = SCARG(uap, a3); 101 SCARG(&semget_args, semflg) = SCARG(uap, a4); 102 return (sys_semget(p, &semget_args, retval)); 103 104 case 2: /* semop() */ 105 SCARG(&semop_args, semid) = SCARG(uap, a2); 106 SCARG(&semop_args, sops) = (struct sembuf *)SCARG(uap, a3); 107 SCARG(&semop_args, nsops) = SCARG(uap, a4); 108 return (sys_semop(p, &semop_args, retval)); 109 110 case 3: /* semconfig() */ 111 SCARG(&semconfig_args, flag) = SCARG(uap, a2); 112 return (sys_semconfig(p, &semconfig_args, retval)); 113 114 default: 115 return (EINVAL); 116 } 117 } 118 #endif 119 120 #ifdef SYSVSHM 121 int 122 compat_10_sys_shmsys(p, v, retval) 123 struct proc *p; 124 void *v; 125 register_t *retval; 126 { 127 struct compat_10_sys_shmsys_args /* { 128 syscallarg(int) which; 129 syscallarg(int) a2; 130 syscallarg(int) a3; 131 syscallarg(int) a4; 132 } */ *uap = v; 133 struct sys_shmat_args /* { 134 syscallarg(int) shmid; 135 syscallarg(void *) shmaddr; 136 syscallarg(int) shmflg; 137 } */ shmat_args; 138 struct compat_14_sys_shmctl_args /* { 139 syscallarg(int) shmid; 140 syscallarg(int) cmd; 141 syscallarg(struct shmid14_ds *) buf; 142 } */ shmctl_args; 143 struct sys_shmdt_args /* { 144 syscallarg(void *) shmaddr; 145 } */ shmdt_args; 146 struct sys_shmget_args /* { 147 syscallarg(key_t) key; 148 syscallarg(int) size; 149 syscallarg(int) shmflg; 150 } */ shmget_args; 151 152 switch (SCARG(uap, which)) { 153 case 0: /* shmat() */ 154 SCARG(&shmat_args, shmid) = SCARG(uap, a2); 155 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3); 156 SCARG(&shmat_args, shmflg) = SCARG(uap, a4); 157 return (sys_shmat(p, &shmat_args, retval)); 158 159 case 1: /* shmctl() */ 160 SCARG(&shmctl_args, shmid) = SCARG(uap, a2); 161 SCARG(&shmctl_args, cmd) = SCARG(uap, a3); 162 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4); 163 return (compat_14_sys_shmctl(p, &shmctl_args, retval)); 164 165 case 2: /* shmdt() */ 166 SCARG(&shmdt_args, shmaddr) = (void *)SCARG(uap, a2); 167 return (sys_shmdt(p, &shmdt_args, retval)); 168 169 case 3: /* shmget() */ 170 SCARG(&shmget_args, key) = SCARG(uap, a2); 171 SCARG(&shmget_args, size) = SCARG(uap, a3); 172 SCARG(&shmget_args, shmflg) = SCARG(uap, a4); 173 return (sys_shmget(p, &shmget_args, retval)); 174 175 default: 176 return (EINVAL); 177 } 178 } 179 #endif 180 181 #ifdef SYSVMSG 182 int 183 compat_10_sys_msgsys(p, v, retval) 184 struct proc *p; 185 void *v; 186 register_t *retval; 187 { 188 struct compat_10_sys_msgsys_args /* { 189 syscallarg(int) which; 190 syscallarg(int) a2; 191 syscallarg(int) a3; 192 syscallarg(int) a4; 193 syscallarg(int) a5; 194 syscallarg(int) a6; 195 } */ *uap = v; 196 struct compat_14_sys_msgctl_args /* { 197 syscallarg(int) msqid; 198 syscallarg(int) cmd; 199 syscallarg(struct msqid14_ds *) buf; 200 } */ msgctl_args; 201 struct sys_msgget_args /* { 202 syscallarg(key_t) key; 203 syscallarg(int) msgflg; 204 } */ msgget_args; 205 struct sys_msgsnd_args /* { 206 syscallarg(int) msqid; 207 syscallarg(void *) msgp; 208 syscallarg(size_t) msgsz; 209 syscallarg(int) msgflg; 210 } */ msgsnd_args; 211 struct sys_msgrcv_args /* { 212 syscallarg(int) msqid; 213 syscallarg(void *) msgp; 214 syscallarg(size_t) msgsz; 215 syscallarg(long) msgtyp; 216 syscallarg(int) msgflg; 217 } */ msgrcv_args; 218 219 switch (SCARG(uap, which)) { 220 case 0: /* msgctl()*/ 221 SCARG(&msgctl_args, msqid) = SCARG(uap, a2); 222 SCARG(&msgctl_args, cmd) = SCARG(uap, a3); 223 SCARG(&msgctl_args, buf) = 224 (struct msqid_ds14 *)SCARG(uap, a4); 225 return (compat_14_sys_msgctl(p, &msgctl_args, retval)); 226 227 case 1: /* msgget() */ 228 SCARG(&msgget_args, key) = SCARG(uap, a2); 229 SCARG(&msgget_args, msgflg) = SCARG(uap, a3); 230 return (sys_msgget(p, &msgget_args, retval)); 231 232 case 2: /* msgsnd() */ 233 SCARG(&msgsnd_args, msqid) = SCARG(uap, a2); 234 SCARG(&msgsnd_args, msgp) = (void *)SCARG(uap, a3); 235 SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4); 236 SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5); 237 return (sys_msgsnd(p, &msgsnd_args, retval)); 238 239 case 3: /* msgrcv() */ 240 SCARG(&msgrcv_args, msqid) = SCARG(uap, a2); 241 SCARG(&msgrcv_args, msgp) = (void *)SCARG(uap, a3); 242 SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4); 243 SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5); 244 SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6); 245 return (sys_msgrcv(p, &msgrcv_args, retval)); 246 247 default: 248 return (EINVAL); 249 } 250 } 251 #endif 252