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