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