1 /* $NetBSD: kern_ipc_10.c,v 1.17 2003/11/19 15:48:21 christos 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.17 2003/11/19 15:48:21 christos 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/proc.h> 42 #include <sys/sem.h> 43 44 #include <sys/mount.h> 45 #include <sys/sa.h> 46 #include <sys/syscallargs.h> 47 48 #include <compat/common/compat_util.h> 49 50 #if defined(SYSVSEM) && !defined(_LP64) 51 int 52 compat_10_sys_semsys(l, v, retval) 53 struct lwp *l; 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 compat_14_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 struct proc *p = l->l_proc; 84 caddr_t sg = stackgap_init(p, 0); 85 86 switch (SCARG(uap, which)) { 87 case 0: /* __semctl() */ 88 SCARG(&__semctl_args, semid) = SCARG(uap, a2); 89 SCARG(&__semctl_args, semnum) = SCARG(uap, a3); 90 SCARG(&__semctl_args, cmd) = SCARG(uap, a4); 91 SCARG(&__semctl_args, arg) = stackgap_alloc(p, &sg, 92 sizeof(union semun *)); 93 copyout(&SCARG(uap, a5), SCARG(&__semctl_args, arg), 94 sizeof(union __semun)); 95 return (compat_14_sys___semctl(l, &__semctl_args, retval)); 96 97 case 1: /* semget() */ 98 SCARG(&semget_args, key) = SCARG(uap, a2); 99 SCARG(&semget_args, nsems) = SCARG(uap, a3); 100 SCARG(&semget_args, semflg) = SCARG(uap, a4); 101 return (sys_semget(l, &semget_args, retval)); 102 103 case 2: /* semop() */ 104 SCARG(&semop_args, semid) = SCARG(uap, a2); 105 SCARG(&semop_args, sops) = 106 (struct sembuf *)(u_long)SCARG(uap, a3); 107 SCARG(&semop_args, nsops) = SCARG(uap, a4); 108 return (sys_semop(l, &semop_args, retval)); 109 110 case 3: /* semconfig() */ 111 SCARG(&semconfig_args, flag) = SCARG(uap, a2); 112 return (sys_semconfig(l, &semconfig_args, retval)); 113 114 default: 115 return (EINVAL); 116 } 117 } 118 #endif 119 120 #if defined(SYSVSHM) && !defined(_LP64) 121 int 122 compat_10_sys_shmsys(l, v, retval) 123 struct lwp *l; 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) = 156 (void *)(u_long)SCARG(uap, a3); 157 SCARG(&shmat_args, shmflg) = SCARG(uap, a4); 158 return (sys_shmat(l, &shmat_args, retval)); 159 160 case 1: /* shmctl() */ 161 SCARG(&shmctl_args, shmid) = SCARG(uap, a2); 162 SCARG(&shmctl_args, cmd) = SCARG(uap, a3); 163 SCARG(&shmctl_args, buf) = 164 (struct shmid_ds14 *)(u_long)SCARG(uap, a4); 165 return (compat_14_sys_shmctl(l, &shmctl_args, retval)); 166 167 case 2: /* shmdt() */ 168 SCARG(&shmdt_args, shmaddr) = 169 (void *)(u_long)SCARG(uap, a2); 170 return (sys_shmdt(l, &shmdt_args, retval)); 171 172 case 3: /* shmget() */ 173 SCARG(&shmget_args, key) = SCARG(uap, a2); 174 SCARG(&shmget_args, size) = SCARG(uap, a3); 175 SCARG(&shmget_args, shmflg) = SCARG(uap, a4); 176 return (sys_shmget(l, &shmget_args, retval)); 177 178 default: 179 return (EINVAL); 180 } 181 } 182 #endif 183 184 #if defined(SYSVMSG) && !defined(_LP64) 185 int 186 compat_10_sys_msgsys(l, v, retval) 187 struct lwp *l; 188 void *v; 189 register_t *retval; 190 { 191 struct compat_10_sys_msgsys_args /* { 192 syscallarg(int) which; 193 syscallarg(int) a2; 194 syscallarg(int) a3; 195 syscallarg(int) a4; 196 syscallarg(int) a5; 197 syscallarg(int) a6; 198 } */ *uap = v; 199 struct compat_14_sys_msgctl_args /* { 200 syscallarg(int) msqid; 201 syscallarg(int) cmd; 202 syscallarg(struct msqid14_ds *) buf; 203 } */ msgctl_args; 204 struct sys_msgget_args /* { 205 syscallarg(key_t) key; 206 syscallarg(int) msgflg; 207 } */ msgget_args; 208 struct sys_msgsnd_args /* { 209 syscallarg(int) msqid; 210 syscallarg(void *) msgp; 211 syscallarg(size_t) msgsz; 212 syscallarg(int) msgflg; 213 } */ msgsnd_args; 214 struct sys_msgrcv_args /* { 215 syscallarg(int) msqid; 216 syscallarg(void *) msgp; 217 syscallarg(size_t) msgsz; 218 syscallarg(long) msgtyp; 219 syscallarg(int) msgflg; 220 } */ msgrcv_args; 221 222 switch (SCARG(uap, which)) { 223 case 0: /* msgctl()*/ 224 SCARG(&msgctl_args, msqid) = SCARG(uap, a2); 225 SCARG(&msgctl_args, cmd) = SCARG(uap, a3); 226 SCARG(&msgctl_args, buf) = 227 (struct msqid_ds14 *)(u_long)SCARG(uap, a4); 228 return (compat_14_sys_msgctl(l, &msgctl_args, retval)); 229 230 case 1: /* msgget() */ 231 SCARG(&msgget_args, key) = SCARG(uap, a2); 232 SCARG(&msgget_args, msgflg) = SCARG(uap, a3); 233 return (sys_msgget(l, &msgget_args, retval)); 234 235 case 2: /* msgsnd() */ 236 SCARG(&msgsnd_args, msqid) = SCARG(uap, a2); 237 SCARG(&msgsnd_args, msgp) = 238 (void *)(u_long)SCARG(uap, a3); 239 SCARG(&msgsnd_args, msgsz) = SCARG(uap, a4); 240 SCARG(&msgsnd_args, msgflg) = SCARG(uap, a5); 241 return (sys_msgsnd(l, &msgsnd_args, retval)); 242 243 case 3: /* msgrcv() */ 244 SCARG(&msgrcv_args, msqid) = SCARG(uap, a2); 245 SCARG(&msgrcv_args, msgp) = 246 (void *)(u_long)SCARG(uap, a3); 247 SCARG(&msgrcv_args, msgsz) = SCARG(uap, a4); 248 SCARG(&msgrcv_args, msgtyp) = SCARG(uap, a5); 249 SCARG(&msgrcv_args, msgflg) = SCARG(uap, a6); 250 return (sys_msgrcv(l, &msgrcv_args, retval)); 251 252 default: 253 return (EINVAL); 254 } 255 } 256 #endif 257