Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_conv.h revision 1.33
      1 /*	$NetBSD: netbsd32_conv.h,v 1.33 2017/10/31 12:43:56 martin 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_from_statvfs(const struct statvfs *sbp, struct netbsd32_statvfs *sb32p)
    293 {
    294 	sb32p->f_flag = sbp->f_flag;
    295 	sb32p->f_bsize = (netbsd32_u_long)sbp->f_bsize;
    296 	sb32p->f_frsize = (netbsd32_u_long)sbp->f_frsize;
    297 	sb32p->f_iosize = (netbsd32_u_long)sbp->f_iosize;
    298 	sb32p->f_blocks = sbp->f_blocks;
    299 	sb32p->f_bfree = sbp->f_bfree;
    300 	sb32p->f_bavail = sbp->f_bavail;
    301 	sb32p->f_bresvd = sbp->f_bresvd;
    302 	sb32p->f_files = sbp->f_files;
    303 	sb32p->f_ffree = sbp->f_ffree;
    304 	sb32p->f_favail = sbp->f_favail;
    305 	sb32p->f_fresvd = sbp->f_fresvd;
    306 	sb32p->f_syncreads = sbp->f_syncreads;
    307 	sb32p->f_syncwrites = sbp->f_syncwrites;
    308 	sb32p->f_asyncreads = sbp->f_asyncreads;
    309 	sb32p->f_asyncwrites = sbp->f_asyncwrites;
    310 	sb32p->f_fsidx = sbp->f_fsidx;
    311 	sb32p->f_fsid = (netbsd32_u_long)sbp->f_fsid;
    312 	sb32p->f_namemax = (netbsd32_u_long)sbp->f_namemax;
    313 	sb32p->f_owner = sbp->f_owner;
    314 	sb32p->f_spare[0] = 0;
    315 	sb32p->f_spare[1] = 0;
    316 	sb32p->f_spare[2] = 0;
    317 	sb32p->f_spare[3] = 0;
    318 #if 1
    319 	/* May as well do the whole batch in one go */
    320 	memcpy(sb32p->f_fstypename, sbp->f_fstypename,
    321 	    sizeof(sb32p->f_fstypename) + sizeof(sb32p->f_mntonname) +
    322 	    sizeof(sb32p->f_mntfromname));
    323 #else
    324 	/* If we want to be careful */
    325 	memcpy(sb32p->f_fstypename, sbp->f_fstypename, sizeof(sb32p->f_fstypename));
    326 	memcpy(sb32p->f_mntonname, sbp->f_mntonname, sizeof(sb32p->f_mntonname));
    327 	memcpy(sb32p->f_mntfromname, sbp->f_mntfromname, sizeof(sb32p->f_mntfromname));
    328 #endif
    329 }
    330 
    331 static __inline void
    332 netbsd32_from_timex(const struct timex *txp, struct netbsd32_timex *tx32p)
    333 {
    334 
    335 	tx32p->modes = txp->modes;
    336 	tx32p->offset = (netbsd32_long)txp->offset;
    337 	tx32p->freq = (netbsd32_long)txp->freq;
    338 	tx32p->maxerror = (netbsd32_long)txp->maxerror;
    339 	tx32p->esterror = (netbsd32_long)txp->esterror;
    340 	tx32p->status = txp->status;
    341 	tx32p->constant = (netbsd32_long)txp->constant;
    342 	tx32p->precision = (netbsd32_long)txp->precision;
    343 	tx32p->tolerance = (netbsd32_long)txp->tolerance;
    344 	tx32p->ppsfreq = (netbsd32_long)txp->ppsfreq;
    345 	tx32p->jitter = (netbsd32_long)txp->jitter;
    346 	tx32p->shift = txp->shift;
    347 	tx32p->stabil = (netbsd32_long)txp->stabil;
    348 	tx32p->jitcnt = (netbsd32_long)txp->jitcnt;
    349 	tx32p->calcnt = (netbsd32_long)txp->calcnt;
    350 	tx32p->errcnt = (netbsd32_long)txp->errcnt;
    351 	tx32p->stbcnt = (netbsd32_long)txp->stbcnt;
    352 }
    353 
    354 static __inline void
    355 netbsd32_to_timex(const struct netbsd32_timex *tx32p, struct timex *txp)
    356 {
    357 
    358 	txp->modes = tx32p->modes;
    359 	txp->offset = (long)tx32p->offset;
    360 	txp->freq = (long)tx32p->freq;
    361 	txp->maxerror = (long)tx32p->maxerror;
    362 	txp->esterror = (long)tx32p->esterror;
    363 	txp->status = tx32p->status;
    364 	txp->constant = (long)tx32p->constant;
    365 	txp->precision = (long)tx32p->precision;
    366 	txp->tolerance = (long)tx32p->tolerance;
    367 	txp->ppsfreq = (long)tx32p->ppsfreq;
    368 	txp->jitter = (long)tx32p->jitter;
    369 	txp->shift = tx32p->shift;
    370 	txp->stabil = (long)tx32p->stabil;
    371 	txp->jitcnt = (long)tx32p->jitcnt;
    372 	txp->calcnt = (long)tx32p->calcnt;
    373 	txp->errcnt = (long)tx32p->errcnt;
    374 	txp->stbcnt = (long)tx32p->stbcnt;
    375 }
    376 
    377 static __inline void
    378 netbsd32_from___stat13(const struct stat *sbp, struct netbsd32_stat13 *sb32p)
    379 {
    380 	memset(sb32p, 0, sizeof(*sb32p));
    381 	sb32p->st_dev = (uint32_t)sbp->st_dev;
    382 	sb32p->st_ino = sbp->st_ino;
    383 	sb32p->st_mode = sbp->st_mode;
    384 	sb32p->st_nlink = sbp->st_nlink;
    385 	sb32p->st_uid = sbp->st_uid;
    386 	sb32p->st_gid = sbp->st_gid;
    387 	sb32p->st_rdev = (uint32_t)sbp->st_rdev;
    388 	sb32p->st_size = sbp->st_size;
    389 	sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
    390 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
    391 	sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
    392 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
    393 	sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
    394 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
    395 	sb32p->st_blksize = sbp->st_blksize;
    396 	sb32p->st_blocks = sbp->st_blocks;
    397 	sb32p->st_flags = sbp->st_flags;
    398 	sb32p->st_gen = sbp->st_gen;
    399 	sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
    400 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
    401 }
    402 
    403 static __inline void
    404 netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p)
    405 {
    406 	memset(sb32p, 0, sizeof(*sb32p));
    407 	sb32p->st_dev = (uint32_t)sbp->st_dev;
    408 	sb32p->st_ino = sbp->st_ino;
    409 	sb32p->st_mode = sbp->st_mode;
    410 	sb32p->st_nlink = sbp->st_nlink;
    411 	sb32p->st_uid = sbp->st_uid;
    412 	sb32p->st_gid = sbp->st_gid;
    413 	sb32p->st_rdev = (uint32_t)sbp->st_rdev;
    414 	sb32p->st_size = sbp->st_size;
    415 	sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec;
    416 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
    417 	sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec;
    418 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
    419 	sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec;
    420 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
    421 	sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec;
    422 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
    423 	sb32p->st_blksize = sbp->st_blksize;
    424 	sb32p->st_blocks = sbp->st_blocks;
    425 	sb32p->st_flags = sbp->st_flags;
    426 	sb32p->st_gen = sbp->st_gen;
    427 }
    428 
    429 static __inline void
    430 netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p)
    431 {
    432 	memset(sb32p, 0, sizeof(*sb32p));
    433 	sb32p->st_dev = sbp->st_dev;
    434 	sb32p->st_ino = sbp->st_ino;
    435 	sb32p->st_mode = sbp->st_mode;
    436 	sb32p->st_nlink = sbp->st_nlink;
    437 	sb32p->st_uid = sbp->st_uid;
    438 	sb32p->st_gid = sbp->st_gid;
    439 	sb32p->st_rdev = sbp->st_rdev;
    440 	sb32p->st_size = sbp->st_size;
    441 	sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec;
    442 	sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec;
    443 	sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec;
    444 	sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec;
    445 	sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec;
    446 	sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec;
    447 	sb32p->st_birthtimespec.tv_sec = (netbsd32_time_t)sbp->st_birthtimespec.tv_sec;
    448 	sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec;
    449 	sb32p->st_blksize = sbp->st_blksize;
    450 	sb32p->st_blocks = sbp->st_blocks;
    451 	sb32p->st_flags = sbp->st_flags;
    452 	sb32p->st_gen = sbp->st_gen;
    453 }
    454 
    455 static __inline void
    456 netbsd32_to_ipc_perm(const struct netbsd32_ipc_perm *ip32p,
    457     struct ipc_perm *ipp)
    458 {
    459 
    460 	ipp->cuid = ip32p->cuid;
    461 	ipp->cgid = ip32p->cgid;
    462 	ipp->uid = ip32p->uid;
    463 	ipp->gid = ip32p->gid;
    464 	ipp->mode = ip32p->mode;
    465 	ipp->_seq = ip32p->_seq;
    466 	ipp->_key = (key_t)ip32p->_key;
    467 }
    468 
    469 static __inline void
    470 netbsd32_from_ipc_perm(const struct ipc_perm *ipp,
    471     struct netbsd32_ipc_perm *ip32p)
    472 {
    473 
    474 	ip32p->cuid = ipp->cuid;
    475 	ip32p->cgid = ipp->cgid;
    476 	ip32p->uid = ipp->uid;
    477 	ip32p->gid = ipp->gid;
    478 	ip32p->mode = ipp->mode;
    479 	ip32p->_seq = ipp->_seq;
    480 	ip32p->_key = (netbsd32_key_t)ipp->_key;
    481 }
    482 
    483 static __inline void
    484 netbsd32_to_msg(const struct netbsd32_msg *m32p, struct msg *mp)
    485 {
    486 
    487 	mp->msg_next = NETBSD32PTR64(m32p->msg_next);
    488 	mp->msg_type = (long)m32p->msg_type;
    489 	mp->msg_ts = m32p->msg_ts;
    490 	mp->msg_spot = m32p->msg_spot;
    491 }
    492 
    493 static __inline void
    494 netbsd32_from_msg(const struct msg *mp, struct netbsd32_msg *m32p)
    495 {
    496 
    497 	NETBSD32PTR32(m32p->msg_next, mp->msg_next);
    498 	m32p->msg_type = (netbsd32_long)mp->msg_type;
    499 	m32p->msg_ts = mp->msg_ts;
    500 	m32p->msg_spot = mp->msg_spot;
    501 }
    502 
    503 static __inline void
    504 netbsd32_to_msqid_ds50(const struct netbsd32_msqid_ds50 *ds32p,
    505     struct msqid_ds *dsp)
    506 {
    507 
    508 	netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm);
    509 	dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes;
    510 	dsp->msg_qnum = (u_long)ds32p->msg_qnum;
    511 	dsp->msg_qbytes = (u_long)ds32p->msg_qbytes;
    512 	dsp->msg_lspid = ds32p->msg_lspid;
    513 	dsp->msg_lrpid = ds32p->msg_lrpid;
    514 	dsp->msg_rtime = (time_t)ds32p->msg_rtime;
    515 	dsp->msg_stime = (time_t)ds32p->msg_stime;
    516 	dsp->msg_ctime = (time_t)ds32p->msg_ctime;
    517 }
    518 
    519 static __inline void
    520 netbsd32_to_msqid_ds(const struct netbsd32_msqid_ds *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_from_msqid_ds50(const struct msqid_ds *dsp,
    537     struct netbsd32_msqid_ds50 *ds32p)
    538 {
    539 
    540 	netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm);
    541 	ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes;
    542 	ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum;
    543 	ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes;
    544 	ds32p->msg_lspid = dsp->msg_lspid;
    545 	ds32p->msg_lrpid = dsp->msg_lrpid;
    546 	ds32p->msg_rtime = (int32_t)dsp->msg_rtime;
    547 	ds32p->msg_stime = (int32_t)dsp->msg_stime;
    548 	ds32p->msg_ctime = (int32_t)dsp->msg_ctime;
    549 }
    550 
    551 static __inline void
    552 netbsd32_from_msqid_ds(const struct msqid_ds *dsp,
    553     struct netbsd32_msqid_ds *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 = dsp->msg_rtime;
    563 	ds32p->msg_stime = dsp->msg_stime;
    564 	ds32p->msg_ctime = dsp->msg_ctime;
    565 }
    566 
    567 static __inline void
    568 netbsd32_to_shmid_ds50(const struct netbsd32_shmid_ds50 *ds32p,
    569     struct shmid_ds *dsp)
    570 {
    571 
    572 	netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm);
    573 	dsp->shm_segsz = ds32p->shm_segsz;
    574 	dsp->shm_lpid = ds32p->shm_lpid;
    575 	dsp->shm_cpid = ds32p->shm_cpid;
    576 	dsp->shm_nattch = ds32p->shm_nattch;
    577 	dsp->shm_atime = (time_t)ds32p->shm_atime;
    578 	dsp->shm_dtime = (time_t)ds32p->shm_dtime;
    579 	dsp->shm_ctime = (time_t)ds32p->shm_ctime;
    580 	dsp->_shm_internal = NETBSD32PTR64(ds32p->_shm_internal);
    581 }
    582 
    583 static __inline void
    584 netbsd32_to_shmid_ds(const struct netbsd32_shmid_ds *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 = (long)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_from_shmid_ds50(const struct shmid_ds *dsp,
    601     struct netbsd32_shmid_ds50 *ds32p)
    602 {
    603 
    604 	netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm);
    605 	ds32p->shm_segsz = dsp->shm_segsz;
    606 	ds32p->shm_lpid = dsp->shm_lpid;
    607 	ds32p->shm_cpid = dsp->shm_cpid;
    608 	ds32p->shm_nattch = dsp->shm_nattch;
    609 	ds32p->shm_atime = (int32_t)dsp->shm_atime;
    610 	ds32p->shm_dtime = (int32_t)dsp->shm_dtime;
    611 	ds32p->shm_ctime = (int32_t)dsp->shm_ctime;
    612 	NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal);
    613 }
    614 
    615 static __inline void
    616 netbsd32_from_shmid_ds(const struct shmid_ds *dsp,
    617     struct netbsd32_shmid_ds *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 = (netbsd32_long)dsp->shm_atime;
    626 	ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime;
    627 	ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime;
    628 	NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal);
    629 }
    630 
    631 static __inline void
    632 netbsd32_to_semid_ds50(const struct netbsd32_semid_ds50 *s32dsp,
    633     struct semid_ds *dsp)
    634 {
    635 
    636 	netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
    637 	dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base);
    638 	dsp->sem_nsems = (time_t)s32dsp->sem_nsems;
    639 	dsp->sem_otime = (time_t)s32dsp->sem_otime;
    640 	dsp->sem_ctime = (time_t)s32dsp->sem_ctime;
    641 }
    642 
    643 static __inline void
    644 netbsd32_to_semid_ds(const struct netbsd32_semid_ds *s32dsp,
    645     struct semid_ds *dsp)
    646 {
    647 
    648 	netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm);
    649 	dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base);
    650 	dsp->sem_nsems = s32dsp->sem_nsems;
    651 	dsp->sem_otime = s32dsp->sem_otime;
    652 	dsp->sem_ctime = s32dsp->sem_ctime;
    653 }
    654 
    655 static __inline void
    656 netbsd32_from_semid_ds50(const struct semid_ds *dsp,
    657     struct netbsd32_semid_ds50 *s32dsp)
    658 {
    659 
    660 	netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
    661 	NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base);
    662 	s32dsp->sem_nsems = (int32_t)dsp->sem_nsems;
    663 	s32dsp->sem_otime = (int32_t)dsp->sem_otime;
    664 	s32dsp->sem_ctime = (int32_t)dsp->sem_ctime;
    665 }
    666 
    667 static __inline void
    668 netbsd32_from_semid_ds(const struct semid_ds *dsp,
    669     struct netbsd32_semid_ds *s32dsp)
    670 {
    671 
    672 	netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm);
    673 	NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base);
    674 	s32dsp->sem_nsems = dsp->sem_nsems;
    675 	s32dsp->sem_otime = dsp->sem_otime;
    676 	s32dsp->sem_ctime = dsp->sem_ctime;
    677 }
    678 
    679 static __inline void
    680 netbsd32_from_loadavg(struct netbsd32_loadavg *av32,
    681     const struct loadavg *av)
    682 {
    683 
    684 	av32->ldavg[0] = av->ldavg[0];
    685 	av32->ldavg[1] = av->ldavg[1];
    686 	av32->ldavg[2] = av->ldavg[2];
    687 	av32->fscale = (netbsd32_long)av->fscale;
    688 }
    689 
    690 static __inline void
    691 netbsd32_to_kevent(struct netbsd32_kevent *ke32, struct kevent *ke)
    692 {
    693 	ke->ident = ke32->ident;
    694 	ke->filter = ke32->filter;
    695 	ke->flags = ke32->flags;
    696 	ke->fflags = ke32->fflags;
    697 	ke->data = ke32->data;
    698 	ke->udata = ke32->udata;
    699 }
    700 
    701 static __inline void
    702 netbsd32_from_kevent(struct kevent *ke, struct netbsd32_kevent *ke32)
    703 {
    704 	ke32->ident = ke->ident;
    705 	ke32->filter = ke->filter;
    706 	ke32->flags = ke->flags;
    707 	ke32->fflags = ke->fflags;
    708 	ke32->data = ke->data;
    709 	ke32->udata = ke->udata;
    710 }
    711 
    712 static __inline void
    713 netbsd32_to_sigevent(const struct netbsd32_sigevent *ev32, struct sigevent *ev)
    714 {
    715 	ev->sigev_notify = ev32->sigev_notify;
    716 	ev->sigev_signo = ev32->sigev_signo;
    717 	/*
    718 	 * XXX sival_ptr, sigev_notify_function and
    719 	 *     sigev_notify_attributes are  currently unused
    720 	 */
    721 	ev->sigev_value.sival_int = ev32->sigev_value.sival_int;
    722 	ev->sigev_notify_function = NETBSD32PTR64(ev32->sigev_notify_function);
    723 	ev->sigev_notify_attributes = NETBSD32PTR64(ev32->sigev_notify_attributes);
    724 }
    725 
    726 static __inline int
    727 netbsd32_to_dirent12(char *buf, int nbytes)
    728 {
    729 	struct dirent *ndp, *nndp, *endp;
    730 	struct dirent12 *odp;
    731 
    732 	odp = (struct dirent12 *)(void *)buf;
    733 	ndp = (struct dirent *)(void *)buf;
    734 	endp = (struct dirent *)(void *)&buf[nbytes];
    735 
    736 	/*
    737 	 * In-place conversion. This works because odp
    738 	 * is smaller than ndp, but it has to be done
    739 	 * in the right sequence.
    740 	 */
    741 	for (; ndp < endp; ndp = nndp) {
    742 		nndp = _DIRENT_NEXT(ndp);
    743 		odp->d_fileno = (u_int32_t)ndp->d_fileno;
    744 		if (ndp->d_namlen >= sizeof(odp->d_name))
    745 			odp->d_namlen = sizeof(odp->d_name) - 1;
    746 		else
    747 			odp->d_namlen = (u_int8_t)ndp->d_namlen;
    748 		odp->d_type = ndp->d_type;
    749 		(void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen);
    750 		odp->d_name[odp->d_namlen] = '\0';
    751 		odp->d_reclen = _DIRENT_SIZE(odp);
    752 		odp = _DIRENT_NEXT(odp);
    753 	}
    754 	return ((char *)(void *)odp) - buf;
    755 }
    756 
    757 static inline int
    758 netbsd32_copyin_plistref(netbsd32_pointer_t n32p, struct plistref *p)
    759 {
    760 	struct netbsd32_plistref n32plist;
    761 	int error;
    762 
    763 	error = copyin(NETBSD32PTR64(n32p), &n32plist,
    764 	    sizeof(struct netbsd32_plistref));
    765 	if (error)
    766 		return error;
    767 	p->pref_plist = NETBSD32PTR64(n32plist.pref_plist);
    768 	p->pref_len = n32plist.pref_len;
    769 	return 0;
    770 }
    771 
    772 static inline int
    773 netbsd32_copyout_plistref(netbsd32_pointer_t n32p, struct plistref *p)
    774 {
    775 	struct netbsd32_plistref n32plist;
    776 
    777 	NETBSD32PTR32(n32plist.pref_plist, p->pref_plist);
    778 	n32plist.pref_len = p->pref_len;
    779 	return copyout(&n32plist, NETBSD32PTR64(n32p),
    780 	    sizeof(struct netbsd32_plistref));
    781 }
    782 
    783 static __inline void
    784 netbsd32_to_mq_attr(const struct netbsd32_mq_attr *a32,
    785     struct mq_attr *attr)
    786 {
    787 	attr->mq_flags = a32->mq_flags;
    788 	attr->mq_maxmsg = a32->mq_maxmsg;
    789 	attr->mq_msgsize = a32->mq_msgsize;
    790 	attr->mq_curmsgs = a32->mq_curmsgs;
    791 }
    792 
    793 static __inline void
    794 netbsd32_from_mq_attr(const struct mq_attr *attr,
    795 	struct netbsd32_mq_attr *a32)
    796 {
    797 	a32->mq_flags = attr->mq_flags;
    798 	a32->mq_maxmsg = attr->mq_maxmsg;
    799 	a32->mq_msgsize = attr->mq_msgsize;
    800 	a32->mq_curmsgs = attr->mq_curmsgs;
    801 }
    802 
    803 #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */
    804