1 1.4 simonb /* $NetBSD: netbsd32_compat_50_sysv.c,v 1.4 2021/01/19 03:20:13 simonb Exp $ */ 2 1.1 pgoyette 3 1.1 pgoyette /*- 4 1.1 pgoyette * Copyright (c) 2008 The NetBSD Foundation, Inc. 5 1.1 pgoyette * All rights reserved. 6 1.1 pgoyette * 7 1.1 pgoyette * This code is derived from software contributed to The NetBSD Foundation 8 1.1 pgoyette * by Christos Zoulas. 9 1.1 pgoyette * 10 1.1 pgoyette * Redistribution and use in source and binary forms, with or without 11 1.1 pgoyette * modification, are permitted provided that the following conditions 12 1.1 pgoyette * are met: 13 1.1 pgoyette * 1. Redistributions of source code must retain the above copyright 14 1.1 pgoyette * notice, this list of conditions and the following disclaimer. 15 1.1 pgoyette * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 pgoyette * notice, this list of conditions and the following disclaimer in the 17 1.1 pgoyette * documentation and/or other materials provided with the distribution. 18 1.1 pgoyette * 19 1.1 pgoyette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 pgoyette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 pgoyette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 pgoyette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 pgoyette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 pgoyette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 pgoyette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 pgoyette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 pgoyette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 pgoyette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 pgoyette * POSSIBILITY OF SUCH DAMAGE. 30 1.1 pgoyette */ 31 1.1 pgoyette #include <sys/cdefs.h> 32 1.4 simonb __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_50_sysv.c,v 1.4 2021/01/19 03:20:13 simonb Exp $"); 33 1.1 pgoyette 34 1.1 pgoyette #if defined(_KERNEL_OPT) 35 1.1 pgoyette #include "opt_sysv.h" 36 1.1 pgoyette #include "opt_compat_netbsd.h" 37 1.1 pgoyette #endif 38 1.1 pgoyette 39 1.1 pgoyette #include <sys/param.h> 40 1.1 pgoyette #include <sys/systm.h> 41 1.2 pgoyette #include <sys/module.h> 42 1.1 pgoyette #include <sys/msg.h> 43 1.1 pgoyette #include <sys/sem.h> 44 1.1 pgoyette #include <sys/shm.h> 45 1.1 pgoyette 46 1.2 pgoyette #include <sys/syscallvar.h> 47 1.2 pgoyette 48 1.1 pgoyette #include <compat/netbsd32/netbsd32.h> 49 1.2 pgoyette #include <compat/netbsd32/netbsd32_syscall.h> 50 1.1 pgoyette #include <compat/netbsd32/netbsd32_syscallargs.h> 51 1.1 pgoyette #include <compat/netbsd32/netbsd32_conv.h> 52 1.1 pgoyette 53 1.1 pgoyette #if defined(COMPAT_50) 54 1.1 pgoyette 55 1.1 pgoyette #if defined(SYSVSEM) 56 1.1 pgoyette 57 1.1 pgoyette int 58 1.1 pgoyette compat_50_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval) 59 1.1 pgoyette { 60 1.1 pgoyette return do_netbsd32___semctl14(l, uap, retval, NULL); 61 1.1 pgoyette } 62 1.1 pgoyette 63 1.1 pgoyette int 64 1.1 pgoyette do_netbsd32___semctl14(struct lwp *l, const struct compat_50_netbsd32___semctl14_args *uap, register_t *retval, void *vkarg) 65 1.1 pgoyette { 66 1.1 pgoyette /* { 67 1.1 pgoyette syscallarg(int) semid; 68 1.1 pgoyette syscallarg(int) semnum; 69 1.1 pgoyette syscallarg(int) cmd; 70 1.1 pgoyette syscallarg(netbsd32_semun50p_t) arg; 71 1.1 pgoyette } */ 72 1.1 pgoyette struct semid_ds sembuf; 73 1.1 pgoyette struct netbsd32_semid_ds50 sembuf32; 74 1.1 pgoyette int cmd, error; 75 1.1 pgoyette void *pass_arg; 76 1.1 pgoyette union __semun karg; 77 1.1 pgoyette union netbsd32_semun50 karg32; 78 1.1 pgoyette 79 1.1 pgoyette cmd = SCARG(uap, cmd); 80 1.1 pgoyette 81 1.1 pgoyette switch (cmd) { 82 1.1 pgoyette case IPC_SET: 83 1.1 pgoyette case IPC_STAT: 84 1.1 pgoyette pass_arg = &sembuf; 85 1.1 pgoyette break; 86 1.1 pgoyette 87 1.1 pgoyette case GETALL: 88 1.1 pgoyette case SETVAL: 89 1.1 pgoyette case SETALL: 90 1.1 pgoyette pass_arg = &karg; 91 1.1 pgoyette break; 92 1.1 pgoyette default: 93 1.1 pgoyette pass_arg = NULL; 94 1.1 pgoyette break; 95 1.1 pgoyette } 96 1.1 pgoyette 97 1.1 pgoyette if (pass_arg) { 98 1.1 pgoyette if (vkarg != NULL) 99 1.1 pgoyette karg32 = *(union netbsd32_semun50 *)vkarg; 100 1.1 pgoyette else { 101 1.1 pgoyette error = copyin(SCARG_P32(uap, arg), &karg32, 102 1.1 pgoyette sizeof(karg32)); 103 1.1 pgoyette if (error) 104 1.1 pgoyette return error; 105 1.1 pgoyette } 106 1.1 pgoyette if (pass_arg == &karg) { 107 1.1 pgoyette switch (cmd) { 108 1.1 pgoyette case GETALL: 109 1.1 pgoyette case SETALL: 110 1.1 pgoyette karg.array = NETBSD32PTR64(karg32.array); 111 1.1 pgoyette break; 112 1.1 pgoyette case SETVAL: 113 1.1 pgoyette karg.val = karg32.val; 114 1.1 pgoyette break; 115 1.1 pgoyette } 116 1.1 pgoyette } 117 1.1 pgoyette if (cmd == IPC_SET) { 118 1.1 pgoyette error = copyin(NETBSD32PTR64(karg32.buf), &sembuf32, 119 1.1 pgoyette sizeof(sembuf32)); 120 1.1 pgoyette if (error) 121 1.4 simonb return error; 122 1.1 pgoyette netbsd32_to_semid_ds50(&sembuf32, &sembuf); 123 1.1 pgoyette } 124 1.1 pgoyette } 125 1.1 pgoyette 126 1.1 pgoyette error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd, 127 1.1 pgoyette pass_arg, retval); 128 1.1 pgoyette 129 1.1 pgoyette if (error == 0 && cmd == IPC_STAT) { 130 1.1 pgoyette netbsd32_from_semid_ds50(&sembuf, &sembuf32); 131 1.1 pgoyette error = copyout(&sembuf32, NETBSD32PTR64(karg32.buf), 132 1.1 pgoyette sizeof(sembuf32)); 133 1.1 pgoyette } 134 1.1 pgoyette 135 1.4 simonb return error; 136 1.1 pgoyette } 137 1.1 pgoyette #endif 138 1.1 pgoyette 139 1.1 pgoyette #if defined(SYSVMSG) 140 1.1 pgoyette 141 1.1 pgoyette int 142 1.1 pgoyette compat_50_netbsd32___msgctl13(struct lwp *l, const struct compat_50_netbsd32___msgctl13_args *uap, register_t *retval) 143 1.1 pgoyette { 144 1.1 pgoyette /* { 145 1.1 pgoyette syscallarg(int) msqid; 146 1.1 pgoyette syscallarg(int) cmd; 147 1.1 pgoyette syscallarg(netbsd32_msqid_ds50p_t) buf; 148 1.1 pgoyette } */ 149 1.1 pgoyette struct msqid_ds ds; 150 1.1 pgoyette struct netbsd32_msqid_ds50 ds32; 151 1.1 pgoyette int error, cmd; 152 1.1 pgoyette 153 1.1 pgoyette cmd = SCARG(uap, cmd); 154 1.1 pgoyette if (cmd == IPC_SET) { 155 1.1 pgoyette error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32)); 156 1.1 pgoyette if (error) 157 1.1 pgoyette return error; 158 1.1 pgoyette netbsd32_to_msqid_ds50(&ds32, &ds); 159 1.1 pgoyette } 160 1.1 pgoyette 161 1.1 pgoyette error = msgctl1(l, SCARG(uap, msqid), cmd, 162 1.1 pgoyette (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL); 163 1.1 pgoyette 164 1.1 pgoyette if (error == 0 && cmd == IPC_STAT) { 165 1.1 pgoyette netbsd32_from_msqid_ds50(&ds, &ds32); 166 1.1 pgoyette error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32)); 167 1.1 pgoyette } 168 1.1 pgoyette 169 1.1 pgoyette return error; 170 1.1 pgoyette } 171 1.1 pgoyette #endif 172 1.1 pgoyette 173 1.1 pgoyette #if defined(SYSVSHM) 174 1.1 pgoyette 175 1.1 pgoyette int 176 1.1 pgoyette compat_50_netbsd32___shmctl13(struct lwp *l, const struct compat_50_netbsd32___shmctl13_args *uap, register_t *retval) 177 1.1 pgoyette { 178 1.1 pgoyette /* { 179 1.1 pgoyette syscallarg(int) shmid; 180 1.1 pgoyette syscallarg(int) cmd; 181 1.1 pgoyette syscallarg(netbsd32_shmid_ds50p_t) buf; 182 1.1 pgoyette } */ 183 1.1 pgoyette struct shmid_ds ds; 184 1.1 pgoyette struct netbsd32_shmid_ds50 ds32; 185 1.1 pgoyette int error, cmd; 186 1.1 pgoyette 187 1.1 pgoyette cmd = SCARG(uap, cmd); 188 1.1 pgoyette if (cmd == IPC_SET) { 189 1.1 pgoyette error = copyin(SCARG_P32(uap, buf), &ds32, sizeof(ds32)); 190 1.1 pgoyette if (error) 191 1.1 pgoyette return error; 192 1.1 pgoyette netbsd32_to_shmid_ds50(&ds32, &ds); 193 1.1 pgoyette } 194 1.1 pgoyette 195 1.1 pgoyette error = shmctl1(l, SCARG(uap, shmid), cmd, 196 1.1 pgoyette (cmd == IPC_SET || cmd == IPC_STAT) ? &ds : NULL); 197 1.1 pgoyette 198 1.1 pgoyette if (error == 0 && cmd == IPC_STAT) { 199 1.1 pgoyette netbsd32_from_shmid_ds50(&ds, &ds32); 200 1.1 pgoyette error = copyout(&ds32, SCARG_P32(uap, buf), sizeof(ds32)); 201 1.1 pgoyette } 202 1.1 pgoyette 203 1.1 pgoyette return error; 204 1.1 pgoyette } 205 1.1 pgoyette #endif 206 1.1 pgoyette 207 1.2 pgoyette #define _PKG_ENTRY(name) \ 208 1.2 pgoyette { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name } 209 1.2 pgoyette 210 1.2 pgoyette static const struct syscall_package compat_sysvipc_50_syscalls[] = { 211 1.2 pgoyette #if defined(SYSVSEM) 212 1.2 pgoyette _PKG_ENTRY(compat_50_netbsd32___semctl14), 213 1.2 pgoyette #endif 214 1.2 pgoyette #if defined(SYSVSHM) 215 1.2 pgoyette _PKG_ENTRY(compat_50_netbsd32___shmctl13), 216 1.2 pgoyette #endif 217 1.2 pgoyette #if defined(SYSVMSG) 218 1.2 pgoyette _PKG_ENTRY(compat_50_netbsd32___msgctl13), 219 1.2 pgoyette #endif 220 1.2 pgoyette { 0, 0, NULL } 221 1.2 pgoyette }; 222 1.2 pgoyette 223 1.2 pgoyette #define REQ1 "sysv_ipc,compat_sysv_50," 224 1.2 pgoyette #define REQ2 "compat_netbsd32,compat_netbsd32_sysvipc," 225 1.2 pgoyette 226 1.2 pgoyette MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_50, REQ1 REQ2); 227 1.2 pgoyette 228 1.2 pgoyette static int 229 1.2 pgoyette compat_netbsd32_sysvipc_50_modcmd(modcmd_t cmd, void *arg) 230 1.2 pgoyette { 231 1.2 pgoyette 232 1.2 pgoyette switch (cmd) { 233 1.2 pgoyette case MODULE_CMD_INIT: 234 1.2 pgoyette return syscall_establish(&emul_netbsd32, 235 1.2 pgoyette compat_sysvipc_50_syscalls); 236 1.2 pgoyette 237 1.2 pgoyette case MODULE_CMD_FINI: 238 1.2 pgoyette return syscall_disestablish(&emul_netbsd32, 239 1.2 pgoyette compat_sysvipc_50_syscalls); 240 1.2 pgoyette 241 1.2 pgoyette default: 242 1.2 pgoyette return ENOTTY; 243 1.2 pgoyette } 244 1.2 pgoyette } 245 1.2 pgoyette 246 1.1 pgoyette #endif /* COMPAT_50 */ 247