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