netbsd32_compat_14_sysv.c revision 1.3.4.2 1 1.3.4.2 christos /* $NetBSD: netbsd32_compat_14_sysv.c,v 1.3.4.2 2019/06/10 22:07:01 christos Exp $ */
2 1.3.4.2 christos
3 1.3.4.2 christos /*
4 1.3.4.2 christos * Copyright (c) 1999 Eduardo E. Horvath
5 1.3.4.2 christos * All rights reserved.
6 1.3.4.2 christos *
7 1.3.4.2 christos * Redistribution and use in source and binary forms, with or without
8 1.3.4.2 christos * modification, are permitted provided that the following conditions
9 1.3.4.2 christos * are met:
10 1.3.4.2 christos * 1. Redistributions of source code must retain the above copyright
11 1.3.4.2 christos * notice, this list of conditions and the following disclaimer.
12 1.3.4.2 christos * 2. Redistributions in binary form must reproduce the above copyright
13 1.3.4.2 christos * notice, this list of conditions and the following disclaimer in the
14 1.3.4.2 christos * documentation and/or other materials provided with the distribution.
15 1.3.4.2 christos * 3. The name of the author may not be used to endorse or promote products
16 1.3.4.2 christos * derived from this software without specific prior written permission.
17 1.3.4.2 christos *
18 1.3.4.2 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.3.4.2 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.3.4.2 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.3.4.2 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.3.4.2 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.3.4.2 christos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.3.4.2 christos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.3.4.2 christos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.3.4.2 christos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.3.4.2 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.3.4.2 christos * SUCH DAMAGE.
29 1.3.4.2 christos */
30 1.3.4.2 christos
31 1.3.4.2 christos #include <sys/cdefs.h>
32 1.3.4.2 christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_14_sysv.c,v 1.3.4.2 2019/06/10 22:07:01 christos Exp $");
33 1.3.4.2 christos
34 1.3.4.2 christos #ifdef _KERNEL_OPT
35 1.3.4.2 christos #include "opt_sysv.h"
36 1.3.4.2 christos #include "opt_compat_netbsd.h"
37 1.3.4.2 christos #endif
38 1.3.4.2 christos
39 1.3.4.2 christos #include <sys/param.h>
40 1.3.4.2 christos #include <sys/ipc.h>
41 1.3.4.2 christos #include <sys/systm.h>
42 1.3.4.2 christos #include <sys/module.h>
43 1.3.4.2 christos #include <sys/signal.h>
44 1.3.4.2 christos #include <sys/proc.h>
45 1.3.4.2 christos #include <sys/mount.h>
46 1.3.4.2 christos #include <sys/msg.h>
47 1.3.4.2 christos #include <sys/sem.h>
48 1.3.4.2 christos #include <sys/shm.h>
49 1.3.4.2 christos
50 1.3.4.2 christos #include <sys/syscallargs.h>
51 1.3.4.2 christos #include <sys/syscallvar.h>
52 1.3.4.2 christos
53 1.3.4.2 christos #include <compat/netbsd32/netbsd32.h>
54 1.3.4.2 christos #include <compat/netbsd32/netbsd32_syscall.h>
55 1.3.4.2 christos #include <compat/netbsd32/netbsd32_syscallargs.h>
56 1.3.4.2 christos #include <compat/sys/siginfo.h>
57 1.3.4.2 christos #include <compat/sys/shm.h>
58 1.3.4.2 christos
59 1.3.4.2 christos #if defined(COMPAT_14)
60 1.3.4.2 christos
61 1.3.4.2 christos #if defined(SYSVMSG)
62 1.3.4.2 christos static inline void
63 1.3.4.2 christos netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *operm, struct ipc_perm *perm)
64 1.3.4.2 christos {
65 1.3.4.2 christos
66 1.3.4.2 christos #define CVT(x) perm->x = operm->x
67 1.3.4.2 christos CVT(uid);
68 1.3.4.2 christos CVT(gid);
69 1.3.4.2 christos CVT(cuid);
70 1.3.4.2 christos CVT(cgid);
71 1.3.4.2 christos CVT(mode);
72 1.3.4.2 christos #undef CVT
73 1.3.4.2 christos }
74 1.3.4.2 christos
75 1.3.4.2 christos static inline void
76 1.3.4.2 christos native_to_netbsd32_ipc_perm14(struct ipc_perm *perm, struct netbsd32_ipc_perm14 *operm)
77 1.3.4.2 christos {
78 1.3.4.2 christos
79 1.3.4.2 christos memset(operm, 0, sizeof *operm);
80 1.3.4.2 christos #define CVT(x) operm->x = perm->x
81 1.3.4.2 christos CVT(uid);
82 1.3.4.2 christos CVT(gid);
83 1.3.4.2 christos CVT(cuid);
84 1.3.4.2 christos CVT(cgid);
85 1.3.4.2 christos CVT(mode);
86 1.3.4.2 christos #undef CVT
87 1.3.4.2 christos
88 1.3.4.2 christos /*
89 1.3.4.2 christos * Not part of the API, but some programs might look at it.
90 1.3.4.2 christos */
91 1.3.4.2 christos operm->seq = perm->_seq;
92 1.3.4.2 christos operm->key = (key_t)perm->_key;
93 1.3.4.2 christos }
94 1.3.4.2 christos
95 1.3.4.2 christos static inline void
96 1.3.4.2 christos netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
97 1.3.4.2 christos {
98 1.3.4.2 christos
99 1.3.4.2 christos netbsd32_ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
100 1.3.4.2 christos
101 1.3.4.2 christos #define CVT(x) msqbuf->x = omsqbuf->x
102 1.3.4.2 christos CVT(msg_qnum);
103 1.3.4.2 christos CVT(msg_qbytes);
104 1.3.4.2 christos CVT(msg_lspid);
105 1.3.4.2 christos CVT(msg_lrpid);
106 1.3.4.2 christos CVT(msg_stime);
107 1.3.4.2 christos CVT(msg_rtime);
108 1.3.4.2 christos CVT(msg_ctime);
109 1.3.4.2 christos #undef CVT
110 1.3.4.2 christos }
111 1.3.4.2 christos
112 1.3.4.2 christos static inline void
113 1.3.4.2 christos native_to_netbsd32_msqid_ds14(struct msqid_ds *msqbuf, struct netbsd32_msqid_ds14 *omsqbuf)
114 1.3.4.2 christos {
115 1.3.4.2 christos
116 1.3.4.2 christos memset(omsqbuf, 0, sizeof *omsqbuf);
117 1.3.4.2 christos native_to_netbsd32_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
118 1.3.4.2 christos
119 1.3.4.2 christos #define CVT(x) omsqbuf->x = msqbuf->x
120 1.3.4.2 christos CVT(msg_qnum);
121 1.3.4.2 christos CVT(msg_qbytes);
122 1.3.4.2 christos CVT(msg_lspid);
123 1.3.4.2 christos CVT(msg_lrpid);
124 1.3.4.2 christos CVT(msg_stime);
125 1.3.4.2 christos CVT(msg_rtime);
126 1.3.4.2 christos CVT(msg_ctime);
127 1.3.4.2 christos #undef CVT
128 1.3.4.2 christos
129 1.3.4.2 christos /*
130 1.3.4.2 christos * Not part of the API, but some programs might look at it.
131 1.3.4.2 christos */
132 1.3.4.2 christos omsqbuf->msg_cbytes = msqbuf->_msg_cbytes;
133 1.3.4.2 christos }
134 1.3.4.2 christos #endif
135 1.3.4.2 christos
136 1.3.4.2 christos #if defined(SYSVSEM)
137 1.3.4.2 christos static inline void
138 1.3.4.2 christos netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *osembuf, struct semid_ds *sembuf)
139 1.3.4.2 christos {
140 1.3.4.2 christos
141 1.3.4.2 christos netbsd32_ipc_perm14_to_native(&osembuf->sem_perm, &sembuf->sem_perm);
142 1.3.4.2 christos
143 1.3.4.2 christos #define CVT(x) sembuf->x = osembuf->x
144 1.3.4.2 christos CVT(sem_nsems);
145 1.3.4.2 christos CVT(sem_otime);
146 1.3.4.2 christos CVT(sem_ctime);
147 1.3.4.2 christos #undef CVT
148 1.3.4.2 christos }
149 1.3.4.2 christos
150 1.3.4.2 christos static inline void
151 1.3.4.2 christos native_to_netbsd32_semid_ds14(struct semid_ds *sembuf, struct netbsd32_semid_ds14 *osembuf)
152 1.3.4.2 christos {
153 1.3.4.2 christos
154 1.3.4.2 christos memset(osembuf, 0, sizeof *osembuf);
155 1.3.4.2 christos native_to_netbsd32_ipc_perm14(&sembuf->sem_perm, &osembuf->sem_perm);
156 1.3.4.2 christos
157 1.3.4.2 christos #define CVT(x) osembuf->x = sembuf->x
158 1.3.4.2 christos CVT(sem_nsems);
159 1.3.4.2 christos CVT(sem_otime);
160 1.3.4.2 christos CVT(sem_ctime);
161 1.3.4.2 christos #undef CVT
162 1.3.4.2 christos }
163 1.3.4.2 christos
164 1.3.4.2 christos static inline void
165 1.3.4.2 christos netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *oshmbuf, struct shmid_ds *shmbuf)
166 1.3.4.2 christos {
167 1.3.4.2 christos
168 1.3.4.2 christos netbsd32_ipc_perm14_to_native(&oshmbuf->shm_perm, &shmbuf->shm_perm);
169 1.3.4.2 christos
170 1.3.4.2 christos #define CVT(x) shmbuf->x = oshmbuf->x
171 1.3.4.2 christos CVT(shm_segsz);
172 1.3.4.2 christos CVT(shm_lpid);
173 1.3.4.2 christos CVT(shm_cpid);
174 1.3.4.2 christos CVT(shm_nattch);
175 1.3.4.2 christos CVT(shm_atime);
176 1.3.4.2 christos CVT(shm_dtime);
177 1.3.4.2 christos CVT(shm_ctime);
178 1.3.4.2 christos #undef CVT
179 1.3.4.2 christos }
180 1.3.4.2 christos
181 1.3.4.2 christos static inline void
182 1.3.4.2 christos native_to_netbsd32_shmid_ds14(struct shmid_ds *shmbuf, struct netbsd32_shmid_ds14 *oshmbuf)
183 1.3.4.2 christos {
184 1.3.4.2 christos
185 1.3.4.2 christos memset(oshmbuf, 0, sizeof *oshmbuf);
186 1.3.4.2 christos native_to_netbsd32_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
187 1.3.4.2 christos
188 1.3.4.2 christos #define CVT(x) oshmbuf->x = shmbuf->x
189 1.3.4.2 christos CVT(shm_segsz);
190 1.3.4.2 christos CVT(shm_lpid);
191 1.3.4.2 christos CVT(shm_cpid);
192 1.3.4.2 christos CVT(shm_nattch);
193 1.3.4.2 christos CVT(shm_atime);
194 1.3.4.2 christos CVT(shm_dtime);
195 1.3.4.2 christos CVT(shm_ctime);
196 1.3.4.2 christos #undef CVT
197 1.3.4.2 christos }
198 1.3.4.2 christos
199 1.3.4.2 christos /*
200 1.3.4.2 christos * the compat_14 system calls
201 1.3.4.2 christos */
202 1.3.4.2 christos int
203 1.3.4.2 christos compat_14_netbsd32_msgctl(struct lwp *l, const struct compat_14_netbsd32_msgctl_args *uap, register_t *retval)
204 1.3.4.2 christos {
205 1.3.4.2 christos /* {
206 1.3.4.2 christos syscallarg(int) msqid;
207 1.3.4.2 christos syscallarg(int) cmd;
208 1.3.4.2 christos syscallarg(struct msqid_ds14 *) buf;
209 1.3.4.2 christos } */
210 1.3.4.2 christos struct msqid_ds msqbuf;
211 1.3.4.2 christos struct netbsd32_msqid_ds14 omsqbuf;
212 1.3.4.2 christos int cmd, error;
213 1.3.4.2 christos
214 1.3.4.2 christos cmd = SCARG(uap, cmd);
215 1.3.4.2 christos
216 1.3.4.2 christos if (cmd == IPC_SET) {
217 1.3.4.2 christos error = copyin(SCARG_P32(uap, buf),
218 1.3.4.2 christos &omsqbuf, sizeof(omsqbuf));
219 1.3.4.2 christos if (error)
220 1.3.4.2 christos return (error);
221 1.3.4.2 christos netbsd32_msqid_ds14_to_native(&omsqbuf, &msqbuf);
222 1.3.4.2 christos }
223 1.3.4.2 christos
224 1.3.4.2 christos error = msgctl1(l, SCARG(uap, msqid), cmd,
225 1.3.4.2 christos (cmd == IPC_SET || cmd == IPC_STAT) ? &msqbuf : NULL);
226 1.3.4.2 christos
227 1.3.4.2 christos if (error == 0 && cmd == IPC_STAT) {
228 1.3.4.2 christos native_to_netbsd32_msqid_ds14(&msqbuf, &omsqbuf);
229 1.3.4.2 christos error = copyout(&omsqbuf,
230 1.3.4.2 christos SCARG_P32(uap, buf), sizeof(omsqbuf));
231 1.3.4.2 christos }
232 1.3.4.2 christos
233 1.3.4.2 christos return (error);
234 1.3.4.2 christos }
235 1.3.4.2 christos #endif
236 1.3.4.2 christos
237 1.3.4.2 christos #if defined(SYSVSEM)
238 1.3.4.2 christos int
239 1.3.4.2 christos compat_14_netbsd32___semctl(struct lwp *l, const struct compat_14_netbsd32___semctl_args *uap, register_t *retval)
240 1.3.4.2 christos {
241 1.3.4.2 christos /* {
242 1.3.4.2 christos syscallarg(int) semid;
243 1.3.4.2 christos syscallarg(int) semnum;
244 1.3.4.2 christos syscallarg(int) cmd;
245 1.3.4.2 christos syscallarg(union __semun *) arg;
246 1.3.4.2 christos } */
247 1.3.4.2 christos union __semun arg;
248 1.3.4.2 christos struct semid_ds sembuf;
249 1.3.4.2 christos struct netbsd32_semid_ds14 osembuf;
250 1.3.4.2 christos int cmd, error;
251 1.3.4.2 christos void *pass_arg = NULL;
252 1.3.4.2 christos
253 1.3.4.2 christos cmd = SCARG(uap, cmd);
254 1.3.4.2 christos
255 1.3.4.2 christos switch (cmd) {
256 1.3.4.2 christos case IPC_SET:
257 1.3.4.2 christos case IPC_STAT:
258 1.3.4.2 christos pass_arg = &sembuf;
259 1.3.4.2 christos break;
260 1.3.4.2 christos
261 1.3.4.2 christos case GETALL:
262 1.3.4.2 christos case SETVAL:
263 1.3.4.2 christos case SETALL:
264 1.3.4.2 christos pass_arg = &arg;
265 1.3.4.2 christos break;
266 1.3.4.2 christos }
267 1.3.4.2 christos
268 1.3.4.2 christos if (pass_arg != NULL) {
269 1.3.4.2 christos error = copyin(NETBSD32IPTR64(SCARG(uap, arg)), &arg,
270 1.3.4.2 christos sizeof(arg));
271 1.3.4.2 christos if (error)
272 1.3.4.2 christos return (error);
273 1.3.4.2 christos if (cmd == IPC_SET) {
274 1.3.4.2 christos error = copyin(arg.buf, &osembuf, sizeof(osembuf));
275 1.3.4.2 christos if (error)
276 1.3.4.2 christos return (error);
277 1.3.4.2 christos netbsd32_semid_ds14_to_native(&osembuf, &sembuf);
278 1.3.4.2 christos }
279 1.3.4.2 christos }
280 1.3.4.2 christos
281 1.3.4.2 christos error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
282 1.3.4.2 christos pass_arg, retval);
283 1.3.4.2 christos
284 1.3.4.2 christos if (error == 0 && cmd == IPC_STAT) {
285 1.3.4.2 christos native_to_netbsd32_semid_ds14(&sembuf, &osembuf);
286 1.3.4.2 christos error = copyout(&osembuf, arg.buf, sizeof(osembuf));
287 1.3.4.2 christos }
288 1.3.4.2 christos
289 1.3.4.2 christos return (error);
290 1.3.4.2 christos }
291 1.3.4.2 christos #endif
292 1.3.4.2 christos
293 1.3.4.2 christos #if defined(SYSVSHM)
294 1.3.4.2 christos int
295 1.3.4.2 christos compat_14_netbsd32_shmctl(struct lwp *l, const struct compat_14_netbsd32_shmctl_args *uap, register_t *retval)
296 1.3.4.2 christos {
297 1.3.4.2 christos /* {
298 1.3.4.2 christos syscallarg(int) shmid;
299 1.3.4.2 christos syscallarg(int) cmd;
300 1.3.4.2 christos syscallarg(struct netbsd32_shmid_ds14 *) buf;
301 1.3.4.2 christos } */
302 1.3.4.2 christos struct shmid_ds shmbuf;
303 1.3.4.2 christos struct netbsd32_shmid_ds14 oshmbuf;
304 1.3.4.2 christos int cmd, error;
305 1.3.4.2 christos
306 1.3.4.2 christos cmd = SCARG(uap, cmd);
307 1.3.4.2 christos
308 1.3.4.2 christos if (cmd == IPC_SET) {
309 1.3.4.2 christos error = copyin(SCARG_P32(uap, buf), &oshmbuf, sizeof(oshmbuf));
310 1.3.4.2 christos if (error)
311 1.3.4.2 christos return (error);
312 1.3.4.2 christos netbsd32_shmid_ds14_to_native(&oshmbuf, &shmbuf);
313 1.3.4.2 christos }
314 1.3.4.2 christos
315 1.3.4.2 christos error = shmctl1(l, SCARG(uap, shmid), cmd,
316 1.3.4.2 christos (cmd == IPC_SET || cmd == IPC_STAT) ? &shmbuf : NULL);
317 1.3.4.2 christos
318 1.3.4.2 christos if (error == 0 && cmd == IPC_STAT) {
319 1.3.4.2 christos native_to_netbsd32_shmid_ds14(&shmbuf, &oshmbuf);
320 1.3.4.2 christos error = copyout(&oshmbuf, SCARG_P32(uap, buf), sizeof(oshmbuf));
321 1.3.4.2 christos }
322 1.3.4.2 christos
323 1.3.4.2 christos return (error);
324 1.3.4.2 christos }
325 1.3.4.2 christos #endif
326 1.3.4.2 christos
327 1.3.4.2 christos #define REQ1 "sysv_ipc,compat_sysv_14,"
328 1.3.4.2 christos #define REQ2 "compat_netbsd32,compat_netbsd32_sysvipc,"
329 1.3.4.2 christos #define REQ3 "compat_netbsd32_sysvipc_50"
330 1.3.4.2 christos
331 1.3.4.2 christos #define _PKG_ENTRY(name) \
332 1.3.4.2 christos { NETBSD32_SYS_ ## name, 0, (sy_call_t *)name }
333 1.3.4.2 christos
334 1.3.4.2 christos static const struct syscall_package compat_sysvipc_14_syscalls[] = {
335 1.3.4.2 christos #if defined(SYSVSEM)
336 1.3.4.2 christos _PKG_ENTRY(compat_14_netbsd32___semctl),
337 1.3.4.2 christos #endif
338 1.3.4.2 christos #if defined(SYSVSHM)
339 1.3.4.2 christos _PKG_ENTRY(compat_14_netbsd32_shmctl),
340 1.3.4.2 christos #endif
341 1.3.4.2 christos #if defined(SYSVMSG)
342 1.3.4.2 christos _PKG_ENTRY(compat_14_netbsd32_msgctl),
343 1.3.4.2 christos #endif
344 1.3.4.2 christos { 0, 0, NULL }
345 1.3.4.2 christos };
346 1.3.4.2 christos
347 1.3.4.2 christos #define REQ1 "sysv_ipc,compat_sysv_14,"
348 1.3.4.2 christos #define REQ2 "compat_netbsd32,compat_netbsd32_sysvipc,"
349 1.3.4.2 christos #define REQ3 "compat_netbsd32_sysvipc_50"
350 1.3.4.2 christos
351 1.3.4.2 christos MODULE(MODULE_CLASS_EXEC, compat_netbsd32_sysvipc_14, REQ1 REQ2 REQ3 );
352 1.3.4.2 christos
353 1.3.4.2 christos static int
354 1.3.4.2 christos compat_netbsd32_sysvipc_14_modcmd(modcmd_t cmd, void *arg)
355 1.3.4.2 christos {
356 1.3.4.2 christos
357 1.3.4.2 christos switch (cmd) {
358 1.3.4.2 christos case MODULE_CMD_INIT:
359 1.3.4.2 christos return syscall_establish(&emul_netbsd32,
360 1.3.4.2 christos compat_sysvipc_14_syscalls);
361 1.3.4.2 christos
362 1.3.4.2 christos case MODULE_CMD_FINI:
363 1.3.4.2 christos return syscall_disestablish(&emul_netbsd32,
364 1.3.4.2 christos compat_sysvipc_14_syscalls);
365 1.3.4.2 christos
366 1.3.4.2 christos default:
367 1.3.4.2 christos return ENOTTY;
368 1.3.4.2 christos }
369 1.3.4.2 christos }
370 1.3.4.2 christos
371 1.3.4.2 christos #endif /* COMPAT_14 */
372