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