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/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
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, NULL, 0, &addr, PAGE_SIZE, 0,
453 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
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, NULL, 0, &start, end - start,
546 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
547 if (rv != KERN_SUCCESS)
550 r.buf = (void *) start;
551 r.nbyte = end - start;
553 error = sys_pread(td, &r);
557 td->td_retval[0] = addr;
562 * After dealing with the ragged ends, there
563 * might be none left.
565 td->td_retval[0] = addr;
573 #if defined(__amd64__) || defined(__ia64__)
574 if (i386_read_exec && (prot & PROT_READ))
578 ap.addr = (void *) addr;
585 return (sys_mmap(td, &ap));
588 #ifdef COMPAT_FREEBSD6
590 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
592 struct freebsd32_mmap_args ap;
597 ap.flags = uap->flags;
602 return (freebsd32_mmap(td, &ap));
607 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
609 struct itimerval itv, oitv, *itvp;
610 struct itimerval32 i32;
613 if (uap->itv != NULL) {
614 error = copyin(uap->itv, &i32, sizeof(i32));
617 TV_CP(i32, itv, it_interval);
618 TV_CP(i32, itv, it_value);
622 error = kern_setitimer(td, uap->which, itvp, &oitv);
623 if (error || uap->oitv == NULL)
625 TV_CP(oitv, i32, it_interval);
626 TV_CP(oitv, i32, it_value);
627 return (copyout(&i32, uap->oitv, sizeof(i32)));
631 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
633 struct itimerval itv;
634 struct itimerval32 i32;
637 error = kern_getitimer(td, uap->which, &itv);
638 if (error || uap->itv == NULL)
640 TV_CP(itv, i32, it_interval);
641 TV_CP(itv, i32, it_value);
642 return (copyout(&i32, uap->itv, sizeof(i32)));
646 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
648 struct timeval32 tv32;
649 struct timeval tv, *tvp;
652 if (uap->tv != NULL) {
653 error = copyin(uap->tv, &tv32, sizeof(tv32));
656 CP(tv32, tv, tv_sec);
657 CP(tv32, tv, tv_usec);
662 * XXX Do pointers need PTRIN()?
664 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
665 sizeof(int32_t) * 8));
669 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
671 struct timespec32 ts32;
673 struct timeval tv, *tvp;
677 if (uap->ts != NULL) {
678 error = copyin(uap->ts, &ts32, sizeof(ts32));
681 CP(ts32, ts, tv_sec);
682 CP(ts32, ts, tv_nsec);
683 TIMESPEC_TO_TIMEVAL(&tv, &ts);
687 if (uap->sm != NULL) {
688 error = copyin(uap->sm, &set, sizeof(set));
695 * XXX Do pointers need PTRIN()?
697 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
698 uset, sizeof(int32_t) * 8);
703 * Copy 'count' items into the destination list pointed to by uap->eventlist.
706 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
708 struct freebsd32_kevent_args *uap;
709 struct kevent32 ks32[KQ_NEVENTS];
712 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
713 uap = (struct freebsd32_kevent_args *)arg;
715 for (i = 0; i < count; i++) {
716 CP(kevp[i], ks32[i], ident);
717 CP(kevp[i], ks32[i], filter);
718 CP(kevp[i], ks32[i], flags);
719 CP(kevp[i], ks32[i], fflags);
720 CP(kevp[i], ks32[i], data);
721 PTROUT_CP(kevp[i], ks32[i], udata);
723 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
725 uap->eventlist += count;
730 * Copy 'count' items from the list pointed to by uap->changelist.
733 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
735 struct freebsd32_kevent_args *uap;
736 struct kevent32 ks32[KQ_NEVENTS];
739 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
740 uap = (struct freebsd32_kevent_args *)arg;
742 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
745 uap->changelist += count;
747 for (i = 0; i < count; i++) {
748 CP(ks32[i], kevp[i], ident);
749 CP(ks32[i], kevp[i], filter);
750 CP(ks32[i], kevp[i], flags);
751 CP(ks32[i], kevp[i], fflags);
752 CP(ks32[i], kevp[i], data);
753 PTRIN_CP(ks32[i], kevp[i], udata);
760 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
762 struct timespec32 ts32;
763 struct timespec ts, *tsp;
764 struct kevent_copyops k_ops = { uap,
765 freebsd32_kevent_copyout,
766 freebsd32_kevent_copyin};
771 error = copyin(uap->timeout, &ts32, sizeof(ts32));
774 CP(ts32, ts, tv_sec);
775 CP(ts32, ts, tv_nsec);
779 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
785 freebsd32_gettimeofday(struct thread *td,
786 struct freebsd32_gettimeofday_args *uap)
789 struct timeval32 atv32;
795 CP(atv, atv32, tv_sec);
796 CP(atv, atv32, tv_usec);
797 error = copyout(&atv32, uap->tp, sizeof (atv32));
799 if (error == 0 && uap->tzp != NULL) {
800 rtz.tz_minuteswest = tz_minuteswest;
801 rtz.tz_dsttime = tz_dsttime;
802 error = copyout(&rtz, uap->tzp, sizeof (rtz));
808 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
814 error = kern_getrusage(td, uap->who, &s);
817 if (uap->rusage != NULL) {
818 freebsd32_rusage_out(&s, &s32);
819 error = copyout(&s32, uap->rusage, sizeof(s32));
825 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
827 struct iovec32 iov32;
834 if (iovcnt > UIO_MAXIOV)
836 iovlen = iovcnt * sizeof(struct iovec);
837 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
838 iov = (struct iovec *)(uio + 1);
839 for (i = 0; i < iovcnt; i++) {
840 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
845 iov[i].iov_base = PTRIN(iov32.iov_base);
846 iov[i].iov_len = iov32.iov_len;
849 uio->uio_iovcnt = iovcnt;
850 uio->uio_segflg = UIO_USERSPACE;
851 uio->uio_offset = -1;
853 for (i = 0; i < iovcnt; i++) {
854 if (iov->iov_len > INT_MAX - uio->uio_resid) {
858 uio->uio_resid += iov->iov_len;
866 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
871 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
874 error = kern_readv(td, uap->fd, auio);
880 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
885 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
888 error = kern_writev(td, uap->fd, auio);
894 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
899 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
902 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
908 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
913 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
916 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
922 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
925 struct iovec32 iov32;
931 if (iovcnt > UIO_MAXIOV)
933 iovlen = iovcnt * sizeof(struct iovec);
934 iov = malloc(iovlen, M_IOV, M_WAITOK);
935 for (i = 0; i < iovcnt; i++) {
936 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
941 iov[i].iov_base = PTRIN(iov32.iov_base);
942 iov[i].iov_len = iov32.iov_len;
949 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
954 error = copyin(msg32, &m32, sizeof(m32));
957 msg->msg_name = PTRIN(m32.msg_name);
958 msg->msg_namelen = m32.msg_namelen;
959 msg->msg_iov = PTRIN(m32.msg_iov);
960 msg->msg_iovlen = m32.msg_iovlen;
961 msg->msg_control = PTRIN(m32.msg_control);
962 msg->msg_controllen = m32.msg_controllen;
963 msg->msg_flags = m32.msg_flags;
968 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
973 m32.msg_name = PTROUT(msg->msg_name);
974 m32.msg_namelen = msg->msg_namelen;
975 m32.msg_iov = PTROUT(msg->msg_iov);
976 m32.msg_iovlen = msg->msg_iovlen;
977 m32.msg_control = PTROUT(msg->msg_control);
978 m32.msg_controllen = msg->msg_controllen;
979 m32.msg_flags = msg->msg_flags;
980 error = copyout(&m32, msg32, sizeof(m32));
985 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
987 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
989 #define FREEBSD32_ALIGN(p) \
990 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
991 #define FREEBSD32_CMSG_SPACE(l) \
992 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
994 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
995 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
997 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1001 socklen_t clen, datalen;
1004 int len, maxlen, copylen;
1008 len = msg->msg_controllen;
1009 maxlen = msg->msg_controllen;
1010 msg->msg_controllen = 0;
1013 ctlbuf = msg->msg_control;
1015 while (m && len > 0) {
1016 cm = mtod(m, struct cmsghdr *);
1019 while (cm != NULL) {
1021 if (sizeof(struct cmsghdr) > clen ||
1022 cm->cmsg_len > clen) {
1027 data = CMSG_DATA(cm);
1028 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1030 /* Adjust message length */
1031 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1036 copylen = sizeof(struct cmsghdr);
1037 if (len < copylen) {
1038 msg->msg_flags |= MSG_CTRUNC;
1042 error = copyout(cm,ctlbuf,copylen);
1046 ctlbuf += FREEBSD32_ALIGN(copylen);
1047 len -= FREEBSD32_ALIGN(copylen);
1054 if (len < copylen) {
1055 msg->msg_flags |= MSG_CTRUNC;
1059 error = copyout(data,ctlbuf,copylen);
1063 ctlbuf += FREEBSD32_ALIGN(copylen);
1064 len -= FREEBSD32_ALIGN(copylen);
1066 if (CMSG_SPACE(datalen) < clen) {
1067 clen -= CMSG_SPACE(datalen);
1068 cm = (struct cmsghdr *)
1069 ((caddr_t)cm + CMSG_SPACE(datalen));
1078 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1086 freebsd32_recvmsg(td, uap)
1088 struct freebsd32_recvmsg_args /* {
1090 struct msghdr32 *msg;
1095 struct msghdr32 m32;
1096 struct iovec *uiov, *iov;
1097 struct mbuf *control = NULL;
1098 struct mbuf **controlp;
1101 error = copyin(uap->msg, &m32, sizeof(m32));
1104 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1107 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1111 msg.msg_flags = uap->flags;
1115 controlp = (msg.msg_control != NULL) ? &control : NULL;
1116 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1120 if (control != NULL)
1121 error = freebsd32_copy_msg_out(&msg, control);
1123 msg.msg_controllen = 0;
1126 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1130 if (control != NULL)
1138 freebsd32_convert_msg_in(struct mbuf **controlp)
1140 struct mbuf *control = *controlp;
1141 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1143 socklen_t clen = control->m_len, datalen;
1149 while (cm != NULL) {
1150 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) {
1155 data = FREEBSD32_CMSG_DATA(cm);
1156 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1158 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type,
1160 controlp = &(*controlp)->m_next;
1162 if (FREEBSD32_CMSG_SPACE(datalen) < clen) {
1163 clen -= FREEBSD32_CMSG_SPACE(datalen);
1164 cm = (struct cmsghdr *)
1165 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen));
1178 freebsd32_sendmsg(struct thread *td,
1179 struct freebsd32_sendmsg_args *uap)
1182 struct msghdr32 m32;
1184 struct mbuf *control = NULL;
1185 struct sockaddr *to = NULL;
1188 error = copyin(uap->msg, &m32, sizeof(m32));
1191 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1194 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1199 if (msg.msg_name != NULL) {
1200 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1208 if (msg.msg_control) {
1209 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1214 error = sockargs(&control, msg.msg_control,
1215 msg.msg_controllen, MT_CONTROL);
1219 error = freebsd32_convert_msg_in(&control);
1224 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1235 freebsd32_recvfrom(struct thread *td,
1236 struct freebsd32_recvfrom_args *uap)
1242 if (uap->fromlenaddr) {
1243 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1244 sizeof(msg.msg_namelen));
1248 msg.msg_namelen = 0;
1251 msg.msg_name = PTRIN(uap->from);
1252 msg.msg_iov = &aiov;
1254 aiov.iov_base = PTRIN(uap->buf);
1255 aiov.iov_len = uap->len;
1256 msg.msg_control = NULL;
1257 msg.msg_flags = uap->flags;
1258 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1259 if (error == 0 && uap->fromlenaddr)
1260 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1261 sizeof (msg.msg_namelen));
1266 freebsd32_settimeofday(struct thread *td,
1267 struct freebsd32_settimeofday_args *uap)
1269 struct timeval32 tv32;
1270 struct timeval tv, *tvp;
1271 struct timezone tz, *tzp;
1275 error = copyin(uap->tv, &tv32, sizeof(tv32));
1278 CP(tv32, tv, tv_sec);
1279 CP(tv32, tv, tv_usec);
1284 error = copyin(uap->tzp, &tz, sizeof(tz));
1290 return (kern_settimeofday(td, tvp, tzp));
1294 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1296 struct timeval32 s32[2];
1297 struct timeval s[2], *sp;
1300 if (uap->tptr != NULL) {
1301 error = copyin(uap->tptr, s32, sizeof(s32));
1304 CP(s32[0], s[0], tv_sec);
1305 CP(s32[0], s[0], tv_usec);
1306 CP(s32[1], s[1], tv_sec);
1307 CP(s32[1], s[1], tv_usec);
1311 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1315 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1317 struct timeval32 s32[2];
1318 struct timeval s[2], *sp;
1321 if (uap->tptr != NULL) {
1322 error = copyin(uap->tptr, s32, sizeof(s32));
1325 CP(s32[0], s[0], tv_sec);
1326 CP(s32[0], s[0], tv_usec);
1327 CP(s32[1], s[1], tv_sec);
1328 CP(s32[1], s[1], tv_usec);
1332 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1336 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1338 struct timeval32 s32[2];
1339 struct timeval s[2], *sp;
1342 if (uap->tptr != NULL) {
1343 error = copyin(uap->tptr, s32, sizeof(s32));
1346 CP(s32[0], s[0], tv_sec);
1347 CP(s32[0], s[0], tv_usec);
1348 CP(s32[1], s[1], tv_sec);
1349 CP(s32[1], s[1], tv_usec);
1353 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1357 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1359 struct timeval32 s32[2];
1360 struct timeval s[2], *sp;
1363 if (uap->times != NULL) {
1364 error = copyin(uap->times, s32, sizeof(s32));
1367 CP(s32[0], s[0], tv_sec);
1368 CP(s32[0], s[0], tv_usec);
1369 CP(s32[1], s[1], tv_sec);
1370 CP(s32[1], s[1], tv_usec);
1374 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1379 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1381 struct timeval32 tv32;
1382 struct timeval delta, olddelta, *deltap;
1386 error = copyin(uap->delta, &tv32, sizeof(tv32));
1389 CP(tv32, delta, tv_sec);
1390 CP(tv32, delta, tv_usec);
1394 error = kern_adjtime(td, deltap, &olddelta);
1395 if (uap->olddelta && error == 0) {
1396 CP(olddelta, tv32, tv_sec);
1397 CP(olddelta, tv32, tv_usec);
1398 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1403 #ifdef COMPAT_FREEBSD4
1405 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1407 struct statfs32 s32;
1411 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1414 copy_statfs(&s, &s32);
1415 return (copyout(&s32, uap->buf, sizeof(s32)));
1419 #ifdef COMPAT_FREEBSD4
1421 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1423 struct statfs32 s32;
1427 error = kern_fstatfs(td, uap->fd, &s);
1430 copy_statfs(&s, &s32);
1431 return (copyout(&s32, uap->buf, sizeof(s32)));
1435 #ifdef COMPAT_FREEBSD4
1437 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1439 struct statfs32 s32;
1444 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1446 error = kern_fhstatfs(td, fh, &s);
1449 copy_statfs(&s, &s32);
1450 return (copyout(&s32, uap->buf, sizeof(s32)));
1455 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1457 struct pread_args ap;
1461 ap.nbyte = uap->nbyte;
1462 ap.offset = PAIR32TO64(off_t,uap->offset);
1463 return (sys_pread(td, &ap));
1467 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1469 struct pwrite_args ap;
1473 ap.nbyte = uap->nbyte;
1474 ap.offset = PAIR32TO64(off_t,uap->offset);
1475 return (sys_pwrite(td, &ap));
1480 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1482 struct lseek_args nuap;
1485 nuap.offset = uap->offset;
1486 nuap.whence = uap->whence;
1487 return (sys_lseek(td, &nuap));
1492 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1495 struct lseek_args ap;
1499 ap.offset = PAIR32TO64(off_t,uap->offset);
1500 ap.whence = uap->whence;
1501 error = sys_lseek(td, &ap);
1502 /* Expand the quad return into two parts for eax and edx */
1503 pos = *(off_t *)(td->td_retval);
1504 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1505 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1510 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1512 struct truncate_args ap;
1514 ap.path = uap->path;
1515 ap.length = PAIR32TO64(off_t,uap->length);
1516 return (sys_truncate(td, &ap));
1520 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1522 struct ftruncate_args ap;
1525 ap.length = PAIR32TO64(off_t,uap->length);
1526 return (sys_ftruncate(td, &ap));
1531 ofreebsd32_getdirentries(struct thread *td,
1532 struct ofreebsd32_getdirentries_args *uap)
1534 struct ogetdirentries_args ap;
1541 ap.count = uap->count;
1543 error = kern_ogetdirentries(td, &ap, &loff);
1546 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1553 freebsd32_getdirentries(struct thread *td,
1554 struct freebsd32_getdirentries_args *uap)
1560 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1561 NULL, UIO_USERSPACE);
1564 if (uap->basep != NULL) {
1566 error = copyout(&base32, uap->basep, sizeof(int32_t));
1571 #ifdef COMPAT_FREEBSD6
1572 /* versions with the 'int pad' argument */
1574 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1576 struct pread_args ap;
1580 ap.nbyte = uap->nbyte;
1581 ap.offset = PAIR32TO64(off_t,uap->offset);
1582 return (sys_pread(td, &ap));
1586 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1588 struct pwrite_args ap;
1592 ap.nbyte = uap->nbyte;
1593 ap.offset = PAIR32TO64(off_t,uap->offset);
1594 return (sys_pwrite(td, &ap));
1598 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1601 struct lseek_args ap;
1605 ap.offset = PAIR32TO64(off_t,uap->offset);
1606 ap.whence = uap->whence;
1607 error = sys_lseek(td, &ap);
1608 /* Expand the quad return into two parts for eax and edx */
1609 pos = *(off_t *)(td->td_retval);
1610 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1611 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1616 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1618 struct truncate_args ap;
1620 ap.path = uap->path;
1621 ap.length = PAIR32TO64(off_t,uap->length);
1622 return (sys_truncate(td, &ap));
1626 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1628 struct ftruncate_args ap;
1631 ap.length = PAIR32TO64(off_t,uap->length);
1632 return (sys_ftruncate(td, &ap));
1634 #endif /* COMPAT_FREEBSD6 */
1644 freebsd32_do_sendfile(struct thread *td,
1645 struct freebsd32_sendfile_args *uap, int compat)
1647 struct sf_hdtr32 hdtr32;
1648 struct sf_hdtr hdtr;
1649 struct uio *hdr_uio, *trl_uio;
1650 struct iovec32 *iov32;
1652 cap_rights_t rights;
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,
1690 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0) {
1694 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1695 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1700 free(hdr_uio, M_IOV);
1702 free(trl_uio, M_IOV);
1706 #ifdef COMPAT_FREEBSD4
1708 freebsd4_freebsd32_sendfile(struct thread *td,
1709 struct freebsd4_freebsd32_sendfile_args *uap)
1711 return (freebsd32_do_sendfile(td,
1712 (struct freebsd32_sendfile_args *)uap, 1));
1717 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1720 return (freebsd32_do_sendfile(td, uap, 0));
1724 copy_stat(struct stat *in, struct stat32 *out)
1727 CP(*in, *out, st_dev);
1728 CP(*in, *out, st_ino);
1729 CP(*in, *out, st_mode);
1730 CP(*in, *out, st_nlink);
1731 CP(*in, *out, st_uid);
1732 CP(*in, *out, st_gid);
1733 CP(*in, *out, st_rdev);
1734 TS_CP(*in, *out, st_atim);
1735 TS_CP(*in, *out, st_mtim);
1736 TS_CP(*in, *out, st_ctim);
1737 CP(*in, *out, st_size);
1738 CP(*in, *out, st_blocks);
1739 CP(*in, *out, st_blksize);
1740 CP(*in, *out, st_flags);
1741 CP(*in, *out, st_gen);
1742 TS_CP(*in, *out, st_birthtim);
1747 copy_ostat(struct stat *in, struct ostat32 *out)
1750 CP(*in, *out, st_dev);
1751 CP(*in, *out, st_ino);
1752 CP(*in, *out, st_mode);
1753 CP(*in, *out, st_nlink);
1754 CP(*in, *out, st_uid);
1755 CP(*in, *out, st_gid);
1756 CP(*in, *out, st_rdev);
1757 CP(*in, *out, st_size);
1758 TS_CP(*in, *out, st_atim);
1759 TS_CP(*in, *out, st_mtim);
1760 TS_CP(*in, *out, st_ctim);
1761 CP(*in, *out, st_blksize);
1762 CP(*in, *out, st_blocks);
1763 CP(*in, *out, st_flags);
1764 CP(*in, *out, st_gen);
1769 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1775 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1778 copy_stat(&sb, &sb32);
1779 error = copyout(&sb32, uap->ub, sizeof (sb32));
1785 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1788 struct ostat32 sb32;
1791 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1794 copy_ostat(&sb, &sb32);
1795 error = copyout(&sb32, uap->ub, sizeof (sb32));
1801 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1807 error = kern_fstat(td, uap->fd, &ub);
1810 copy_stat(&ub, &ub32);
1811 error = copyout(&ub32, uap->ub, sizeof(ub32));
1817 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1820 struct ostat32 ub32;
1823 error = kern_fstat(td, uap->fd, &ub);
1826 copy_ostat(&ub, &ub32);
1827 error = copyout(&ub32, uap->ub, sizeof(ub32));
1833 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1839 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1842 copy_stat(&ub, &ub32);
1843 error = copyout(&ub32, uap->buf, sizeof(ub32));
1848 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1854 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1857 copy_stat(&sb, &sb32);
1858 error = copyout(&sb32, uap->ub, sizeof (sb32));
1864 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1867 struct ostat32 sb32;
1870 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1873 copy_ostat(&sb, &sb32);
1874 error = copyout(&sb32, uap->ub, sizeof (sb32));
1880 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1882 int error, name[CTL_MAXNAME];
1885 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1887 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1891 oldlen = fuword32(uap->oldlenp);
1894 error = userland_sysctl(td, name, uap->namelen,
1895 uap->old, &oldlen, 1,
1896 uap->new, uap->newlen, &j, SCTL_MASK32);
1897 if (error && error != ENOMEM)
1900 suword32(uap->oldlenp, j);
1905 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1911 error = copyin(uap->jail, &version, sizeof(uint32_t));
1918 /* FreeBSD single IPv4 jails. */
1919 struct jail32_v0 j32_v0;
1921 bzero(&j, sizeof(struct jail));
1922 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1925 CP(j32_v0, j, version);
1926 PTRIN_CP(j32_v0, j, path);
1927 PTRIN_CP(j32_v0, j, hostname);
1928 j.ip4s = j32_v0.ip_number;
1934 * Version 1 was used by multi-IPv4 jail implementations
1935 * that never made it into the official kernel.
1939 case 2: /* JAIL_API_VERSION */
1941 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1944 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1947 CP(j32, j, version);
1948 PTRIN_CP(j32, j, path);
1949 PTRIN_CP(j32, j, hostname);
1950 PTRIN_CP(j32, j, jailname);
1953 PTRIN_CP(j32, j, ip4);
1954 PTRIN_CP(j32, j, ip6);
1959 /* Sci-Fi jails are not supported, sorry. */
1962 return (kern_jail(td, &j));
1966 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1971 /* Check that we have an even number of iovecs. */
1972 if (uap->iovcnt & 1)
1975 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1978 error = kern_jail_set(td, auio, uap->flags);
1984 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1986 struct iovec32 iov32;
1990 /* Check that we have an even number of iovecs. */
1991 if (uap->iovcnt & 1)
1994 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1997 error = kern_jail_get(td, auio, uap->flags);
1999 for (i = 0; i < uap->iovcnt; i++) {
2000 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2001 CP(auio->uio_iov[i], iov32, iov_len);
2002 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2011 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2013 struct sigaction32 s32;
2014 struct sigaction sa, osa, *sap;
2018 error = copyin(uap->act, &s32, sizeof(s32));
2021 sa.sa_handler = PTRIN(s32.sa_u);
2022 CP(s32, sa, sa_flags);
2023 CP(s32, sa, sa_mask);
2027 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2028 if (error == 0 && uap->oact != NULL) {
2029 s32.sa_u = PTROUT(osa.sa_handler);
2030 CP(osa, s32, sa_flags);
2031 CP(osa, s32, sa_mask);
2032 error = copyout(&s32, uap->oact, sizeof(s32));
2037 #ifdef COMPAT_FREEBSD4
2039 freebsd4_freebsd32_sigaction(struct thread *td,
2040 struct freebsd4_freebsd32_sigaction_args *uap)
2042 struct sigaction32 s32;
2043 struct sigaction sa, osa, *sap;
2047 error = copyin(uap->act, &s32, sizeof(s32));
2050 sa.sa_handler = PTRIN(s32.sa_u);
2051 CP(s32, sa, sa_flags);
2052 CP(s32, sa, sa_mask);
2056 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2057 if (error == 0 && uap->oact != NULL) {
2058 s32.sa_u = PTROUT(osa.sa_handler);
2059 CP(osa, s32, sa_flags);
2060 CP(osa, s32, sa_mask);
2061 error = copyout(&s32, uap->oact, sizeof(s32));
2068 struct osigaction32 {
2077 ofreebsd32_sigaction(struct thread *td,
2078 struct ofreebsd32_sigaction_args *uap)
2080 struct osigaction32 s32;
2081 struct sigaction sa, osa, *sap;
2084 if (uap->signum <= 0 || uap->signum >= ONSIG)
2088 error = copyin(uap->nsa, &s32, sizeof(s32));
2091 sa.sa_handler = PTRIN(s32.sa_u);
2092 CP(s32, sa, sa_flags);
2093 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2097 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2098 if (error == 0 && uap->osa != NULL) {
2099 s32.sa_u = PTROUT(osa.sa_handler);
2100 CP(osa, s32, sa_flags);
2101 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2102 error = copyout(&s32, uap->osa, sizeof(s32));
2108 ofreebsd32_sigprocmask(struct thread *td,
2109 struct ofreebsd32_sigprocmask_args *uap)
2114 OSIG2SIG(uap->mask, set);
2115 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2116 SIG2OSIG(oset, td->td_retval[0]);
2121 ofreebsd32_sigpending(struct thread *td,
2122 struct ofreebsd32_sigpending_args *uap)
2124 struct proc *p = td->td_proc;
2128 siglist = p->p_siglist;
2129 SIGSETOR(siglist, td->td_siglist);
2131 SIG2OSIG(siglist, td->td_retval[0]);
2136 u_int32_t sv_handler;
2142 ofreebsd32_sigvec(struct thread *td,
2143 struct ofreebsd32_sigvec_args *uap)
2145 struct sigvec32 vec;
2146 struct sigaction sa, osa, *sap;
2149 if (uap->signum <= 0 || uap->signum >= ONSIG)
2153 error = copyin(uap->nsv, &vec, sizeof(vec));
2156 sa.sa_handler = PTRIN(vec.sv_handler);
2157 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2158 sa.sa_flags = vec.sv_flags;
2159 sa.sa_flags ^= SA_RESTART;
2163 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2164 if (error == 0 && uap->osv != NULL) {
2165 vec.sv_handler = PTROUT(osa.sa_handler);
2166 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2167 vec.sv_flags = osa.sa_flags;
2168 vec.sv_flags &= ~SA_NOCLDWAIT;
2169 vec.sv_flags ^= SA_RESTART;
2170 error = copyout(&vec, uap->osv, sizeof(vec));
2176 ofreebsd32_sigblock(struct thread *td,
2177 struct ofreebsd32_sigblock_args *uap)
2181 OSIG2SIG(uap->mask, set);
2182 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2183 SIG2OSIG(oset, td->td_retval[0]);
2188 ofreebsd32_sigsetmask(struct thread *td,
2189 struct ofreebsd32_sigsetmask_args *uap)
2193 OSIG2SIG(uap->mask, set);
2194 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2195 SIG2OSIG(oset, td->td_retval[0]);
2200 ofreebsd32_sigsuspend(struct thread *td,
2201 struct ofreebsd32_sigsuspend_args *uap)
2205 OSIG2SIG(uap->mask, mask);
2206 return (kern_sigsuspend(td, mask));
2215 ofreebsd32_sigstack(struct thread *td,
2216 struct ofreebsd32_sigstack_args *uap)
2218 struct sigstack32 s32;
2219 struct sigstack nss, oss;
2220 int error = 0, unss;
2222 if (uap->nss != NULL) {
2223 error = copyin(uap->nss, &s32, sizeof(s32));
2226 nss.ss_sp = PTRIN(s32.ss_sp);
2227 CP(s32, nss, ss_onstack);
2232 oss.ss_sp = td->td_sigstk.ss_sp;
2233 oss.ss_onstack = sigonstack(cpu_getstack(td));
2235 td->td_sigstk.ss_sp = nss.ss_sp;
2236 td->td_sigstk.ss_size = 0;
2237 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2238 td->td_pflags |= TDP_ALTSTACK;
2240 if (uap->oss != NULL) {
2241 s32.ss_sp = PTROUT(oss.ss_sp);
2242 CP(oss, s32, ss_onstack);
2243 error = copyout(&s32, uap->oss, sizeof(s32));
2250 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2252 struct timespec32 rmt32, rqt32;
2253 struct timespec rmt, rqt;
2256 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2260 CP(rqt32, rqt, tv_sec);
2261 CP(rqt32, rqt, tv_nsec);
2264 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2266 error = kern_nanosleep(td, &rqt, &rmt);
2267 if (error && uap->rmtp) {
2270 CP(rmt, rmt32, tv_sec);
2271 CP(rmt, rmt32, tv_nsec);
2273 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2281 freebsd32_clock_gettime(struct thread *td,
2282 struct freebsd32_clock_gettime_args *uap)
2284 struct timespec ats;
2285 struct timespec32 ats32;
2288 error = kern_clock_gettime(td, uap->clock_id, &ats);
2290 CP(ats, ats32, tv_sec);
2291 CP(ats, ats32, tv_nsec);
2292 error = copyout(&ats32, uap->tp, sizeof(ats32));
2298 freebsd32_clock_settime(struct thread *td,
2299 struct freebsd32_clock_settime_args *uap)
2301 struct timespec ats;
2302 struct timespec32 ats32;
2305 error = copyin(uap->tp, &ats32, sizeof(ats32));
2308 CP(ats32, ats, tv_sec);
2309 CP(ats32, ats, tv_nsec);
2311 return (kern_clock_settime(td, uap->clock_id, &ats));
2315 freebsd32_clock_getres(struct thread *td,
2316 struct freebsd32_clock_getres_args *uap)
2319 struct timespec32 ts32;
2322 if (uap->tp == NULL)
2324 error = kern_clock_getres(td, uap->clock_id, &ts);
2326 CP(ts, ts32, tv_sec);
2327 CP(ts, ts32, tv_nsec);
2328 error = copyout(&ts32, uap->tp, sizeof(ts32));
2333 int freebsd32_ktimer_create(struct thread *td,
2334 struct freebsd32_ktimer_create_args *uap)
2336 struct sigevent32 ev32;
2337 struct sigevent ev, *evp;
2340 if (uap->evp == NULL) {
2344 error = copyin(uap->evp, &ev32, sizeof(ev32));
2347 error = convert_sigevent32(&ev32, &ev);
2351 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2353 error = copyout(&id, uap->timerid, sizeof(int));
2355 kern_ktimer_delete(td, id);
2361 freebsd32_ktimer_settime(struct thread *td,
2362 struct freebsd32_ktimer_settime_args *uap)
2364 struct itimerspec32 val32, oval32;
2365 struct itimerspec val, oval, *ovalp;
2368 error = copyin(uap->value, &val32, sizeof(val32));
2372 ovalp = uap->ovalue != NULL ? &oval : NULL;
2373 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2374 if (error == 0 && uap->ovalue != NULL) {
2375 ITS_CP(oval, oval32);
2376 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2382 freebsd32_ktimer_gettime(struct thread *td,
2383 struct freebsd32_ktimer_gettime_args *uap)
2385 struct itimerspec32 val32;
2386 struct itimerspec val;
2389 error = kern_ktimer_gettime(td, uap->timerid, &val);
2392 error = copyout(&val32, uap->value, sizeof(val32));
2398 freebsd32_clock_getcpuclockid2(struct thread *td,
2399 struct freebsd32_clock_getcpuclockid2_args *uap)
2404 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2405 uap->which, &clk_id);
2407 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2412 freebsd32_thr_new(struct thread *td,
2413 struct freebsd32_thr_new_args *uap)
2415 struct thr_param32 param32;
2416 struct thr_param param;
2419 if (uap->param_size < 0 ||
2420 uap->param_size > sizeof(struct thr_param32))
2422 bzero(¶m, sizeof(struct thr_param));
2423 bzero(¶m32, sizeof(struct thr_param32));
2424 error = copyin(uap->param, ¶m32, uap->param_size);
2427 param.start_func = PTRIN(param32.start_func);
2428 param.arg = PTRIN(param32.arg);
2429 param.stack_base = PTRIN(param32.stack_base);
2430 param.stack_size = param32.stack_size;
2431 param.tls_base = PTRIN(param32.tls_base);
2432 param.tls_size = param32.tls_size;
2433 param.child_tid = PTRIN(param32.child_tid);
2434 param.parent_tid = PTRIN(param32.parent_tid);
2435 param.flags = param32.flags;
2436 param.rtp = PTRIN(param32.rtp);
2437 param.spare[0] = PTRIN(param32.spare[0]);
2438 param.spare[1] = PTRIN(param32.spare[1]);
2439 param.spare[2] = PTRIN(param32.spare[2]);
2441 return (kern_thr_new(td, ¶m));
2445 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2447 struct timespec32 ts32;
2448 struct timespec ts, *tsp;
2453 if (uap->timeout != NULL) {
2454 error = copyin((const void *)uap->timeout, (void *)&ts32,
2455 sizeof(struct timespec32));
2458 ts.tv_sec = ts32.tv_sec;
2459 ts.tv_nsec = ts32.tv_nsec;
2462 return (kern_thr_suspend(td, tsp));
2466 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2468 bzero(dst, sizeof(*dst));
2469 dst->si_signo = src->si_signo;
2470 dst->si_errno = src->si_errno;
2471 dst->si_code = src->si_code;
2472 dst->si_pid = src->si_pid;
2473 dst->si_uid = src->si_uid;
2474 dst->si_status = src->si_status;
2475 dst->si_addr = (uintptr_t)src->si_addr;
2476 dst->si_value.sival_int = src->si_value.sival_int;
2477 dst->si_timerid = src->si_timerid;
2478 dst->si_overrun = src->si_overrun;
2482 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2484 struct timespec32 ts32;
2486 struct timespec *timeout;
2489 struct siginfo32 si32;
2493 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2496 ts.tv_sec = ts32.tv_sec;
2497 ts.tv_nsec = ts32.tv_nsec;
2502 error = copyin(uap->set, &set, sizeof(set));
2506 error = kern_sigtimedwait(td, set, &ksi, timeout);
2511 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2512 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2516 td->td_retval[0] = ksi.ksi_signo;
2524 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2527 struct siginfo32 si32;
2531 error = copyin(uap->set, &set, sizeof(set));
2535 error = kern_sigtimedwait(td, set, &ksi, NULL);
2540 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2541 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2544 td->td_retval[0] = ksi.ksi_signo;
2549 freebsd32_cpuset_setid(struct thread *td,
2550 struct freebsd32_cpuset_setid_args *uap)
2552 struct cpuset_setid_args ap;
2554 ap.which = uap->which;
2555 ap.id = PAIR32TO64(id_t,uap->id);
2556 ap.setid = uap->setid;
2558 return (sys_cpuset_setid(td, &ap));
2562 freebsd32_cpuset_getid(struct thread *td,
2563 struct freebsd32_cpuset_getid_args *uap)
2565 struct cpuset_getid_args ap;
2567 ap.level = uap->level;
2568 ap.which = uap->which;
2569 ap.id = PAIR32TO64(id_t,uap->id);
2570 ap.setid = uap->setid;
2572 return (sys_cpuset_getid(td, &ap));
2576 freebsd32_cpuset_getaffinity(struct thread *td,
2577 struct freebsd32_cpuset_getaffinity_args *uap)
2579 struct cpuset_getaffinity_args ap;
2581 ap.level = uap->level;
2582 ap.which = uap->which;
2583 ap.id = PAIR32TO64(id_t,uap->id);
2584 ap.cpusetsize = uap->cpusetsize;
2585 ap.mask = uap->mask;
2587 return (sys_cpuset_getaffinity(td, &ap));
2591 freebsd32_cpuset_setaffinity(struct thread *td,
2592 struct freebsd32_cpuset_setaffinity_args *uap)
2594 struct cpuset_setaffinity_args ap;
2596 ap.level = uap->level;
2597 ap.which = uap->which;
2598 ap.id = PAIR32TO64(id_t,uap->id);
2599 ap.cpusetsize = uap->cpusetsize;
2600 ap.mask = uap->mask;
2602 return (sys_cpuset_setaffinity(td, &ap));
2606 freebsd32_nmount(struct thread *td,
2607 struct freebsd32_nmount_args /* {
2609 unsigned int iovcnt;
2618 * Mount flags are now 64-bits. On 32-bit archtectures only
2619 * 32-bits are passed in, but from here on everything handles
2620 * 64-bit flags correctly.
2624 AUDIT_ARG_FFLAGS(flags);
2627 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2628 * userspace to set this flag, but we must filter it out if we want
2629 * MNT_UPDATE on the root file system to work.
2630 * MNT_ROOTFS should only be set by the kernel when mounting its
2633 flags &= ~MNT_ROOTFS;
2636 * check that we have an even number of iovec's
2637 * and that we have at least two options.
2639 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2642 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2645 error = vfs_donmount(td, flags, auio);
2653 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2655 struct yyy32 *p32, s32;
2656 struct yyy *p = NULL, s;
2661 error = copyin(uap->zzz, &s32, sizeof(s32));
2667 error = kern_xxx(td, p);
2672 error = copyout(&s32, p32, sizeof(s32));
2679 syscall32_register(int *offset, struct sysent *new_sysent,
2680 struct sysent *old_sysent)
2682 if (*offset == NO_SYSCALL) {
2685 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2686 if (freebsd32_sysent[i].sy_call ==
2687 (sy_call_t *)lkmnosys)
2689 if (i == SYS_MAXSYSCALL)
2692 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2694 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2695 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2698 *old_sysent = freebsd32_sysent[*offset];
2699 freebsd32_sysent[*offset] = *new_sysent;
2704 syscall32_deregister(int *offset, struct sysent *old_sysent)
2708 freebsd32_sysent[*offset] = *old_sysent;
2713 syscall32_module_handler(struct module *mod, int what, void *arg)
2715 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2721 error = syscall32_register(data->offset, data->new_sysent,
2724 /* Leave a mark so we know to safely unload below. */
2725 data->offset = NULL;
2728 ms.intval = *data->offset;
2730 module_setspecific(mod, &ms);
2733 error = data->chainevh(mod, what, data->chainarg);
2737 * MOD_LOAD failed, so just return without calling the
2738 * chained handler since we didn't pass along the MOD_LOAD
2741 if (data->offset == NULL)
2743 if (data->chainevh) {
2744 error = data->chainevh(mod, what, data->chainarg);
2748 error = syscall32_deregister(data->offset, &data->old_sysent);
2753 error = data->chainevh(mod, what, data->chainarg);
2759 syscall32_helper_register(struct syscall_helper_data *sd)
2761 struct syscall_helper_data *sd1;
2764 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2765 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2768 syscall32_helper_unregister(sd);
2771 sd1->registered = 1;
2777 syscall32_helper_unregister(struct syscall_helper_data *sd)
2779 struct syscall_helper_data *sd1;
2781 for (sd1 = sd; sd1->registered != 0; sd1++) {
2782 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2783 sd1->registered = 0;
2789 freebsd32_copyout_strings(struct image_params *imgp)
2793 char *stringp, *destp;
2794 u_int32_t *stack_base;
2795 struct freebsd32_ps_strings *arginfo;
2796 char canary[sizeof(long) * 8];
2797 int32_t pagesizes32[MAXPAGESIZES];
2798 size_t execpath_len;
2802 * Calculate string base and vector table pointers.
2803 * Also deal with signal trampoline code for this exec type.
2805 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2806 execpath_len = strlen(imgp->execpath) + 1;
2809 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2811 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2812 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2815 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
2816 roundup(execpath_len, sizeof(char *)) -
2817 roundup(sizeof(canary), sizeof(char *)) -
2818 roundup(sizeof(pagesizes32), sizeof(char *)) -
2819 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
2825 copyout(imgp->proc->p_sysent->sv_sigcode,
2826 ((caddr_t)arginfo - szsigcode), szsigcode);
2829 * Copy the image path for the rtld.
2831 if (execpath_len != 0) {
2832 imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
2833 copyout(imgp->execpath, (void *)imgp->execpathp,
2838 * Prepare the canary for SSP.
2840 arc4rand(canary, sizeof(canary), 0);
2841 imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len -
2843 copyout(canary, (void *)imgp->canary, sizeof(canary));
2844 imgp->canarylen = sizeof(canary);
2847 * Prepare the pagesizes array.
2849 for (i = 0; i < MAXPAGESIZES; i++)
2850 pagesizes32[i] = (uint32_t)pagesizes[i];
2851 imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len -
2852 roundup(sizeof(canary), sizeof(char *)) - sizeof(pagesizes32);
2853 copyout(pagesizes32, (void *)imgp->pagesizes, sizeof(pagesizes32));
2854 imgp->pagesizeslen = sizeof(pagesizes32);
2857 * If we have a valid auxargs ptr, prepare some room
2860 if (imgp->auxargs) {
2862 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2863 * lower compatibility.
2865 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2868 * The '+ 2' is for the null pointers at the end of each of
2869 * the arg and env vector sets,and imgp->auxarg_size is room
2870 * for argument of Runtime loader.
2872 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2873 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2877 * The '+ 2' is for the null pointers at the end of each of
2878 * the arg and env vector sets
2880 vectp = (u_int32_t *)
2881 (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t));
2884 * vectp also becomes our initial stack base
2888 stringp = imgp->args->begin_argv;
2889 argc = imgp->args->argc;
2890 envc = imgp->args->envc;
2892 * Copy out strings - arguments and environment.
2894 copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
2897 * Fill in "ps_strings" struct for ps, w, etc.
2899 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2900 suword32(&arginfo->ps_nargvstr, argc);
2903 * Fill in argument portion of vector table.
2905 for (; argc > 0; --argc) {
2906 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2907 while (*stringp++ != 0)
2912 /* a null vector table pointer separates the argp's from the envp's */
2913 suword32(vectp++, 0);
2915 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2916 suword32(&arginfo->ps_nenvstr, envc);
2919 * Fill in environment portion of vector table.
2921 for (; envc > 0; --envc) {
2922 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2923 while (*stringp++ != 0)
2928 /* end of vector table is a null pointer */
2931 return ((register_t *)stack_base);
2935 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2937 struct kld_file_stat stat;
2938 struct kld32_file_stat stat32;
2941 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2944 if (version != sizeof(struct kld32_file_stat_1) &&
2945 version != sizeof(struct kld32_file_stat))
2948 error = kern_kldstat(td, uap->fileid, &stat);
2952 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2953 CP(stat, stat32, refs);
2954 CP(stat, stat32, id);
2955 PTROUT_CP(stat, stat32, address);
2956 CP(stat, stat32, size);
2957 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2958 return (copyout(&stat32, uap->stat, version));
2962 freebsd32_posix_fallocate(struct thread *td,
2963 struct freebsd32_posix_fallocate_args *uap)
2966 return (kern_posix_fallocate(td, uap->fd,
2967 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len)));
2971 freebsd32_posix_fadvise(struct thread *td,
2972 struct freebsd32_posix_fadvise_args *uap)
2975 return (kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2976 PAIR32TO64(off_t, uap->len), uap->advice));
2980 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
2983 CP(*sig32, *sig, sigev_notify);
2984 switch (sig->sigev_notify) {
2987 case SIGEV_THREAD_ID:
2988 CP(*sig32, *sig, sigev_notify_thread_id);
2991 CP(*sig32, *sig, sigev_signo);
2992 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2995 CP(*sig32, *sig, sigev_notify_kqueue);
2996 CP(*sig32, *sig, sigev_notify_kevent_flags);
2997 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3006 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3013 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3021 return (kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),