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