1 /* $NetBSD: netbsd32_compat_14.c,v 1.20 2007/12/08 18:36:17 dsl Exp $ */
4 * Copyright (c) 1999 Eduardo E. Horvath
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_14.c,v 1.20 2007/12/08 18:36:17 dsl Exp $");
34 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/signal.h>
39 #include <sys/mount.h>
54 #include <sys/syscallargs.h>
55 #include <compat/netbsd32/netbsd32.h>
56 #include <compat/netbsd32/netbsd32_syscallargs.h>
57 #include <compat/sys/shm.h>
60 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14
*, struct ipc_perm
*);
62 native_to_netbsd32_ipc_perm14(struct ipc_perm
*, struct netbsd32_ipc_perm14
*);
64 native_to_netbsd32_msqid_ds14(struct msqid_ds
*, struct netbsd32_msqid_ds14
*);
66 netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14
*, struct msqid_ds
*);
68 native_to_netbsd32_semid_ds14(struct semid_ds
*, struct netbsd32_semid_ds14
*);
70 netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14
*, struct semid_ds
*);
72 netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14
*, struct shmid_ds
*);
74 native_to_netbsd32_shmid_ds14(struct shmid_ds
*, struct netbsd32_shmid_ds14
*);
77 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14
*operm
, struct ipc_perm
*perm
)
80 #define CVT(x) perm->x = operm->x
90 native_to_netbsd32_ipc_perm14(struct ipc_perm
*perm
, struct netbsd32_ipc_perm14
*operm
)
93 #define CVT(x) operm->x = perm->x
102 * Not part of the API, but some programs might look at it.
104 operm
->seq
= perm
->_seq
;
105 operm
->key
= (key_t
)perm
->_key
;
109 netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14
*omsqbuf
, struct msqid_ds
*msqbuf
)
112 netbsd32_ipc_perm14_to_native(&omsqbuf
->msg_perm
, &msqbuf
->msg_perm
);
114 #define CVT(x) msqbuf->x = omsqbuf->x
126 native_to_netbsd32_msqid_ds14(struct msqid_ds
*msqbuf
, struct netbsd32_msqid_ds14
*omsqbuf
)
129 native_to_netbsd32_ipc_perm14(&msqbuf
->msg_perm
, &omsqbuf
->msg_perm
);
131 #define CVT(x) omsqbuf->x = msqbuf->x
142 * Not part of the API, but some programs might look at it.
144 omsqbuf
->msg_cbytes
= msqbuf
->_msg_cbytes
;
148 netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14
*osembuf
, struct semid_ds
*sembuf
)
151 netbsd32_ipc_perm14_to_native(&osembuf
->sem_perm
, &sembuf
->sem_perm
);
153 #define CVT(x) sembuf->x = osembuf->x
161 native_to_netbsd32_semid_ds14(struct semid_ds
*sembuf
, struct netbsd32_semid_ds14
*osembuf
)
164 native_to_netbsd32_ipc_perm14(&sembuf
->sem_perm
, &osembuf
->sem_perm
);
166 #define CVT(x) osembuf->x = sembuf->x
174 netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14
*oshmbuf
, struct shmid_ds
*shmbuf
)
177 netbsd32_ipc_perm14_to_native(&oshmbuf
->shm_perm
, &shmbuf
->shm_perm
);
179 #define CVT(x) shmbuf->x = oshmbuf->x
191 native_to_netbsd32_shmid_ds14(struct shmid_ds
*shmbuf
, struct netbsd32_shmid_ds14
*oshmbuf
)
194 native_to_netbsd32_ipc_perm14(&shmbuf
->shm_perm
, &oshmbuf
->shm_perm
);
196 #define CVT(x) oshmbuf->x = shmbuf->x
208 * the compat_14 system calls
211 compat_14_netbsd32_msgctl(struct lwp
*l
, const struct compat_14_netbsd32_msgctl_args
*uap
, register_t
*retval
)
214 syscallarg(int) msqid;
216 syscallarg(struct msqid_ds14 *) buf;
218 struct msqid_ds msqbuf
;
219 struct netbsd32_msqid_ds14 omsqbuf
;
222 cmd
= SCARG(uap
, cmd
);
224 if (cmd
== IPC_SET
) {
225 error
= copyin(SCARG_P32(uap
, buf
),
226 &omsqbuf
, sizeof(omsqbuf
));
229 netbsd32_msqid_ds14_to_native(&omsqbuf
, &msqbuf
);
232 error
= msgctl1(l
, SCARG(uap
, msqid
), cmd
,
233 (cmd
== IPC_SET
|| cmd
== IPC_STAT
) ? &msqbuf
: NULL
);
235 if (error
== 0 && cmd
== IPC_STAT
) {
236 native_to_netbsd32_msqid_ds14(&msqbuf
, &omsqbuf
);
237 error
= copyout(&omsqbuf
,
238 SCARG_P32(uap
, buf
), sizeof(omsqbuf
));
245 compat_14_netbsd32___semctl(struct lwp
*l
, const struct compat_14_netbsd32___semctl_args
*uap
, register_t
*retval
)
248 syscallarg(int) semid;
249 syscallarg(int) semnum;
251 syscallarg(union __semun *) arg;
254 struct semid_ds sembuf
;
255 struct netbsd32_semid_ds14 osembuf
;
257 void *pass_arg
= NULL
;
259 cmd
= SCARG(uap
, cmd
);
274 if (pass_arg
!= NULL
) {
275 error
= copyin(NETBSD32IPTR64(SCARG(uap
, arg
)), &arg
,
279 if (cmd
== IPC_SET
) {
280 error
= copyin(arg
.buf
, &osembuf
, sizeof(osembuf
));
283 netbsd32_semid_ds14_to_native(&osembuf
, &sembuf
);
287 error
= semctl1(l
, SCARG(uap
, semid
), SCARG(uap
, semnum
), cmd
,
290 if (error
== 0 && cmd
== IPC_STAT
) {
291 native_to_netbsd32_semid_ds14(&sembuf
, &osembuf
);
292 error
= copyout(&osembuf
, arg
.buf
, sizeof(osembuf
));
299 compat_14_netbsd32_shmctl(struct lwp
*l
, const struct compat_14_netbsd32_shmctl_args
*uap
, register_t
*retval
)
302 syscallarg(int) shmid;
304 syscallarg(struct netbsd32_shmid_ds14 *) buf;
306 struct shmid_ds shmbuf
;
307 struct netbsd32_shmid_ds14 oshmbuf
;
310 cmd
= SCARG(uap
, cmd
);
312 if (cmd
== IPC_SET
) {
313 error
= copyin(SCARG_P32(uap
, buf
), &oshmbuf
, sizeof(oshmbuf
));
316 netbsd32_shmid_ds14_to_native(&oshmbuf
, &shmbuf
);
319 error
= shmctl1(l
, SCARG(uap
, shmid
), cmd
,
320 (cmd
== IPC_SET
|| cmd
== IPC_STAT
) ? &shmbuf
: NULL
);
322 if (error
== 0 && cmd
== IPC_STAT
) {
323 native_to_netbsd32_shmid_ds14(&shmbuf
, &oshmbuf
);
324 error
= copyout(&oshmbuf
, SCARG_P32(uap
, buf
), sizeof(oshmbuf
));