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/capability.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.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_misc.h>
106 #include <compat/freebsd32/freebsd32_signal.h>
107 #include <compat/freebsd32/freebsd32_proto.h>
109 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
112 CTASSERT(sizeof(struct timeval32) == 8);
113 CTASSERT(sizeof(struct timespec32) == 8);
114 CTASSERT(sizeof(struct itimerval32) == 16);
116 CTASSERT(sizeof(struct statfs32) == 256);
118 CTASSERT(sizeof(struct rusage32) == 72);
120 CTASSERT(sizeof(struct sigaltstack32) == 12);
121 CTASSERT(sizeof(struct kevent32) == 20);
122 CTASSERT(sizeof(struct iovec32) == 8);
123 CTASSERT(sizeof(struct msghdr32) == 28);
125 CTASSERT(sizeof(struct stat32) == 96);
127 CTASSERT(sizeof(struct sigaction32) == 24);
129 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
130 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
133 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
136 TV_CP(*s, *s32, ru_utime);
137 TV_CP(*s, *s32, ru_stime);
138 CP(*s, *s32, ru_maxrss);
139 CP(*s, *s32, ru_ixrss);
140 CP(*s, *s32, ru_idrss);
141 CP(*s, *s32, ru_isrss);
142 CP(*s, *s32, ru_minflt);
143 CP(*s, *s32, ru_majflt);
144 CP(*s, *s32, ru_nswap);
145 CP(*s, *s32, ru_inblock);
146 CP(*s, *s32, ru_oublock);
147 CP(*s, *s32, ru_msgsnd);
148 CP(*s, *s32, ru_msgrcv);
149 CP(*s, *s32, ru_nsignals);
150 CP(*s, *s32, ru_nvcsw);
151 CP(*s, *s32, ru_nivcsw);
155 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
158 struct rusage32 ru32;
159 struct rusage ru, *rup;
161 if (uap->rusage != NULL)
165 error = kern_wait(td, uap->pid, &status, uap->options, rup);
168 if (uap->status != NULL)
169 error = copyout(&status, uap->status, sizeof(status));
170 if (uap->rusage != NULL && error == 0) {
171 freebsd32_rusage_out(&ru, &ru32);
172 error = copyout(&ru32, uap->rusage, sizeof(ru32));
178 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
180 struct wrusage32 wru32;
181 struct __wrusage wru, *wrup;
182 struct siginfo32 si32;
183 struct __siginfo si, *sip;
186 if (uap->wrusage != NULL)
190 if (uap->info != NULL) {
192 bzero(sip, sizeof(*sip));
195 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
196 &status, uap->options, wrup, sip);
199 if (uap->status != NULL)
200 error = copyout(&status, uap->status, sizeof(status));
201 if (uap->wrusage != NULL && error == 0) {
202 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
203 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
204 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
206 if (uap->info != NULL && error == 0) {
207 siginfo_to_siginfo32 (&si, &si32);
208 error = copyout(&si32, uap->info, sizeof(si32));
213 #ifdef COMPAT_FREEBSD4
215 copy_statfs(struct statfs *in, struct statfs32 *out)
218 statfs_scale_blocks(in, INT32_MAX);
219 bzero(out, sizeof(*out));
220 CP(*in, *out, f_bsize);
221 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
222 CP(*in, *out, f_blocks);
223 CP(*in, *out, f_bfree);
224 CP(*in, *out, f_bavail);
225 out->f_files = MIN(in->f_files, INT32_MAX);
226 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
227 CP(*in, *out, f_fsid);
228 CP(*in, *out, f_owner);
229 CP(*in, *out, f_type);
230 CP(*in, *out, f_flags);
231 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
232 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
233 strlcpy(out->f_fstypename,
234 in->f_fstypename, MFSNAMELEN);
235 strlcpy(out->f_mntonname,
236 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
237 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
238 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
239 strlcpy(out->f_mntfromname,
240 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
244 #ifdef COMPAT_FREEBSD4
246 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
248 struct statfs *buf, *sp;
249 struct statfs32 stat32;
253 count = uap->bufsize / sizeof(struct statfs32);
254 size = count * sizeof(struct statfs);
255 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
257 count = td->td_retval[0];
259 while (count > 0 && error == 0) {
260 copy_statfs(sp, &stat32);
261 error = copyout(&stat32, uap->buf, sizeof(stat32));
273 freebsd32_sigaltstack(struct thread *td,
274 struct freebsd32_sigaltstack_args *uap)
276 struct sigaltstack32 s32;
277 struct sigaltstack ss, oss, *ssp;
280 if (uap->ss != NULL) {
281 error = copyin(uap->ss, &s32, sizeof(s32));
284 PTRIN_CP(s32, ss, ss_sp);
285 CP(s32, ss, ss_size);
286 CP(s32, ss, ss_flags);
290 error = kern_sigaltstack(td, ssp, &oss);
291 if (error == 0 && uap->oss != NULL) {
292 PTROUT_CP(oss, s32, ss_sp);
293 CP(oss, s32, ss_size);
294 CP(oss, s32, ss_flags);
295 error = copyout(&s32, uap->oss, sizeof(s32));
301 * Custom version of exec_copyin_args() so that we can translate
305 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
306 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
313 bzero(args, sizeof(*args));
318 * Allocate demand-paged memory for the file name, argument, and
319 * environment strings.
321 error = exec_alloc_args(args);
326 * Copy the file name.
329 args->fname = args->buf;
330 error = (segflg == UIO_SYSSPACE) ?
331 copystr(fname, args->fname, PATH_MAX, &length) :
332 copyinstr(fname, args->fname, PATH_MAX, &length);
338 args->begin_argv = args->buf + length;
339 args->endp = args->begin_argv;
340 args->stringspace = ARG_MAX;
343 * extract arguments first
347 error = copyin(p32++, &arg, sizeof(arg));
353 error = copyinstr(argp, args->endp, args->stringspace, &length);
355 if (error == ENAMETOOLONG)
359 args->stringspace -= length;
360 args->endp += length;
364 args->begin_envv = args->endp;
367 * extract environment strings
372 error = copyin(p32++, &arg, sizeof(arg));
378 error = copyinstr(envp, args->endp, args->stringspace,
381 if (error == ENAMETOOLONG)
385 args->stringspace -= length;
386 args->endp += length;
394 exec_free_args(args);
399 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
401 struct image_args eargs;
404 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
405 uap->argv, uap->envv);
407 error = kern_execve(td, &eargs, NULL);
412 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
414 struct image_args eargs;
417 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
418 uap->argv, uap->envv);
421 error = kern_execve(td, &eargs, NULL);
428 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
429 int prot, int fd, off_t pos)
432 vm_map_entry_t entry;
435 map = &td->td_proc->p_vmspace->vm_map;
437 prot |= VM_PROT_WRITE;
439 if (vm_map_lookup_entry(map, start, &entry)) {
440 if ((entry->protection & prot) != prot) {
441 rv = vm_map_protect(map,
444 entry->protection | prot,
446 if (rv != KERN_SUCCESS)
450 vm_offset_t addr = trunc_page(start);
451 rv = vm_map_find(map, 0, 0,
452 &addr, PAGE_SIZE, FALSE, prot,
454 if (rv != KERN_SUCCESS)
461 r.buf = (void *) start;
462 r.nbyte = end - start;
464 return (sys_pread(td, &r));
466 while (start < end) {
467 subyte((void *) start, 0);
476 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
478 struct mprotect_args ap;
480 ap.addr = PTRIN(uap->addr);
483 #if defined(__amd64__) || defined(__ia64__)
484 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
485 ap.prot |= PROT_EXEC;
487 return (sys_mprotect(td, &ap));
491 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
494 vm_offset_t addr = (vm_offset_t) uap->addr;
495 vm_size_t len = uap->len;
496 int prot = uap->prot;
497 int flags = uap->flags;
499 off_t pos = PAIR32TO64(off_t,uap->pos);
505 * Attempt to handle page size hassles.
507 pageoff = (pos & PAGE_MASK);
508 if (flags & MAP_FIXED) {
509 vm_offset_t start, end;
513 if (start != trunc_page(start)) {
514 error = freebsd32_mmap_partial(td, start,
515 round_page(start), prot,
518 pos += round_page(start) - start;
519 start = round_page(start);
521 if (end != round_page(end)) {
522 vm_offset_t t = trunc_page(end);
523 error = freebsd32_mmap_partial(td, t, end,
526 end = trunc_page(end);
528 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
530 * We can't map this region at all. The specified
531 * address doesn't have the same alignment as the file
532 * position. Fake the mapping by simply reading the
533 * entire region into memory. First we need to make
534 * sure the region exists.
540 prot |= VM_PROT_WRITE;
541 map = &td->td_proc->p_vmspace->vm_map;
542 rv = vm_map_remove(map, start, end);
543 if (rv != KERN_SUCCESS)
545 rv = vm_map_find(map, 0, 0,
546 &start, end - start, FALSE,
547 prot, VM_PROT_ALL, 0);
548 if (rv != KERN_SUCCESS)
551 r.buf = (void *) start;
552 r.nbyte = end - start;
554 error = sys_pread(td, &r);
558 td->td_retval[0] = addr;
563 * After dealing with the ragged ends, there
564 * might be none left.
566 td->td_retval[0] = addr;
574 #if defined(__amd64__) || defined(__ia64__)
575 if (i386_read_exec && (prot & PROT_READ))
579 ap.addr = (void *) addr;
586 return (sys_mmap(td, &ap));
589 #ifdef COMPAT_FREEBSD6
591 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
593 struct freebsd32_mmap_args ap;
598 ap.flags = uap->flags;
603 return (freebsd32_mmap(td, &ap));
608 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
610 struct itimerval itv, oitv, *itvp;
611 struct itimerval32 i32;
614 if (uap->itv != NULL) {
615 error = copyin(uap->itv, &i32, sizeof(i32));
618 TV_CP(i32, itv, it_interval);
619 TV_CP(i32, itv, it_value);
623 error = kern_setitimer(td, uap->which, itvp, &oitv);
624 if (error || uap->oitv == NULL)
626 TV_CP(oitv, i32, it_interval);
627 TV_CP(oitv, i32, it_value);
628 return (copyout(&i32, uap->oitv, sizeof(i32)));
632 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
634 struct itimerval itv;
635 struct itimerval32 i32;
638 error = kern_getitimer(td, uap->which, &itv);
639 if (error || uap->itv == NULL)
641 TV_CP(itv, i32, it_interval);
642 TV_CP(itv, i32, it_value);
643 return (copyout(&i32, uap->itv, sizeof(i32)));
647 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
649 struct timeval32 tv32;
650 struct timeval tv, *tvp;
653 if (uap->tv != NULL) {
654 error = copyin(uap->tv, &tv32, sizeof(tv32));
657 CP(tv32, tv, tv_sec);
658 CP(tv32, tv, tv_usec);
663 * XXX Do pointers need PTRIN()?
665 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
666 sizeof(int32_t) * 8));
670 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
672 struct timespec32 ts32;
674 struct timeval tv, *tvp;
678 if (uap->ts != NULL) {
679 error = copyin(uap->ts, &ts32, sizeof(ts32));
682 CP(ts32, ts, tv_sec);
683 CP(ts32, ts, tv_nsec);
684 TIMESPEC_TO_TIMEVAL(&tv, &ts);
688 if (uap->sm != NULL) {
689 error = copyin(uap->sm, &set, sizeof(set));
696 * XXX Do pointers need PTRIN()?
698 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
699 uset, sizeof(int32_t) * 8);
704 * Copy 'count' items into the destination list pointed to by uap->eventlist.
707 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
709 struct freebsd32_kevent_args *uap;
710 struct kevent32 ks32[KQ_NEVENTS];
713 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
714 uap = (struct freebsd32_kevent_args *)arg;
716 for (i = 0; i < count; i++) {
717 CP(kevp[i], ks32[i], ident);
718 CP(kevp[i], ks32[i], filter);
719 CP(kevp[i], ks32[i], flags);
720 CP(kevp[i], ks32[i], fflags);
721 CP(kevp[i], ks32[i], data);
722 PTROUT_CP(kevp[i], ks32[i], udata);
724 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
726 uap->eventlist += count;
731 * Copy 'count' items from the list pointed to by uap->changelist.
734 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
736 struct freebsd32_kevent_args *uap;
737 struct kevent32 ks32[KQ_NEVENTS];
740 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
741 uap = (struct freebsd32_kevent_args *)arg;
743 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
746 uap->changelist += count;
748 for (i = 0; i < count; i++) {
749 CP(ks32[i], kevp[i], ident);
750 CP(ks32[i], kevp[i], filter);
751 CP(ks32[i], kevp[i], flags);
752 CP(ks32[i], kevp[i], fflags);
753 CP(ks32[i], kevp[i], data);
754 PTRIN_CP(ks32[i], kevp[i], udata);
761 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
763 struct timespec32 ts32;
764 struct timespec ts, *tsp;
765 struct kevent_copyops k_ops = { uap,
766 freebsd32_kevent_copyout,
767 freebsd32_kevent_copyin};
772 error = copyin(uap->timeout, &ts32, sizeof(ts32));
775 CP(ts32, ts, tv_sec);
776 CP(ts32, ts, tv_nsec);
780 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
786 freebsd32_gettimeofday(struct thread *td,
787 struct freebsd32_gettimeofday_args *uap)
790 struct timeval32 atv32;
796 CP(atv, atv32, tv_sec);
797 CP(atv, atv32, tv_usec);
798 error = copyout(&atv32, uap->tp, sizeof (atv32));
800 if (error == 0 && uap->tzp != NULL) {
801 rtz.tz_minuteswest = tz_minuteswest;
802 rtz.tz_dsttime = tz_dsttime;
803 error = copyout(&rtz, uap->tzp, sizeof (rtz));
809 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
815 error = kern_getrusage(td, uap->who, &s);
818 if (uap->rusage != NULL) {
819 freebsd32_rusage_out(&s, &s32);
820 error = copyout(&s32, uap->rusage, sizeof(s32));
826 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
828 struct iovec32 iov32;
835 if (iovcnt > UIO_MAXIOV)
837 iovlen = iovcnt * sizeof(struct iovec);
838 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
839 iov = (struct iovec *)(uio + 1);
840 for (i = 0; i < iovcnt; i++) {
841 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
846 iov[i].iov_base = PTRIN(iov32.iov_base);
847 iov[i].iov_len = iov32.iov_len;
850 uio->uio_iovcnt = iovcnt;
851 uio->uio_segflg = UIO_USERSPACE;
852 uio->uio_offset = -1;
854 for (i = 0; i < iovcnt; i++) {
855 if (iov->iov_len > INT_MAX - uio->uio_resid) {
859 uio->uio_resid += iov->iov_len;
867 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
872 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
875 error = kern_readv(td, uap->fd, auio);
881 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
886 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
889 error = kern_writev(td, uap->fd, auio);
895 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
900 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
903 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
909 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
914 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
917 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
923 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
926 struct iovec32 iov32;
932 if (iovcnt > UIO_MAXIOV)
934 iovlen = iovcnt * sizeof(struct iovec);
935 iov = malloc(iovlen, M_IOV, M_WAITOK);
936 for (i = 0; i < iovcnt; i++) {
937 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
942 iov[i].iov_base = PTRIN(iov32.iov_base);
943 iov[i].iov_len = iov32.iov_len;
950 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
955 error = copyin(msg32, &m32, sizeof(m32));
958 msg->msg_name = PTRIN(m32.msg_name);
959 msg->msg_namelen = m32.msg_namelen;
960 msg->msg_iov = PTRIN(m32.msg_iov);
961 msg->msg_iovlen = m32.msg_iovlen;
962 msg->msg_control = PTRIN(m32.msg_control);
963 msg->msg_controllen = m32.msg_controllen;
964 msg->msg_flags = m32.msg_flags;
969 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
974 m32.msg_name = PTROUT(msg->msg_name);
975 m32.msg_namelen = msg->msg_namelen;
976 m32.msg_iov = PTROUT(msg->msg_iov);
977 m32.msg_iovlen = msg->msg_iovlen;
978 m32.msg_control = PTROUT(msg->msg_control);
979 m32.msg_controllen = msg->msg_controllen;
980 m32.msg_flags = msg->msg_flags;
981 error = copyout(&m32, msg32, sizeof(m32));
986 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
988 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
990 #define FREEBSD32_ALIGN(p) \
991 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
992 #define FREEBSD32_CMSG_SPACE(l) \
993 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
995 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
996 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
998 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1002 socklen_t clen, datalen;
1005 int len, maxlen, copylen;
1009 len = msg->msg_controllen;
1010 maxlen = msg->msg_controllen;
1011 msg->msg_controllen = 0;
1014 ctlbuf = msg->msg_control;
1016 while (m && len > 0) {
1017 cm = mtod(m, struct cmsghdr *);
1020 while (cm != NULL) {
1022 if (sizeof(struct cmsghdr) > clen ||
1023 cm->cmsg_len > clen) {
1028 data = CMSG_DATA(cm);
1029 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1031 /* Adjust message length */
1032 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1037 copylen = sizeof(struct cmsghdr);
1038 if (len < copylen) {
1039 msg->msg_flags |= MSG_CTRUNC;
1043 error = copyout(cm,ctlbuf,copylen);
1047 ctlbuf += FREEBSD32_ALIGN(copylen);
1048 len -= FREEBSD32_ALIGN(copylen);
1055 if (len < copylen) {
1056 msg->msg_flags |= MSG_CTRUNC;
1060 error = copyout(data,ctlbuf,copylen);
1064 ctlbuf += FREEBSD32_ALIGN(copylen);
1065 len -= FREEBSD32_ALIGN(copylen);
1067 if (CMSG_SPACE(datalen) < clen) {
1068 clen -= CMSG_SPACE(datalen);
1069 cm = (struct cmsghdr *)
1070 ((caddr_t)cm + CMSG_SPACE(datalen));
1079 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1087 freebsd32_recvmsg(td, uap)
1089 struct freebsd32_recvmsg_args /* {
1091 struct msghdr32 *msg;
1096 struct msghdr32 m32;
1097 struct iovec *uiov, *iov;
1098 struct mbuf *control = NULL;
1099 struct mbuf **controlp;
1102 error = copyin(uap->msg, &m32, sizeof(m32));
1105 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1108 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1112 msg.msg_flags = uap->flags;
1116 controlp = (msg.msg_control != NULL) ? &control : NULL;
1117 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1121 if (control != NULL)
1122 error = freebsd32_copy_msg_out(&msg, control);
1124 msg.msg_controllen = 0;
1127 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1131 if (control != NULL)
1139 freebsd32_convert_msg_in(struct mbuf **controlp)
1141 struct mbuf *control = *controlp;
1142 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1144 socklen_t clen = control->m_len, datalen;
1150 while (cm != NULL) {
1151 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) {
1156 data = FREEBSD32_CMSG_DATA(cm);
1157 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1159 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type,
1161 controlp = &(*controlp)->m_next;
1163 if (FREEBSD32_CMSG_SPACE(datalen) < clen) {
1164 clen -= FREEBSD32_CMSG_SPACE(datalen);
1165 cm = (struct cmsghdr *)
1166 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen));
1179 freebsd32_sendmsg(struct thread *td,
1180 struct freebsd32_sendmsg_args *uap)
1183 struct msghdr32 m32;
1185 struct mbuf *control = NULL;
1186 struct sockaddr *to = NULL;
1189 error = copyin(uap->msg, &m32, sizeof(m32));
1192 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1195 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1200 if (msg.msg_name != NULL) {
1201 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1209 if (msg.msg_control) {
1210 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1215 error = sockargs(&control, msg.msg_control,
1216 msg.msg_controllen, MT_CONTROL);
1220 error = freebsd32_convert_msg_in(&control);
1225 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1236 freebsd32_recvfrom(struct thread *td,
1237 struct freebsd32_recvfrom_args *uap)
1243 if (uap->fromlenaddr) {
1244 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1245 sizeof(msg.msg_namelen));
1249 msg.msg_namelen = 0;
1252 msg.msg_name = PTRIN(uap->from);
1253 msg.msg_iov = &aiov;
1255 aiov.iov_base = PTRIN(uap->buf);
1256 aiov.iov_len = uap->len;
1257 msg.msg_control = NULL;
1258 msg.msg_flags = uap->flags;
1259 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1260 if (error == 0 && uap->fromlenaddr)
1261 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1262 sizeof (msg.msg_namelen));
1267 freebsd32_settimeofday(struct thread *td,
1268 struct freebsd32_settimeofday_args *uap)
1270 struct timeval32 tv32;
1271 struct timeval tv, *tvp;
1272 struct timezone tz, *tzp;
1276 error = copyin(uap->tv, &tv32, sizeof(tv32));
1279 CP(tv32, tv, tv_sec);
1280 CP(tv32, tv, tv_usec);
1285 error = copyin(uap->tzp, &tz, sizeof(tz));
1291 return (kern_settimeofday(td, tvp, tzp));
1295 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1297 struct timeval32 s32[2];
1298 struct timeval s[2], *sp;
1301 if (uap->tptr != NULL) {
1302 error = copyin(uap->tptr, s32, sizeof(s32));
1305 CP(s32[0], s[0], tv_sec);
1306 CP(s32[0], s[0], tv_usec);
1307 CP(s32[1], s[1], tv_sec);
1308 CP(s32[1], s[1], tv_usec);
1312 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1316 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1318 struct timeval32 s32[2];
1319 struct timeval s[2], *sp;
1322 if (uap->tptr != NULL) {
1323 error = copyin(uap->tptr, s32, sizeof(s32));
1326 CP(s32[0], s[0], tv_sec);
1327 CP(s32[0], s[0], tv_usec);
1328 CP(s32[1], s[1], tv_sec);
1329 CP(s32[1], s[1], tv_usec);
1333 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1337 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1339 struct timeval32 s32[2];
1340 struct timeval s[2], *sp;
1343 if (uap->tptr != NULL) {
1344 error = copyin(uap->tptr, s32, sizeof(s32));
1347 CP(s32[0], s[0], tv_sec);
1348 CP(s32[0], s[0], tv_usec);
1349 CP(s32[1], s[1], tv_sec);
1350 CP(s32[1], s[1], tv_usec);
1354 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1358 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1360 struct timeval32 s32[2];
1361 struct timeval s[2], *sp;
1364 if (uap->times != NULL) {
1365 error = copyin(uap->times, s32, sizeof(s32));
1368 CP(s32[0], s[0], tv_sec);
1369 CP(s32[0], s[0], tv_usec);
1370 CP(s32[1], s[1], tv_sec);
1371 CP(s32[1], s[1], tv_usec);
1375 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1380 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1382 struct timeval32 tv32;
1383 struct timeval delta, olddelta, *deltap;
1387 error = copyin(uap->delta, &tv32, sizeof(tv32));
1390 CP(tv32, delta, tv_sec);
1391 CP(tv32, delta, tv_usec);
1395 error = kern_adjtime(td, deltap, &olddelta);
1396 if (uap->olddelta && error == 0) {
1397 CP(olddelta, tv32, tv_sec);
1398 CP(olddelta, tv32, tv_usec);
1399 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1404 #ifdef COMPAT_FREEBSD4
1406 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1408 struct statfs32 s32;
1412 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1415 copy_statfs(&s, &s32);
1416 return (copyout(&s32, uap->buf, sizeof(s32)));
1420 #ifdef COMPAT_FREEBSD4
1422 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1424 struct statfs32 s32;
1428 error = kern_fstatfs(td, uap->fd, &s);
1431 copy_statfs(&s, &s32);
1432 return (copyout(&s32, uap->buf, sizeof(s32)));
1436 #ifdef COMPAT_FREEBSD4
1438 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1440 struct statfs32 s32;
1445 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1447 error = kern_fhstatfs(td, fh, &s);
1450 copy_statfs(&s, &s32);
1451 return (copyout(&s32, uap->buf, sizeof(s32)));
1456 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1458 struct pread_args ap;
1462 ap.nbyte = uap->nbyte;
1463 ap.offset = PAIR32TO64(off_t,uap->offset);
1464 return (sys_pread(td, &ap));
1468 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1470 struct pwrite_args ap;
1474 ap.nbyte = uap->nbyte;
1475 ap.offset = PAIR32TO64(off_t,uap->offset);
1476 return (sys_pwrite(td, &ap));
1481 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1483 struct lseek_args nuap;
1486 nuap.offset = uap->offset;
1487 nuap.whence = uap->whence;
1488 return (sys_lseek(td, &nuap));
1493 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1496 struct lseek_args ap;
1500 ap.offset = PAIR32TO64(off_t,uap->offset);
1501 ap.whence = uap->whence;
1502 error = sys_lseek(td, &ap);
1503 /* Expand the quad return into two parts for eax and edx */
1504 pos = *(off_t *)(td->td_retval);
1505 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1506 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1511 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1513 struct truncate_args ap;
1515 ap.path = uap->path;
1516 ap.length = PAIR32TO64(off_t,uap->length);
1517 return (sys_truncate(td, &ap));
1521 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1523 struct ftruncate_args ap;
1526 ap.length = PAIR32TO64(off_t,uap->length);
1527 return (sys_ftruncate(td, &ap));
1532 ofreebsd32_getdirentries(struct thread *td,
1533 struct ofreebsd32_getdirentries_args *uap)
1535 struct ogetdirentries_args ap;
1542 ap.count = uap->count;
1544 error = kern_ogetdirentries(td, &ap, &loff);
1547 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1554 freebsd32_getdirentries(struct thread *td,
1555 struct freebsd32_getdirentries_args *uap)
1561 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1562 NULL, UIO_USERSPACE);
1565 if (uap->basep != NULL) {
1567 error = copyout(&base32, uap->basep, sizeof(int32_t));
1572 #ifdef COMPAT_FREEBSD6
1573 /* versions with the 'int pad' argument */
1575 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1577 struct pread_args ap;
1581 ap.nbyte = uap->nbyte;
1582 ap.offset = PAIR32TO64(off_t,uap->offset);
1583 return (sys_pread(td, &ap));
1587 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1589 struct pwrite_args ap;
1593 ap.nbyte = uap->nbyte;
1594 ap.offset = PAIR32TO64(off_t,uap->offset);
1595 return (sys_pwrite(td, &ap));
1599 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1602 struct lseek_args ap;
1606 ap.offset = PAIR32TO64(off_t,uap->offset);
1607 ap.whence = uap->whence;
1608 error = sys_lseek(td, &ap);
1609 /* Expand the quad return into two parts for eax and edx */
1610 pos = *(off_t *)(td->td_retval);
1611 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1612 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1617 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1619 struct truncate_args ap;
1621 ap.path = uap->path;
1622 ap.length = PAIR32TO64(off_t,uap->length);
1623 return (sys_truncate(td, &ap));
1627 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1629 struct ftruncate_args ap;
1632 ap.length = PAIR32TO64(off_t,uap->length);
1633 return (sys_ftruncate(td, &ap));
1635 #endif /* COMPAT_FREEBSD6 */
1645 freebsd32_do_sendfile(struct thread *td,
1646 struct freebsd32_sendfile_args *uap, int compat)
1648 struct sf_hdtr32 hdtr32;
1649 struct sf_hdtr hdtr;
1650 struct uio *hdr_uio, *trl_uio;
1651 struct iovec32 *iov32;
1656 offset = PAIR32TO64(off_t, uap->offset);
1660 hdr_uio = trl_uio = NULL;
1662 if (uap->hdtr != NULL) {
1663 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1666 PTRIN_CP(hdtr32, hdtr, headers);
1667 CP(hdtr32, hdtr, hdr_cnt);
1668 PTRIN_CP(hdtr32, hdtr, trailers);
1669 CP(hdtr32, hdtr, trl_cnt);
1671 if (hdtr.headers != NULL) {
1672 iov32 = PTRIN(hdtr32.headers);
1673 error = freebsd32_copyinuio(iov32,
1674 hdtr32.hdr_cnt, &hdr_uio);
1678 if (hdtr.trailers != NULL) {
1679 iov32 = PTRIN(hdtr32.trailers);
1680 error = freebsd32_copyinuio(iov32,
1681 hdtr32.trl_cnt, &trl_uio);
1687 AUDIT_ARG_FD(uap->fd);
1689 if ((error = fget_read(td, uap->fd, CAP_PREAD, &fp)) != 0)
1692 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1693 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1698 free(hdr_uio, M_IOV);
1700 free(trl_uio, M_IOV);
1704 #ifdef COMPAT_FREEBSD4
1706 freebsd4_freebsd32_sendfile(struct thread *td,
1707 struct freebsd4_freebsd32_sendfile_args *uap)
1709 return (freebsd32_do_sendfile(td,
1710 (struct freebsd32_sendfile_args *)uap, 1));
1715 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1718 return (freebsd32_do_sendfile(td, uap, 0));
1722 copy_stat(struct stat *in, struct stat32 *out)
1725 CP(*in, *out, st_dev);
1726 CP(*in, *out, st_ino);
1727 CP(*in, *out, st_mode);
1728 CP(*in, *out, st_nlink);
1729 CP(*in, *out, st_uid);
1730 CP(*in, *out, st_gid);
1731 CP(*in, *out, st_rdev);
1732 TS_CP(*in, *out, st_atim);
1733 TS_CP(*in, *out, st_mtim);
1734 TS_CP(*in, *out, st_ctim);
1735 CP(*in, *out, st_size);
1736 CP(*in, *out, st_blocks);
1737 CP(*in, *out, st_blksize);
1738 CP(*in, *out, st_flags);
1739 CP(*in, *out, st_gen);
1740 TS_CP(*in, *out, st_birthtim);
1745 copy_ostat(struct stat *in, struct ostat32 *out)
1748 CP(*in, *out, st_dev);
1749 CP(*in, *out, st_ino);
1750 CP(*in, *out, st_mode);
1751 CP(*in, *out, st_nlink);
1752 CP(*in, *out, st_uid);
1753 CP(*in, *out, st_gid);
1754 CP(*in, *out, st_rdev);
1755 CP(*in, *out, st_size);
1756 TS_CP(*in, *out, st_atim);
1757 TS_CP(*in, *out, st_mtim);
1758 TS_CP(*in, *out, st_ctim);
1759 CP(*in, *out, st_blksize);
1760 CP(*in, *out, st_blocks);
1761 CP(*in, *out, st_flags);
1762 CP(*in, *out, st_gen);
1767 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1773 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1776 copy_stat(&sb, &sb32);
1777 error = copyout(&sb32, uap->ub, sizeof (sb32));
1783 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1786 struct ostat32 sb32;
1789 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1792 copy_ostat(&sb, &sb32);
1793 error = copyout(&sb32, uap->ub, sizeof (sb32));
1799 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1805 error = kern_fstat(td, uap->fd, &ub);
1808 copy_stat(&ub, &ub32);
1809 error = copyout(&ub32, uap->ub, sizeof(ub32));
1815 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1818 struct ostat32 ub32;
1821 error = kern_fstat(td, uap->fd, &ub);
1824 copy_ostat(&ub, &ub32);
1825 error = copyout(&ub32, uap->ub, sizeof(ub32));
1831 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1837 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1840 copy_stat(&ub, &ub32);
1841 error = copyout(&ub32, uap->buf, sizeof(ub32));
1846 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1852 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1855 copy_stat(&sb, &sb32);
1856 error = copyout(&sb32, uap->ub, sizeof (sb32));
1862 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1865 struct ostat32 sb32;
1868 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1871 copy_ostat(&sb, &sb32);
1872 error = copyout(&sb32, uap->ub, sizeof (sb32));
1878 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1880 int error, name[CTL_MAXNAME];
1883 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1885 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1889 oldlen = fuword32(uap->oldlenp);
1892 error = userland_sysctl(td, name, uap->namelen,
1893 uap->old, &oldlen, 1,
1894 uap->new, uap->newlen, &j, SCTL_MASK32);
1895 if (error && error != ENOMEM)
1898 suword32(uap->oldlenp, j);
1903 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1909 error = copyin(uap->jail, &version, sizeof(uint32_t));
1916 /* FreeBSD single IPv4 jails. */
1917 struct jail32_v0 j32_v0;
1919 bzero(&j, sizeof(struct jail));
1920 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1923 CP(j32_v0, j, version);
1924 PTRIN_CP(j32_v0, j, path);
1925 PTRIN_CP(j32_v0, j, hostname);
1926 j.ip4s = j32_v0.ip_number;
1932 * Version 1 was used by multi-IPv4 jail implementations
1933 * that never made it into the official kernel.
1937 case 2: /* JAIL_API_VERSION */
1939 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1942 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1945 CP(j32, j, version);
1946 PTRIN_CP(j32, j, path);
1947 PTRIN_CP(j32, j, hostname);
1948 PTRIN_CP(j32, j, jailname);
1951 PTRIN_CP(j32, j, ip4);
1952 PTRIN_CP(j32, j, ip6);
1957 /* Sci-Fi jails are not supported, sorry. */
1960 return (kern_jail(td, &j));
1964 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1969 /* Check that we have an even number of iovecs. */
1970 if (uap->iovcnt & 1)
1973 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1976 error = kern_jail_set(td, auio, uap->flags);
1982 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1984 struct iovec32 iov32;
1988 /* Check that we have an even number of iovecs. */
1989 if (uap->iovcnt & 1)
1992 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1995 error = kern_jail_get(td, auio, uap->flags);
1997 for (i = 0; i < uap->iovcnt; i++) {
1998 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1999 CP(auio->uio_iov[i], iov32, iov_len);
2000 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2009 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2011 struct sigaction32 s32;
2012 struct sigaction sa, osa, *sap;
2016 error = copyin(uap->act, &s32, sizeof(s32));
2019 sa.sa_handler = PTRIN(s32.sa_u);
2020 CP(s32, sa, sa_flags);
2021 CP(s32, sa, sa_mask);
2025 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2026 if (error == 0 && uap->oact != NULL) {
2027 s32.sa_u = PTROUT(osa.sa_handler);
2028 CP(osa, s32, sa_flags);
2029 CP(osa, s32, sa_mask);
2030 error = copyout(&s32, uap->oact, sizeof(s32));
2035 #ifdef COMPAT_FREEBSD4
2037 freebsd4_freebsd32_sigaction(struct thread *td,
2038 struct freebsd4_freebsd32_sigaction_args *uap)
2040 struct sigaction32 s32;
2041 struct sigaction sa, osa, *sap;
2045 error = copyin(uap->act, &s32, sizeof(s32));
2048 sa.sa_handler = PTRIN(s32.sa_u);
2049 CP(s32, sa, sa_flags);
2050 CP(s32, sa, sa_mask);
2054 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2055 if (error == 0 && uap->oact != NULL) {
2056 s32.sa_u = PTROUT(osa.sa_handler);
2057 CP(osa, s32, sa_flags);
2058 CP(osa, s32, sa_mask);
2059 error = copyout(&s32, uap->oact, sizeof(s32));
2066 struct osigaction32 {
2075 ofreebsd32_sigaction(struct thread *td,
2076 struct ofreebsd32_sigaction_args *uap)
2078 struct osigaction32 s32;
2079 struct sigaction sa, osa, *sap;
2082 if (uap->signum <= 0 || uap->signum >= ONSIG)
2086 error = copyin(uap->nsa, &s32, sizeof(s32));
2089 sa.sa_handler = PTRIN(s32.sa_u);
2090 CP(s32, sa, sa_flags);
2091 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2095 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2096 if (error == 0 && uap->osa != NULL) {
2097 s32.sa_u = PTROUT(osa.sa_handler);
2098 CP(osa, s32, sa_flags);
2099 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2100 error = copyout(&s32, uap->osa, sizeof(s32));
2106 ofreebsd32_sigprocmask(struct thread *td,
2107 struct ofreebsd32_sigprocmask_args *uap)
2112 OSIG2SIG(uap->mask, set);
2113 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2114 SIG2OSIG(oset, td->td_retval[0]);
2119 ofreebsd32_sigpending(struct thread *td,
2120 struct ofreebsd32_sigpending_args *uap)
2122 struct proc *p = td->td_proc;
2126 siglist = p->p_siglist;
2127 SIGSETOR(siglist, td->td_siglist);
2129 SIG2OSIG(siglist, td->td_retval[0]);
2134 u_int32_t sv_handler;
2140 ofreebsd32_sigvec(struct thread *td,
2141 struct ofreebsd32_sigvec_args *uap)
2143 struct sigvec32 vec;
2144 struct sigaction sa, osa, *sap;
2147 if (uap->signum <= 0 || uap->signum >= ONSIG)
2151 error = copyin(uap->nsv, &vec, sizeof(vec));
2154 sa.sa_handler = PTRIN(vec.sv_handler);
2155 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2156 sa.sa_flags = vec.sv_flags;
2157 sa.sa_flags ^= SA_RESTART;
2161 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2162 if (error == 0 && uap->osv != NULL) {
2163 vec.sv_handler = PTROUT(osa.sa_handler);
2164 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2165 vec.sv_flags = osa.sa_flags;
2166 vec.sv_flags &= ~SA_NOCLDWAIT;
2167 vec.sv_flags ^= SA_RESTART;
2168 error = copyout(&vec, uap->osv, sizeof(vec));
2174 ofreebsd32_sigblock(struct thread *td,
2175 struct ofreebsd32_sigblock_args *uap)
2179 OSIG2SIG(uap->mask, set);
2180 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2181 SIG2OSIG(oset, td->td_retval[0]);
2186 ofreebsd32_sigsetmask(struct thread *td,
2187 struct ofreebsd32_sigsetmask_args *uap)
2191 OSIG2SIG(uap->mask, set);
2192 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2193 SIG2OSIG(oset, td->td_retval[0]);
2198 ofreebsd32_sigsuspend(struct thread *td,
2199 struct ofreebsd32_sigsuspend_args *uap)
2203 OSIG2SIG(uap->mask, mask);
2204 return (kern_sigsuspend(td, mask));
2213 ofreebsd32_sigstack(struct thread *td,
2214 struct ofreebsd32_sigstack_args *uap)
2216 struct sigstack32 s32;
2217 struct sigstack nss, oss;
2218 int error = 0, unss;
2220 if (uap->nss != NULL) {
2221 error = copyin(uap->nss, &s32, sizeof(s32));
2224 nss.ss_sp = PTRIN(s32.ss_sp);
2225 CP(s32, nss, ss_onstack);
2230 oss.ss_sp = td->td_sigstk.ss_sp;
2231 oss.ss_onstack = sigonstack(cpu_getstack(td));
2233 td->td_sigstk.ss_sp = nss.ss_sp;
2234 td->td_sigstk.ss_size = 0;
2235 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2236 td->td_pflags |= TDP_ALTSTACK;
2238 if (uap->oss != NULL) {
2239 s32.ss_sp = PTROUT(oss.ss_sp);
2240 CP(oss, s32, ss_onstack);
2241 error = copyout(&s32, uap->oss, sizeof(s32));
2248 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2250 struct timespec32 rmt32, rqt32;
2251 struct timespec rmt, rqt;
2254 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2258 CP(rqt32, rqt, tv_sec);
2259 CP(rqt32, rqt, tv_nsec);
2262 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2264 error = kern_nanosleep(td, &rqt, &rmt);
2265 if (error && uap->rmtp) {
2268 CP(rmt, rmt32, tv_sec);
2269 CP(rmt, rmt32, tv_nsec);
2271 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2279 freebsd32_clock_gettime(struct thread *td,
2280 struct freebsd32_clock_gettime_args *uap)
2282 struct timespec ats;
2283 struct timespec32 ats32;
2286 error = kern_clock_gettime(td, uap->clock_id, &ats);
2288 CP(ats, ats32, tv_sec);
2289 CP(ats, ats32, tv_nsec);
2290 error = copyout(&ats32, uap->tp, sizeof(ats32));
2296 freebsd32_clock_settime(struct thread *td,
2297 struct freebsd32_clock_settime_args *uap)
2299 struct timespec ats;
2300 struct timespec32 ats32;
2303 error = copyin(uap->tp, &ats32, sizeof(ats32));
2306 CP(ats32, ats, tv_sec);
2307 CP(ats32, ats, tv_nsec);
2309 return (kern_clock_settime(td, uap->clock_id, &ats));
2313 freebsd32_clock_getres(struct thread *td,
2314 struct freebsd32_clock_getres_args *uap)
2317 struct timespec32 ts32;
2320 if (uap->tp == NULL)
2322 error = kern_clock_getres(td, uap->clock_id, &ts);
2324 CP(ts, ts32, tv_sec);
2325 CP(ts, ts32, tv_nsec);
2326 error = copyout(&ts32, uap->tp, sizeof(ts32));
2331 int freebsd32_ktimer_create(struct thread *td,
2332 struct freebsd32_ktimer_create_args *uap)
2334 struct sigevent32 ev32;
2335 struct sigevent ev, *evp;
2338 if (uap->evp == NULL) {
2342 error = copyin(uap->evp, &ev32, sizeof(ev32));
2345 error = convert_sigevent32(&ev32, &ev);
2349 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2351 error = copyout(&id, uap->timerid, sizeof(int));
2353 kern_ktimer_delete(td, id);
2359 freebsd32_ktimer_settime(struct thread *td,
2360 struct freebsd32_ktimer_settime_args *uap)
2362 struct itimerspec32 val32, oval32;
2363 struct itimerspec val, oval, *ovalp;
2366 error = copyin(uap->value, &val32, sizeof(val32));
2370 ovalp = uap->ovalue != NULL ? &oval : NULL;
2371 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2372 if (error == 0 && uap->ovalue != NULL) {
2373 ITS_CP(oval, oval32);
2374 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2380 freebsd32_ktimer_gettime(struct thread *td,
2381 struct freebsd32_ktimer_gettime_args *uap)
2383 struct itimerspec32 val32;
2384 struct itimerspec val;
2387 error = kern_ktimer_gettime(td, uap->timerid, &val);
2390 error = copyout(&val32, uap->value, sizeof(val32));
2396 freebsd32_clock_getcpuclockid2(struct thread *td,
2397 struct freebsd32_clock_getcpuclockid2_args *uap)
2402 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2403 uap->which, &clk_id);
2405 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2410 freebsd32_thr_new(struct thread *td,
2411 struct freebsd32_thr_new_args *uap)
2413 struct thr_param32 param32;
2414 struct thr_param param;
2417 if (uap->param_size < 0 ||
2418 uap->param_size > sizeof(struct thr_param32))
2420 bzero(¶m, sizeof(struct thr_param));
2421 bzero(¶m32, sizeof(struct thr_param32));
2422 error = copyin(uap->param, ¶m32, uap->param_size);
2425 param.start_func = PTRIN(param32.start_func);
2426 param.arg = PTRIN(param32.arg);
2427 param.stack_base = PTRIN(param32.stack_base);
2428 param.stack_size = param32.stack_size;
2429 param.tls_base = PTRIN(param32.tls_base);
2430 param.tls_size = param32.tls_size;
2431 param.child_tid = PTRIN(param32.child_tid);
2432 param.parent_tid = PTRIN(param32.parent_tid);
2433 param.flags = param32.flags;
2434 param.rtp = PTRIN(param32.rtp);
2435 param.spare[0] = PTRIN(param32.spare[0]);
2436 param.spare[1] = PTRIN(param32.spare[1]);
2437 param.spare[2] = PTRIN(param32.spare[2]);
2439 return (kern_thr_new(td, ¶m));
2443 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2445 struct timespec32 ts32;
2446 struct timespec ts, *tsp;
2451 if (uap->timeout != NULL) {
2452 error = copyin((const void *)uap->timeout, (void *)&ts32,
2453 sizeof(struct timespec32));
2456 ts.tv_sec = ts32.tv_sec;
2457 ts.tv_nsec = ts32.tv_nsec;
2460 return (kern_thr_suspend(td, tsp));
2464 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2466 bzero(dst, sizeof(*dst));
2467 dst->si_signo = src->si_signo;
2468 dst->si_errno = src->si_errno;
2469 dst->si_code = src->si_code;
2470 dst->si_pid = src->si_pid;
2471 dst->si_uid = src->si_uid;
2472 dst->si_status = src->si_status;
2473 dst->si_addr = (uintptr_t)src->si_addr;
2474 dst->si_value.sival_int = src->si_value.sival_int;
2475 dst->si_timerid = src->si_timerid;
2476 dst->si_overrun = src->si_overrun;
2480 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2482 struct timespec32 ts32;
2484 struct timespec *timeout;
2487 struct siginfo32 si32;
2491 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2494 ts.tv_sec = ts32.tv_sec;
2495 ts.tv_nsec = ts32.tv_nsec;
2500 error = copyin(uap->set, &set, sizeof(set));
2504 error = kern_sigtimedwait(td, set, &ksi, timeout);
2509 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2510 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2514 td->td_retval[0] = ksi.ksi_signo;
2522 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2525 struct siginfo32 si32;
2529 error = copyin(uap->set, &set, sizeof(set));
2533 error = kern_sigtimedwait(td, set, &ksi, NULL);
2538 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2539 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2542 td->td_retval[0] = ksi.ksi_signo;
2547 freebsd32_cpuset_setid(struct thread *td,
2548 struct freebsd32_cpuset_setid_args *uap)
2550 struct cpuset_setid_args ap;
2552 ap.which = uap->which;
2553 ap.id = PAIR32TO64(id_t,uap->id);
2554 ap.setid = uap->setid;
2556 return (sys_cpuset_setid(td, &ap));
2560 freebsd32_cpuset_getid(struct thread *td,
2561 struct freebsd32_cpuset_getid_args *uap)
2563 struct cpuset_getid_args ap;
2565 ap.level = uap->level;
2566 ap.which = uap->which;
2567 ap.id = PAIR32TO64(id_t,uap->id);
2568 ap.setid = uap->setid;
2570 return (sys_cpuset_getid(td, &ap));
2574 freebsd32_cpuset_getaffinity(struct thread *td,
2575 struct freebsd32_cpuset_getaffinity_args *uap)
2577 struct cpuset_getaffinity_args ap;
2579 ap.level = uap->level;
2580 ap.which = uap->which;
2581 ap.id = PAIR32TO64(id_t,uap->id);
2582 ap.cpusetsize = uap->cpusetsize;
2583 ap.mask = uap->mask;
2585 return (sys_cpuset_getaffinity(td, &ap));
2589 freebsd32_cpuset_setaffinity(struct thread *td,
2590 struct freebsd32_cpuset_setaffinity_args *uap)
2592 struct cpuset_setaffinity_args ap;
2594 ap.level = uap->level;
2595 ap.which = uap->which;
2596 ap.id = PAIR32TO64(id_t,uap->id);
2597 ap.cpusetsize = uap->cpusetsize;
2598 ap.mask = uap->mask;
2600 return (sys_cpuset_setaffinity(td, &ap));
2604 freebsd32_nmount(struct thread *td,
2605 struct freebsd32_nmount_args /* {
2607 unsigned int iovcnt;
2616 * Mount flags are now 64-bits. On 32-bit archtectures only
2617 * 32-bits are passed in, but from here on everything handles
2618 * 64-bit flags correctly.
2622 AUDIT_ARG_FFLAGS(flags);
2625 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2626 * userspace to set this flag, but we must filter it out if we want
2627 * MNT_UPDATE on the root file system to work.
2628 * MNT_ROOTFS should only be set by the kernel when mounting its
2631 flags &= ~MNT_ROOTFS;
2634 * check that we have an even number of iovec's
2635 * and that we have at least two options.
2637 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2640 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2643 error = vfs_donmount(td, flags, auio);
2651 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2653 struct yyy32 *p32, s32;
2654 struct yyy *p = NULL, s;
2659 error = copyin(uap->zzz, &s32, sizeof(s32));
2665 error = kern_xxx(td, p);
2670 error = copyout(&s32, p32, sizeof(s32));
2677 syscall32_register(int *offset, struct sysent *new_sysent,
2678 struct sysent *old_sysent)
2680 if (*offset == NO_SYSCALL) {
2683 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2684 if (freebsd32_sysent[i].sy_call ==
2685 (sy_call_t *)lkmnosys)
2687 if (i == SYS_MAXSYSCALL)
2690 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2692 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2693 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2696 *old_sysent = freebsd32_sysent[*offset];
2697 freebsd32_sysent[*offset] = *new_sysent;
2702 syscall32_deregister(int *offset, struct sysent *old_sysent)
2706 freebsd32_sysent[*offset] = *old_sysent;
2711 syscall32_module_handler(struct module *mod, int what, void *arg)
2713 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2719 error = syscall32_register(data->offset, data->new_sysent,
2722 /* Leave a mark so we know to safely unload below. */
2723 data->offset = NULL;
2726 ms.intval = *data->offset;
2728 module_setspecific(mod, &ms);
2731 error = data->chainevh(mod, what, data->chainarg);
2735 * MOD_LOAD failed, so just return without calling the
2736 * chained handler since we didn't pass along the MOD_LOAD
2739 if (data->offset == NULL)
2741 if (data->chainevh) {
2742 error = data->chainevh(mod, what, data->chainarg);
2746 error = syscall32_deregister(data->offset, &data->old_sysent);
2751 error = data->chainevh(mod, what, data->chainarg);
2757 syscall32_helper_register(struct syscall_helper_data *sd)
2759 struct syscall_helper_data *sd1;
2762 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2763 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2766 syscall32_helper_unregister(sd);
2769 sd1->registered = 1;
2775 syscall32_helper_unregister(struct syscall_helper_data *sd)
2777 struct syscall_helper_data *sd1;
2779 for (sd1 = sd; sd1->registered != 0; sd1++) {
2780 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2781 sd1->registered = 0;
2787 freebsd32_copyout_strings(struct image_params *imgp)
2791 char *stringp, *destp;
2792 u_int32_t *stack_base;
2793 struct freebsd32_ps_strings *arginfo;
2794 char canary[sizeof(long) * 8];
2795 int32_t pagesizes32[MAXPAGESIZES];
2796 size_t execpath_len;
2800 * Calculate string base and vector table pointers.
2801 * Also deal with signal trampoline code for this exec type.
2803 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2804 execpath_len = strlen(imgp->execpath) + 1;
2807 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2809 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2810 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2813 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
2814 roundup(execpath_len, sizeof(char *)) -
2815 roundup(sizeof(canary), sizeof(char *)) -
2816 roundup(sizeof(pagesizes32), sizeof(char *)) -
2817 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
2823 copyout(imgp->proc->p_sysent->sv_sigcode,
2824 ((caddr_t)arginfo - szsigcode), szsigcode);
2827 * Copy the image path for the rtld.
2829 if (execpath_len != 0) {
2830 imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
2831 copyout(imgp->execpath, (void *)imgp->execpathp,
2836 * Prepare the canary for SSP.
2838 arc4rand(canary, sizeof(canary), 0);
2839 imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len -
2841 copyout(canary, (void *)imgp->canary, sizeof(canary));
2842 imgp->canarylen = sizeof(canary);
2845 * Prepare the pagesizes array.
2847 for (i = 0; i < MAXPAGESIZES; i++)
2848 pagesizes32[i] = (uint32_t)pagesizes[i];
2849 imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len -
2850 roundup(sizeof(canary), sizeof(char *)) - sizeof(pagesizes32);
2851 copyout(pagesizes32, (void *)imgp->pagesizes, sizeof(pagesizes32));
2852 imgp->pagesizeslen = sizeof(pagesizes32);
2855 * If we have a valid auxargs ptr, prepare some room
2858 if (imgp->auxargs) {
2860 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2861 * lower compatibility.
2863 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2866 * The '+ 2' is for the null pointers at the end of each of
2867 * the arg and env vector sets,and imgp->auxarg_size is room
2868 * for argument of Runtime loader.
2870 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2871 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2875 * The '+ 2' is for the null pointers at the end of each of
2876 * the arg and env vector sets
2878 vectp = (u_int32_t *)
2879 (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t));
2882 * vectp also becomes our initial stack base
2886 stringp = imgp->args->begin_argv;
2887 argc = imgp->args->argc;
2888 envc = imgp->args->envc;
2890 * Copy out strings - arguments and environment.
2892 copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
2895 * Fill in "ps_strings" struct for ps, w, etc.
2897 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2898 suword32(&arginfo->ps_nargvstr, argc);
2901 * Fill in argument portion of vector table.
2903 for (; argc > 0; --argc) {
2904 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2905 while (*stringp++ != 0)
2910 /* a null vector table pointer separates the argp's from the envp's */
2911 suword32(vectp++, 0);
2913 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2914 suword32(&arginfo->ps_nenvstr, envc);
2917 * Fill in environment portion of vector table.
2919 for (; envc > 0; --envc) {
2920 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2921 while (*stringp++ != 0)
2926 /* end of vector table is a null pointer */
2929 return ((register_t *)stack_base);
2933 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2935 struct kld_file_stat stat;
2936 struct kld32_file_stat stat32;
2939 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2942 if (version != sizeof(struct kld32_file_stat_1) &&
2943 version != sizeof(struct kld32_file_stat))
2946 error = kern_kldstat(td, uap->fileid, &stat);
2950 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2951 CP(stat, stat32, refs);
2952 CP(stat, stat32, id);
2953 PTROUT_CP(stat, stat32, address);
2954 CP(stat, stat32, size);
2955 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2956 return (copyout(&stat32, uap->stat, version));
2960 freebsd32_posix_fallocate(struct thread *td,
2961 struct freebsd32_posix_fallocate_args *uap)
2964 return (kern_posix_fallocate(td, uap->fd,
2965 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len)));
2969 freebsd32_posix_fadvise(struct thread *td,
2970 struct freebsd32_posix_fadvise_args *uap)
2973 return (kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2974 PAIR32TO64(off_t, uap->len), uap->advice));
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);