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