xref: /netbsd-src/sys/compat/netbsd32/netbsd32_conv.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: netbsd32_conv.h,v 1.35 2018/05/10 02:36:07 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1998, 2001 Matthew R. Green
5  * All rights reserved.
6  *
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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _COMPAT_NETBSD32_NETBSD32_CONV_H_
30 #define _COMPAT_NETBSD32_NETBSD32_CONV_H_
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/dirent.h>
36 #include <sys/ipc.h>
37 #include <sys/msg.h>
38 #define msg __msg /* Don't ask me! */
39 #include <sys/sem.h>
40 #include <sys/shm.h>
41 #include <sys/socket.h>
42 #include <sys/stat.h>
43 #include <sys/time.h>
44 #include <sys/timex.h>
45 #include <sys/event.h>
46 
47 #include <compat/sys/dirent.h>
48 
49 #include <prop/plistref.h>
50 
51 #include <compat/netbsd32/netbsd32.h>
52 
53 /* converters for structures that we need */
54 static __inline void
55 netbsd32_from_timeval50(const struct timeval *tv,
56     struct netbsd32_timeval50 *tv32)
57 {
58 
59 	tv32->tv_sec = (netbsd32_time50_t)tv->tv_sec;
60 	tv32->tv_usec = (netbsd32_long)tv->tv_usec;
61 }
62 
63 static __inline void
64 netbsd32_from_timeval(const struct timeval *tv,
65     struct netbsd32_timeval *tv32)
66 {
67 
68 	tv32->tv_sec = (netbsd32_time_t)tv->tv_sec;
69 	tv32->tv_usec = tv->tv_usec;
70 }
71 
72 static __inline void
73 netbsd32_to_timeval50(const struct netbsd32_timeval50 *tv32,
74     struct timeval *tv)
75 {
76 
77 	tv->tv_sec = (time_t)tv32->tv_sec;
78 	tv->tv_usec = tv32->tv_usec;
79 }
80 
81 static __inline void
82 netbsd32_to_timeval(const struct netbsd32_timeval *tv32,
83     struct timeval *tv)
84 {
85 
86 	tv->tv_sec = (time_t)tv32->tv_sec;
87 	tv->tv_usec = tv32->tv_usec;
88 }
89 
90 static __inline void
91 netbsd32_from_itimerval50(const struct itimerval *itv,
92     struct netbsd32_itimerval50 *itv32)
93 {
94 
95 	netbsd32_from_timeval50(&itv->it_interval,
96 			     &itv32->it_interval);
97 	netbsd32_from_timeval50(&itv->it_value,
98 			     &itv32->it_value);
99 }
100 
101 static __inline void
102 netbsd32_from_itimerval(const struct itimerval *itv,
103     struct netbsd32_itimerval *itv32)
104 {
105 
106 	netbsd32_from_timeval(&itv->it_interval,
107 			     &itv32->it_interval);
108 	netbsd32_from_timeval(&itv->it_value,
109 			     &itv32->it_value);
110 }
111 
112 static __inline void
113 netbsd32_to_itimerval50(const struct netbsd32_itimerval50 *itv32,
114     struct itimerval *itv)
115 {
116 
117 	netbsd32_to_timeval50(&itv32->it_interval, &itv->it_interval);
118 	netbsd32_to_timeval50(&itv32->it_value, &itv->it_value);
119 }
120 
121 static __inline void
122 netbsd32_to_itimerval(const struct netbsd32_itimerval *itv32,
123     struct itimerval *itv)
124 {
125 
126 	netbsd32_to_timeval(&itv32->it_interval, &itv->it_interval);
127 	netbsd32_to_timeval(&itv32->it_value, &itv->it_value);
128 }
129 
130 static __inline void
131 netbsd32_to_timespec50(const struct netbsd32_timespec50 *s32p,
132     struct timespec *p)
133 {
134 
135 	p->tv_sec = (time_t)s32p->tv_sec;
136 	p->tv_nsec = (long)s32p->tv_nsec;
137 }
138 
139 static __inline void
140 netbsd32_to_timespec(const struct netbsd32_timespec *s32p,
141     struct timespec *p)
142 {
143 
144 	p->tv_sec = (time_t)s32p->tv_sec;
145 	p->tv_nsec = (long)s32p->tv_nsec;
146 }
147 
148 static __inline void
149 netbsd32_from_timespec50(const struct timespec *p,
150     struct netbsd32_timespec50 *s32p)
151 {
152 
153 	s32p->tv_sec = (netbsd32_time50_t)p->tv_sec;
154 	s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
155 }
156 
157 static __inline void
158 netbsd32_from_timespec(const struct timespec *p,
159     struct netbsd32_timespec *s32p)
160 {
161 
162 	s32p->tv_sec = (netbsd32_time_t)p->tv_sec;
163 	s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
164 }
165 
166 static __inline void
167 netbsd32_from_rusage(const struct rusage *rup,
168     struct netbsd32_rusage *ru32p)
169 {
170 
171 	netbsd32_from_timeval(&rup->ru_utime, &ru32p->ru_utime);
172 	netbsd32_from_timeval(&rup->ru_stime, &ru32p->ru_stime);
173 #define C(var)	ru32p->var = (netbsd32_long)rup->var
174 	C(ru_maxrss);
175 	C(ru_ixrss);
176 	C(ru_idrss);
177 	C(ru_isrss);
178 	C(ru_minflt);
179 	C(ru_majflt);
180 	C(ru_nswap);
181 	C(ru_inblock);
182 	C(ru_oublock);
183 	C(ru_msgsnd);
184 	C(ru_msgrcv);
185 	C(ru_nsignals);
186 	C(ru_nvcsw);
187 	C(ru_nivcsw);
188 #undef C
189 }
190 
191 static __inline void
192 netbsd32_to_rusage(const struct netbsd32_rusage *ru32p,
193     struct rusage *rup)
194 {
195 
196 	netbsd32_to_timeval(&ru32p->ru_utime, &rup->ru_utime);
197 	netbsd32_to_timeval(&ru32p->ru_stime, &rup->ru_stime);
198 #define C(var)	rup->var = (long)ru32p->var
199 	C(ru_maxrss);
200 	C(ru_ixrss);
201 	C(ru_idrss);
202 	C(ru_isrss);
203 	C(ru_minflt);
204 	C(ru_majflt);
205 	C(ru_nswap);
206 	C(ru_inblock);
207 	C(ru_oublock);
208 	C(ru_msgsnd);
209 	C(ru_msgrcv);
210 	C(ru_nsignals);
211 	C(ru_nvcsw);
212 	C(ru_nivcsw);
213 #undef C
214 }
215 
216 static __inline void
217 netbsd32_from_rusage50(const struct rusage *rup,
218     struct netbsd32_rusage50 *ru32p)
219 {
220 
221 	netbsd32_from_timeval50(&rup->ru_utime, &ru32p->ru_utime);
222 	netbsd32_from_timeval50(&rup->ru_stime, &ru32p->ru_stime);
223 #define C(var)	ru32p->var = (netbsd32_long)rup->var
224 	C(ru_maxrss);
225 	C(ru_ixrss);
226 	C(ru_idrss);
227 	C(ru_isrss);
228 	C(ru_minflt);
229 	C(ru_majflt);
230 	C(ru_nswap);
231 	C(ru_inblock);
232 	C(ru_oublock);
233 	C(ru_msgsnd);
234 	C(ru_msgrcv);
235 	C(ru_nsignals);
236 	C(ru_nvcsw);
237 	C(ru_nivcsw);
238 #undef C
239 }
240 
241 static __inline int
242 netbsd32_to_iovecin(const struct netbsd32_iovec *iov32p, struct iovec *iovp,
243     int len)
244 {
245 	int i, error=0;
246 	u_int32_t iov_base;
247 	u_int32_t iov_len;
248 	/*
249 	 * We could allocate an iov32p, do a copyin, and translate
250 	 * each field and then free it all up, or we could copyin
251 	 * each field separately.  I'm doing the latter to reduce
252 	 * the number of MALLOC()s.
253 	 */
254 	for (i = 0; i < len; i++, iovp++, iov32p++) {
255 		if ((error = copyin(&iov32p->iov_base, &iov_base, sizeof(iov_base))))
256 		    return (error);
257 		if ((error = copyin(&iov32p->iov_len, &iov_len, sizeof(iov_len))))
258 		    return (error);
259 		iovp->iov_base = (void *)(u_long)iov_base;
260 		iovp->iov_len = (size_t)iov_len;
261 	}
262 	return error;
263 }
264 
265 /* msg_iov must be done separately */
266 static __inline void
267 netbsd32_to_msghdr(const struct netbsd32_msghdr *mhp32, struct msghdr *mhp)
268 {
269 
270 	mhp->msg_name = NETBSD32PTR64(mhp32->msg_name);
271 	mhp->msg_namelen = mhp32->msg_namelen;
272 	mhp->msg_iovlen = (size_t)mhp32->msg_iovlen;
273 	mhp->msg_control = NETBSD32PTR64(mhp32->msg_control);
274 	mhp->msg_controllen = mhp32->msg_controllen;
275 	mhp->msg_flags = mhp32->msg_flags;
276 }
277 
278 /* msg_iov must be done separately */
279 static __inline void
280 netbsd32_from_msghdr(struct netbsd32_msghdr *mhp32, const struct msghdr *mhp)
281 {
282 
283 	NETBSD32PTR32(mhp32->msg_name, mhp->msg_name);
284 	mhp32->msg_namelen = mhp->msg_namelen;
285 	mhp32->msg_iovlen = mhp->msg_iovlen;
286 	NETBSD32PTR32(mhp32->msg_control, mhp->msg_control);
287 	mhp32->msg_controllen = mhp->msg_controllen;
288 	mhp32->msg_flags = mhp->msg_flags;
289 }
290 
291 static __inline void
292 netbsd32_to_mmsghdr(const struct netbsd32_mmsghdr *mmsg32,
293     struct mmsghdr *mmsg)
294 {
295     netbsd32_to_msghdr(&mmsg32->msg_hdr, &mmsg->msg_hdr);
296     mmsg->msg_len = mmsg32->msg_len;
297 }
298 
299 static __inline void
300 netbsd32_from_mmsghdr(struct netbsd32_mmsghdr *mmsg32,
301     const struct mmsghdr *mmsg)
302 {
303     netbsd32_from_msghdr(&mmsg32->msg_hdr, &mmsg->msg_hdr);
304     mmsg32->msg_len = mmsg->msg_len;
305 }
306 
307 static __inline void
308 netbsd32_from_statvfs(const struct statvfs *sbp, struct netbsd32_statvfs *sb32p)
309 {
310 	sb32p->f_flag = sbp->f_flag;
311 	sb32p->f_bsize = (netbsd32_u_long)sbp->f_bsize;
312 	sb32p->f_frsize = (netbsd32_u_long)sbp->f_frsize;
313 	sb32p->f_iosize = (netbsd32_u_long)sbp->f_iosize;
314 	sb32p->f_blocks = sbp->f_blocks;
315 	sb32p->f_bfree = sbp->f_bfree;
316 	sb32p->f_bavail = sbp->f_bavail;
317 	sb32p->f_bresvd = sbp->f_bresvd;
318 	sb32p->f_files = sbp->f_files;
319 	sb32p->f_ffree = sbp->f_ffree;
320 	sb32p->f_favail = sbp->f_favail;
321 	sb32p->f_fresvd = sbp->f_fresvd;
322 	sb32p->f_syncreads = sbp->f_syncreads;
323 	sb32p->f_syncwrites = sbp->f_syncwrites;
324 	sb32p->f_asyncreads = sbp->f_asyncreads;
325 	sb32p->f_asyncwrites = sbp->f_asyncwrites;
326 	sb32p->f_fsidx = sbp->f_fsidx;
327 	sb32p->f_fsid = (netbsd32_u_long)sbp->f_fsid;
328 	sb32p->f_namemax = (netbsd32_u_long)sbp->f_namemax;
329 	sb32p->f_owner = sbp->f_owner;
330 	sb32p->f_spare[0] = 0;
331 	sb32p->f_spare[1] = 0;
332 	sb32p->f_spare[2] = 0;
333 	sb32p->f_spare[3] = 0;
334 #if 1
335 	/* May as well do the whole batch in one go */
336 	memcpy(sb32p->f_fstypename, sbp->f_fstypename,
337 	    sizeof(sb32p->f_fstypename) + sizeof(sb32p->f_mntonname) +
338 	    sizeof(sb32p->f_mntfromname));
339 #else
340 	/* If we want to be careful */
341 	memcpy(sb32p->f_fstypename, sbp->f_fstypename, sizeof(sb32p->f_fstypename));
342 	memcpy(sb32p->f_mntonname, sbp->f_mntonname, sizeof(sb32p->f_mntonname));
343 	memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, sizeof(sb32p->f_mntfromname));
344 #endif
345 }
346 
347 static __inline void
348 netbsd32_from_timex(const struct timex *txp, struct netbsd32_timex *tx32p)
349 {
350 
351 	tx32p->modes = txp->modes;
352 	tx32p->offset = (netbsd32_long)txp->offset;
353 	tx32p->freq = (netbsd32_long)txp->freq;
354 	tx32p->maxerror = (netbsd32_long)txp->maxerror;
355 	tx32p->esterror = (netbsd32_long)txp->esterror;
356 	tx32p->status = txp->status;
357 	tx32p->constant = (netbsd32_long)txp->constant;
358 	tx32p->precision = (netbsd32_long)txp->precision;
359 	tx32p->tolerance = (netbsd32_long)txp->tolerance;
360 	tx32p->ppsfreq = (netbsd32_long)txp->ppsfreq;
361 	tx32p->jitter = (netbsd32_long)txp->jitter;
362 	tx32p->shift = txp->shift;
363 	tx32p->stabil = (netbsd32_long)txp->stabil;
364 	tx32p->jitcnt = (netbsd32_long)txp->jitcnt;
365 	tx32p->calcnt = (netbsd32_long)txp->calcnt;
366 	tx32p->errcnt = (netbsd32_long)txp->errcnt;
367 	tx32p->stbcnt = (netbsd32_long)txp->stbcnt;
368 }
369 
370 static __inline void
371 netbsd32_to_timex(const struct netbsd32_timex *tx32p, struct timex *txp)
372 {
373 
374 	txp->modes = tx32p->modes;
375 	txp->offset = (long)tx32p->offset;
376 	txp->freq = (long)tx32p->freq;
377 	txp->maxerror = (long)tx32p->maxerror;
378 	txp->esterror = (long)tx32p->esterror;
379 	txp->status = tx32p->status;
380 	txp->constant = (long)tx32p->constant;
381 	txp->precision = (long)tx32p->precision;
382 	txp->tolerance = (long)tx32p->tolerance;
383 	txp->ppsfreq = (long)tx32p->ppsfreq;
384 	txp->jitter = (long)tx32p->jitter;
385 	txp->shift = tx32p->shift;
386 	txp->stabil = (long)tx32p->stabil;
387 	txp->jitcnt = (long)tx32p->jitcnt;
388 	txp->calcnt = (long)tx32p->calcnt;
389 	txp->errcnt = (long)tx32p->errcnt;
390 	txp->stbcnt = (long)tx32p->stbcnt;
391 }
392 
393 static __inline void
394 netbsd32_from___stat13(const struct stat *sbp, struct netbsd32_stat13 *sb32p)
395 {
396 	memset(sb32p, 0, sizeof(*sb32p));
397 	sb32p->st_dev = (uint32_t)sbp->st_dev;
398 	sb32p->st_ino = sbp->st_ino;
399 	sb32p->st_mode = sbp->st_mode;
400 	sb32p->st_nlink = sbp->st_nlink;
401 	sb32p->st_uid = sbp->st_uid;
402 	sb32p->st_gid = sbp->st_gid;
403 	sb32p->st_rdev = (uint32_t)sbp->st_rdev;
404 	sb32p->st_size = sbp->st_size;
405 	sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
406 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
407 	sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
408 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
409 	sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
410 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
411 	sb32p->st_blksize = sbp->st_blksize;
412 	sb32p->st_blocks = sbp->st_blocks;
413 	sb32p->st_flags = sbp->st_flags;
414 	sb32p->st_gen = sbp->st_gen;
415 	sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
416 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
417 }
418 
419 static __inline void
420 netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p)
421 {
422 	memset(sb32p, 0, sizeof(*sb32p));
423 	sb32p->st_dev = (uint32_t)sbp->st_dev;
424 	sb32p->st_ino = sbp->st_ino;
425 	sb32p->st_mode = sbp->st_mode;
426 	sb32p->st_nlink = sbp->st_nlink;
427 	sb32p->st_uid = sbp->st_uid;
428 	sb32p->st_gid = sbp->st_gid;
429 	sb32p->st_rdev = (uint32_t)sbp->st_rdev;
430 	sb32p->st_size = sbp->st_size;
431 	sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
432 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
433 	sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
434 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
435 	sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
436 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
437 	sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
438 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
439 	sb32p->st_blksize = sbp->st_blksize;
440 	sb32p->st_blocks = sbp->st_blocks;
441 	sb32p->st_flags = sbp->st_flags;
442 	sb32p->st_gen = sbp->st_gen;
443 }
444 
445 static __inline void
446 netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p)
447 {
448 	memset(sb32p, 0, sizeof(*sb32p));
449 	sb32p->st_dev = sbp->st_dev;
450 	sb32p->st_ino = sbp->st_ino;
451 	sb32p->st_mode = sbp->st_mode;
452 	sb32p->st_nlink = sbp->st_nlink;
453 	sb32p->st_uid = sbp->st_uid;
454 	sb32p->st_gid = sbp->st_gid;
455 	sb32p->st_rdev = sbp->st_rdev;
456 	sb32p->st_size = sbp->st_size;
457 	sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
458 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
459 	sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
460 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
461 	sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
462 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
463 	sb32p->st_birthtimespec.tv_sec = (netbsd32_time_t)sbp->st_birthtimespec.tv_sec;
464 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
465 	sb32p->st_blksize = sbp->st_blksize;
466 	sb32p->st_blocks = sbp->st_blocks;
467 	sb32p->st_flags = sbp->st_flags;
468 	sb32p->st_gen = sbp->st_gen;
469 }
470 
471 static __inline void
472 netbsd32_to_ipc_perm(const struct netbsd32_ipc_perm *ip32p,
473     struct ipc_perm *ipp)
474 {
475 
476 	ipp->cuid = ip32p->cuid;
477 	ipp->cgid = ip32p->cgid;
478 	ipp->uid = ip32p->uid;
479 	ipp->gid = ip32p->gid;
480 	ipp->mode = ip32p->mode;
481 	ipp->_seq = ip32p->_seq;
482 	ipp->_key = (key_t)ip32p->_key;
483 }
484 
485 static __inline void
486 netbsd32_from_ipc_perm(const struct ipc_perm *ipp,
487     struct netbsd32_ipc_perm *ip32p)
488 {
489 
490 	ip32p->cuid = ipp->cuid;
491 	ip32p->cgid = ipp->cgid;
492 	ip32p->uid = ipp->uid;
493 	ip32p->gid = ipp->gid;
494 	ip32p->mode = ipp->mode;
495 	ip32p->_seq = ipp->_seq;
496 	ip32p->_key = (netbsd32_key_t)ipp->_key;
497 }
498 
499 static __inline void
500 netbsd32_to_msg(const struct netbsd32_msg *m32p, struct msg *mp)
501 {
502 
503 	mp->msg_next = NETBSD32PTR64(m32p->msg_next);
504 	mp->msg_type = (long)m32p->msg_type;
505 	mp->msg_ts = m32p->msg_ts;
506 	mp->msg_spot = m32p->msg_spot;
507 }
508 
509 static __inline void
510 netbsd32_from_msg(const struct msg *mp, struct netbsd32_msg *m32p)
511 {
512 
513 	NETBSD32PTR32(m32p->msg_next, mp->msg_next);
514 	m32p->msg_type = (netbsd32_long)mp->msg_type;
515 	m32p->msg_ts = mp->msg_ts;
516 	m32p->msg_spot = mp->msg_spot;
517 }
518 
519 static __inline void
520 netbsd32_to_msqid_ds50(const struct netbsd32_msqid_ds50 *ds32p,
521     struct msqid_ds *dsp)
522 {
523 
524 	netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
525 	dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
526 	dsp->msg_qnum = (u_long)ds32p->msg_qnum;
527 	dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
528 	dsp->msg_lspid = ds32p->msg_lspid;
529 	dsp->msg_lrpid = ds32p->msg_lrpid;
530 	dsp->msg_rtime = (time_t)ds32p->msg_rtime;
531 	dsp->msg_stime = (time_t)ds32p->msg_stime;
532 	dsp->msg_ctime = (time_t)ds32p->msg_ctime;
533 }
534 
535 static __inline void
536 netbsd32_to_msqid_ds(const struct netbsd32_msqid_ds *ds32p,
537     struct msqid_ds *dsp)
538 {
539 
540 	netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
541 	dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
542 	dsp->msg_qnum = (u_long)ds32p->msg_qnum;
543 	dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
544 	dsp->msg_lspid = ds32p->msg_lspid;
545 	dsp->msg_lrpid = ds32p->msg_lrpid;
546 	dsp->msg_rtime = (time_t)ds32p->msg_rtime;
547 	dsp->msg_stime = (time_t)ds32p->msg_stime;
548 	dsp->msg_ctime = (time_t)ds32p->msg_ctime;
549 }
550 
551 static __inline void
552 netbsd32_from_msqid_ds50(const struct msqid_ds *dsp,
553     struct netbsd32_msqid_ds50 *ds32p)
554 {
555 
556 	netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
557 	ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
558 	ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
559 	ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
560 	ds32p->msg_lspid = dsp->msg_lspid;
561 	ds32p->msg_lrpid = dsp->msg_lrpid;
562 	ds32p->msg_rtime = (int32_t)dsp->msg_rtime;
563 	ds32p->msg_stime = (int32_t)dsp->msg_stime;
564 	ds32p->msg_ctime = (int32_t)dsp->msg_ctime;
565 }
566 
567 static __inline void
568 netbsd32_from_msqid_ds(const struct msqid_ds *dsp,
569     struct netbsd32_msqid_ds *ds32p)
570 {
571 
572 	netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
573 	ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
574 	ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
575 	ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
576 	ds32p->msg_lspid = dsp->msg_lspid;
577 	ds32p->msg_lrpid = dsp->msg_lrpid;
578 	ds32p->msg_rtime = dsp->msg_rtime;
579 	ds32p->msg_stime = dsp->msg_stime;
580 	ds32p->msg_ctime = dsp->msg_ctime;
581 }
582 
583 static __inline void
584 netbsd32_to_shmid_ds50(const struct netbsd32_shmid_ds50 *ds32p,
585     struct shmid_ds *dsp)
586 {
587 
588 	netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
589 	dsp->shm_segsz = ds32p->shm_segsz;
590 	dsp->shm_lpid = ds32p->shm_lpid;
591 	dsp->shm_cpid = ds32p->shm_cpid;
592 	dsp->shm_nattch = ds32p->shm_nattch;
593 	dsp->shm_atime = (time_t)ds32p->shm_atime;
594 	dsp->shm_dtime = (time_t)ds32p->shm_dtime;
595 	dsp->shm_ctime = (time_t)ds32p->shm_ctime;
596 	dsp->_shm_internal = NETBSD32PTR64(ds32p->_shm_internal);
597 }
598 
599 static __inline void
600 netbsd32_to_shmid_ds(const struct netbsd32_shmid_ds *ds32p,
601     struct shmid_ds *dsp)
602 {
603 
604 	netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
605 	dsp->shm_segsz = ds32p->shm_segsz;
606 	dsp->shm_lpid = ds32p->shm_lpid;
607 	dsp->shm_cpid = ds32p->shm_cpid;
608 	dsp->shm_nattch = ds32p->shm_nattch;
609 	dsp->shm_atime = (long)ds32p->shm_atime;
610 	dsp->shm_dtime = (time_t)ds32p->shm_dtime;
611 	dsp->shm_ctime = (time_t)ds32p->shm_ctime;
612 	dsp->_shm_internal = NETBSD32PTR64(ds32p->_shm_internal);
613 }
614 
615 static __inline void
616 netbsd32_from_shmid_ds50(const struct shmid_ds *dsp,
617     struct netbsd32_shmid_ds50 *ds32p)
618 {
619 
620 	netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
621 	ds32p->shm_segsz = dsp->shm_segsz;
622 	ds32p->shm_lpid = dsp->shm_lpid;
623 	ds32p->shm_cpid = dsp->shm_cpid;
624 	ds32p->shm_nattch = dsp->shm_nattch;
625 	ds32p->shm_atime = (int32_t)dsp->shm_atime;
626 	ds32p->shm_dtime = (int32_t)dsp->shm_dtime;
627 	ds32p->shm_ctime = (int32_t)dsp->shm_ctime;
628 	NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal);
629 }
630 
631 static __inline void
632 netbsd32_from_shmid_ds(const struct shmid_ds *dsp,
633     struct netbsd32_shmid_ds *ds32p)
634 {
635 
636 	netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
637 	ds32p->shm_segsz = dsp->shm_segsz;
638 	ds32p->shm_lpid = dsp->shm_lpid;
639 	ds32p->shm_cpid = dsp->shm_cpid;
640 	ds32p->shm_nattch = dsp->shm_nattch;
641 	ds32p->shm_atime = (netbsd32_long)dsp->shm_atime;
642 	ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime;
643 	ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime;
644 	NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal);
645 }
646 
647 static __inline void
648 netbsd32_to_semid_ds50(const struct netbsd32_semid_ds50 *s32dsp,
649     struct semid_ds *dsp)
650 {
651 
652 	netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
653 	dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base);
654 	dsp->sem_nsems = (time_t)s32dsp->sem_nsems;
655 	dsp->sem_otime = (time_t)s32dsp->sem_otime;
656 	dsp->sem_ctime = (time_t)s32dsp->sem_ctime;
657 }
658 
659 static __inline void
660 netbsd32_to_semid_ds(const struct netbsd32_semid_ds *s32dsp,
661     struct semid_ds *dsp)
662 {
663 
664 	netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
665 	dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base);
666 	dsp->sem_nsems = s32dsp->sem_nsems;
667 	dsp->sem_otime = s32dsp->sem_otime;
668 	dsp->sem_ctime = s32dsp->sem_ctime;
669 }
670 
671 static __inline void
672 netbsd32_from_semid_ds50(const struct semid_ds *dsp,
673     struct netbsd32_semid_ds50 *s32dsp)
674 {
675 
676 	netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
677 	NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base);
678 	s32dsp->sem_nsems = (int32_t)dsp->sem_nsems;
679 	s32dsp->sem_otime = (int32_t)dsp->sem_otime;
680 	s32dsp->sem_ctime = (int32_t)dsp->sem_ctime;
681 }
682 
683 static __inline void
684 netbsd32_from_semid_ds(const struct semid_ds *dsp,
685     struct netbsd32_semid_ds *s32dsp)
686 {
687 
688 	netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
689 	NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base);
690 	s32dsp->sem_nsems = dsp->sem_nsems;
691 	s32dsp->sem_otime = dsp->sem_otime;
692 	s32dsp->sem_ctime = dsp->sem_ctime;
693 }
694 
695 static __inline void
696 netbsd32_from_loadavg(struct netbsd32_loadavg *av32,
697     const struct loadavg *av)
698 {
699 
700 	av32->ldavg[0] = av->ldavg[0];
701 	av32->ldavg[1] = av->ldavg[1];
702 	av32->ldavg[2] = av->ldavg[2];
703 	av32->fscale = (netbsd32_long)av->fscale;
704 }
705 
706 static __inline void
707 netbsd32_to_kevent(struct netbsd32_kevent *ke32, struct kevent *ke)
708 {
709 	ke->ident = ke32->ident;
710 	ke->filter = ke32->filter;
711 	ke->flags = ke32->flags;
712 	ke->fflags = ke32->fflags;
713 	ke->data = ke32->data;
714 	ke->udata = ke32->udata;
715 }
716 
717 static __inline void
718 netbsd32_from_kevent(struct kevent *ke, struct netbsd32_kevent *ke32)
719 {
720 	ke32->ident = ke->ident;
721 	ke32->filter = ke->filter;
722 	ke32->flags = ke->flags;
723 	ke32->fflags = ke->fflags;
724 	ke32->data = ke->data;
725 	ke32->udata = ke->udata;
726 }
727 
728 static __inline void
729 netbsd32_to_sigevent(const struct netbsd32_sigevent *ev32, struct sigevent *ev)
730 {
731 	ev->sigev_notify = ev32->sigev_notify;
732 	ev->sigev_signo = ev32->sigev_signo;
733 	/*
734 	 * XXX sival_ptr, sigev_notify_function and
735 	 *     sigev_notify_attributes are  currently unused
736 	 */
737 	ev->sigev_value.sival_int = ev32->sigev_value.sival_int;
738 	ev->sigev_notify_function = NETBSD32PTR64(ev32->sigev_notify_function);
739 	ev->sigev_notify_attributes = NETBSD32PTR64(ev32->sigev_notify_attributes);
740 }
741 
742 static __inline int
743 netbsd32_to_dirent12(char *buf, int nbytes)
744 {
745 	struct dirent *ndp, *nndp, *endp;
746 	struct dirent12 *odp;
747 
748 	odp = (struct dirent12 *)(void *)buf;
749 	ndp = (struct dirent *)(void *)buf;
750 	endp = (struct dirent *)(void *)&buf[nbytes];
751 
752 	/*
753 	 * In-place conversion. This works because odp
754 	 * is smaller than ndp, but it has to be done
755 	 * in the right sequence.
756 	 */
757 	for (; ndp < endp; ndp = nndp) {
758 		nndp = _DIRENT_NEXT(ndp);
759 		odp->d_fileno = (u_int32_t)ndp->d_fileno;
760 		if (ndp->d_namlen >= sizeof(odp->d_name))
761 			odp->d_namlen = sizeof(odp->d_name) - 1;
762 		else
763 			odp->d_namlen = (u_int8_t)ndp->d_namlen;
764 		odp->d_type = ndp->d_type;
765 		(void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen);
766 		odp->d_name[odp->d_namlen] = '\0';
767 		odp->d_reclen = _DIRENT_SIZE(odp);
768 		odp = _DIRENT_NEXT(odp);
769 	}
770 	return ((char *)(void *)odp) - buf;
771 }
772 
773 static __inline int
774 netbsd32_copyin_plistref(netbsd32_pointer_t n32p, struct plistref *p)
775 {
776 	struct netbsd32_plistref n32plist;
777 	int error;
778 
779 	error = copyin(NETBSD32PTR64(n32p), &n32plist,
780 	    sizeof(struct netbsd32_plistref));
781 	if (error)
782 		return error;
783 	p->pref_plist = NETBSD32PTR64(n32plist.pref_plist);
784 	p->pref_len = n32plist.pref_len;
785 	return 0;
786 }
787 
788 static __inline int
789 netbsd32_copyout_plistref(netbsd32_pointer_t n32p, struct plistref *p)
790 {
791 	struct netbsd32_plistref n32plist;
792 
793 	NETBSD32PTR32(n32plist.pref_plist, p->pref_plist);
794 	n32plist.pref_len = p->pref_len;
795 	return copyout(&n32plist, NETBSD32PTR64(n32p),
796 	    sizeof(struct netbsd32_plistref));
797 }
798 
799 static __inline void
800 netbsd32_to_mq_attr(const struct netbsd32_mq_attr *a32,
801     struct mq_attr *attr)
802 {
803 	attr->mq_flags = a32->mq_flags;
804 	attr->mq_maxmsg = a32->mq_maxmsg;
805 	attr->mq_msgsize = a32->mq_msgsize;
806 	attr->mq_curmsgs = a32->mq_curmsgs;
807 }
808 
809 static __inline void
810 netbsd32_from_mq_attr(const struct mq_attr *attr,
811 	struct netbsd32_mq_attr *a32)
812 {
813 	a32->mq_flags = attr->mq_flags;
814 	a32->mq_maxmsg = attr->mq_maxmsg;
815 	a32->mq_msgsize = attr->mq_msgsize;
816 	a32->mq_curmsgs = attr->mq_curmsgs;
817 }
818 
819 #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */
820