2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include "opt_inet6.h"
34 #define __ELF_WORD_SIZE 32
36 #include <sys/param.h>
38 #include <sys/clock.h>
40 #include <sys/fcntl.h>
41 #include <sys/filedesc.h>
42 #include <sys/imgact.h>
44 #include <sys/kernel.h>
45 #include <sys/limits.h>
46 #include <sys/linker.h>
48 #include <sys/malloc.h>
49 #include <sys/file.h> /* Must come after sys/malloc.h */
50 #include <sys/imgact.h>
53 #include <sys/module.h>
54 #include <sys/mount.h>
55 #include <sys/mutex.h>
56 #include <sys/namei.h>
58 #include <sys/procctl.h>
59 #include <sys/reboot.h>
60 #include <sys/resource.h>
61 #include <sys/resourcevar.h>
62 #include <sys/selinfo.h>
63 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
64 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
65 #include <sys/signal.h>
66 #include <sys/signalvar.h>
67 #include <sys/socket.h>
68 #include <sys/socketvar.h>
70 #include <sys/syscall.h>
71 #include <sys/syscallsubr.h>
72 #include <sys/sysctl.h>
73 #include <sys/sysent.h>
74 #include <sys/sysproto.h>
75 #include <sys/systm.h>
77 #include <sys/unistd.h>
78 #include <sys/ucontext.h>
79 #include <sys/vnode.h>
87 #include <netinet/in.h>
91 #include <vm/vm_param.h>
93 #include <vm/vm_map.h>
94 #include <vm/vm_object.h>
95 #include <vm/vm_extern.h>
97 #include <machine/cpu.h>
98 #include <machine/elf.h>
100 #include <security/audit/audit.h>
102 #include <compat/freebsd32/freebsd32_util.h>
103 #include <compat/freebsd32/freebsd32.h>
104 #include <compat/freebsd32/freebsd32_ipc.h>
105 #include <compat/freebsd32/freebsd32_signal.h>
106 #include <compat/freebsd32/freebsd32_proto.h>
108 CTASSERT(sizeof(struct timeval32) == 8);
109 CTASSERT(sizeof(struct timespec32) == 8);
110 CTASSERT(sizeof(struct itimerval32) == 16);
111 CTASSERT(sizeof(struct statfs32) == 256);
112 CTASSERT(sizeof(struct rusage32) == 72);
113 CTASSERT(sizeof(struct sigaltstack32) == 12);
114 CTASSERT(sizeof(struct kevent32) == 20);
115 CTASSERT(sizeof(struct iovec32) == 8);
116 CTASSERT(sizeof(struct msghdr32) == 28);
117 CTASSERT(sizeof(struct stat32) == 96);
118 CTASSERT(sizeof(struct sigaction32) == 24);
120 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
121 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
123 #if BYTE_ORDER == BIG_ENDIAN
124 #define PAIR32TO64(type, name) ((name ## 2) | ((type)(name ## 1) << 32))
128 #define PAIR32TO64(type, name) ((name ## 1) | ((type)(name ## 2) << 32))
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
249 struct statfs *buf, *sp;
250 struct statfs32 stat32;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
258 count = td->td_retval[0];
260 while (count > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
274 freebsd32_sigaltstack(struct thread *td,
275 struct freebsd32_sigaltstack_args *uap)
277 struct sigaltstack32 s32;
278 struct sigaltstack ss, oss, *ssp;
281 if (uap->ss != NULL) {
282 error = copyin(uap->ss, &s32, sizeof(s32));
285 PTRIN_CP(s32, ss, ss_sp);
286 CP(s32, ss, ss_size);
287 CP(s32, ss, ss_flags);
291 error = kern_sigaltstack(td, ssp, &oss);
292 if (error == 0 && uap->oss != NULL) {
293 PTROUT_CP(oss, s32, ss_sp);
294 CP(oss, s32, ss_size);
295 CP(oss, s32, ss_flags);
296 error = copyout(&s32, uap->oss, sizeof(s32));
302 * Custom version of exec_copyin_args() so that we can translate
306 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
307 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
314 bzero(args, sizeof(*args));
319 * Allocate demand-paged memory for the file name, argument, and
320 * environment strings.
322 error = exec_alloc_args(args);
327 * Copy the file name.
330 args->fname = args->buf;
331 error = (segflg == UIO_SYSSPACE) ?
332 copystr(fname, args->fname, PATH_MAX, &length) :
333 copyinstr(fname, args->fname, PATH_MAX, &length);
339 args->begin_argv = args->buf + length;
340 args->endp = args->begin_argv;
341 args->stringspace = ARG_MAX;
344 * extract arguments first
348 error = copyin(p32++, &arg, sizeof(arg));
354 error = copyinstr(argp, args->endp, args->stringspace, &length);
356 if (error == ENAMETOOLONG)
360 args->stringspace -= length;
361 args->endp += length;
365 args->begin_envv = args->endp;
368 * extract environment strings
373 error = copyin(p32++, &arg, sizeof(arg));
379 error = copyinstr(envp, args->endp, args->stringspace,
382 if (error == ENAMETOOLONG)
386 args->stringspace -= length;
387 args->endp += length;
395 exec_free_args(args);
400 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
402 struct image_args eargs;
405 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
406 uap->argv, uap->envv);
408 error = kern_execve(td, &eargs, NULL);
413 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
415 struct image_args eargs;
418 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
419 uap->argv, uap->envv);
422 error = kern_execve(td, &eargs, NULL);
429 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
430 int prot, int fd, off_t pos)
433 vm_map_entry_t entry;
436 map = &td->td_proc->p_vmspace->vm_map;
438 prot |= VM_PROT_WRITE;
440 if (vm_map_lookup_entry(map, start, &entry)) {
441 if ((entry->protection & prot) != prot) {
442 rv = vm_map_protect(map,
445 entry->protection | prot,
447 if (rv != KERN_SUCCESS)
451 vm_offset_t addr = trunc_page(start);
452 rv = vm_map_find(map, 0, 0,
453 &addr, PAGE_SIZE, FALSE, prot,
455 if (rv != KERN_SUCCESS)
462 r.buf = (void *) start;
463 r.nbyte = end - start;
465 return (sys_pread(td, &r));
467 while (start < end) {
468 subyte((void *) start, 0);
477 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
479 struct mprotect_args ap;
481 ap.addr = PTRIN(uap->addr);
484 #if defined(__amd64__) || defined(__ia64__)
485 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
486 ap.prot |= PROT_EXEC;
488 return (sys_mprotect(td, &ap));
492 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
495 vm_offset_t addr = (vm_offset_t) uap->addr;
496 vm_size_t len = uap->len;
497 int prot = uap->prot;
498 int flags = uap->flags;
500 off_t pos = PAIR32TO64(off_t,uap->pos);
506 * Attempt to handle page size hassles.
508 pageoff = (pos & PAGE_MASK);
509 if (flags & MAP_FIXED) {
510 vm_offset_t start, end;
514 if (start != trunc_page(start)) {
515 error = freebsd32_mmap_partial(td, start,
516 round_page(start), prot,
519 pos += round_page(start) - start;
520 start = round_page(start);
522 if (end != round_page(end)) {
523 vm_offset_t t = trunc_page(end);
524 error = freebsd32_mmap_partial(td, t, end,
527 end = trunc_page(end);
529 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
531 * We can't map this region at all. The specified
532 * address doesn't have the same alignment as the file
533 * position. Fake the mapping by simply reading the
534 * entire region into memory. First we need to make
535 * sure the region exists.
541 prot |= VM_PROT_WRITE;
542 map = &td->td_proc->p_vmspace->vm_map;
543 rv = vm_map_remove(map, start, end);
544 if (rv != KERN_SUCCESS)
546 rv = vm_map_find(map, 0, 0,
547 &start, end - start, FALSE,
548 prot, VM_PROT_ALL, 0);
549 if (rv != KERN_SUCCESS)
552 r.buf = (void *) start;
553 r.nbyte = end - start;
555 error = sys_pread(td, &r);
559 td->td_retval[0] = addr;
564 * After dealing with the ragged ends, there
565 * might be none left.
567 td->td_retval[0] = addr;
575 #if defined(__amd64__) || defined(__ia64__)
576 if (i386_read_exec && (prot & PROT_READ))
580 ap.addr = (void *) addr;
587 return (sys_mmap(td, &ap));
590 #ifdef COMPAT_FREEBSD6
592 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
594 struct freebsd32_mmap_args ap;
599 ap.flags = uap->flags;
604 return (freebsd32_mmap(td, &ap));
609 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
611 struct itimerval itv, oitv, *itvp;
612 struct itimerval32 i32;
615 if (uap->itv != NULL) {
616 error = copyin(uap->itv, &i32, sizeof(i32));
619 TV_CP(i32, itv, it_interval);
620 TV_CP(i32, itv, it_value);
624 error = kern_setitimer(td, uap->which, itvp, &oitv);
625 if (error || uap->oitv == NULL)
627 TV_CP(oitv, i32, it_interval);
628 TV_CP(oitv, i32, it_value);
629 return (copyout(&i32, uap->oitv, sizeof(i32)));
633 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
635 struct itimerval itv;
636 struct itimerval32 i32;
639 error = kern_getitimer(td, uap->which, &itv);
640 if (error || uap->itv == NULL)
642 TV_CP(itv, i32, it_interval);
643 TV_CP(itv, i32, it_value);
644 return (copyout(&i32, uap->itv, sizeof(i32)));
648 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
650 struct timeval32 tv32;
651 struct timeval tv, *tvp;
654 if (uap->tv != NULL) {
655 error = copyin(uap->tv, &tv32, sizeof(tv32));
658 CP(tv32, tv, tv_sec);
659 CP(tv32, tv, tv_usec);
664 * XXX Do pointers need PTRIN()?
666 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
667 sizeof(int32_t) * 8));
671 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
673 struct timespec32 ts32;
675 struct timeval tv, *tvp;
679 if (uap->ts != NULL) {
680 error = copyin(uap->ts, &ts32, sizeof(ts32));
683 CP(ts32, ts, tv_sec);
684 CP(ts32, ts, tv_nsec);
685 TIMESPEC_TO_TIMEVAL(&tv, &ts);
689 if (uap->sm != NULL) {
690 error = copyin(uap->sm, &set, sizeof(set));
697 * XXX Do pointers need PTRIN()?
699 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
700 uset, sizeof(int32_t) * 8);
705 * Copy 'count' items into the destination list pointed to by uap->eventlist.
708 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
710 struct freebsd32_kevent_args *uap;
711 struct kevent32 ks32[KQ_NEVENTS];
714 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
715 uap = (struct freebsd32_kevent_args *)arg;
717 for (i = 0; i < count; i++) {
718 CP(kevp[i], ks32[i], ident);
719 CP(kevp[i], ks32[i], filter);
720 CP(kevp[i], ks32[i], flags);
721 CP(kevp[i], ks32[i], fflags);
722 CP(kevp[i], ks32[i], data);
723 PTROUT_CP(kevp[i], ks32[i], udata);
725 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
727 uap->eventlist += count;
732 * Copy 'count' items from the list pointed to by uap->changelist.
735 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
737 struct freebsd32_kevent_args *uap;
738 struct kevent32 ks32[KQ_NEVENTS];
741 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
742 uap = (struct freebsd32_kevent_args *)arg;
744 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
747 uap->changelist += count;
749 for (i = 0; i < count; i++) {
750 CP(ks32[i], kevp[i], ident);
751 CP(ks32[i], kevp[i], filter);
752 CP(ks32[i], kevp[i], flags);
753 CP(ks32[i], kevp[i], fflags);
754 CP(ks32[i], kevp[i], data);
755 PTRIN_CP(ks32[i], kevp[i], udata);
762 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
764 struct timespec32 ts32;
765 struct timespec ts, *tsp;
766 struct kevent_copyops k_ops = { uap,
767 freebsd32_kevent_copyout,
768 freebsd32_kevent_copyin};
773 error = copyin(uap->timeout, &ts32, sizeof(ts32));
776 CP(ts32, ts, tv_sec);
777 CP(ts32, ts, tv_nsec);
781 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
787 freebsd32_gettimeofday(struct thread *td,
788 struct freebsd32_gettimeofday_args *uap)
791 struct timeval32 atv32;
797 CP(atv, atv32, tv_sec);
798 CP(atv, atv32, tv_usec);
799 error = copyout(&atv32, uap->tp, sizeof (atv32));
801 if (error == 0 && uap->tzp != NULL) {
802 rtz.tz_minuteswest = tz_minuteswest;
803 rtz.tz_dsttime = tz_dsttime;
804 error = copyout(&rtz, uap->tzp, sizeof (rtz));
810 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
816 error = kern_getrusage(td, uap->who, &s);
819 if (uap->rusage != NULL) {
820 freebsd32_rusage_out(&s, &s32);
821 error = copyout(&s32, uap->rusage, sizeof(s32));
827 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
829 struct iovec32 iov32;
836 if (iovcnt > UIO_MAXIOV)
838 iovlen = iovcnt * sizeof(struct iovec);
839 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
840 iov = (struct iovec *)(uio + 1);
841 for (i = 0; i < iovcnt; i++) {
842 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
847 iov[i].iov_base = PTRIN(iov32.iov_base);
848 iov[i].iov_len = iov32.iov_len;
851 uio->uio_iovcnt = iovcnt;
852 uio->uio_segflg = UIO_USERSPACE;
853 uio->uio_offset = -1;
855 for (i = 0; i < iovcnt; i++) {
856 if (iov->iov_len > INT_MAX - uio->uio_resid) {
860 uio->uio_resid += iov->iov_len;
868 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
873 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
876 error = kern_readv(td, uap->fd, auio);
882 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
887 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
890 error = kern_writev(td, uap->fd, auio);
896 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
901 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
904 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
910 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
915 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
918 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
924 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
927 struct iovec32 iov32;
933 if (iovcnt > UIO_MAXIOV)
935 iovlen = iovcnt * sizeof(struct iovec);
936 iov = malloc(iovlen, M_IOV, M_WAITOK);
937 for (i = 0; i < iovcnt; i++) {
938 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
943 iov[i].iov_base = PTRIN(iov32.iov_base);
944 iov[i].iov_len = iov32.iov_len;
951 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
956 error = copyin(msg32, &m32, sizeof(m32));
959 msg->msg_name = PTRIN(m32.msg_name);
960 msg->msg_namelen = m32.msg_namelen;
961 msg->msg_iov = PTRIN(m32.msg_iov);
962 msg->msg_iovlen = m32.msg_iovlen;
963 msg->msg_control = PTRIN(m32.msg_control);
964 msg->msg_controllen = m32.msg_controllen;
965 msg->msg_flags = m32.msg_flags;
970 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
975 m32.msg_name = PTROUT(msg->msg_name);
976 m32.msg_namelen = msg->msg_namelen;
977 m32.msg_iov = PTROUT(msg->msg_iov);
978 m32.msg_iovlen = msg->msg_iovlen;
979 m32.msg_control = PTROUT(msg->msg_control);
980 m32.msg_controllen = msg->msg_controllen;
981 m32.msg_flags = msg->msg_flags;
982 error = copyout(&m32, msg32, sizeof(m32));
986 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
987 #define FREEBSD32_ALIGN(p) \
988 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
989 #define FREEBSD32_CMSG_SPACE(l) \
990 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
992 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
993 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
995 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
999 socklen_t clen, datalen;
1002 int len, maxlen, copylen;
1006 len = msg->msg_controllen;
1007 maxlen = msg->msg_controllen;
1008 msg->msg_controllen = 0;
1011 ctlbuf = msg->msg_control;
1013 while (m && len > 0) {
1014 cm = mtod(m, struct cmsghdr *);
1017 while (cm != NULL) {
1019 if (sizeof(struct cmsghdr) > clen ||
1020 cm->cmsg_len > clen) {
1025 data = CMSG_DATA(cm);
1026 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1028 /* Adjust message length */
1029 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1034 copylen = sizeof(struct cmsghdr);
1035 if (len < copylen) {
1036 msg->msg_flags |= MSG_CTRUNC;
1040 error = copyout(cm,ctlbuf,copylen);
1044 ctlbuf += FREEBSD32_ALIGN(copylen);
1045 len -= FREEBSD32_ALIGN(copylen);
1052 if (len < copylen) {
1053 msg->msg_flags |= MSG_CTRUNC;
1057 error = copyout(data,ctlbuf,copylen);
1061 ctlbuf += FREEBSD32_ALIGN(copylen);
1062 len -= FREEBSD32_ALIGN(copylen);
1064 if (CMSG_SPACE(datalen) < clen) {
1065 clen -= CMSG_SPACE(datalen);
1066 cm = (struct cmsghdr *)
1067 ((caddr_t)cm + CMSG_SPACE(datalen));
1076 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1084 freebsd32_recvmsg(td, uap)
1086 struct freebsd32_recvmsg_args /* {
1088 struct msghdr32 *msg;
1093 struct msghdr32 m32;
1094 struct iovec *uiov, *iov;
1095 struct mbuf *control = NULL;
1096 struct mbuf **controlp;
1099 error = copyin(uap->msg, &m32, sizeof(m32));
1102 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1105 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1109 msg.msg_flags = uap->flags;
1113 controlp = (msg.msg_control != NULL) ? &control : NULL;
1114 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1118 if (control != NULL)
1119 error = freebsd32_copy_msg_out(&msg, control);
1121 msg.msg_controllen = 0;
1124 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1128 if (control != NULL)
1136 freebsd32_convert_msg_in(struct mbuf **controlp)
1138 struct mbuf *control = *controlp;
1139 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1141 socklen_t clen = control->m_len, datalen;
1147 while (cm != NULL) {
1148 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) {
1153 data = FREEBSD32_CMSG_DATA(cm);
1154 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1156 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type,
1158 controlp = &(*controlp)->m_next;
1160 if (FREEBSD32_CMSG_SPACE(datalen) < clen) {
1161 clen -= FREEBSD32_CMSG_SPACE(datalen);
1162 cm = (struct cmsghdr *)
1163 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen));
1176 freebsd32_sendmsg(struct thread *td,
1177 struct freebsd32_sendmsg_args *uap)
1180 struct msghdr32 m32;
1182 struct mbuf *control = NULL;
1183 struct sockaddr *to = NULL;
1186 error = copyin(uap->msg, &m32, sizeof(m32));
1189 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1192 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1197 if (msg.msg_name != NULL) {
1198 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1206 if (msg.msg_control) {
1207 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1212 error = sockargs(&control, msg.msg_control,
1213 msg.msg_controllen, MT_CONTROL);
1217 error = freebsd32_convert_msg_in(&control);
1222 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1233 freebsd32_recvfrom(struct thread *td,
1234 struct freebsd32_recvfrom_args *uap)
1240 if (uap->fromlenaddr) {
1241 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1242 sizeof(msg.msg_namelen));
1246 msg.msg_namelen = 0;
1249 msg.msg_name = PTRIN(uap->from);
1250 msg.msg_iov = &aiov;
1252 aiov.iov_base = PTRIN(uap->buf);
1253 aiov.iov_len = uap->len;
1254 msg.msg_control = NULL;
1255 msg.msg_flags = uap->flags;
1256 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1257 if (error == 0 && uap->fromlenaddr)
1258 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1259 sizeof (msg.msg_namelen));
1264 freebsd32_settimeofday(struct thread *td,
1265 struct freebsd32_settimeofday_args *uap)
1267 struct timeval32 tv32;
1268 struct timeval tv, *tvp;
1269 struct timezone tz, *tzp;
1273 error = copyin(uap->tv, &tv32, sizeof(tv32));
1276 CP(tv32, tv, tv_sec);
1277 CP(tv32, tv, tv_usec);
1282 error = copyin(uap->tzp, &tz, sizeof(tz));
1288 return (kern_settimeofday(td, tvp, tzp));
1292 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1294 struct timeval32 s32[2];
1295 struct timeval s[2], *sp;
1298 if (uap->tptr != NULL) {
1299 error = copyin(uap->tptr, s32, sizeof(s32));
1302 CP(s32[0], s[0], tv_sec);
1303 CP(s32[0], s[0], tv_usec);
1304 CP(s32[1], s[1], tv_sec);
1305 CP(s32[1], s[1], tv_usec);
1309 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1313 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1315 struct timeval32 s32[2];
1316 struct timeval s[2], *sp;
1319 if (uap->tptr != NULL) {
1320 error = copyin(uap->tptr, s32, sizeof(s32));
1323 CP(s32[0], s[0], tv_sec);
1324 CP(s32[0], s[0], tv_usec);
1325 CP(s32[1], s[1], tv_sec);
1326 CP(s32[1], s[1], tv_usec);
1330 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1334 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1336 struct timeval32 s32[2];
1337 struct timeval s[2], *sp;
1340 if (uap->tptr != NULL) {
1341 error = copyin(uap->tptr, s32, sizeof(s32));
1344 CP(s32[0], s[0], tv_sec);
1345 CP(s32[0], s[0], tv_usec);
1346 CP(s32[1], s[1], tv_sec);
1347 CP(s32[1], s[1], tv_usec);
1351 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1355 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1357 struct timeval32 s32[2];
1358 struct timeval s[2], *sp;
1361 if (uap->times != NULL) {
1362 error = copyin(uap->times, s32, sizeof(s32));
1365 CP(s32[0], s[0], tv_sec);
1366 CP(s32[0], s[0], tv_usec);
1367 CP(s32[1], s[1], tv_sec);
1368 CP(s32[1], s[1], tv_usec);
1372 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1377 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1379 struct timeval32 tv32;
1380 struct timeval delta, olddelta, *deltap;
1384 error = copyin(uap->delta, &tv32, sizeof(tv32));
1387 CP(tv32, delta, tv_sec);
1388 CP(tv32, delta, tv_usec);
1392 error = kern_adjtime(td, deltap, &olddelta);
1393 if (uap->olddelta && error == 0) {
1394 CP(olddelta, tv32, tv_sec);
1395 CP(olddelta, tv32, tv_usec);
1396 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1401 #ifdef COMPAT_FREEBSD4
1403 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1405 struct statfs32 s32;
1409 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1412 copy_statfs(&s, &s32);
1413 return (copyout(&s32, uap->buf, sizeof(s32)));
1417 #ifdef COMPAT_FREEBSD4
1419 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1421 struct statfs32 s32;
1425 error = kern_fstatfs(td, uap->fd, &s);
1428 copy_statfs(&s, &s32);
1429 return (copyout(&s32, uap->buf, sizeof(s32)));
1433 #ifdef COMPAT_FREEBSD4
1435 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1437 struct statfs32 s32;
1442 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1444 error = kern_fhstatfs(td, fh, &s);
1447 copy_statfs(&s, &s32);
1448 return (copyout(&s32, uap->buf, sizeof(s32)));
1453 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1455 struct pread_args ap;
1459 ap.nbyte = uap->nbyte;
1460 ap.offset = PAIR32TO64(off_t,uap->offset);
1461 return (sys_pread(td, &ap));
1465 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1467 struct pwrite_args ap;
1471 ap.nbyte = uap->nbyte;
1472 ap.offset = PAIR32TO64(off_t,uap->offset);
1473 return (sys_pwrite(td, &ap));
1478 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1480 struct lseek_args nuap;
1483 nuap.offset = uap->offset;
1484 nuap.whence = uap->whence;
1485 return (sys_lseek(td, &nuap));
1490 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1493 struct lseek_args ap;
1497 ap.offset = PAIR32TO64(off_t,uap->offset);
1498 ap.whence = uap->whence;
1499 error = sys_lseek(td, &ap);
1500 /* Expand the quad return into two parts for eax and edx */
1501 pos = *(off_t *)(td->td_retval);
1502 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1503 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1508 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1510 struct truncate_args ap;
1512 ap.path = uap->path;
1513 ap.length = PAIR32TO64(off_t,uap->length);
1514 return (sys_truncate(td, &ap));
1518 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1520 struct ftruncate_args ap;
1523 ap.length = PAIR32TO64(off_t,uap->length);
1524 return (sys_ftruncate(td, &ap));
1529 ofreebsd32_getdirentries(struct thread *td,
1530 struct ofreebsd32_getdirentries_args *uap)
1532 struct ogetdirentries_args ap;
1539 ap.count = uap->count;
1541 error = kern_ogetdirentries(td, &ap, &loff);
1544 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1551 freebsd32_getdirentries(struct thread *td,
1552 struct freebsd32_getdirentries_args *uap)
1558 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base);
1561 if (uap->basep != NULL) {
1563 error = copyout(&base32, uap->basep, sizeof(int32_t));
1568 #ifdef COMPAT_FREEBSD6
1569 /* versions with the 'int pad' argument */
1571 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1573 struct pread_args ap;
1577 ap.nbyte = uap->nbyte;
1578 ap.offset = PAIR32TO64(off_t,uap->offset);
1579 return (sys_pread(td, &ap));
1583 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1585 struct pwrite_args ap;
1589 ap.nbyte = uap->nbyte;
1590 ap.offset = PAIR32TO64(off_t,uap->offset);
1591 return (sys_pwrite(td, &ap));
1595 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1598 struct lseek_args ap;
1602 ap.offset = PAIR32TO64(off_t,uap->offset);
1603 ap.whence = uap->whence;
1604 error = sys_lseek(td, &ap);
1605 /* Expand the quad return into two parts for eax and edx */
1606 pos = *(off_t *)(td->td_retval);
1607 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1608 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1613 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1615 struct truncate_args ap;
1617 ap.path = uap->path;
1618 ap.length = PAIR32TO64(off_t,uap->length);
1619 return (sys_truncate(td, &ap));
1623 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1625 struct ftruncate_args ap;
1628 ap.length = PAIR32TO64(off_t,uap->length);
1629 return (sys_ftruncate(td, &ap));
1631 #endif /* COMPAT_FREEBSD6 */
1641 freebsd32_do_sendfile(struct thread *td,
1642 struct freebsd32_sendfile_args *uap, int compat)
1644 struct sendfile_args ap;
1645 struct sf_hdtr32 hdtr32;
1646 struct sf_hdtr hdtr;
1647 struct uio *hdr_uio, *trl_uio;
1648 struct iovec32 *iov32;
1651 hdr_uio = trl_uio = NULL;
1655 ap.offset = PAIR32TO64(off_t,uap->offset);
1656 ap.nbytes = uap->nbytes;
1657 ap.hdtr = (struct sf_hdtr *)uap->hdtr; /* XXX not used */
1658 ap.sbytes = uap->sbytes;
1659 ap.flags = uap->flags;
1661 if (uap->hdtr != NULL) {
1662 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1665 PTRIN_CP(hdtr32, hdtr, headers);
1666 CP(hdtr32, hdtr, hdr_cnt);
1667 PTRIN_CP(hdtr32, hdtr, trailers);
1668 CP(hdtr32, hdtr, trl_cnt);
1670 if (hdtr.headers != NULL) {
1671 iov32 = PTRIN(hdtr32.headers);
1672 error = freebsd32_copyinuio(iov32,
1673 hdtr32.hdr_cnt, &hdr_uio);
1677 if (hdtr.trailers != NULL) {
1678 iov32 = PTRIN(hdtr32.trailers);
1679 error = freebsd32_copyinuio(iov32,
1680 hdtr32.trl_cnt, &trl_uio);
1686 error = kern_sendfile(td, &ap, hdr_uio, trl_uio, compat);
1689 free(hdr_uio, M_IOV);
1691 free(trl_uio, M_IOV);
1695 #ifdef COMPAT_FREEBSD4
1697 freebsd4_freebsd32_sendfile(struct thread *td,
1698 struct freebsd4_freebsd32_sendfile_args *uap)
1700 return (freebsd32_do_sendfile(td,
1701 (struct freebsd32_sendfile_args *)uap, 1));
1706 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1709 return (freebsd32_do_sendfile(td, uap, 0));
1713 copy_stat(struct stat *in, struct stat32 *out)
1716 CP(*in, *out, st_dev);
1717 CP(*in, *out, st_ino);
1718 CP(*in, *out, st_mode);
1719 CP(*in, *out, st_nlink);
1720 CP(*in, *out, st_uid);
1721 CP(*in, *out, st_gid);
1722 CP(*in, *out, st_rdev);
1723 TS_CP(*in, *out, st_atim);
1724 TS_CP(*in, *out, st_mtim);
1725 TS_CP(*in, *out, st_ctim);
1726 CP(*in, *out, st_size);
1727 CP(*in, *out, st_blocks);
1728 CP(*in, *out, st_blksize);
1729 CP(*in, *out, st_flags);
1730 CP(*in, *out, st_gen);
1731 TS_CP(*in, *out, st_birthtim);
1736 copy_ostat(struct stat *in, struct ostat32 *out)
1739 CP(*in, *out, st_dev);
1740 CP(*in, *out, st_ino);
1741 CP(*in, *out, st_mode);
1742 CP(*in, *out, st_nlink);
1743 CP(*in, *out, st_uid);
1744 CP(*in, *out, st_gid);
1745 CP(*in, *out, st_rdev);
1746 CP(*in, *out, st_size);
1747 TS_CP(*in, *out, st_atim);
1748 TS_CP(*in, *out, st_mtim);
1749 TS_CP(*in, *out, st_ctim);
1750 CP(*in, *out, st_blksize);
1751 CP(*in, *out, st_blocks);
1752 CP(*in, *out, st_flags);
1753 CP(*in, *out, st_gen);
1758 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1764 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1767 copy_stat(&sb, &sb32);
1768 error = copyout(&sb32, uap->ub, sizeof (sb32));
1774 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1777 struct ostat32 sb32;
1780 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1783 copy_ostat(&sb, &sb32);
1784 error = copyout(&sb32, uap->ub, sizeof (sb32));
1790 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1796 error = kern_fstat(td, uap->fd, &ub);
1799 copy_stat(&ub, &ub32);
1800 error = copyout(&ub32, uap->ub, sizeof(ub32));
1806 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1809 struct ostat32 ub32;
1812 error = kern_fstat(td, uap->fd, &ub);
1815 copy_ostat(&ub, &ub32);
1816 error = copyout(&ub32, uap->ub, sizeof(ub32));
1822 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1828 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1831 copy_stat(&ub, &ub32);
1832 error = copyout(&ub32, uap->buf, sizeof(ub32));
1837 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1843 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1846 copy_stat(&sb, &sb32);
1847 error = copyout(&sb32, uap->ub, sizeof (sb32));
1853 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1856 struct ostat32 sb32;
1859 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1862 copy_ostat(&sb, &sb32);
1863 error = copyout(&sb32, uap->ub, sizeof (sb32));
1869 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1871 int error, name[CTL_MAXNAME];
1874 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1876 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1880 oldlen = fuword32(uap->oldlenp);
1883 error = userland_sysctl(td, name, uap->namelen,
1884 uap->old, &oldlen, 1,
1885 uap->new, uap->newlen, &j, SCTL_MASK32);
1886 if (error && error != ENOMEM)
1889 suword32(uap->oldlenp, j);
1894 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1900 error = copyin(uap->jail, &version, sizeof(uint32_t));
1907 /* FreeBSD single IPv4 jails. */
1908 struct jail32_v0 j32_v0;
1910 bzero(&j, sizeof(struct jail));
1911 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1914 CP(j32_v0, j, version);
1915 PTRIN_CP(j32_v0, j, path);
1916 PTRIN_CP(j32_v0, j, hostname);
1917 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1923 * Version 1 was used by multi-IPv4 jail implementations
1924 * that never made it into the official kernel.
1928 case 2: /* JAIL_API_VERSION */
1930 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1933 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1936 CP(j32, j, version);
1937 PTRIN_CP(j32, j, path);
1938 PTRIN_CP(j32, j, hostname);
1939 PTRIN_CP(j32, j, jailname);
1942 PTRIN_CP(j32, j, ip4);
1943 PTRIN_CP(j32, j, ip6);
1948 /* Sci-Fi jails are not supported, sorry. */
1951 return (kern_jail(td, &j));
1955 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1960 /* Check that we have an even number of iovecs. */
1961 if (uap->iovcnt & 1)
1964 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1967 error = kern_jail_set(td, auio, uap->flags);
1973 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1975 struct iovec32 iov32;
1979 /* Check that we have an even number of iovecs. */
1980 if (uap->iovcnt & 1)
1983 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1986 error = kern_jail_get(td, auio, uap->flags);
1988 for (i = 0; i < uap->iovcnt; i++) {
1989 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1990 CP(auio->uio_iov[i], iov32, iov_len);
1991 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2000 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2002 struct sigaction32 s32;
2003 struct sigaction sa, osa, *sap;
2007 error = copyin(uap->act, &s32, sizeof(s32));
2010 sa.sa_handler = PTRIN(s32.sa_u);
2011 CP(s32, sa, sa_flags);
2012 CP(s32, sa, sa_mask);
2016 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2017 if (error == 0 && uap->oact != NULL) {
2018 s32.sa_u = PTROUT(osa.sa_handler);
2019 CP(osa, s32, sa_flags);
2020 CP(osa, s32, sa_mask);
2021 error = copyout(&s32, uap->oact, sizeof(s32));
2026 #ifdef COMPAT_FREEBSD4
2028 freebsd4_freebsd32_sigaction(struct thread *td,
2029 struct freebsd4_freebsd32_sigaction_args *uap)
2031 struct sigaction32 s32;
2032 struct sigaction sa, osa, *sap;
2036 error = copyin(uap->act, &s32, sizeof(s32));
2039 sa.sa_handler = PTRIN(s32.sa_u);
2040 CP(s32, sa, sa_flags);
2041 CP(s32, sa, sa_mask);
2045 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2046 if (error == 0 && uap->oact != NULL) {
2047 s32.sa_u = PTROUT(osa.sa_handler);
2048 CP(osa, s32, sa_flags);
2049 CP(osa, s32, sa_mask);
2050 error = copyout(&s32, uap->oact, sizeof(s32));
2057 struct osigaction32 {
2066 ofreebsd32_sigaction(struct thread *td,
2067 struct ofreebsd32_sigaction_args *uap)
2069 struct osigaction32 s32;
2070 struct sigaction sa, osa, *sap;
2073 if (uap->signum <= 0 || uap->signum >= ONSIG)
2077 error = copyin(uap->nsa, &s32, sizeof(s32));
2080 sa.sa_handler = PTRIN(s32.sa_u);
2081 CP(s32, sa, sa_flags);
2082 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2086 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2087 if (error == 0 && uap->osa != NULL) {
2088 s32.sa_u = PTROUT(osa.sa_handler);
2089 CP(osa, s32, sa_flags);
2090 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2091 error = copyout(&s32, uap->osa, sizeof(s32));
2097 ofreebsd32_sigprocmask(struct thread *td,
2098 struct ofreebsd32_sigprocmask_args *uap)
2103 OSIG2SIG(uap->mask, set);
2104 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2105 SIG2OSIG(oset, td->td_retval[0]);
2110 ofreebsd32_sigpending(struct thread *td,
2111 struct ofreebsd32_sigpending_args *uap)
2113 struct proc *p = td->td_proc;
2117 siglist = p->p_siglist;
2118 SIGSETOR(siglist, td->td_siglist);
2120 SIG2OSIG(siglist, td->td_retval[0]);
2125 u_int32_t sv_handler;
2131 ofreebsd32_sigvec(struct thread *td,
2132 struct ofreebsd32_sigvec_args *uap)
2134 struct sigvec32 vec;
2135 struct sigaction sa, osa, *sap;
2138 if (uap->signum <= 0 || uap->signum >= ONSIG)
2142 error = copyin(uap->nsv, &vec, sizeof(vec));
2145 sa.sa_handler = PTRIN(vec.sv_handler);
2146 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2147 sa.sa_flags = vec.sv_flags;
2148 sa.sa_flags ^= SA_RESTART;
2152 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2153 if (error == 0 && uap->osv != NULL) {
2154 vec.sv_handler = PTROUT(osa.sa_handler);
2155 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2156 vec.sv_flags = osa.sa_flags;
2157 vec.sv_flags &= ~SA_NOCLDWAIT;
2158 vec.sv_flags ^= SA_RESTART;
2159 error = copyout(&vec, uap->osv, sizeof(vec));
2165 ofreebsd32_sigblock(struct thread *td,
2166 struct ofreebsd32_sigblock_args *uap)
2170 OSIG2SIG(uap->mask, set);
2171 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2172 SIG2OSIG(oset, td->td_retval[0]);
2177 ofreebsd32_sigsetmask(struct thread *td,
2178 struct ofreebsd32_sigsetmask_args *uap)
2182 OSIG2SIG(uap->mask, set);
2183 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2184 SIG2OSIG(oset, td->td_retval[0]);
2189 ofreebsd32_sigsuspend(struct thread *td,
2190 struct ofreebsd32_sigsuspend_args *uap)
2194 OSIG2SIG(uap->mask, mask);
2195 return (kern_sigsuspend(td, mask));
2204 ofreebsd32_sigstack(struct thread *td,
2205 struct ofreebsd32_sigstack_args *uap)
2207 struct sigstack32 s32;
2208 struct sigstack nss, oss;
2209 int error = 0, unss;
2211 if (uap->nss != NULL) {
2212 error = copyin(uap->nss, &s32, sizeof(s32));
2215 nss.ss_sp = PTRIN(s32.ss_sp);
2216 CP(s32, nss, ss_onstack);
2221 oss.ss_sp = td->td_sigstk.ss_sp;
2222 oss.ss_onstack = sigonstack(cpu_getstack(td));
2224 td->td_sigstk.ss_sp = nss.ss_sp;
2225 td->td_sigstk.ss_size = 0;
2226 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2227 td->td_pflags |= TDP_ALTSTACK;
2229 if (uap->oss != NULL) {
2230 s32.ss_sp = PTROUT(oss.ss_sp);
2231 CP(oss, s32, ss_onstack);
2232 error = copyout(&s32, uap->oss, sizeof(s32));
2239 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2241 struct timespec32 rmt32, rqt32;
2242 struct timespec rmt, rqt;
2245 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2249 CP(rqt32, rqt, tv_sec);
2250 CP(rqt32, rqt, tv_nsec);
2253 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2255 error = kern_nanosleep(td, &rqt, &rmt);
2256 if (error && uap->rmtp) {
2259 CP(rmt, rmt32, tv_sec);
2260 CP(rmt, rmt32, tv_nsec);
2262 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2270 freebsd32_clock_gettime(struct thread *td,
2271 struct freebsd32_clock_gettime_args *uap)
2273 struct timespec ats;
2274 struct timespec32 ats32;
2277 error = kern_clock_gettime(td, uap->clock_id, &ats);
2279 CP(ats, ats32, tv_sec);
2280 CP(ats, ats32, tv_nsec);
2281 error = copyout(&ats32, uap->tp, sizeof(ats32));
2287 freebsd32_clock_settime(struct thread *td,
2288 struct freebsd32_clock_settime_args *uap)
2290 struct timespec ats;
2291 struct timespec32 ats32;
2294 error = copyin(uap->tp, &ats32, sizeof(ats32));
2297 CP(ats32, ats, tv_sec);
2298 CP(ats32, ats, tv_nsec);
2300 return (kern_clock_settime(td, uap->clock_id, &ats));
2304 freebsd32_clock_getres(struct thread *td,
2305 struct freebsd32_clock_getres_args *uap)
2308 struct timespec32 ts32;
2311 if (uap->tp == NULL)
2313 error = kern_clock_getres(td, uap->clock_id, &ts);
2315 CP(ts, ts32, tv_sec);
2316 CP(ts, ts32, tv_nsec);
2317 error = copyout(&ts32, uap->tp, sizeof(ts32));
2323 freebsd32_ktimer_create(struct thread *td,
2324 struct freebsd32_ktimer_create_args *uap)
2326 struct sigevent32 ev32;
2327 struct sigevent ev, *evp;
2330 if (uap->evp == NULL) {
2334 error = copyin(uap->evp, &ev32, sizeof(ev32));
2337 error = convert_sigevent32(&ev32, &ev);
2341 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2343 error = copyout(&id, uap->timerid, sizeof(int));
2345 kern_ktimer_delete(td, id);
2351 freebsd32_ktimer_settime(struct thread *td,
2352 struct freebsd32_ktimer_settime_args *uap)
2354 struct itimerspec32 val32, oval32;
2355 struct itimerspec val, oval, *ovalp;
2358 error = copyin(uap->value, &val32, sizeof(val32));
2362 ovalp = uap->ovalue != NULL ? &oval : NULL;
2363 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2364 if (error == 0 && uap->ovalue != NULL) {
2365 ITS_CP(oval, oval32);
2366 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2372 freebsd32_ktimer_gettime(struct thread *td,
2373 struct freebsd32_ktimer_gettime_args *uap)
2375 struct itimerspec32 val32;
2376 struct itimerspec val;
2379 error = kern_ktimer_gettime(td, uap->timerid, &val);
2382 error = copyout(&val32, uap->value, sizeof(val32));
2388 freebsd32_clock_getcpuclockid2(struct thread *td,
2389 struct freebsd32_clock_getcpuclockid2_args *uap)
2394 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2395 uap->which, &clk_id);
2397 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2402 freebsd32_thr_new(struct thread *td,
2403 struct freebsd32_thr_new_args *uap)
2405 struct thr_param32 param32;
2406 struct thr_param param;
2409 if (uap->param_size < 0 ||
2410 uap->param_size > sizeof(struct thr_param32))
2412 bzero(¶m, sizeof(struct thr_param));
2413 bzero(¶m32, sizeof(struct thr_param32));
2414 error = copyin(uap->param, ¶m32, uap->param_size);
2417 param.start_func = PTRIN(param32.start_func);
2418 param.arg = PTRIN(param32.arg);
2419 param.stack_base = PTRIN(param32.stack_base);
2420 param.stack_size = param32.stack_size;
2421 param.tls_base = PTRIN(param32.tls_base);
2422 param.tls_size = param32.tls_size;
2423 param.child_tid = PTRIN(param32.child_tid);
2424 param.parent_tid = PTRIN(param32.parent_tid);
2425 param.flags = param32.flags;
2426 param.rtp = PTRIN(param32.rtp);
2427 param.spare[0] = PTRIN(param32.spare[0]);
2428 param.spare[1] = PTRIN(param32.spare[1]);
2429 param.spare[2] = PTRIN(param32.spare[2]);
2431 return (kern_thr_new(td, ¶m));
2435 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2437 struct timespec32 ts32;
2438 struct timespec ts, *tsp;
2443 if (uap->timeout != NULL) {
2444 error = copyin((const void *)uap->timeout, (void *)&ts32,
2445 sizeof(struct timespec32));
2448 ts.tv_sec = ts32.tv_sec;
2449 ts.tv_nsec = ts32.tv_nsec;
2452 return (kern_thr_suspend(td, tsp));
2456 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2458 bzero(dst, sizeof(*dst));
2459 dst->si_signo = src->si_signo;
2460 dst->si_errno = src->si_errno;
2461 dst->si_code = src->si_code;
2462 dst->si_pid = src->si_pid;
2463 dst->si_uid = src->si_uid;
2464 dst->si_status = src->si_status;
2465 dst->si_addr = (uintptr_t)src->si_addr;
2466 dst->si_value.sival_int = src->si_value.sival_int;
2467 dst->si_timerid = src->si_timerid;
2468 dst->si_overrun = src->si_overrun;
2472 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2474 struct timespec32 ts32;
2476 struct timespec *timeout;
2479 struct siginfo32 si32;
2483 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2486 ts.tv_sec = ts32.tv_sec;
2487 ts.tv_nsec = ts32.tv_nsec;
2492 error = copyin(uap->set, &set, sizeof(set));
2496 error = kern_sigtimedwait(td, set, &ksi, timeout);
2501 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2502 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2506 td->td_retval[0] = ksi.ksi_signo;
2514 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2517 struct siginfo32 si32;
2521 error = copyin(uap->set, &set, sizeof(set));
2525 error = kern_sigtimedwait(td, set, &ksi, NULL);
2530 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2531 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2534 td->td_retval[0] = ksi.ksi_signo;
2539 freebsd32_cpuset_setid(struct thread *td,
2540 struct freebsd32_cpuset_setid_args *uap)
2542 struct cpuset_setid_args ap;
2544 ap.which = uap->which;
2545 ap.id = PAIR32TO64(id_t,uap->id);
2546 ap.setid = uap->setid;
2548 return (sys_cpuset_setid(td, &ap));
2552 freebsd32_cpuset_getid(struct thread *td,
2553 struct freebsd32_cpuset_getid_args *uap)
2555 struct cpuset_getid_args ap;
2557 ap.level = uap->level;
2558 ap.which = uap->which;
2559 ap.id = PAIR32TO64(id_t,uap->id);
2560 ap.setid = uap->setid;
2562 return (sys_cpuset_getid(td, &ap));
2566 freebsd32_cpuset_getaffinity(struct thread *td,
2567 struct freebsd32_cpuset_getaffinity_args *uap)
2569 struct cpuset_getaffinity_args ap;
2571 ap.level = uap->level;
2572 ap.which = uap->which;
2573 ap.id = PAIR32TO64(id_t,uap->id);
2574 ap.cpusetsize = uap->cpusetsize;
2575 ap.mask = uap->mask;
2577 return (sys_cpuset_getaffinity(td, &ap));
2581 freebsd32_cpuset_setaffinity(struct thread *td,
2582 struct freebsd32_cpuset_setaffinity_args *uap)
2584 struct cpuset_setaffinity_args ap;
2586 ap.level = uap->level;
2587 ap.which = uap->which;
2588 ap.id = PAIR32TO64(id_t,uap->id);
2589 ap.cpusetsize = uap->cpusetsize;
2590 ap.mask = uap->mask;
2592 return (sys_cpuset_setaffinity(td, &ap));
2596 freebsd32_nmount(struct thread *td,
2597 struct freebsd32_nmount_args /* {
2599 unsigned int iovcnt;
2608 * Mount flags are now 64-bits. On 32-bit archtectures only
2609 * 32-bits are passed in, but from here on everything handles
2610 * 64-bit flags correctly.
2614 AUDIT_ARG_FFLAGS(flags);
2617 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2618 * userspace to set this flag, but we must filter it out if we want
2619 * MNT_UPDATE on the root file system to work.
2620 * MNT_ROOTFS should only be set by the kernel when mounting its
2623 flags &= ~MNT_ROOTFS;
2626 * check that we have an even number of iovec's
2627 * and that we have at least two options.
2629 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2632 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2635 error = vfs_donmount(td, flags, auio);
2643 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2645 struct yyy32 *p32, s32;
2646 struct yyy *p = NULL, s;
2651 error = copyin(uap->zzz, &s32, sizeof(s32));
2657 error = kern_xxx(td, p);
2662 error = copyout(&s32, p32, sizeof(s32));
2669 syscall32_register(int *offset, struct sysent *new_sysent,
2670 struct sysent *old_sysent)
2672 if (*offset == NO_SYSCALL) {
2675 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2676 if (freebsd32_sysent[i].sy_call ==
2677 (sy_call_t *)lkmnosys)
2679 if (i == SYS_MAXSYSCALL)
2682 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2684 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2685 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2688 *old_sysent = freebsd32_sysent[*offset];
2689 freebsd32_sysent[*offset] = *new_sysent;
2694 syscall32_deregister(int *offset, struct sysent *old_sysent)
2698 freebsd32_sysent[*offset] = *old_sysent;
2703 syscall32_module_handler(struct module *mod, int what, void *arg)
2705 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2711 error = syscall32_register(data->offset, data->new_sysent,
2714 /* Leave a mark so we know to safely unload below. */
2715 data->offset = NULL;
2718 ms.intval = *data->offset;
2720 module_setspecific(mod, &ms);
2723 error = data->chainevh(mod, what, data->chainarg);
2727 * MOD_LOAD failed, so just return without calling the
2728 * chained handler since we didn't pass along the MOD_LOAD
2731 if (data->offset == NULL)
2733 if (data->chainevh) {
2734 error = data->chainevh(mod, what, data->chainarg);
2738 error = syscall32_deregister(data->offset, &data->old_sysent);
2743 error = data->chainevh(mod, what, data->chainarg);
2749 syscall32_helper_register(struct syscall_helper_data *sd)
2751 struct syscall_helper_data *sd1;
2754 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2755 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2758 syscall32_helper_unregister(sd);
2761 sd1->registered = 1;
2767 syscall32_helper_unregister(struct syscall_helper_data *sd)
2769 struct syscall_helper_data *sd1;
2771 for (sd1 = sd; sd1->registered != 0; sd1++) {
2772 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2773 sd1->registered = 0;
2779 freebsd32_copyout_strings(struct image_params *imgp)
2785 u_int32_t *stack_base;
2786 struct freebsd32_ps_strings *arginfo;
2787 char canary[sizeof(long) * 8];
2788 int32_t pagesizes32[MAXPAGESIZES];
2789 size_t execpath_len;
2793 * Calculate string base and vector table pointers.
2794 * Also deal with signal trampoline code for this exec type.
2796 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2797 execpath_len = strlen(imgp->execpath) + 1;
2800 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2802 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2803 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2806 destp = (uintptr_t)arginfo;
2811 if (szsigcode != 0) {
2813 destp = rounddown2(destp, sizeof(uint32_t));
2814 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2819 * Copy the image path for the rtld.
2821 if (execpath_len != 0) {
2822 destp -= execpath_len;
2823 imgp->execpathp = destp;
2824 copyout(imgp->execpath, (void *)destp, execpath_len);
2828 * Prepare the canary for SSP.
2830 arc4rand(canary, sizeof(canary), 0);
2831 destp -= sizeof(canary);
2832 imgp->canary = destp;
2833 copyout(canary, (void *)destp, sizeof(canary));
2834 imgp->canarylen = sizeof(canary);
2837 * Prepare the pagesizes array.
2839 for (i = 0; i < MAXPAGESIZES; i++)
2840 pagesizes32[i] = (uint32_t)pagesizes[i];
2841 destp -= sizeof(pagesizes32);
2842 destp = rounddown2(destp, sizeof(uint32_t));
2843 imgp->pagesizes = destp;
2844 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2845 imgp->pagesizeslen = sizeof(pagesizes32);
2847 destp -= ARG_MAX - imgp->args->stringspace;
2848 destp = rounddown2(destp, sizeof(uint32_t));
2851 * If we have a valid auxargs ptr, prepare some room
2854 if (imgp->auxargs) {
2856 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2857 * lower compatibility.
2859 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2862 * The '+ 2' is for the null pointers at the end of each of
2863 * the arg and env vector sets,and imgp->auxarg_size is room
2864 * for argument of Runtime loader.
2866 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2867 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2871 * The '+ 2' is for the null pointers at the end of each of
2872 * the arg and env vector sets
2874 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2875 imgp->args->envc + 2) * sizeof(u_int32_t));
2879 * vectp also becomes our initial stack base
2883 stringp = imgp->args->begin_argv;
2884 argc = imgp->args->argc;
2885 envc = imgp->args->envc;
2887 * Copy out strings - arguments and environment.
2889 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2892 * Fill in "ps_strings" struct for ps, w, etc.
2894 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2895 suword32(&arginfo->ps_nargvstr, argc);
2898 * Fill in argument portion of vector table.
2900 for (; argc > 0; --argc) {
2901 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2902 while (*stringp++ != 0)
2907 /* a null vector table pointer separates the argp's from the envp's */
2908 suword32(vectp++, 0);
2910 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2911 suword32(&arginfo->ps_nenvstr, envc);
2914 * Fill in environment portion of vector table.
2916 for (; envc > 0; --envc) {
2917 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2918 while (*stringp++ != 0)
2923 /* end of vector table is a null pointer */
2926 return ((register_t *)stack_base);
2930 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2932 struct kld_file_stat stat;
2933 struct kld32_file_stat stat32;
2936 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2939 if (version != sizeof(struct kld32_file_stat_1) &&
2940 version != sizeof(struct kld32_file_stat))
2943 error = kern_kldstat(td, uap->fileid, &stat);
2947 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2948 CP(stat, stat32, refs);
2949 CP(stat, stat32, id);
2950 PTROUT_CP(stat, stat32, address);
2951 CP(stat, stat32, size);
2952 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2953 return (copyout(&stat32, uap->stat, version));
2957 freebsd32_posix_fallocate(struct thread *td,
2958 struct freebsd32_posix_fallocate_args *uap)
2961 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
2962 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
2967 freebsd32_posix_fadvise(struct thread *td,
2968 struct freebsd32_posix_fadvise_args *uap)
2971 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
2972 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
2978 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
2981 CP(*sig32, *sig, sigev_notify);
2982 switch (sig->sigev_notify) {
2985 case SIGEV_THREAD_ID:
2986 CP(*sig32, *sig, sigev_notify_thread_id);
2989 CP(*sig32, *sig, sigev_signo);
2990 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2993 CP(*sig32, *sig, sigev_notify_kqueue);
2994 CP(*sig32, *sig, sigev_notify_kevent_flags);
2995 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3004 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3011 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3019 return (kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),