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