freebsd32_misc.c revision 161343
1/*- 2 * Copyright (c) 2002 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/compat/freebsd32/freebsd32_misc.c 161343 2006-08-16 00:02:36Z jkim $"); 29 30#include "opt_compat.h" 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/bus.h> 35#include <sys/exec.h> 36#include <sys/fcntl.h> 37#include <sys/filedesc.h> 38#include <sys/namei.h> 39#include <sys/imgact.h> 40#include <sys/kernel.h> 41#include <sys/limits.h> 42#include <sys/lock.h> 43#include <sys/malloc.h> 44#include <sys/file.h> /* Must come after sys/malloc.h */ 45#include <sys/mbuf.h> 46#include <sys/mman.h> 47#include <sys/module.h> 48#include <sys/mount.h> 49#include <sys/mutex.h> 50#include <sys/namei.h> 51#include <sys/param.h> 52#include <sys/proc.h> 53#include <sys/reboot.h> 54#include <sys/resource.h> 55#include <sys/resourcevar.h> 56#include <sys/selinfo.h> 57#include <sys/eventvar.h> /* Must come after sys/selinfo.h */ 58#include <sys/pipe.h> /* Must come after sys/selinfo.h */ 59#include <sys/signal.h> 60#include <sys/signalvar.h> 61#include <sys/socket.h> 62#include <sys/socketvar.h> 63#include <sys/stat.h> 64#include <sys/syscall.h> 65#include <sys/syscallsubr.h> 66#include <sys/sysctl.h> 67#include <sys/sysent.h> 68#include <sys/sysproto.h> 69#include <sys/systm.h> 70#include <sys/unistd.h> 71#include <sys/vnode.h> 72#include <sys/wait.h> 73#include <sys/ipc.h> 74#include <sys/shm.h> 75 76#include <vm/vm.h> 77#include <vm/vm_kern.h> 78#include <vm/vm_param.h> 79#include <vm/pmap.h> 80#include <vm/vm_map.h> 81#include <vm/vm_object.h> 82#include <vm/vm_extern.h> 83 84#include <machine/cpu.h> 85 86#include <compat/freebsd32/freebsd32_util.h> 87#include <compat/freebsd32/freebsd32.h> 88#include <compat/freebsd32/freebsd32_proto.h> 89 90CTASSERT(sizeof(struct timeval32) == 8); 91CTASSERT(sizeof(struct timespec32) == 8); 92CTASSERT(sizeof(struct statfs32) == 256); 93CTASSERT(sizeof(struct rusage32) == 72); 94 95int 96freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap) 97{ 98 int error, status; 99 struct rusage32 ru32; 100 struct rusage ru, *rup; 101 102 if (uap->rusage != NULL) 103 rup = &ru; 104 else 105 rup = NULL; 106 error = kern_wait(td, uap->pid, &status, uap->options, rup); 107 if (error) 108 return (error); 109 if (uap->status != NULL) 110 error = copyout(&status, uap->status, sizeof(status)); 111 if (uap->rusage != NULL && error == 0) { 112 TV_CP(ru, ru32, ru_utime); 113 TV_CP(ru, ru32, ru_stime); 114 CP(ru, ru32, ru_maxrss); 115 CP(ru, ru32, ru_ixrss); 116 CP(ru, ru32, ru_idrss); 117 CP(ru, ru32, ru_isrss); 118 CP(ru, ru32, ru_minflt); 119 CP(ru, ru32, ru_majflt); 120 CP(ru, ru32, ru_nswap); 121 CP(ru, ru32, ru_inblock); 122 CP(ru, ru32, ru_oublock); 123 CP(ru, ru32, ru_msgsnd); 124 CP(ru, ru32, ru_msgrcv); 125 CP(ru, ru32, ru_nsignals); 126 CP(ru, ru32, ru_nvcsw); 127 CP(ru, ru32, ru_nivcsw); 128 error = copyout(&ru32, uap->rusage, sizeof(ru32)); 129 } 130 return (error); 131} 132 133#ifdef COMPAT_FREEBSD4 134static void 135copy_statfs(struct statfs *in, struct statfs32 *out) 136{ 137 138 bzero(out, sizeof(*out)); 139 CP(*in, *out, f_bsize); 140 CP(*in, *out, f_iosize); 141 CP(*in, *out, f_blocks); 142 CP(*in, *out, f_bfree); 143 CP(*in, *out, f_bavail); 144 CP(*in, *out, f_files); 145 CP(*in, *out, f_ffree); 146 CP(*in, *out, f_fsid); 147 CP(*in, *out, f_owner); 148 CP(*in, *out, f_type); 149 CP(*in, *out, f_flags); 150 CP(*in, *out, f_flags); 151 CP(*in, *out, f_syncwrites); 152 CP(*in, *out, f_asyncwrites); 153 strlcpy(out->f_fstypename, 154 in->f_fstypename, MFSNAMELEN); 155 strlcpy(out->f_mntonname, 156 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN)); 157 CP(*in, *out, f_syncreads); 158 CP(*in, *out, f_asyncreads); 159 strlcpy(out->f_mntfromname, 160 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN)); 161} 162#endif 163 164#ifdef COMPAT_FREEBSD4 165int 166freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap) 167{ 168 struct statfs *buf, *sp; 169 struct statfs32 stat32; 170 size_t count, size; 171 int error; 172 173 count = uap->bufsize / sizeof(struct statfs32); 174 size = count * sizeof(struct statfs); 175 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags); 176 if (size > 0) { 177 count = td->td_retval[0]; 178 sp = buf; 179 while (count > 0 && error == 0) { 180 copy_statfs(sp, &stat32); 181 error = copyout(&stat32, uap->buf, sizeof(stat32)); 182 sp++; 183 uap->buf++; 184 count--; 185 } 186 free(buf, M_TEMP); 187 } 188 return (error); 189} 190#endif 191 192struct sigaltstack32 { 193 u_int32_t ss_sp; 194 u_int32_t ss_size; 195 int ss_flags; 196}; 197 198CTASSERT(sizeof(struct sigaltstack32) == 12); 199 200int 201freebsd32_sigaltstack(struct thread *td, 202 struct freebsd32_sigaltstack_args *uap) 203{ 204 struct sigaltstack32 s32; 205 struct sigaltstack ss, oss, *ssp; 206 int error; 207 208 if (uap->ss != NULL) { 209 error = copyin(uap->ss, &s32, sizeof(s32)); 210 if (error) 211 return (error); 212 PTRIN_CP(s32, ss, ss_sp); 213 CP(s32, ss, ss_size); 214 CP(s32, ss, ss_flags); 215 ssp = &ss; 216 } else 217 ssp = NULL; 218 error = kern_sigaltstack(td, ssp, &oss); 219 if (error == 0 && uap->oss != NULL) { 220 PTROUT_CP(oss, s32, ss_sp); 221 CP(oss, s32, ss_size); 222 CP(oss, s32, ss_flags); 223 error = copyout(&s32, uap->oss, sizeof(s32)); 224 } 225 return (error); 226} 227 228/* 229 * Custom version of exec_copyin_args() so that we can translate 230 * the pointers. 231 */ 232static int 233freebsd32_exec_copyin_args(struct image_args *args, char *fname, 234 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv) 235{ 236 char *argp, *envp; 237 u_int32_t *p32, arg; 238 size_t length; 239 int error; 240 241 bzero(args, sizeof(*args)); 242 if (argv == NULL) 243 return (EFAULT); 244 245 /* 246 * Allocate temporary demand zeroed space for argument and 247 * environment strings 248 */ 249 args->buf = (char *) kmem_alloc_wait(exec_map, 250 PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); 251 if (args->buf == NULL) 252 return (ENOMEM); 253 args->begin_argv = args->buf; 254 args->endp = args->begin_argv; 255 args->stringspace = ARG_MAX; 256 257 args->fname = args->buf + ARG_MAX; 258 259 /* 260 * Copy the file name. 261 */ 262 error = (segflg == UIO_SYSSPACE) ? 263 copystr(fname, args->fname, PATH_MAX, &length) : 264 copyinstr(fname, args->fname, PATH_MAX, &length); 265 if (error != 0) 266 goto err_exit; 267 268 /* 269 * extract arguments first 270 */ 271 p32 = argv; 272 for (;;) { 273 error = copyin(p32++, &arg, sizeof(arg)); 274 if (error) 275 goto err_exit; 276 if (arg == 0) 277 break; 278 argp = PTRIN(arg); 279 error = copyinstr(argp, args->endp, args->stringspace, &length); 280 if (error) { 281 if (error == ENAMETOOLONG) 282 error = E2BIG; 283 goto err_exit; 284 } 285 args->stringspace -= length; 286 args->endp += length; 287 args->argc++; 288 } 289 290 args->begin_envv = args->endp; 291 292 /* 293 * extract environment strings 294 */ 295 if (envv) { 296 p32 = envv; 297 for (;;) { 298 error = copyin(p32++, &arg, sizeof(arg)); 299 if (error) 300 goto err_exit; 301 if (arg == 0) 302 break; 303 envp = PTRIN(arg); 304 error = copyinstr(envp, args->endp, args->stringspace, 305 &length); 306 if (error) { 307 if (error == ENAMETOOLONG) 308 error = E2BIG; 309 goto err_exit; 310 } 311 args->stringspace -= length; 312 args->endp += length; 313 args->envc++; 314 } 315 } 316 317 return (0); 318 319err_exit: 320 kmem_free_wakeup(exec_map, (vm_offset_t)args->buf, 321 PATH_MAX + ARG_MAX + MAXSHELLCMDLEN); 322 args->buf = NULL; 323 return (error); 324} 325 326int 327freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap) 328{ 329 struct image_args eargs; 330 int error; 331 332 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE, 333 uap->argv, uap->envv); 334 if (error == 0) 335 error = kern_execve(td, &eargs, NULL); 336 return (error); 337} 338 339#ifdef __ia64__ 340static int 341freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end, 342 int prot, int fd, off_t pos) 343{ 344 vm_map_t map; 345 vm_map_entry_t entry; 346 int rv; 347 348 map = &td->td_proc->p_vmspace->vm_map; 349 if (fd != -1) 350 prot |= VM_PROT_WRITE; 351 352 if (vm_map_lookup_entry(map, start, &entry)) { 353 if ((entry->protection & prot) != prot) { 354 rv = vm_map_protect(map, 355 trunc_page(start), 356 round_page(end), 357 entry->protection | prot, 358 FALSE); 359 if (rv != KERN_SUCCESS) 360 return (EINVAL); 361 } 362 } else { 363 vm_offset_t addr = trunc_page(start); 364 rv = vm_map_find(map, 0, 0, 365 &addr, PAGE_SIZE, FALSE, prot, 366 VM_PROT_ALL, 0); 367 if (rv != KERN_SUCCESS) 368 return (EINVAL); 369 } 370 371 if (fd != -1) { 372 struct pread_args r; 373 r.fd = fd; 374 r.buf = (void *) start; 375 r.nbyte = end - start; 376 r.offset = pos; 377 return (pread(td, &r)); 378 } else { 379 while (start < end) { 380 subyte((void *) start, 0); 381 start++; 382 } 383 return (0); 384 } 385} 386#endif 387 388int 389freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap) 390{ 391 struct mmap_args ap; 392 vm_offset_t addr = (vm_offset_t) uap->addr; 393 vm_size_t len = uap->len; 394 int prot = uap->prot; 395 int flags = uap->flags; 396 int fd = uap->fd; 397 off_t pos = (uap->poslo 398 | ((off_t)uap->poshi << 32)); 399#ifdef __ia64__ 400 vm_size_t pageoff; 401 int error; 402 403 /* 404 * Attempt to handle page size hassles. 405 */ 406 pageoff = (pos & PAGE_MASK); 407 if (flags & MAP_FIXED) { 408 vm_offset_t start, end; 409 start = addr; 410 end = addr + len; 411 412 mtx_lock(&Giant); 413 if (start != trunc_page(start)) { 414 error = freebsd32_mmap_partial(td, start, 415 round_page(start), prot, 416 fd, pos); 417 if (fd != -1) 418 pos += round_page(start) - start; 419 start = round_page(start); 420 } 421 if (end != round_page(end)) { 422 vm_offset_t t = trunc_page(end); 423 error = freebsd32_mmap_partial(td, t, end, 424 prot, fd, 425 pos + t - start); 426 end = trunc_page(end); 427 } 428 if (end > start && fd != -1 && (pos & PAGE_MASK)) { 429 /* 430 * We can't map this region at all. The specified 431 * address doesn't have the same alignment as the file 432 * position. Fake the mapping by simply reading the 433 * entire region into memory. First we need to make 434 * sure the region exists. 435 */ 436 vm_map_t map; 437 struct pread_args r; 438 int rv; 439 440 prot |= VM_PROT_WRITE; 441 map = &td->td_proc->p_vmspace->vm_map; 442 rv = vm_map_remove(map, start, end); 443 if (rv != KERN_SUCCESS) { 444 mtx_unlock(&Giant); 445 return (EINVAL); 446 } 447 rv = vm_map_find(map, 0, 0, 448 &start, end - start, FALSE, 449 prot, VM_PROT_ALL, 0); 450 mtx_unlock(&Giant); 451 if (rv != KERN_SUCCESS) 452 return (EINVAL); 453 r.fd = fd; 454 r.buf = (void *) start; 455 r.nbyte = end - start; 456 r.offset = pos; 457 error = pread(td, &r); 458 if (error) 459 return (error); 460 461 td->td_retval[0] = addr; 462 return (0); 463 } 464 mtx_unlock(&Giant); 465 if (end == start) { 466 /* 467 * After dealing with the ragged ends, there 468 * might be none left. 469 */ 470 td->td_retval[0] = addr; 471 return (0); 472 } 473 addr = start; 474 len = end - start; 475 } 476#endif 477 478 ap.addr = (void *) addr; 479 ap.len = len; 480 ap.prot = prot; 481 ap.flags = flags; 482 ap.fd = fd; 483 ap.pos = pos; 484 485 return (mmap(td, &ap)); 486} 487 488struct itimerval32 { 489 struct timeval32 it_interval; 490 struct timeval32 it_value; 491}; 492 493CTASSERT(sizeof(struct itimerval32) == 16); 494 495int 496freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap) 497{ 498 struct itimerval itv, oitv, *itvp; 499 struct itimerval32 i32; 500 int error; 501 502 if (uap->itv != NULL) { 503 error = copyin(uap->itv, &i32, sizeof(i32)); 504 if (error) 505 return (error); 506 TV_CP(i32, itv, it_interval); 507 TV_CP(i32, itv, it_value); 508 itvp = &itv; 509 } else 510 itvp = NULL; 511 error = kern_setitimer(td, uap->which, itvp, &oitv); 512 if (error || uap->oitv == NULL) 513 return (error); 514 TV_CP(oitv, i32, it_interval); 515 TV_CP(oitv, i32, it_value); 516 return (copyout(&i32, uap->oitv, sizeof(i32))); 517} 518 519int 520freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap) 521{ 522 struct itimerval itv; 523 struct itimerval32 i32; 524 int error; 525 526 error = kern_getitimer(td, uap->which, &itv); 527 if (error || uap->itv == NULL) 528 return (error); 529 TV_CP(itv, i32, it_interval); 530 TV_CP(itv, i32, it_value); 531 return (copyout(&i32, uap->itv, sizeof(i32))); 532} 533 534int 535freebsd32_select(struct thread *td, struct freebsd32_select_args *uap) 536{ 537 struct timeval32 tv32; 538 struct timeval tv, *tvp; 539 int error; 540 541 if (uap->tv != NULL) { 542 error = copyin(uap->tv, &tv32, sizeof(tv32)); 543 if (error) 544 return (error); 545 CP(tv32, tv, tv_sec); 546 CP(tv32, tv, tv_usec); 547 tvp = &tv; 548 } else 549 tvp = NULL; 550 /* 551 * XXX big-endian needs to convert the fd_sets too. 552 * XXX Do pointers need PTRIN()? 553 */ 554 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp)); 555} 556 557struct kevent32 { 558 u_int32_t ident; /* identifier for this event */ 559 short filter; /* filter for event */ 560 u_short flags; 561 u_int fflags; 562 int32_t data; 563 u_int32_t udata; /* opaque user data identifier */ 564}; 565 566CTASSERT(sizeof(struct kevent32) == 20); 567static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count); 568static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count); 569 570/* 571 * Copy 'count' items into the destination list pointed to by uap->eventlist. 572 */ 573static int 574freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count) 575{ 576 struct freebsd32_kevent_args *uap; 577 struct kevent32 ks32[KQ_NEVENTS]; 578 int i, error = 0; 579 580 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count)); 581 uap = (struct freebsd32_kevent_args *)arg; 582 583 for (i = 0; i < count; i++) { 584 CP(kevp[i], ks32[i], ident); 585 CP(kevp[i], ks32[i], filter); 586 CP(kevp[i], ks32[i], flags); 587 CP(kevp[i], ks32[i], fflags); 588 CP(kevp[i], ks32[i], data); 589 PTROUT_CP(kevp[i], ks32[i], udata); 590 } 591 error = copyout(ks32, uap->eventlist, count * sizeof *ks32); 592 if (error == 0) 593 uap->eventlist += count; 594 return (error); 595} 596 597/* 598 * Copy 'count' items from the list pointed to by uap->changelist. 599 */ 600static int 601freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count) 602{ 603 struct freebsd32_kevent_args *uap; 604 struct kevent32 ks32[KQ_NEVENTS]; 605 int i, error = 0; 606 607 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count)); 608 uap = (struct freebsd32_kevent_args *)arg; 609 610 error = copyin(uap->changelist, ks32, count * sizeof *ks32); 611 if (error) 612 goto done; 613 uap->changelist += count; 614 615 for (i = 0; i < count; i++) { 616 CP(ks32[i], kevp[i], ident); 617 CP(ks32[i], kevp[i], filter); 618 CP(ks32[i], kevp[i], flags); 619 CP(ks32[i], kevp[i], fflags); 620 CP(ks32[i], kevp[i], data); 621 PTRIN_CP(ks32[i], kevp[i], udata); 622 } 623done: 624 return (error); 625} 626 627int 628freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap) 629{ 630 struct timespec32 ts32; 631 struct timespec ts, *tsp; 632 struct kevent_copyops k_ops = { uap, 633 freebsd32_kevent_copyout, 634 freebsd32_kevent_copyin}; 635 int error; 636 637 638 if (uap->timeout) { 639 error = copyin(uap->timeout, &ts32, sizeof(ts32)); 640 if (error) 641 return (error); 642 CP(ts32, ts, tv_sec); 643 CP(ts32, ts, tv_nsec); 644 tsp = &ts; 645 } else 646 tsp = NULL; 647 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents, 648 &k_ops, tsp); 649 return (error); 650} 651 652int 653freebsd32_gettimeofday(struct thread *td, 654 struct freebsd32_gettimeofday_args *uap) 655{ 656 struct timeval atv; 657 struct timeval32 atv32; 658 struct timezone rtz; 659 int error = 0; 660 661 if (uap->tp) { 662 microtime(&atv); 663 CP(atv, atv32, tv_sec); 664 CP(atv, atv32, tv_usec); 665 error = copyout(&atv32, uap->tp, sizeof (atv32)); 666 } 667 if (error == 0 && uap->tzp != NULL) { 668 rtz.tz_minuteswest = tz_minuteswest; 669 rtz.tz_dsttime = tz_dsttime; 670 error = copyout(&rtz, uap->tzp, sizeof (rtz)); 671 } 672 return (error); 673} 674 675int 676freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap) 677{ 678 struct rusage32 s32; 679 struct rusage s; 680 int error; 681 682 error = kern_getrusage(td, uap->who, &s); 683 if (error) 684 return (error); 685 if (uap->rusage != NULL) { 686 TV_CP(s, s32, ru_utime); 687 TV_CP(s, s32, ru_stime); 688 CP(s, s32, ru_maxrss); 689 CP(s, s32, ru_ixrss); 690 CP(s, s32, ru_idrss); 691 CP(s, s32, ru_isrss); 692 CP(s, s32, ru_minflt); 693 CP(s, s32, ru_majflt); 694 CP(s, s32, ru_nswap); 695 CP(s, s32, ru_inblock); 696 CP(s, s32, ru_oublock); 697 CP(s, s32, ru_msgsnd); 698 CP(s, s32, ru_msgrcv); 699 CP(s, s32, ru_nsignals); 700 CP(s, s32, ru_nvcsw); 701 CP(s, s32, ru_nivcsw); 702 error = copyout(&s32, uap->rusage, sizeof(s32)); 703 } 704 return (error); 705} 706 707struct iovec32 { 708 u_int32_t iov_base; 709 int iov_len; 710}; 711 712CTASSERT(sizeof(struct iovec32) == 8); 713 714static int 715freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop) 716{ 717 struct iovec32 iov32; 718 struct iovec *iov; 719 struct uio *uio; 720 u_int iovlen; 721 int error, i; 722 723 *uiop = NULL; 724 if (iovcnt > UIO_MAXIOV) 725 return (EINVAL); 726 iovlen = iovcnt * sizeof(struct iovec); 727 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK); 728 iov = (struct iovec *)(uio + 1); 729 for (i = 0; i < iovcnt; i++) { 730 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32)); 731 if (error) { 732 free(uio, M_IOV); 733 return (error); 734 } 735 iov[i].iov_base = PTRIN(iov32.iov_base); 736 iov[i].iov_len = iov32.iov_len; 737 } 738 uio->uio_iov = iov; 739 uio->uio_iovcnt = iovcnt; 740 uio->uio_segflg = UIO_USERSPACE; 741 uio->uio_offset = -1; 742 uio->uio_resid = 0; 743 for (i = 0; i < iovcnt; i++) { 744 if (iov->iov_len > INT_MAX - uio->uio_resid) { 745 free(uio, M_IOV); 746 return (EINVAL); 747 } 748 uio->uio_resid += iov->iov_len; 749 iov++; 750 } 751 *uiop = uio; 752 return (0); 753} 754 755int 756freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap) 757{ 758 struct uio *auio; 759 int error; 760 761 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 762 if (error) 763 return (error); 764 error = kern_readv(td, uap->fd, auio); 765 free(auio, M_IOV); 766 return (error); 767} 768 769int 770freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap) 771{ 772 struct uio *auio; 773 int error; 774 775 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 776 if (error) 777 return (error); 778 error = kern_writev(td, uap->fd, auio); 779 free(auio, M_IOV); 780 return (error); 781} 782 783int 784freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap) 785{ 786 struct uio *auio; 787 int error; 788 789 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 790 if (error) 791 return (error); 792 error = kern_preadv(td, uap->fd, auio, uap->offset); 793 free(auio, M_IOV); 794 return (error); 795} 796 797int 798freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap) 799{ 800 struct uio *auio; 801 int error; 802 803 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio); 804 if (error) 805 return (error); 806 error = kern_pwritev(td, uap->fd, auio, uap->offset); 807 free(auio, M_IOV); 808 return (error); 809} 810 811static int 812freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp, 813 int error) 814{ 815 struct iovec32 iov32; 816 struct iovec *iov; 817 u_int iovlen; 818 int i; 819 820 *iovp = NULL; 821 if (iovcnt > UIO_MAXIOV) 822 return (error); 823 iovlen = iovcnt * sizeof(struct iovec); 824 iov = malloc(iovlen, M_IOV, M_WAITOK); 825 for (i = 0; i < iovcnt; i++) { 826 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32)); 827 if (error) { 828 free(iov, M_IOV); 829 return (error); 830 } 831 iov[i].iov_base = PTRIN(iov32.iov_base); 832 iov[i].iov_len = iov32.iov_len; 833 } 834 *iovp = iov; 835 return (0); 836} 837 838struct msghdr32 { 839 u_int32_t msg_name; 840 socklen_t msg_namelen; 841 u_int32_t msg_iov; 842 int msg_iovlen; 843 u_int32_t msg_control; 844 socklen_t msg_controllen; 845 int msg_flags; 846}; 847CTASSERT(sizeof(struct msghdr32) == 28); 848 849static int 850freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg) 851{ 852 struct msghdr32 m32; 853 int error; 854 855 error = copyin(msg32, &m32, sizeof(m32)); 856 if (error) 857 return (error); 858 msg->msg_name = PTRIN(m32.msg_name); 859 msg->msg_namelen = m32.msg_namelen; 860 msg->msg_iov = PTRIN(m32.msg_iov); 861 msg->msg_iovlen = m32.msg_iovlen; 862 msg->msg_control = PTRIN(m32.msg_control); 863 msg->msg_controllen = m32.msg_controllen; 864 msg->msg_flags = m32.msg_flags; 865 return (0); 866} 867 868static int 869freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32) 870{ 871 struct msghdr32 m32; 872 int error; 873 874 m32.msg_name = PTROUT(msg->msg_name); 875 m32.msg_namelen = msg->msg_namelen; 876 m32.msg_iov = PTROUT(msg->msg_iov); 877 m32.msg_iovlen = msg->msg_iovlen; 878 m32.msg_control = PTROUT(msg->msg_control); 879 m32.msg_controllen = msg->msg_controllen; 880 m32.msg_flags = msg->msg_flags; 881 error = copyout(&m32, msg32, sizeof(m32)); 882 return (error); 883} 884 885#define FREEBSD32_ALIGNBYTES (sizeof(int) - 1) 886#define FREEBSD32_ALIGN(p) \ 887 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES) 888#define FREEBSD32_CMSG_SPACE(l) \ 889 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l)) 890 891#define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \ 892 FREEBSD32_ALIGN(sizeof(struct cmsghdr))) 893static int 894freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control) 895{ 896 struct cmsghdr *cm; 897 void *data; 898 socklen_t clen, datalen; 899 int error; 900 caddr_t ctlbuf; 901 int len, maxlen, copylen; 902 struct mbuf *m; 903 error = 0; 904 905 len = msg->msg_controllen; 906 maxlen = msg->msg_controllen; 907 msg->msg_controllen = 0; 908 909 m = control; 910 ctlbuf = msg->msg_control; 911 912 while (m && len > 0) { 913 cm = mtod(m, struct cmsghdr *); 914 clen = m->m_len; 915 916 while (cm != NULL) { 917 918 if (sizeof(struct cmsghdr) > clen || 919 cm->cmsg_len > clen) { 920 error = EINVAL; 921 break; 922 } 923 924 data = CMSG_DATA(cm); 925 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; 926 927 /* Adjust message length */ 928 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + 929 datalen; 930 931 932 /* Copy cmsghdr */ 933 copylen = sizeof(struct cmsghdr); 934 if (len < copylen) { 935 msg->msg_flags |= MSG_CTRUNC; 936 copylen = len; 937 } 938 939 error = copyout(cm,ctlbuf,copylen); 940 if (error) 941 goto exit; 942 943 ctlbuf += FREEBSD32_ALIGN(copylen); 944 len -= FREEBSD32_ALIGN(copylen); 945 946 if (len <= 0) 947 break; 948 949 /* Copy data */ 950 copylen = datalen; 951 if (len < copylen) { 952 msg->msg_flags |= MSG_CTRUNC; 953 copylen = len; 954 } 955 956 error = copyout(data,ctlbuf,copylen); 957 if (error) 958 goto exit; 959 960 ctlbuf += FREEBSD32_ALIGN(copylen); 961 len -= FREEBSD32_ALIGN(copylen); 962 963 if (CMSG_SPACE(datalen) < clen) { 964 clen -= CMSG_SPACE(datalen); 965 cm = (struct cmsghdr *) 966 ((caddr_t)cm + CMSG_SPACE(datalen)); 967 } else { 968 clen = 0; 969 cm = NULL; 970 } 971 } 972 m = m->m_next; 973 } 974 975 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control; 976 977exit: 978 return (error); 979 980} 981 982int 983freebsd32_recvmsg(td, uap) 984 struct thread *td; 985 struct freebsd32_recvmsg_args /* { 986 int s; 987 struct msghdr32 *msg; 988 int flags; 989 } */ *uap; 990{ 991 struct msghdr msg; 992 struct msghdr32 m32; 993 struct iovec *uiov, *iov; 994 struct mbuf *control = NULL; 995 struct mbuf **controlp; 996 997 int error; 998 error = copyin(uap->msg, &m32, sizeof(m32)); 999 if (error) 1000 return (error); 1001 error = freebsd32_copyinmsghdr(uap->msg, &msg); 1002 if (error) 1003 return (error); 1004 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov, 1005 EMSGSIZE); 1006 if (error) 1007 return (error); 1008 msg.msg_flags = uap->flags; 1009 uiov = msg.msg_iov; 1010 msg.msg_iov = iov; 1011 1012 controlp = (msg.msg_control != NULL) ? &control : NULL; 1013 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp); 1014 if (error == 0) { 1015 msg.msg_iov = uiov; 1016 1017 if (control != NULL) 1018 error = freebsd32_copy_msg_out(&msg, control); 1019 1020 if (error == 0) 1021 error = freebsd32_copyoutmsghdr(&msg, uap->msg); 1022 } 1023 free(iov, M_IOV); 1024 1025 if (control != NULL) 1026 m_freem(control); 1027 1028 return (error); 1029} 1030 1031 1032static int 1033freebsd32_convert_msg_in(struct mbuf **controlp) 1034{ 1035 struct mbuf *control = *controlp; 1036 struct cmsghdr *cm = mtod(control, struct cmsghdr *); 1037 void *data; 1038 socklen_t clen = control->m_len, datalen; 1039 int error; 1040 1041 error = 0; 1042 *controlp = NULL; 1043 1044 while (cm != NULL) { 1045 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) { 1046 error = EINVAL; 1047 break; 1048 } 1049 1050 data = FREEBSD32_CMSG_DATA(cm); 1051 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data; 1052 1053 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type, 1054 cm->cmsg_level); 1055 controlp = &(*controlp)->m_next; 1056 1057 if (FREEBSD32_CMSG_SPACE(datalen) < clen) { 1058 clen -= FREEBSD32_CMSG_SPACE(datalen); 1059 cm = (struct cmsghdr *) 1060 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen)); 1061 } else { 1062 clen = 0; 1063 cm = NULL; 1064 } 1065 } 1066 1067 m_freem(control); 1068 return (error); 1069} 1070 1071 1072int 1073freebsd32_sendmsg(struct thread *td, 1074 struct freebsd32_sendmsg_args *uap) 1075{ 1076 struct msghdr msg; 1077 struct msghdr32 m32; 1078 struct iovec *iov; 1079 struct mbuf *control = NULL; 1080 struct sockaddr *to = NULL; 1081 int error; 1082 1083 error = copyin(uap->msg, &m32, sizeof(m32)); 1084 if (error) 1085 return (error); 1086 error = freebsd32_copyinmsghdr(uap->msg, &msg); 1087 if (error) 1088 return (error); 1089 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov, 1090 EMSGSIZE); 1091 if (error) 1092 return (error); 1093 msg.msg_iov = iov; 1094 if (msg.msg_name != NULL) { 1095 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen); 1096 if (error) { 1097 to = NULL; 1098 goto out; 1099 } 1100 msg.msg_name = to; 1101 } 1102 1103 if (msg.msg_control) { 1104 if (msg.msg_controllen < sizeof(struct cmsghdr)) { 1105 error = EINVAL; 1106 goto out; 1107 } 1108 1109 error = sockargs(&control, msg.msg_control, 1110 msg.msg_controllen, MT_CONTROL); 1111 if (error) 1112 goto out; 1113 1114 error = freebsd32_convert_msg_in(&control); 1115 if (error) 1116 goto out; 1117 } 1118 1119 error = kern_sendit(td, uap->s, &msg, uap->flags, control, 1120 UIO_USERSPACE); 1121 1122out: 1123 free(iov, M_IOV); 1124 if (to) 1125 free(to, M_SONAME); 1126 return (error); 1127} 1128 1129int 1130freebsd32_recvfrom(struct thread *td, 1131 struct freebsd32_recvfrom_args *uap) 1132{ 1133 struct msghdr msg; 1134 struct iovec aiov; 1135 int error; 1136 1137 if (uap->fromlenaddr) { 1138 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen, 1139 sizeof(msg.msg_namelen)); 1140 if (error) 1141 return (error); 1142 } else { 1143 msg.msg_namelen = 0; 1144 } 1145 1146 msg.msg_name = PTRIN(uap->from); 1147 msg.msg_iov = &aiov; 1148 msg.msg_iovlen = 1; 1149 aiov.iov_base = PTRIN(uap->buf); 1150 aiov.iov_len = uap->len; 1151 msg.msg_control = NULL; 1152 msg.msg_flags = uap->flags; 1153 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL); 1154 if (error == 0 && uap->fromlenaddr) 1155 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr), 1156 sizeof (msg.msg_namelen)); 1157 return (error); 1158} 1159 1160int 1161freebsd32_settimeofday(struct thread *td, 1162 struct freebsd32_settimeofday_args *uap) 1163{ 1164 struct timeval32 tv32; 1165 struct timeval tv, *tvp; 1166 struct timezone tz, *tzp; 1167 int error; 1168 1169 if (uap->tv) { 1170 error = copyin(uap->tv, &tv32, sizeof(tv32)); 1171 if (error) 1172 return (error); 1173 CP(tv32, tv, tv_sec); 1174 CP(tv32, tv, tv_usec); 1175 tvp = &tv; 1176 } else 1177 tvp = NULL; 1178 if (uap->tzp) { 1179 error = copyin(uap->tzp, &tz, sizeof(tz)); 1180 if (error) 1181 return (error); 1182 tzp = &tz; 1183 } else 1184 tzp = NULL; 1185 return (kern_settimeofday(td, tvp, tzp)); 1186} 1187 1188int 1189freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap) 1190{ 1191 struct timeval32 s32[2]; 1192 struct timeval s[2], *sp; 1193 int error; 1194 1195 if (uap->tptr != NULL) { 1196 error = copyin(uap->tptr, s32, sizeof(s32)); 1197 if (error) 1198 return (error); 1199 CP(s32[0], s[0], tv_sec); 1200 CP(s32[0], s[0], tv_usec); 1201 CP(s32[1], s[1], tv_sec); 1202 CP(s32[1], s[1], tv_usec); 1203 sp = s; 1204 } else 1205 sp = NULL; 1206 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE)); 1207} 1208 1209int 1210freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap) 1211{ 1212 struct timeval32 s32[2]; 1213 struct timeval s[2], *sp; 1214 int error; 1215 1216 if (uap->tptr != NULL) { 1217 error = copyin(uap->tptr, s32, sizeof(s32)); 1218 if (error) 1219 return (error); 1220 CP(s32[0], s[0], tv_sec); 1221 CP(s32[0], s[0], tv_usec); 1222 CP(s32[1], s[1], tv_sec); 1223 CP(s32[1], s[1], tv_usec); 1224 sp = s; 1225 } else 1226 sp = NULL; 1227 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE)); 1228} 1229 1230int 1231freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap) 1232{ 1233 struct timeval32 s32[2]; 1234 struct timeval s[2], *sp; 1235 int error; 1236 1237 if (uap->tptr != NULL) { 1238 error = copyin(uap->tptr, s32, sizeof(s32)); 1239 if (error) 1240 return (error); 1241 CP(s32[0], s[0], tv_sec); 1242 CP(s32[0], s[0], tv_usec); 1243 CP(s32[1], s[1], tv_sec); 1244 CP(s32[1], s[1], tv_usec); 1245 sp = s; 1246 } else 1247 sp = NULL; 1248 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE)); 1249} 1250 1251 1252int 1253freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap) 1254{ 1255 struct timeval32 tv32; 1256 struct timeval delta, olddelta, *deltap; 1257 int error; 1258 1259 if (uap->delta) { 1260 error = copyin(uap->delta, &tv32, sizeof(tv32)); 1261 if (error) 1262 return (error); 1263 CP(tv32, delta, tv_sec); 1264 CP(tv32, delta, tv_usec); 1265 deltap = δ 1266 } else 1267 deltap = NULL; 1268 error = kern_adjtime(td, deltap, &olddelta); 1269 if (uap->olddelta && error == 0) { 1270 CP(olddelta, tv32, tv_sec); 1271 CP(olddelta, tv32, tv_usec); 1272 error = copyout(&tv32, uap->olddelta, sizeof(tv32)); 1273 } 1274 return (error); 1275} 1276 1277#ifdef COMPAT_FREEBSD4 1278int 1279freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap) 1280{ 1281 struct statfs32 s32; 1282 struct statfs s; 1283 int error; 1284 1285 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s); 1286 if (error) 1287 return (error); 1288 copy_statfs(&s, &s32); 1289 return (copyout(&s32, uap->buf, sizeof(s32))); 1290} 1291#endif 1292 1293#ifdef COMPAT_FREEBSD4 1294int 1295freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap) 1296{ 1297 struct statfs32 s32; 1298 struct statfs s; 1299 int error; 1300 1301 error = kern_fstatfs(td, uap->fd, &s); 1302 if (error) 1303 return (error); 1304 copy_statfs(&s, &s32); 1305 return (copyout(&s32, uap->buf, sizeof(s32))); 1306} 1307#endif 1308 1309#ifdef COMPAT_FREEBSD4 1310int 1311freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap) 1312{ 1313 struct statfs32 s32; 1314 struct statfs s; 1315 fhandle_t fh; 1316 int error; 1317 1318 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0) 1319 return (error); 1320 error = kern_fhstatfs(td, fh, &s); 1321 if (error) 1322 return (error); 1323 copy_statfs(&s, &s32); 1324 return (copyout(&s32, uap->buf, sizeof(s32))); 1325} 1326#endif 1327 1328int 1329freebsd32_semsys(struct thread *td, struct freebsd32_semsys_args *uap) 1330{ 1331 /* 1332 * Vector through to semsys if it is loaded. 1333 */ 1334 return sysent[SYS_semsys].sy_call(td, uap); 1335} 1336 1337int 1338freebsd32_msgsys(struct thread *td, struct freebsd32_msgsys_args *uap) 1339{ 1340 /* 1341 * Vector through to msgsys if it is loaded. 1342 */ 1343 return sysent[SYS_msgsys].sy_call(td, uap); 1344} 1345 1346int 1347freebsd32_shmsys(struct thread *td, struct freebsd32_shmsys_args *uap) 1348{ 1349 1350 switch (uap->which) { 1351 case 0: { /* shmat */ 1352 struct shmat_args ap; 1353 1354 ap.shmid = uap->a2; 1355 ap.shmaddr = PTRIN(uap->a3); 1356 ap.shmflg = uap->a4; 1357 return (sysent[SYS_shmat].sy_call(td, &ap)); 1358 } 1359 case 2: { /* shmdt */ 1360 struct shmdt_args ap; 1361 1362 ap.shmaddr = PTRIN(uap->a2); 1363 return (sysent[SYS_shmdt].sy_call(td, &ap)); 1364 } 1365 case 3: { /* shmget */ 1366 struct shmget_args ap; 1367 1368 ap.key = uap->a2; 1369 ap.size = uap->a3; 1370 ap.shmflg = uap->a4; 1371 return (sysent[SYS_shmget].sy_call(td, &ap)); 1372 } 1373 case 4: { /* shmctl */ 1374 struct freebsd32_shmctl_args ap; 1375 1376 ap.shmid = uap->a2; 1377 ap.cmd = uap->a3; 1378 ap.buf = PTRIN(uap->a4); 1379 return (freebsd32_shmctl(td, &ap)); 1380 } 1381 case 1: /* oshmctl */ 1382 default: 1383 return (EINVAL); 1384 } 1385} 1386 1387struct ipc_perm32 { 1388 uint16_t cuid; 1389 uint16_t cgid; 1390 uint16_t uid; 1391 uint16_t gid; 1392 uint16_t mode; 1393 uint16_t seq; 1394 uint32_t key; 1395}; 1396struct shmid_ds32 { 1397 struct ipc_perm32 shm_perm; 1398 int32_t shm_segsz; 1399 int32_t shm_lpid; 1400 int32_t shm_cpid; 1401 int16_t shm_nattch; 1402 int32_t shm_atime; 1403 int32_t shm_dtime; 1404 int32_t shm_ctime; 1405 uint32_t shm_internal; 1406}; 1407struct shm_info32 { 1408 int32_t used_ids; 1409 uint32_t shm_tot; 1410 uint32_t shm_rss; 1411 uint32_t shm_swp; 1412 uint32_t swap_attempts; 1413 uint32_t swap_successes; 1414}; 1415struct shminfo32 { 1416 uint32_t shmmax; 1417 uint32_t shmmin; 1418 uint32_t shmmni; 1419 uint32_t shmseg; 1420 uint32_t shmall; 1421}; 1422 1423int 1424freebsd32_shmctl(struct thread *td, struct freebsd32_shmctl_args *uap) 1425{ 1426 int error = 0; 1427 union { 1428 struct shmid_ds shmid_ds; 1429 struct shm_info shm_info; 1430 struct shminfo shminfo; 1431 } u; 1432 union { 1433 struct shmid_ds32 shmid_ds32; 1434 struct shm_info32 shm_info32; 1435 struct shminfo32 shminfo32; 1436 } u32; 1437 size_t sz; 1438 1439 if (uap->cmd == IPC_SET) { 1440 if ((error = copyin(uap->buf, &u32.shmid_ds32, 1441 sizeof(u32.shmid_ds32)))) 1442 goto done; 1443 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.cuid); 1444 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.cgid); 1445 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.uid); 1446 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.gid); 1447 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.mode); 1448 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.seq); 1449 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.key); 1450 CP(u32.shmid_ds32, u.shmid_ds, shm_segsz); 1451 CP(u32.shmid_ds32, u.shmid_ds, shm_lpid); 1452 CP(u32.shmid_ds32, u.shmid_ds, shm_cpid); 1453 CP(u32.shmid_ds32, u.shmid_ds, shm_nattch); 1454 CP(u32.shmid_ds32, u.shmid_ds, shm_atime); 1455 CP(u32.shmid_ds32, u.shmid_ds, shm_dtime); 1456 CP(u32.shmid_ds32, u.shmid_ds, shm_ctime); 1457 PTRIN_CP(u32.shmid_ds32, u.shmid_ds, shm_internal); 1458 } 1459 1460 error = kern_shmctl(td, uap->shmid, uap->cmd, (void *)&u, &sz); 1461 if (error) 1462 goto done; 1463 1464 /* Cases in which we need to copyout */ 1465 switch (uap->cmd) { 1466 case IPC_INFO: 1467 CP(u.shminfo, u32.shminfo32, shmmax); 1468 CP(u.shminfo, u32.shminfo32, shmmin); 1469 CP(u.shminfo, u32.shminfo32, shmmni); 1470 CP(u.shminfo, u32.shminfo32, shmseg); 1471 CP(u.shminfo, u32.shminfo32, shmall); 1472 error = copyout(&u32.shminfo32, uap->buf, 1473 sizeof(u32.shminfo32)); 1474 break; 1475 case SHM_INFO: 1476 CP(u.shm_info, u32.shm_info32, used_ids); 1477 CP(u.shm_info, u32.shm_info32, shm_rss); 1478 CP(u.shm_info, u32.shm_info32, shm_tot); 1479 CP(u.shm_info, u32.shm_info32, shm_swp); 1480 CP(u.shm_info, u32.shm_info32, swap_attempts); 1481 CP(u.shm_info, u32.shm_info32, swap_successes); 1482 error = copyout(&u32.shm_info32, uap->buf, 1483 sizeof(u32.shm_info32)); 1484 break; 1485 case SHM_STAT: 1486 case IPC_STAT: 1487 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.cuid); 1488 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.cgid); 1489 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.uid); 1490 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.gid); 1491 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.mode); 1492 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.seq); 1493 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.key); 1494 CP(u.shmid_ds, u32.shmid_ds32, shm_segsz); 1495 CP(u.shmid_ds, u32.shmid_ds32, shm_lpid); 1496 CP(u.shmid_ds, u32.shmid_ds32, shm_cpid); 1497 CP(u.shmid_ds, u32.shmid_ds32, shm_nattch); 1498 CP(u.shmid_ds, u32.shmid_ds32, shm_atime); 1499 CP(u.shmid_ds, u32.shmid_ds32, shm_dtime); 1500 CP(u.shmid_ds, u32.shmid_ds32, shm_ctime); 1501 PTROUT_CP(u.shmid_ds, u32.shmid_ds32, shm_internal); 1502 error = copyout(&u32.shmid_ds32, uap->buf, 1503 sizeof(u32.shmid_ds32)); 1504 break; 1505 } 1506 1507done: 1508 if (error) { 1509 /* Invalidate the return value */ 1510 td->td_retval[0] = -1; 1511 } 1512 return (error); 1513} 1514 1515int 1516freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap) 1517{ 1518 struct pread_args ap; 1519 1520 ap.fd = uap->fd; 1521 ap.buf = uap->buf; 1522 ap.nbyte = uap->nbyte; 1523 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32)); 1524 return (pread(td, &ap)); 1525} 1526 1527int 1528freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap) 1529{ 1530 struct pwrite_args ap; 1531 1532 ap.fd = uap->fd; 1533 ap.buf = uap->buf; 1534 ap.nbyte = uap->nbyte; 1535 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32)); 1536 return (pwrite(td, &ap)); 1537} 1538 1539int 1540freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap) 1541{ 1542 int error; 1543 struct lseek_args ap; 1544 off_t pos; 1545 1546 ap.fd = uap->fd; 1547 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32)); 1548 ap.whence = uap->whence; 1549 error = lseek(td, &ap); 1550 /* Expand the quad return into two parts for eax and edx */ 1551 pos = *(off_t *)(td->td_retval); 1552 td->td_retval[0] = pos & 0xffffffff; /* %eax */ 1553 td->td_retval[1] = pos >> 32; /* %edx */ 1554 return error; 1555} 1556 1557int 1558freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap) 1559{ 1560 struct truncate_args ap; 1561 1562 ap.path = uap->path; 1563 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32)); 1564 return (truncate(td, &ap)); 1565} 1566 1567int 1568freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap) 1569{ 1570 struct ftruncate_args ap; 1571 1572 ap.fd = uap->fd; 1573 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32)); 1574 return (ftruncate(td, &ap)); 1575} 1576 1577struct sf_hdtr32 { 1578 uint32_t headers; 1579 int hdr_cnt; 1580 uint32_t trailers; 1581 int trl_cnt; 1582}; 1583 1584static int 1585freebsd32_do_sendfile(struct thread *td, 1586 struct freebsd32_sendfile_args *uap, int compat) 1587{ 1588 struct sendfile_args ap; 1589 struct sf_hdtr32 hdtr32; 1590 struct sf_hdtr hdtr; 1591 struct uio *hdr_uio, *trl_uio; 1592 struct iovec32 *iov32; 1593 int error; 1594 1595 hdr_uio = trl_uio = NULL; 1596 1597 ap.fd = uap->fd; 1598 ap.s = uap->s; 1599 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32)); 1600 ap.nbytes = uap->nbytes; 1601 ap.hdtr = (struct sf_hdtr *)uap->hdtr; /* XXX not used */ 1602 ap.sbytes = uap->sbytes; 1603 ap.flags = uap->flags; 1604 1605 if (uap->hdtr != NULL) { 1606 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32)); 1607 if (error) 1608 goto out; 1609 PTRIN_CP(hdtr32, hdtr, headers); 1610 CP(hdtr32, hdtr, hdr_cnt); 1611 PTRIN_CP(hdtr32, hdtr, trailers); 1612 CP(hdtr32, hdtr, trl_cnt); 1613 1614 if (hdtr.headers != NULL) { 1615 iov32 = PTRIN(hdtr32.headers); 1616 error = freebsd32_copyinuio(iov32, 1617 hdtr32.hdr_cnt, &hdr_uio); 1618 if (error) 1619 goto out; 1620 } 1621 if (hdtr.trailers != NULL) { 1622 iov32 = PTRIN(hdtr32.trailers); 1623 error = freebsd32_copyinuio(iov32, 1624 hdtr32.trl_cnt, &trl_uio); 1625 if (error) 1626 goto out; 1627 } 1628 } 1629 1630 error = kern_sendfile(td, &ap, hdr_uio, trl_uio, compat); 1631out: 1632 if (hdr_uio) 1633 free(hdr_uio, M_IOV); 1634 if (trl_uio) 1635 free(trl_uio, M_IOV); 1636 return (error); 1637} 1638 1639#ifdef COMPAT_FREEBSD4 1640int 1641freebsd4_freebsd32_sendfile(struct thread *td, 1642 struct freebsd4_freebsd32_sendfile_args *uap) 1643{ 1644 return (freebsd32_do_sendfile(td, 1645 (struct freebsd32_sendfile_args *)uap, 1)); 1646} 1647#endif 1648 1649int 1650freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap) 1651{ 1652 1653 return (freebsd32_do_sendfile(td, uap, 0)); 1654} 1655 1656struct stat32 { 1657 dev_t st_dev; 1658 ino_t st_ino; 1659 mode_t st_mode; 1660 nlink_t st_nlink; 1661 uid_t st_uid; 1662 gid_t st_gid; 1663 dev_t st_rdev; 1664 struct timespec32 st_atimespec; 1665 struct timespec32 st_mtimespec; 1666 struct timespec32 st_ctimespec; 1667 off_t st_size; 1668 int64_t st_blocks; 1669 u_int32_t st_blksize; 1670 u_int32_t st_flags; 1671 u_int32_t st_gen; 1672 struct timespec32 st_birthtimespec; 1673 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32)); 1674 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32)); 1675}; 1676 1677 1678CTASSERT(sizeof(struct stat32) == 96); 1679 1680static void 1681copy_stat( struct stat *in, struct stat32 *out) 1682{ 1683 CP(*in, *out, st_dev); 1684 CP(*in, *out, st_ino); 1685 CP(*in, *out, st_mode); 1686 CP(*in, *out, st_nlink); 1687 CP(*in, *out, st_uid); 1688 CP(*in, *out, st_gid); 1689 CP(*in, *out, st_rdev); 1690 TS_CP(*in, *out, st_atimespec); 1691 TS_CP(*in, *out, st_mtimespec); 1692 TS_CP(*in, *out, st_ctimespec); 1693 CP(*in, *out, st_size); 1694 CP(*in, *out, st_blocks); 1695 CP(*in, *out, st_blksize); 1696 CP(*in, *out, st_flags); 1697 CP(*in, *out, st_gen); 1698} 1699 1700int 1701freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap) 1702{ 1703 struct stat sb; 1704 struct stat32 sb32; 1705 int error; 1706 1707 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb); 1708 if (error) 1709 return (error); 1710 copy_stat(&sb, &sb32); 1711 error = copyout(&sb32, uap->ub, sizeof (sb32)); 1712 return (error); 1713} 1714 1715int 1716freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap) 1717{ 1718 struct stat ub; 1719 struct stat32 ub32; 1720 int error; 1721 1722 error = kern_fstat(td, uap->fd, &ub); 1723 if (error) 1724 return (error); 1725 copy_stat(&ub, &ub32); 1726 error = copyout(&ub32, uap->ub, sizeof(ub32)); 1727 return (error); 1728} 1729 1730int 1731freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap) 1732{ 1733 struct stat sb; 1734 struct stat32 sb32; 1735 int error; 1736 1737 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb); 1738 if (error) 1739 return (error); 1740 copy_stat(&sb, &sb32); 1741 error = copyout(&sb32, uap->ub, sizeof (sb32)); 1742 return (error); 1743} 1744 1745/* 1746 * MPSAFE 1747 */ 1748int 1749freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap) 1750{ 1751 int error, name[CTL_MAXNAME]; 1752 size_t j, oldlen; 1753 1754 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2) 1755 return (EINVAL); 1756 error = copyin(uap->name, name, uap->namelen * sizeof(int)); 1757 if (error) 1758 return (error); 1759 mtx_lock(&Giant); 1760 if (uap->oldlenp) 1761 oldlen = fuword32(uap->oldlenp); 1762 else 1763 oldlen = 0; 1764 error = userland_sysctl(td, name, uap->namelen, 1765 uap->old, &oldlen, 1, 1766 uap->new, uap->newlen, &j, SCTL_MASK32); 1767 if (error && error != ENOMEM) 1768 goto done2; 1769 if (uap->oldlenp) 1770 suword32(uap->oldlenp, j); 1771done2: 1772 mtx_unlock(&Giant); 1773 return (error); 1774} 1775 1776struct sigaction32 { 1777 u_int32_t sa_u; 1778 int sa_flags; 1779 sigset_t sa_mask; 1780}; 1781 1782CTASSERT(sizeof(struct sigaction32) == 24); 1783 1784int 1785freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap) 1786{ 1787 struct sigaction32 s32; 1788 struct sigaction sa, osa, *sap; 1789 int error; 1790 1791 if (uap->act) { 1792 error = copyin(uap->act, &s32, sizeof(s32)); 1793 if (error) 1794 return (error); 1795 sa.sa_handler = PTRIN(s32.sa_u); 1796 CP(s32, sa, sa_flags); 1797 CP(s32, sa, sa_mask); 1798 sap = &sa; 1799 } else 1800 sap = NULL; 1801 error = kern_sigaction(td, uap->sig, sap, &osa, 0); 1802 if (error == 0 && uap->oact != NULL) { 1803 s32.sa_u = PTROUT(osa.sa_handler); 1804 CP(osa, s32, sa_flags); 1805 CP(osa, s32, sa_mask); 1806 error = copyout(&s32, uap->oact, sizeof(s32)); 1807 } 1808 return (error); 1809} 1810 1811#ifdef COMPAT_FREEBSD4 1812int 1813freebsd4_freebsd32_sigaction(struct thread *td, 1814 struct freebsd4_freebsd32_sigaction_args *uap) 1815{ 1816 struct sigaction32 s32; 1817 struct sigaction sa, osa, *sap; 1818 int error; 1819 1820 if (uap->act) { 1821 error = copyin(uap->act, &s32, sizeof(s32)); 1822 if (error) 1823 return (error); 1824 sa.sa_handler = PTRIN(s32.sa_u); 1825 CP(s32, sa, sa_flags); 1826 CP(s32, sa, sa_mask); 1827 sap = &sa; 1828 } else 1829 sap = NULL; 1830 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4); 1831 if (error == 0 && uap->oact != NULL) { 1832 s32.sa_u = PTROUT(osa.sa_handler); 1833 CP(osa, s32, sa_flags); 1834 CP(osa, s32, sa_mask); 1835 error = copyout(&s32, uap->oact, sizeof(s32)); 1836 } 1837 return (error); 1838} 1839#endif 1840 1841#ifdef COMPAT_43 1842struct osigaction32 { 1843 u_int32_t sa_u; 1844 osigset_t sa_mask; 1845 int sa_flags; 1846}; 1847 1848#define ONSIG 32 1849 1850int 1851ofreebsd32_sigaction(struct thread *td, 1852 struct ofreebsd32_sigaction_args *uap) 1853{ 1854 struct osigaction32 s32; 1855 struct sigaction sa, osa, *sap; 1856 int error; 1857 1858 if (uap->signum <= 0 || uap->signum >= ONSIG) 1859 return (EINVAL); 1860 1861 if (uap->nsa) { 1862 error = copyin(uap->nsa, &s32, sizeof(s32)); 1863 if (error) 1864 return (error); 1865 sa.sa_handler = PTRIN(s32.sa_u); 1866 CP(s32, sa, sa_flags); 1867 OSIG2SIG(s32.sa_mask, sa.sa_mask); 1868 sap = &sa; 1869 } else 1870 sap = NULL; 1871 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET); 1872 if (error == 0 && uap->osa != NULL) { 1873 s32.sa_u = PTROUT(osa.sa_handler); 1874 CP(osa, s32, sa_flags); 1875 SIG2OSIG(osa.sa_mask, s32.sa_mask); 1876 error = copyout(&s32, uap->osa, sizeof(s32)); 1877 } 1878 return (error); 1879} 1880 1881int 1882ofreebsd32_sigprocmask(struct thread *td, 1883 struct ofreebsd32_sigprocmask_args *uap) 1884{ 1885 sigset_t set, oset; 1886 int error; 1887 1888 OSIG2SIG(uap->mask, set); 1889 error = kern_sigprocmask(td, uap->how, &set, &oset, 1); 1890 SIG2OSIG(oset, td->td_retval[0]); 1891 return (error); 1892} 1893 1894int 1895ofreebsd32_sigpending(struct thread *td, 1896 struct ofreebsd32_sigpending_args *uap) 1897{ 1898 struct proc *p = td->td_proc; 1899 sigset_t siglist; 1900 1901 PROC_LOCK(p); 1902 siglist = p->p_siglist; 1903 SIGSETOR(siglist, td->td_siglist); 1904 PROC_UNLOCK(p); 1905 SIG2OSIG(siglist, td->td_retval[0]); 1906 return (0); 1907} 1908 1909struct sigvec32 { 1910 u_int32_t sv_handler; 1911 int sv_mask; 1912 int sv_flags; 1913}; 1914 1915int 1916ofreebsd32_sigvec(struct thread *td, 1917 struct ofreebsd32_sigvec_args *uap) 1918{ 1919 struct sigvec32 vec; 1920 struct sigaction sa, osa, *sap; 1921 int error; 1922 1923 if (uap->signum <= 0 || uap->signum >= ONSIG) 1924 return (EINVAL); 1925 1926 if (uap->nsv) { 1927 error = copyin(uap->nsv, &vec, sizeof(vec)); 1928 if (error) 1929 return (error); 1930 sa.sa_handler = PTRIN(vec.sv_handler); 1931 OSIG2SIG(vec.sv_mask, sa.sa_mask); 1932 sa.sa_flags = vec.sv_flags; 1933 sa.sa_flags ^= SA_RESTART; 1934 sap = &sa; 1935 } else 1936 sap = NULL; 1937 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET); 1938 if (error == 0 && uap->osv != NULL) { 1939 vec.sv_handler = PTROUT(osa.sa_handler); 1940 SIG2OSIG(osa.sa_mask, vec.sv_mask); 1941 vec.sv_flags = osa.sa_flags; 1942 vec.sv_flags &= ~SA_NOCLDWAIT; 1943 vec.sv_flags ^= SA_RESTART; 1944 error = copyout(&vec, uap->osv, sizeof(vec)); 1945 } 1946 return (error); 1947} 1948 1949int 1950ofreebsd32_sigblock(struct thread *td, 1951 struct ofreebsd32_sigblock_args *uap) 1952{ 1953 struct proc *p = td->td_proc; 1954 sigset_t set; 1955 1956 OSIG2SIG(uap->mask, set); 1957 SIG_CANTMASK(set); 1958 PROC_LOCK(p); 1959 SIG2OSIG(td->td_sigmask, td->td_retval[0]); 1960 SIGSETOR(td->td_sigmask, set); 1961 PROC_UNLOCK(p); 1962 return (0); 1963} 1964 1965int 1966ofreebsd32_sigsetmask(struct thread *td, 1967 struct ofreebsd32_sigsetmask_args *uap) 1968{ 1969 struct proc *p = td->td_proc; 1970 sigset_t set; 1971 1972 OSIG2SIG(uap->mask, set); 1973 SIG_CANTMASK(set); 1974 PROC_LOCK(p); 1975 SIG2OSIG(td->td_sigmask, td->td_retval[0]); 1976 SIGSETLO(td->td_sigmask, set); 1977 signotify(td); 1978 PROC_UNLOCK(p); 1979 return (0); 1980} 1981 1982int 1983ofreebsd32_sigsuspend(struct thread *td, 1984 struct ofreebsd32_sigsuspend_args *uap) 1985{ 1986 struct proc *p = td->td_proc; 1987 sigset_t mask; 1988 1989 PROC_LOCK(p); 1990 td->td_oldsigmask = td->td_sigmask; 1991 td->td_pflags |= TDP_OLDMASK; 1992 OSIG2SIG(uap->mask, mask); 1993 SIG_CANTMASK(mask); 1994 SIGSETLO(td->td_sigmask, mask); 1995 signotify(td); 1996 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "opause", 0) == 0) 1997 /* void */; 1998 PROC_UNLOCK(p); 1999 /* always return EINTR rather than ERESTART... */ 2000 return (EINTR); 2001} 2002 2003struct sigstack32 { 2004 u_int32_t ss_sp; 2005 int ss_onstack; 2006}; 2007 2008int 2009ofreebsd32_sigstack(struct thread *td, 2010 struct ofreebsd32_sigstack_args *uap) 2011{ 2012 struct sigstack32 s32; 2013 struct sigstack nss, oss; 2014 int error = 0; 2015 2016 if (uap->nss != NULL) { 2017 error = copyin(uap->nss, &s32, sizeof(s32)); 2018 if (error) 2019 return (error); 2020 nss.ss_sp = PTRIN(s32.ss_sp); 2021 CP(s32, nss, ss_onstack); 2022 } 2023 oss.ss_sp = td->td_sigstk.ss_sp; 2024 oss.ss_onstack = sigonstack(cpu_getstack(td)); 2025 if (uap->nss != NULL) { 2026 td->td_sigstk.ss_sp = nss.ss_sp; 2027 td->td_sigstk.ss_size = 0; 2028 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK; 2029 td->td_pflags |= TDP_ALTSTACK; 2030 } 2031 if (uap->oss != NULL) { 2032 s32.ss_sp = PTROUT(oss.ss_sp); 2033 CP(oss, s32, ss_onstack); 2034 error = copyout(&s32, uap->oss, sizeof(s32)); 2035 } 2036 return (error); 2037} 2038#endif 2039 2040int 2041freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap) 2042{ 2043 struct timespec32 rmt32, rqt32; 2044 struct timespec rmt, rqt; 2045 int error; 2046 2047 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32)); 2048 if (error) 2049 return (error); 2050 2051 CP(rqt32, rqt, tv_sec); 2052 CP(rqt32, rqt, tv_nsec); 2053 2054 if (uap->rmtp && 2055 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE)) 2056 return (EFAULT); 2057 error = kern_nanosleep(td, &rqt, &rmt); 2058 if (error && uap->rmtp) { 2059 int error2; 2060 2061 CP(rmt, rmt32, tv_sec); 2062 CP(rmt, rmt32, tv_nsec); 2063 2064 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32)); 2065 if (error2) 2066 error = error2; 2067 } 2068 return (error); 2069} 2070 2071int 2072freebsd32_clock_gettime(struct thread *td, 2073 struct freebsd32_clock_gettime_args *uap) 2074{ 2075 struct timespec ats; 2076 struct timespec32 ats32; 2077 int error; 2078 2079 error = kern_clock_gettime(td, uap->clock_id, &ats); 2080 if (error == 0) { 2081 CP(ats, ats32, tv_sec); 2082 CP(ats, ats32, tv_nsec); 2083 error = copyout(&ats32, uap->tp, sizeof(ats32)); 2084 } 2085 return (error); 2086} 2087 2088int 2089freebsd32_clock_settime(struct thread *td, 2090 struct freebsd32_clock_settime_args *uap) 2091{ 2092 struct timespec ats; 2093 struct timespec32 ats32; 2094 int error; 2095 2096 error = copyin(uap->tp, &ats32, sizeof(ats32)); 2097 if (error) 2098 return (error); 2099 CP(ats32, ats, tv_sec); 2100 CP(ats32, ats, tv_nsec); 2101 2102 return (kern_clock_settime(td, uap->clock_id, &ats)); 2103} 2104 2105int 2106freebsd32_clock_getres(struct thread *td, 2107 struct freebsd32_clock_getres_args *uap) 2108{ 2109 struct timespec ts; 2110 struct timespec32 ts32; 2111 int error; 2112 2113 if (uap->tp == NULL) 2114 return (0); 2115 error = kern_clock_getres(td, uap->clock_id, &ts); 2116 if (error == 0) { 2117 CP(ts, ts32, tv_sec); 2118 CP(ts, ts32, tv_nsec); 2119 error = copyout(&ts32, uap->tp, sizeof(ts32)); 2120 } 2121 return (error); 2122} 2123 2124#if 0 2125 2126int 2127freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap) 2128{ 2129 int error; 2130 struct yyy32 *p32, s32; 2131 struct yyy *p = NULL, s; 2132 2133 if (uap->zzz) { 2134 error = copyin(uap->zzz, &s32, sizeof(s32)); 2135 if (error) 2136 return (error); 2137 /* translate in */ 2138 p = &s; 2139 } 2140 error = kern_xxx(td, p); 2141 if (error) 2142 return (error); 2143 if (uap->zzz) { 2144 /* translate out */ 2145 error = copyout(&s32, p32, sizeof(s32)); 2146 } 2147 return (error); 2148} 2149 2150#endif 2151