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