1 /* $NetBSD: netbsd32_conv.h,v 1.28 2014/03/18 18:20:41 riastradh 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 memset(sb32p, 0, sizeof(*sb32p)); 387 sb32p->st_dev = (uint32_t)sbp->st_dev; 388 sb32p->st_ino = sbp->st_ino; 389 sb32p->st_mode = sbp->st_mode; 390 sb32p->st_nlink = sbp->st_nlink; 391 sb32p->st_uid = sbp->st_uid; 392 sb32p->st_gid = sbp->st_gid; 393 sb32p->st_rdev = (uint32_t)sbp->st_rdev; 394 sb32p->st_size = sbp->st_size; 395 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec; 396 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 397 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec; 398 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 399 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec; 400 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec; 401 sb32p->st_blksize = sbp->st_blksize; 402 sb32p->st_blocks = sbp->st_blocks; 403 sb32p->st_flags = sbp->st_flags; 404 sb32p->st_gen = sbp->st_gen; 405 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec; 406 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec; 407 } 408 409 static __inline void 410 netbsd32_from___stat50(const struct stat *sbp, struct netbsd32_stat50 *sb32p) 411 { 412 memset(sb32p, 0, sizeof(*sb32p)); 413 sb32p->st_dev = (uint32_t)sbp->st_dev; 414 sb32p->st_ino = sbp->st_ino; 415 sb32p->st_mode = sbp->st_mode; 416 sb32p->st_nlink = sbp->st_nlink; 417 sb32p->st_uid = sbp->st_uid; 418 sb32p->st_gid = sbp->st_gid; 419 sb32p->st_rdev = (uint32_t)sbp->st_rdev; 420 sb32p->st_size = sbp->st_size; 421 sb32p->st_atimespec.tv_sec = (int32_t)sbp->st_atimespec.tv_sec; 422 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 423 sb32p->st_mtimespec.tv_sec = (int32_t)sbp->st_mtimespec.tv_sec; 424 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 425 sb32p->st_ctimespec.tv_sec = (int32_t)sbp->st_ctimespec.tv_sec; 426 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec; 427 sb32p->st_birthtimespec.tv_sec = (int32_t)sbp->st_birthtimespec.tv_sec; 428 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec; 429 sb32p->st_blksize = sbp->st_blksize; 430 sb32p->st_blocks = sbp->st_blocks; 431 sb32p->st_flags = sbp->st_flags; 432 sb32p->st_gen = sbp->st_gen; 433 } 434 435 static __inline void 436 netbsd32_from_stat(const struct stat *sbp, struct netbsd32_stat *sb32p) 437 { 438 memset(sb32p, 0, sizeof(*sb32p)); 439 sb32p->st_dev = sbp->st_dev; 440 sb32p->st_ino = sbp->st_ino; 441 sb32p->st_mode = sbp->st_mode; 442 sb32p->st_nlink = sbp->st_nlink; 443 sb32p->st_uid = sbp->st_uid; 444 sb32p->st_gid = sbp->st_gid; 445 sb32p->st_rdev = sbp->st_rdev; 446 sb32p->st_size = sbp->st_size; 447 sb32p->st_atimespec.tv_sec = (netbsd32_time_t)sbp->st_atimespec.tv_sec; 448 sb32p->st_atimespec.tv_nsec = (netbsd32_long)sbp->st_atimespec.tv_nsec; 449 sb32p->st_mtimespec.tv_sec = (netbsd32_time_t)sbp->st_mtimespec.tv_sec; 450 sb32p->st_mtimespec.tv_nsec = (netbsd32_long)sbp->st_mtimespec.tv_nsec; 451 sb32p->st_ctimespec.tv_sec = (netbsd32_time_t)sbp->st_ctimespec.tv_sec; 452 sb32p->st_ctimespec.tv_nsec = (netbsd32_long)sbp->st_ctimespec.tv_nsec; 453 sb32p->st_birthtimespec.tv_sec = (netbsd32_time_t)sbp->st_birthtimespec.tv_sec; 454 sb32p->st_birthtimespec.tv_nsec = (netbsd32_long)sbp->st_birthtimespec.tv_nsec; 455 sb32p->st_blksize = sbp->st_blksize; 456 sb32p->st_blocks = sbp->st_blocks; 457 sb32p->st_flags = sbp->st_flags; 458 sb32p->st_gen = sbp->st_gen; 459 } 460 461 static __inline void 462 netbsd32_to_ipc_perm(const struct netbsd32_ipc_perm *ip32p, 463 struct ipc_perm *ipp) 464 { 465 466 ipp->cuid = ip32p->cuid; 467 ipp->cgid = ip32p->cgid; 468 ipp->uid = ip32p->uid; 469 ipp->gid = ip32p->gid; 470 ipp->mode = ip32p->mode; 471 ipp->_seq = ip32p->_seq; 472 ipp->_key = (key_t)ip32p->_key; 473 } 474 475 static __inline void 476 netbsd32_from_ipc_perm(const struct ipc_perm *ipp, 477 struct netbsd32_ipc_perm *ip32p) 478 { 479 480 ip32p->cuid = ipp->cuid; 481 ip32p->cgid = ipp->cgid; 482 ip32p->uid = ipp->uid; 483 ip32p->gid = ipp->gid; 484 ip32p->mode = ipp->mode; 485 ip32p->_seq = ipp->_seq; 486 ip32p->_key = (netbsd32_key_t)ipp->_key; 487 } 488 489 static __inline void 490 netbsd32_to_msg(const struct netbsd32_msg *m32p, struct msg *mp) 491 { 492 493 mp->msg_next = NETBSD32PTR64(m32p->msg_next); 494 mp->msg_type = (long)m32p->msg_type; 495 mp->msg_ts = m32p->msg_ts; 496 mp->msg_spot = m32p->msg_spot; 497 } 498 499 static __inline void 500 netbsd32_from_msg(const struct msg *mp, struct netbsd32_msg *m32p) 501 { 502 503 NETBSD32PTR32(m32p->msg_next, mp->msg_next); 504 m32p->msg_type = (netbsd32_long)mp->msg_type; 505 m32p->msg_ts = mp->msg_ts; 506 m32p->msg_spot = mp->msg_spot; 507 } 508 509 static __inline void 510 netbsd32_to_msqid_ds50(const struct netbsd32_msqid_ds50 *ds32p, 511 struct msqid_ds *dsp) 512 { 513 514 netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm); 515 dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes; 516 dsp->msg_qnum = (u_long)ds32p->msg_qnum; 517 dsp->msg_qbytes = (u_long)ds32p->msg_qbytes; 518 dsp->msg_lspid = ds32p->msg_lspid; 519 dsp->msg_lrpid = ds32p->msg_lrpid; 520 dsp->msg_rtime = (time_t)ds32p->msg_rtime; 521 dsp->msg_stime = (time_t)ds32p->msg_stime; 522 dsp->msg_ctime = (time_t)ds32p->msg_ctime; 523 } 524 525 static __inline void 526 netbsd32_to_msqid_ds(const struct netbsd32_msqid_ds *ds32p, 527 struct msqid_ds *dsp) 528 { 529 530 netbsd32_to_ipc_perm(&ds32p->msg_perm, &dsp->msg_perm); 531 dsp->_msg_cbytes = (u_long)ds32p->_msg_cbytes; 532 dsp->msg_qnum = (u_long)ds32p->msg_qnum; 533 dsp->msg_qbytes = (u_long)ds32p->msg_qbytes; 534 dsp->msg_lspid = ds32p->msg_lspid; 535 dsp->msg_lrpid = ds32p->msg_lrpid; 536 dsp->msg_rtime = (time_t)ds32p->msg_rtime; 537 dsp->msg_stime = (time_t)ds32p->msg_stime; 538 dsp->msg_ctime = (time_t)ds32p->msg_ctime; 539 } 540 541 static __inline void 542 netbsd32_from_msqid_ds50(const struct msqid_ds *dsp, 543 struct netbsd32_msqid_ds50 *ds32p) 544 { 545 546 netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm); 547 ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes; 548 ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum; 549 ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes; 550 ds32p->msg_lspid = dsp->msg_lspid; 551 ds32p->msg_lrpid = dsp->msg_lrpid; 552 ds32p->msg_rtime = (int32_t)dsp->msg_rtime; 553 ds32p->msg_stime = (int32_t)dsp->msg_stime; 554 ds32p->msg_ctime = (int32_t)dsp->msg_ctime; 555 } 556 557 static __inline void 558 netbsd32_from_msqid_ds(const struct msqid_ds *dsp, 559 struct netbsd32_msqid_ds *ds32p) 560 { 561 562 netbsd32_from_ipc_perm(&dsp->msg_perm, &ds32p->msg_perm); 563 ds32p->_msg_cbytes = (netbsd32_u_long)dsp->_msg_cbytes; 564 ds32p->msg_qnum = (netbsd32_u_long)dsp->msg_qnum; 565 ds32p->msg_qbytes = (netbsd32_u_long)dsp->msg_qbytes; 566 ds32p->msg_lspid = dsp->msg_lspid; 567 ds32p->msg_lrpid = dsp->msg_lrpid; 568 ds32p->msg_rtime = dsp->msg_rtime; 569 ds32p->msg_stime = dsp->msg_stime; 570 ds32p->msg_ctime = dsp->msg_ctime; 571 } 572 573 static __inline void 574 netbsd32_to_shmid_ds50(const struct netbsd32_shmid_ds50 *ds32p, 575 struct shmid_ds *dsp) 576 { 577 578 netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm); 579 dsp->shm_segsz = ds32p->shm_segsz; 580 dsp->shm_lpid = ds32p->shm_lpid; 581 dsp->shm_cpid = ds32p->shm_cpid; 582 dsp->shm_nattch = ds32p->shm_nattch; 583 dsp->shm_atime = (time_t)ds32p->shm_atime; 584 dsp->shm_dtime = (time_t)ds32p->shm_dtime; 585 dsp->shm_ctime = (time_t)ds32p->shm_ctime; 586 dsp->_shm_internal = NETBSD32PTR64(ds32p->_shm_internal); 587 } 588 589 static __inline void 590 netbsd32_to_shmid_ds(const struct netbsd32_shmid_ds *ds32p, 591 struct shmid_ds *dsp) 592 { 593 594 netbsd32_to_ipc_perm(&ds32p->shm_perm, &dsp->shm_perm); 595 dsp->shm_segsz = ds32p->shm_segsz; 596 dsp->shm_lpid = ds32p->shm_lpid; 597 dsp->shm_cpid = ds32p->shm_cpid; 598 dsp->shm_nattch = ds32p->shm_nattch; 599 dsp->shm_atime = (long)ds32p->shm_atime; 600 dsp->shm_dtime = (time_t)ds32p->shm_dtime; 601 dsp->shm_ctime = (time_t)ds32p->shm_ctime; 602 dsp->_shm_internal = NETBSD32PTR64(ds32p->_shm_internal); 603 } 604 605 static __inline void 606 netbsd32_from_shmid_ds50(const struct shmid_ds *dsp, 607 struct netbsd32_shmid_ds50 *ds32p) 608 { 609 610 netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm); 611 ds32p->shm_segsz = dsp->shm_segsz; 612 ds32p->shm_lpid = dsp->shm_lpid; 613 ds32p->shm_cpid = dsp->shm_cpid; 614 ds32p->shm_nattch = dsp->shm_nattch; 615 ds32p->shm_atime = (int32_t)dsp->shm_atime; 616 ds32p->shm_dtime = (int32_t)dsp->shm_dtime; 617 ds32p->shm_ctime = (int32_t)dsp->shm_ctime; 618 NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal); 619 } 620 621 static __inline void 622 netbsd32_from_shmid_ds(const struct shmid_ds *dsp, 623 struct netbsd32_shmid_ds *ds32p) 624 { 625 626 netbsd32_from_ipc_perm(&dsp->shm_perm, &ds32p->shm_perm); 627 ds32p->shm_segsz = dsp->shm_segsz; 628 ds32p->shm_lpid = dsp->shm_lpid; 629 ds32p->shm_cpid = dsp->shm_cpid; 630 ds32p->shm_nattch = dsp->shm_nattch; 631 ds32p->shm_atime = (netbsd32_long)dsp->shm_atime; 632 ds32p->shm_dtime = (netbsd32_long)dsp->shm_dtime; 633 ds32p->shm_ctime = (netbsd32_long)dsp->shm_ctime; 634 NETBSD32PTR32(ds32p->_shm_internal, dsp->_shm_internal); 635 } 636 637 static __inline void 638 netbsd32_to_semid_ds50(const struct netbsd32_semid_ds50 *s32dsp, 639 struct semid_ds *dsp) 640 { 641 642 netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm); 643 dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base); 644 dsp->sem_nsems = (time_t)s32dsp->sem_nsems; 645 dsp->sem_otime = (time_t)s32dsp->sem_otime; 646 dsp->sem_ctime = (time_t)s32dsp->sem_ctime; 647 } 648 649 static __inline void 650 netbsd32_to_semid_ds(const struct netbsd32_semid_ds *s32dsp, 651 struct semid_ds *dsp) 652 { 653 654 netbsd32_to_ipc_perm(&s32dsp->sem_perm, &dsp->sem_perm); 655 dsp->_sem_base = NETBSD32PTR64(s32dsp->_sem_base); 656 dsp->sem_nsems = s32dsp->sem_nsems; 657 dsp->sem_otime = s32dsp->sem_otime; 658 dsp->sem_ctime = s32dsp->sem_ctime; 659 } 660 661 static __inline void 662 netbsd32_from_semid_ds50(const struct semid_ds *dsp, 663 struct netbsd32_semid_ds50 *s32dsp) 664 { 665 666 netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm); 667 NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base); 668 s32dsp->sem_nsems = (int32_t)dsp->sem_nsems; 669 s32dsp->sem_otime = (int32_t)dsp->sem_otime; 670 s32dsp->sem_ctime = (int32_t)dsp->sem_ctime; 671 } 672 673 static __inline void 674 netbsd32_from_semid_ds(const struct semid_ds *dsp, 675 struct netbsd32_semid_ds *s32dsp) 676 { 677 678 netbsd32_from_ipc_perm(&dsp->sem_perm, &s32dsp->sem_perm); 679 NETBSD32PTR32(s32dsp->_sem_base, dsp->_sem_base); 680 s32dsp->sem_nsems = dsp->sem_nsems; 681 s32dsp->sem_otime = dsp->sem_otime; 682 s32dsp->sem_ctime = dsp->sem_ctime; 683 } 684 685 static __inline void 686 netbsd32_from_loadavg(struct netbsd32_loadavg *av32, 687 const struct loadavg *av) 688 { 689 690 av32->ldavg[0] = av->ldavg[0]; 691 av32->ldavg[1] = av->ldavg[1]; 692 av32->ldavg[2] = av->ldavg[2]; 693 av32->fscale = (netbsd32_long)av->fscale; 694 } 695 696 static __inline void 697 netbsd32_to_kevent(struct netbsd32_kevent *ke32, struct kevent *ke) 698 { 699 ke->ident = ke32->ident; 700 ke->filter = ke32->filter; 701 ke->flags = ke32->flags; 702 ke->fflags = ke32->fflags; 703 ke->data = ke32->data; 704 ke->udata = ke32->udata; 705 } 706 707 static __inline void 708 netbsd32_from_kevent(struct kevent *ke, struct netbsd32_kevent *ke32) 709 { 710 ke32->ident = ke->ident; 711 ke32->filter = ke->filter; 712 ke32->flags = ke->flags; 713 ke32->fflags = ke->fflags; 714 ke32->data = ke->data; 715 ke32->udata = ke->udata; 716 } 717 718 static __inline void 719 netbsd32_to_sigevent(const struct netbsd32_sigevent *ev32, struct sigevent *ev) 720 { 721 ev->sigev_notify = ev32->sigev_notify; 722 ev->sigev_signo = ev32->sigev_signo; 723 /* 724 * XXX sival_ptr, sigev_notify_function and 725 * sigev_notify_attributes are currently unused 726 */ 727 ev->sigev_value.sival_int = ev32->sigev_value.sival_int; 728 ev->sigev_notify_function = NETBSD32PTR64(ev32->sigev_notify_function); 729 ev->sigev_notify_attributes = NETBSD32PTR64(ev32->sigev_notify_attributes); 730 } 731 732 static __inline int 733 netbsd32_to_dirent12(char *buf, int nbytes) 734 { 735 struct dirent *ndp, *nndp, *endp; 736 struct dirent12 *odp; 737 738 odp = (struct dirent12 *)(void *)buf; 739 ndp = (struct dirent *)(void *)buf; 740 endp = (struct dirent *)(void *)&buf[nbytes]; 741 742 /* 743 * In-place conversion. This works because odp 744 * is smaller than ndp, but it has to be done 745 * in the right sequence. 746 */ 747 for (; ndp < endp; ndp = nndp) { 748 nndp = _DIRENT_NEXT(ndp); 749 odp->d_fileno = (u_int32_t)ndp->d_fileno; 750 if (ndp->d_namlen >= sizeof(odp->d_name)) 751 odp->d_namlen = sizeof(odp->d_name) - 1; 752 else 753 odp->d_namlen = (u_int8_t)ndp->d_namlen; 754 odp->d_type = ndp->d_type; 755 (void)memcpy(odp->d_name, ndp->d_name, (size_t)odp->d_namlen); 756 odp->d_name[odp->d_namlen] = '\0'; 757 odp->d_reclen = _DIRENT_SIZE(odp); 758 odp = _DIRENT_NEXT(odp); 759 } 760 return ((char *)(void *)odp) - buf; 761 } 762 763 static inline int 764 netbsd32_copyin_plistref(netbsd32_pointer_t n32p, struct plistref *p) 765 { 766 struct netbsd32_plistref n32plist; 767 int error; 768 769 error = copyin(NETBSD32PTR64(n32p), &n32plist, 770 sizeof(struct netbsd32_plistref)); 771 if (error) 772 return error; 773 p->pref_plist = NETBSD32PTR64(n32plist.pref_plist); 774 p->pref_len = n32plist.pref_len; 775 return 0; 776 } 777 778 static inline int 779 netbsd32_copyout_plistref(netbsd32_pointer_t n32p, struct plistref *p) 780 { 781 struct netbsd32_plistref n32plist; 782 783 NETBSD32PTR32(n32plist.pref_plist, p->pref_plist); 784 n32plist.pref_len = p->pref_len; 785 return copyout(&n32plist, NETBSD32PTR64(n32p), 786 sizeof(struct netbsd32_plistref)); 787 } 788 789 #endif /* _COMPAT_NETBSD32_NETBSD32_CONV_H_ */ 790