Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / compat / netbsd32 / netbsd32_compat_14.c
blobbd83149d96aafa3d4cf713de3b8839bd4596241d
1 /* $NetBSD: netbsd32_compat_14.c,v 1.20 2007/12/08 18:36:17 dsl Exp $ */
3 /*
4 * Copyright (c) 1999 Eduardo E. Horvath
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
28 * SUCH DAMAGE.
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>
35 #include <sys/ipc.h>
36 #include <sys/systm.h>
37 #include <sys/signal.h>
38 #include <sys/proc.h>
39 #include <sys/mount.h>
40 #include <sys/msg.h>
41 #include <sys/sem.h>
42 #include <sys/shm.h>
44 #ifndef SYSVMSG
45 #define SYSVMSG
46 #endif
47 #ifndef SYSVSEM
48 #define SYSVSEM
49 #endif
50 #ifndef SYSVSHM
51 #define SYSVSHM
52 #endif
54 #include <sys/syscallargs.h>
55 #include <compat/netbsd32/netbsd32.h>
56 #include <compat/netbsd32/netbsd32_syscallargs.h>
57 #include <compat/sys/shm.h>
59 static inline void
60 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *, struct ipc_perm *);
61 static inline void
62 native_to_netbsd32_ipc_perm14(struct ipc_perm *, struct netbsd32_ipc_perm14 *);
63 static inline void
64 native_to_netbsd32_msqid_ds14(struct msqid_ds *, struct netbsd32_msqid_ds14 *);
65 static inline void
66 netbsd32_msqid_ds14_to_native(struct netbsd32_msqid_ds14 *, struct msqid_ds *);
67 static inline void
68 native_to_netbsd32_semid_ds14(struct semid_ds *, struct netbsd32_semid_ds14 *);
69 static inline void
70 netbsd32_semid_ds14_to_native(struct netbsd32_semid_ds14 *, struct semid_ds *);
71 static inline void
72 netbsd32_shmid_ds14_to_native(struct netbsd32_shmid_ds14 *, struct shmid_ds *);
73 static inline void
74 native_to_netbsd32_shmid_ds14(struct shmid_ds *, struct netbsd32_shmid_ds14 *);
76 static inline void
77 netbsd32_ipc_perm14_to_native(struct netbsd32_ipc_perm14 *operm, struct ipc_perm *perm)
80 #define CVT(x) perm->x = operm->x
81 CVT(uid);
82 CVT(gid);
83 CVT(cuid);
84 CVT(cgid);
85 CVT(mode);
86 #undef CVT
89 static inline void
90 native_to_netbsd32_ipc_perm14(struct ipc_perm *perm, struct netbsd32_ipc_perm14 *operm)
93 #define CVT(x) operm->x = perm->x
94 CVT(uid);
95 CVT(gid);
96 CVT(cuid);
97 CVT(cgid);
98 CVT(mode);
99 #undef CVT
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;
108 static inline void
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
115 CVT(msg_qnum);
116 CVT(msg_qbytes);
117 CVT(msg_lspid);
118 CVT(msg_lrpid);
119 CVT(msg_stime);
120 CVT(msg_rtime);
121 CVT(msg_ctime);
122 #undef CVT
125 static inline void
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
132 CVT(msg_qnum);
133 CVT(msg_qbytes);
134 CVT(msg_lspid);
135 CVT(msg_lrpid);
136 CVT(msg_stime);
137 CVT(msg_rtime);
138 CVT(msg_ctime);
139 #undef CVT
142 * Not part of the API, but some programs might look at it.
144 omsqbuf->msg_cbytes = msqbuf->_msg_cbytes;
147 static inline void
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
154 CVT(sem_nsems);
155 CVT(sem_otime);
156 CVT(sem_ctime);
157 #undef CVT
160 static inline void
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
167 CVT(sem_nsems);
168 CVT(sem_otime);
169 CVT(sem_ctime);
170 #undef CVT
173 static inline void
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
180 CVT(shm_segsz);
181 CVT(shm_lpid);
182 CVT(shm_cpid);
183 CVT(shm_nattch);
184 CVT(shm_atime);
185 CVT(shm_dtime);
186 CVT(shm_ctime);
187 #undef CVT
190 static inline void
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
197 CVT(shm_segsz);
198 CVT(shm_lpid);
199 CVT(shm_cpid);
200 CVT(shm_nattch);
201 CVT(shm_atime);
202 CVT(shm_dtime);
203 CVT(shm_ctime);
204 #undef CVT
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)
213 /* {
214 syscallarg(int) msqid;
215 syscallarg(int) cmd;
216 syscallarg(struct msqid_ds14 *) buf;
217 } */
218 struct msqid_ds msqbuf;
219 struct netbsd32_msqid_ds14 omsqbuf;
220 int cmd, error;
222 cmd = SCARG(uap, cmd);
224 if (cmd == IPC_SET) {
225 error = copyin(SCARG_P32(uap, buf),
226 &omsqbuf, sizeof(omsqbuf));
227 if (error)
228 return (error);
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));
241 return (error);
245 compat_14_netbsd32___semctl(struct lwp *l, const struct compat_14_netbsd32___semctl_args *uap, register_t *retval)
247 /* {
248 syscallarg(int) semid;
249 syscallarg(int) semnum;
250 syscallarg(int) cmd;
251 syscallarg(union __semun *) arg;
252 } */
253 union __semun arg;
254 struct semid_ds sembuf;
255 struct netbsd32_semid_ds14 osembuf;
256 int cmd, error;
257 void *pass_arg = NULL;
259 cmd = SCARG(uap, cmd);
261 switch (cmd) {
262 case IPC_SET:
263 case IPC_STAT:
264 pass_arg = &sembuf;
265 break;
267 case GETALL:
268 case SETVAL:
269 case SETALL:
270 pass_arg = &arg;
271 break;
274 if (pass_arg != NULL) {
275 error = copyin(NETBSD32IPTR64(SCARG(uap, arg)), &arg,
276 sizeof(arg));
277 if (error)
278 return (error);
279 if (cmd == IPC_SET) {
280 error = copyin(arg.buf, &osembuf, sizeof(osembuf));
281 if (error)
282 return (error);
283 netbsd32_semid_ds14_to_native(&osembuf, &sembuf);
287 error = semctl1(l, SCARG(uap, semid), SCARG(uap, semnum), cmd,
288 pass_arg, retval);
290 if (error == 0 && cmd == IPC_STAT) {
291 native_to_netbsd32_semid_ds14(&sembuf, &osembuf);
292 error = copyout(&osembuf, arg.buf, sizeof(osembuf));
295 return (error);
299 compat_14_netbsd32_shmctl(struct lwp *l, const struct compat_14_netbsd32_shmctl_args *uap, register_t *retval)
301 /* {
302 syscallarg(int) shmid;
303 syscallarg(int) cmd;
304 syscallarg(struct netbsd32_shmid_ds14 *) buf;
305 } */
306 struct shmid_ds shmbuf;
307 struct netbsd32_shmid_ds14 oshmbuf;
308 int cmd, error;
310 cmd = SCARG(uap, cmd);
312 if (cmd == IPC_SET) {
313 error = copyin(SCARG_P32(uap, buf), &oshmbuf, sizeof(oshmbuf));
314 if (error)
315 return (error);
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));
327 return (error);