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