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/capsicum.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,
248 struct freebsd4_freebsd32_getfsstat_args *uap)
250 struct statfs *buf, *sp;
251 struct statfs32 stat32;
255 count = uap->bufsize / sizeof(struct statfs32);
256 size = count * sizeof(struct statfs);
257 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
259 count = td->td_retval[0];
261 while (count > 0 && error == 0) {
262 copy_statfs(sp, &stat32);
263 error = copyout(&stat32, uap->buf, sizeof(stat32));
275 freebsd32_sigaltstack(struct thread *td,
276 struct freebsd32_sigaltstack_args *uap)
278 struct sigaltstack32 s32;
279 struct sigaltstack ss, oss, *ssp;
282 if (uap->ss != NULL) {
283 error = copyin(uap->ss, &s32, sizeof(s32));
286 PTRIN_CP(s32, ss, ss_sp);
287 CP(s32, ss, ss_size);
288 CP(s32, ss, ss_flags);
292 error = kern_sigaltstack(td, ssp, &oss);
293 if (error == 0 && uap->oss != NULL) {
294 PTROUT_CP(oss, s32, ss_sp);
295 CP(oss, s32, ss_size);
296 CP(oss, s32, ss_flags);
297 error = copyout(&s32, uap->oss, sizeof(s32));
303 * Custom version of exec_copyin_args() so that we can translate
307 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
308 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
315 bzero(args, sizeof(*args));
320 * Allocate demand-paged memory for the file name, argument, and
321 * environment strings.
323 error = exec_alloc_args(args);
328 * Copy the file name.
331 args->fname = args->buf;
332 error = (segflg == UIO_SYSSPACE) ?
333 copystr(fname, args->fname, PATH_MAX, &length) :
334 copyinstr(fname, args->fname, PATH_MAX, &length);
340 args->begin_argv = args->buf + length;
341 args->endp = args->begin_argv;
342 args->stringspace = ARG_MAX;
345 * extract arguments first
349 error = copyin(p32++, &arg, sizeof(arg));
355 error = copyinstr(argp, args->endp, args->stringspace, &length);
357 if (error == ENAMETOOLONG)
361 args->stringspace -= length;
362 args->endp += length;
366 args->begin_envv = args->endp;
369 * extract environment strings
374 error = copyin(p32++, &arg, sizeof(arg));
380 error = copyinstr(envp, args->endp, args->stringspace,
383 if (error == ENAMETOOLONG)
387 args->stringspace -= length;
388 args->endp += length;
396 exec_free_args(args);
401 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
403 struct image_args eargs;
404 struct vmspace *oldvmspace;
407 error = pre_execve(td, &oldvmspace);
410 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
411 uap->argv, uap->envv);
413 error = kern_execve(td, &eargs, NULL);
414 post_execve(td, error, oldvmspace);
419 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
421 struct image_args eargs;
422 struct vmspace *oldvmspace;
425 error = pre_execve(td, &oldvmspace);
428 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
429 uap->argv, uap->envv);
432 error = kern_execve(td, &eargs, NULL);
434 post_execve(td, error, oldvmspace);
440 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
441 int prot, int fd, off_t pos)
444 vm_map_entry_t entry;
447 map = &td->td_proc->p_vmspace->vm_map;
449 prot |= VM_PROT_WRITE;
451 if (vm_map_lookup_entry(map, start, &entry)) {
452 if ((entry->protection & prot) != prot) {
453 rv = vm_map_protect(map,
456 entry->protection | prot,
458 if (rv != KERN_SUCCESS)
462 vm_offset_t addr = trunc_page(start);
463 rv = vm_map_find(map, NULL, 0, &addr, PAGE_SIZE, 0,
464 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
465 if (rv != KERN_SUCCESS)
472 r.buf = (void *) start;
473 r.nbyte = end - start;
475 return (sys_pread(td, &r));
477 while (start < end) {
478 subyte((void *) start, 0);
487 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
489 struct mprotect_args ap;
491 ap.addr = PTRIN(uap->addr);
494 #if defined(__amd64__) || defined(__ia64__)
495 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
496 ap.prot |= PROT_EXEC;
498 return (sys_mprotect(td, &ap));
502 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
505 vm_offset_t addr = (vm_offset_t) uap->addr;
506 vm_size_t len = uap->len;
507 int prot = uap->prot;
508 int flags = uap->flags;
510 off_t pos = PAIR32TO64(off_t,uap->pos);
516 * Attempt to handle page size hassles.
518 pageoff = (pos & PAGE_MASK);
519 if (flags & MAP_FIXED) {
520 vm_offset_t start, end;
524 if (start != trunc_page(start)) {
525 error = freebsd32_mmap_partial(td, start,
526 round_page(start), prot,
529 pos += round_page(start) - start;
530 start = round_page(start);
532 if (end != round_page(end)) {
533 vm_offset_t t = trunc_page(end);
534 error = freebsd32_mmap_partial(td, t, end,
537 end = trunc_page(end);
539 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
541 * We can't map this region at all. The specified
542 * address doesn't have the same alignment as the file
543 * position. Fake the mapping by simply reading the
544 * entire region into memory. First we need to make
545 * sure the region exists.
551 prot |= VM_PROT_WRITE;
552 map = &td->td_proc->p_vmspace->vm_map;
553 rv = vm_map_remove(map, start, end);
554 if (rv != KERN_SUCCESS)
556 rv = vm_map_find(map, NULL, 0, &start, end - start,
557 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
558 if (rv != KERN_SUCCESS)
561 r.buf = (void *) start;
562 r.nbyte = end - start;
564 error = sys_pread(td, &r);
568 td->td_retval[0] = addr;
573 * After dealing with the ragged ends, there
574 * might be none left.
576 td->td_retval[0] = addr;
584 #if defined(__amd64__) || defined(__ia64__)
585 if (i386_read_exec && (prot & PROT_READ))
589 ap.addr = (void *) addr;
596 return (sys_mmap(td, &ap));
599 #ifdef COMPAT_FREEBSD6
601 freebsd6_freebsd32_mmap(struct thread *td,
602 struct freebsd6_freebsd32_mmap_args *uap)
604 struct freebsd32_mmap_args ap;
609 ap.flags = uap->flags;
614 return (freebsd32_mmap(td, &ap));
619 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
621 struct itimerval itv, oitv, *itvp;
622 struct itimerval32 i32;
625 if (uap->itv != NULL) {
626 error = copyin(uap->itv, &i32, sizeof(i32));
629 TV_CP(i32, itv, it_interval);
630 TV_CP(i32, itv, it_value);
634 error = kern_setitimer(td, uap->which, itvp, &oitv);
635 if (error || uap->oitv == NULL)
637 TV_CP(oitv, i32, it_interval);
638 TV_CP(oitv, i32, it_value);
639 return (copyout(&i32, uap->oitv, sizeof(i32)));
643 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
645 struct itimerval itv;
646 struct itimerval32 i32;
649 error = kern_getitimer(td, uap->which, &itv);
650 if (error || uap->itv == NULL)
652 TV_CP(itv, i32, it_interval);
653 TV_CP(itv, i32, it_value);
654 return (copyout(&i32, uap->itv, sizeof(i32)));
658 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
660 struct timeval32 tv32;
661 struct timeval tv, *tvp;
664 if (uap->tv != NULL) {
665 error = copyin(uap->tv, &tv32, sizeof(tv32));
668 CP(tv32, tv, tv_sec);
669 CP(tv32, tv, tv_usec);
674 * XXX Do pointers need PTRIN()?
676 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
677 sizeof(int32_t) * 8));
681 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
683 struct timespec32 ts32;
685 struct timeval tv, *tvp;
689 if (uap->ts != NULL) {
690 error = copyin(uap->ts, &ts32, sizeof(ts32));
693 CP(ts32, ts, tv_sec);
694 CP(ts32, ts, tv_nsec);
695 TIMESPEC_TO_TIMEVAL(&tv, &ts);
699 if (uap->sm != NULL) {
700 error = copyin(uap->sm, &set, sizeof(set));
707 * XXX Do pointers need PTRIN()?
709 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
710 uset, sizeof(int32_t) * 8);
715 * Copy 'count' items into the destination list pointed to by uap->eventlist.
718 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
720 struct freebsd32_kevent_args *uap;
721 struct kevent32 ks32[KQ_NEVENTS];
724 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
725 uap = (struct freebsd32_kevent_args *)arg;
727 for (i = 0; i < count; i++) {
728 CP(kevp[i], ks32[i], ident);
729 CP(kevp[i], ks32[i], filter);
730 CP(kevp[i], ks32[i], flags);
731 CP(kevp[i], ks32[i], fflags);
732 CP(kevp[i], ks32[i], data);
733 PTROUT_CP(kevp[i], ks32[i], udata);
735 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
737 uap->eventlist += count;
742 * Copy 'count' items from the list pointed to by uap->changelist.
745 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
747 struct freebsd32_kevent_args *uap;
748 struct kevent32 ks32[KQ_NEVENTS];
751 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
752 uap = (struct freebsd32_kevent_args *)arg;
754 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
757 uap->changelist += count;
759 for (i = 0; i < count; i++) {
760 CP(ks32[i], kevp[i], ident);
761 CP(ks32[i], kevp[i], filter);
762 CP(ks32[i], kevp[i], flags);
763 CP(ks32[i], kevp[i], fflags);
764 CP(ks32[i], kevp[i], data);
765 PTRIN_CP(ks32[i], kevp[i], udata);
772 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
774 struct timespec32 ts32;
775 struct timespec ts, *tsp;
776 struct kevent_copyops k_ops = { uap,
777 freebsd32_kevent_copyout,
778 freebsd32_kevent_copyin};
783 error = copyin(uap->timeout, &ts32, sizeof(ts32));
786 CP(ts32, ts, tv_sec);
787 CP(ts32, ts, tv_nsec);
791 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
797 freebsd32_gettimeofday(struct thread *td,
798 struct freebsd32_gettimeofday_args *uap)
801 struct timeval32 atv32;
807 CP(atv, atv32, tv_sec);
808 CP(atv, atv32, tv_usec);
809 error = copyout(&atv32, uap->tp, sizeof (atv32));
811 if (error == 0 && uap->tzp != NULL) {
812 rtz.tz_minuteswest = tz_minuteswest;
813 rtz.tz_dsttime = tz_dsttime;
814 error = copyout(&rtz, uap->tzp, sizeof (rtz));
820 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
826 error = kern_getrusage(td, uap->who, &s);
829 if (uap->rusage != NULL) {
830 freebsd32_rusage_out(&s, &s32);
831 error = copyout(&s32, uap->rusage, sizeof(s32));
837 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
839 struct iovec32 iov32;
846 if (iovcnt > UIO_MAXIOV)
848 iovlen = iovcnt * sizeof(struct iovec);
849 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
850 iov = (struct iovec *)(uio + 1);
851 for (i = 0; i < iovcnt; i++) {
852 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
857 iov[i].iov_base = PTRIN(iov32.iov_base);
858 iov[i].iov_len = iov32.iov_len;
861 uio->uio_iovcnt = iovcnt;
862 uio->uio_segflg = UIO_USERSPACE;
863 uio->uio_offset = -1;
865 for (i = 0; i < iovcnt; i++) {
866 if (iov->iov_len > INT_MAX - uio->uio_resid) {
870 uio->uio_resid += iov->iov_len;
878 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
883 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
886 error = kern_readv(td, uap->fd, auio);
892 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
897 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
900 error = kern_writev(td, uap->fd, auio);
906 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
911 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
914 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
920 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
925 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
928 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
934 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
937 struct iovec32 iov32;
943 if (iovcnt > UIO_MAXIOV)
945 iovlen = iovcnt * sizeof(struct iovec);
946 iov = malloc(iovlen, M_IOV, M_WAITOK);
947 for (i = 0; i < iovcnt; i++) {
948 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
953 iov[i].iov_base = PTRIN(iov32.iov_base);
954 iov[i].iov_len = iov32.iov_len;
961 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
966 error = copyin(msg32, &m32, sizeof(m32));
969 msg->msg_name = PTRIN(m32.msg_name);
970 msg->msg_namelen = m32.msg_namelen;
971 msg->msg_iov = PTRIN(m32.msg_iov);
972 msg->msg_iovlen = m32.msg_iovlen;
973 msg->msg_control = PTRIN(m32.msg_control);
974 msg->msg_controllen = m32.msg_controllen;
975 msg->msg_flags = m32.msg_flags;
980 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
985 m32.msg_name = PTROUT(msg->msg_name);
986 m32.msg_namelen = msg->msg_namelen;
987 m32.msg_iov = PTROUT(msg->msg_iov);
988 m32.msg_iovlen = msg->msg_iovlen;
989 m32.msg_control = PTROUT(msg->msg_control);
990 m32.msg_controllen = msg->msg_controllen;
991 m32.msg_flags = msg->msg_flags;
992 error = copyout(&m32, msg32, sizeof(m32));
997 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
999 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
1001 #define FREEBSD32_ALIGN(p) \
1002 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
1003 #define FREEBSD32_CMSG_SPACE(l) \
1004 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
1006 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1007 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1009 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1013 socklen_t clen, datalen;
1016 int len, maxlen, copylen;
1020 len = msg->msg_controllen;
1021 maxlen = msg->msg_controllen;
1022 msg->msg_controllen = 0;
1025 ctlbuf = msg->msg_control;
1027 while (m && len > 0) {
1028 cm = mtod(m, struct cmsghdr *);
1031 while (cm != NULL) {
1033 if (sizeof(struct cmsghdr) > clen ||
1034 cm->cmsg_len > clen) {
1039 data = CMSG_DATA(cm);
1040 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1042 /* Adjust message length */
1043 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1048 copylen = sizeof(struct cmsghdr);
1049 if (len < copylen) {
1050 msg->msg_flags |= MSG_CTRUNC;
1054 error = copyout(cm,ctlbuf,copylen);
1058 ctlbuf += FREEBSD32_ALIGN(copylen);
1059 len -= FREEBSD32_ALIGN(copylen);
1066 if (len < copylen) {
1067 msg->msg_flags |= MSG_CTRUNC;
1071 error = copyout(data,ctlbuf,copylen);
1075 ctlbuf += FREEBSD32_ALIGN(copylen);
1076 len -= FREEBSD32_ALIGN(copylen);
1078 if (CMSG_SPACE(datalen) < clen) {
1079 clen -= CMSG_SPACE(datalen);
1080 cm = (struct cmsghdr *)
1081 ((caddr_t)cm + CMSG_SPACE(datalen));
1090 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1098 freebsd32_recvmsg(td, uap)
1100 struct freebsd32_recvmsg_args /* {
1102 struct msghdr32 *msg;
1107 struct msghdr32 m32;
1108 struct iovec *uiov, *iov;
1109 struct mbuf *control = NULL;
1110 struct mbuf **controlp;
1113 error = copyin(uap->msg, &m32, sizeof(m32));
1116 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1119 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1123 msg.msg_flags = uap->flags;
1127 controlp = (msg.msg_control != NULL) ? &control : NULL;
1128 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1132 if (control != NULL)
1133 error = freebsd32_copy_msg_out(&msg, control);
1135 msg.msg_controllen = 0;
1138 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1142 if (control != NULL)
1149 * Copy-in the array of control messages constructed using alignment
1150 * and padding suitable for a 32-bit environment and construct an
1151 * mbuf using alignment and padding suitable for a 64-bit kernel.
1152 * The alignment and padding are defined indirectly by CMSG_DATA(),
1153 * CMSG_SPACE() and CMSG_LEN().
1156 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1160 u_int idx, len, msglen;
1163 buflen = FREEBSD32_ALIGN(buflen);
1165 if (buflen > MCLBYTES)
1169 * Iterate over the buffer and get the length of each message
1170 * in there. This has 32-bit alignment and padding. Use it to
1171 * determine the length of these messages when using 64-bit
1172 * alignment and padding.
1176 while (idx < buflen) {
1177 error = copyin(buf + idx, &msglen, sizeof(msglen));
1180 if (msglen < sizeof(struct cmsghdr))
1182 msglen = FREEBSD32_ALIGN(msglen);
1183 if (idx + msglen > buflen)
1186 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1187 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1188 len += CMSG_ALIGN(msglen);
1194 m = m_get(M_WAITOK, MT_CONTROL);
1196 MCLGET(m, M_WAITOK);
1199 md = mtod(m, void *);
1200 while (buflen > 0) {
1201 error = copyin(buf, md, sizeof(struct cmsghdr));
1204 msglen = *(u_int *)md;
1205 msglen = FREEBSD32_ALIGN(msglen);
1207 /* Modify the message length to account for alignment. */
1208 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1209 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1211 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1212 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1213 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1215 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1217 error = copyin(buf, md, msglen);
1220 md = (char *)md + CMSG_ALIGN(msglen);
1234 freebsd32_sendmsg(struct thread *td,
1235 struct freebsd32_sendmsg_args *uap)
1238 struct msghdr32 m32;
1240 struct mbuf *control = NULL;
1241 struct sockaddr *to = NULL;
1244 error = copyin(uap->msg, &m32, sizeof(m32));
1247 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1250 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1255 if (msg.msg_name != NULL) {
1256 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1264 if (msg.msg_control) {
1265 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1270 error = freebsd32_copyin_control(&control, msg.msg_control,
1271 msg.msg_controllen);
1275 msg.msg_control = NULL;
1276 msg.msg_controllen = 0;
1279 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1290 freebsd32_recvfrom(struct thread *td,
1291 struct freebsd32_recvfrom_args *uap)
1297 if (uap->fromlenaddr) {
1298 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1299 sizeof(msg.msg_namelen));
1303 msg.msg_namelen = 0;
1306 msg.msg_name = PTRIN(uap->from);
1307 msg.msg_iov = &aiov;
1309 aiov.iov_base = PTRIN(uap->buf);
1310 aiov.iov_len = uap->len;
1311 msg.msg_control = NULL;
1312 msg.msg_flags = uap->flags;
1313 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1314 if (error == 0 && uap->fromlenaddr)
1315 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1316 sizeof (msg.msg_namelen));
1321 freebsd32_settimeofday(struct thread *td,
1322 struct freebsd32_settimeofday_args *uap)
1324 struct timeval32 tv32;
1325 struct timeval tv, *tvp;
1326 struct timezone tz, *tzp;
1330 error = copyin(uap->tv, &tv32, sizeof(tv32));
1333 CP(tv32, tv, tv_sec);
1334 CP(tv32, tv, tv_usec);
1339 error = copyin(uap->tzp, &tz, sizeof(tz));
1345 return (kern_settimeofday(td, tvp, tzp));
1349 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1351 struct timeval32 s32[2];
1352 struct timeval s[2], *sp;
1355 if (uap->tptr != NULL) {
1356 error = copyin(uap->tptr, s32, sizeof(s32));
1359 CP(s32[0], s[0], tv_sec);
1360 CP(s32[0], s[0], tv_usec);
1361 CP(s32[1], s[1], tv_sec);
1362 CP(s32[1], s[1], tv_usec);
1366 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1370 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1372 struct timeval32 s32[2];
1373 struct timeval s[2], *sp;
1376 if (uap->tptr != NULL) {
1377 error = copyin(uap->tptr, s32, sizeof(s32));
1380 CP(s32[0], s[0], tv_sec);
1381 CP(s32[0], s[0], tv_usec);
1382 CP(s32[1], s[1], tv_sec);
1383 CP(s32[1], s[1], tv_usec);
1387 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1391 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1393 struct timeval32 s32[2];
1394 struct timeval s[2], *sp;
1397 if (uap->tptr != NULL) {
1398 error = copyin(uap->tptr, s32, sizeof(s32));
1401 CP(s32[0], s[0], tv_sec);
1402 CP(s32[0], s[0], tv_usec);
1403 CP(s32[1], s[1], tv_sec);
1404 CP(s32[1], s[1], tv_usec);
1408 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1412 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1414 struct timeval32 s32[2];
1415 struct timeval s[2], *sp;
1418 if (uap->times != NULL) {
1419 error = copyin(uap->times, s32, sizeof(s32));
1422 CP(s32[0], s[0], tv_sec);
1423 CP(s32[0], s[0], tv_usec);
1424 CP(s32[1], s[1], tv_sec);
1425 CP(s32[1], s[1], tv_usec);
1429 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1434 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1436 struct timespec32 ts32[2];
1437 struct timespec ts[2], *tsp;
1440 if (uap->times != NULL) {
1441 error = copyin(uap->times, ts32, sizeof(ts32));
1444 CP(ts32[0], ts[0], tv_sec);
1445 CP(ts32[0], ts[0], tv_nsec);
1446 CP(ts32[1], ts[1], tv_sec);
1447 CP(ts32[1], ts[1], tv_nsec);
1451 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1455 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1457 struct timespec32 ts32[2];
1458 struct timespec ts[2], *tsp;
1461 if (uap->times != NULL) {
1462 error = copyin(uap->times, ts32, sizeof(ts32));
1465 CP(ts32[0], ts[0], tv_sec);
1466 CP(ts32[0], ts[0], tv_nsec);
1467 CP(ts32[1], ts[1], tv_sec);
1468 CP(ts32[1], ts[1], tv_nsec);
1472 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1473 tsp, UIO_SYSSPACE, uap->flag));
1477 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1479 struct timeval32 tv32;
1480 struct timeval delta, olddelta, *deltap;
1484 error = copyin(uap->delta, &tv32, sizeof(tv32));
1487 CP(tv32, delta, tv_sec);
1488 CP(tv32, delta, tv_usec);
1492 error = kern_adjtime(td, deltap, &olddelta);
1493 if (uap->olddelta && error == 0) {
1494 CP(olddelta, tv32, tv_sec);
1495 CP(olddelta, tv32, tv_usec);
1496 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1501 #ifdef COMPAT_FREEBSD4
1503 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1505 struct statfs32 s32;
1509 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1512 copy_statfs(&s, &s32);
1513 return (copyout(&s32, uap->buf, sizeof(s32)));
1517 #ifdef COMPAT_FREEBSD4
1519 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1521 struct statfs32 s32;
1525 error = kern_fstatfs(td, uap->fd, &s);
1528 copy_statfs(&s, &s32);
1529 return (copyout(&s32, uap->buf, sizeof(s32)));
1533 #ifdef COMPAT_FREEBSD4
1535 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1537 struct statfs32 s32;
1542 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1544 error = kern_fhstatfs(td, fh, &s);
1547 copy_statfs(&s, &s32);
1548 return (copyout(&s32, uap->buf, sizeof(s32)));
1553 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1555 struct pread_args ap;
1559 ap.nbyte = uap->nbyte;
1560 ap.offset = PAIR32TO64(off_t,uap->offset);
1561 return (sys_pread(td, &ap));
1565 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1567 struct pwrite_args ap;
1571 ap.nbyte = uap->nbyte;
1572 ap.offset = PAIR32TO64(off_t,uap->offset);
1573 return (sys_pwrite(td, &ap));
1578 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1580 struct lseek_args nuap;
1583 nuap.offset = uap->offset;
1584 nuap.whence = uap->whence;
1585 return (sys_lseek(td, &nuap));
1590 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1593 struct lseek_args ap;
1597 ap.offset = PAIR32TO64(off_t,uap->offset);
1598 ap.whence = uap->whence;
1599 error = sys_lseek(td, &ap);
1600 /* Expand the quad return into two parts for eax and edx */
1601 pos = *(off_t *)(td->td_retval);
1602 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1603 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1608 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1610 struct truncate_args ap;
1612 ap.path = uap->path;
1613 ap.length = PAIR32TO64(off_t,uap->length);
1614 return (sys_truncate(td, &ap));
1618 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1620 struct ftruncate_args ap;
1623 ap.length = PAIR32TO64(off_t,uap->length);
1624 return (sys_ftruncate(td, &ap));
1629 ofreebsd32_getdirentries(struct thread *td,
1630 struct ofreebsd32_getdirentries_args *uap)
1632 struct ogetdirentries_args ap;
1639 ap.count = uap->count;
1641 error = kern_ogetdirentries(td, &ap, &loff);
1644 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1651 freebsd32_getdirentries(struct thread *td,
1652 struct freebsd32_getdirentries_args *uap)
1658 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1659 NULL, UIO_USERSPACE);
1662 if (uap->basep != NULL) {
1664 error = copyout(&base32, uap->basep, sizeof(int32_t));
1669 #ifdef COMPAT_FREEBSD6
1670 /* versions with the 'int pad' argument */
1672 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1674 struct pread_args ap;
1678 ap.nbyte = uap->nbyte;
1679 ap.offset = PAIR32TO64(off_t,uap->offset);
1680 return (sys_pread(td, &ap));
1684 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1686 struct pwrite_args ap;
1690 ap.nbyte = uap->nbyte;
1691 ap.offset = PAIR32TO64(off_t,uap->offset);
1692 return (sys_pwrite(td, &ap));
1696 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1699 struct lseek_args ap;
1703 ap.offset = PAIR32TO64(off_t,uap->offset);
1704 ap.whence = uap->whence;
1705 error = sys_lseek(td, &ap);
1706 /* Expand the quad return into two parts for eax and edx */
1707 pos = *(off_t *)(td->td_retval);
1708 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1709 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1714 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1716 struct truncate_args ap;
1718 ap.path = uap->path;
1719 ap.length = PAIR32TO64(off_t,uap->length);
1720 return (sys_truncate(td, &ap));
1724 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1726 struct ftruncate_args ap;
1729 ap.length = PAIR32TO64(off_t,uap->length);
1730 return (sys_ftruncate(td, &ap));
1732 #endif /* COMPAT_FREEBSD6 */
1742 freebsd32_do_sendfile(struct thread *td,
1743 struct freebsd32_sendfile_args *uap, int compat)
1745 struct sf_hdtr32 hdtr32;
1746 struct sf_hdtr hdtr;
1747 struct uio *hdr_uio, *trl_uio;
1748 struct iovec32 *iov32;
1750 cap_rights_t rights;
1754 offset = PAIR32TO64(off_t, uap->offset);
1758 hdr_uio = trl_uio = NULL;
1760 if (uap->hdtr != NULL) {
1761 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1764 PTRIN_CP(hdtr32, hdtr, headers);
1765 CP(hdtr32, hdtr, hdr_cnt);
1766 PTRIN_CP(hdtr32, hdtr, trailers);
1767 CP(hdtr32, hdtr, trl_cnt);
1769 if (hdtr.headers != NULL) {
1770 iov32 = PTRIN(hdtr32.headers);
1771 error = freebsd32_copyinuio(iov32,
1772 hdtr32.hdr_cnt, &hdr_uio);
1776 if (hdtr.trailers != NULL) {
1777 iov32 = PTRIN(hdtr32.trailers);
1778 error = freebsd32_copyinuio(iov32,
1779 hdtr32.trl_cnt, &trl_uio);
1785 AUDIT_ARG_FD(uap->fd);
1787 if ((error = fget_read(td, uap->fd,
1788 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0) {
1792 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1793 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1798 free(hdr_uio, M_IOV);
1800 free(trl_uio, M_IOV);
1804 #ifdef COMPAT_FREEBSD4
1806 freebsd4_freebsd32_sendfile(struct thread *td,
1807 struct freebsd4_freebsd32_sendfile_args *uap)
1809 return (freebsd32_do_sendfile(td,
1810 (struct freebsd32_sendfile_args *)uap, 1));
1815 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1818 return (freebsd32_do_sendfile(td, uap, 0));
1822 copy_stat(struct stat *in, struct stat32 *out)
1825 CP(*in, *out, st_dev);
1826 CP(*in, *out, st_ino);
1827 CP(*in, *out, st_mode);
1828 CP(*in, *out, st_nlink);
1829 CP(*in, *out, st_uid);
1830 CP(*in, *out, st_gid);
1831 CP(*in, *out, st_rdev);
1832 TS_CP(*in, *out, st_atim);
1833 TS_CP(*in, *out, st_mtim);
1834 TS_CP(*in, *out, st_ctim);
1835 CP(*in, *out, st_size);
1836 CP(*in, *out, st_blocks);
1837 CP(*in, *out, st_blksize);
1838 CP(*in, *out, st_flags);
1839 CP(*in, *out, st_gen);
1840 TS_CP(*in, *out, st_birthtim);
1845 copy_ostat(struct stat *in, struct ostat32 *out)
1848 CP(*in, *out, st_dev);
1849 CP(*in, *out, st_ino);
1850 CP(*in, *out, st_mode);
1851 CP(*in, *out, st_nlink);
1852 CP(*in, *out, st_uid);
1853 CP(*in, *out, st_gid);
1854 CP(*in, *out, st_rdev);
1855 CP(*in, *out, st_size);
1856 TS_CP(*in, *out, st_atim);
1857 TS_CP(*in, *out, st_mtim);
1858 TS_CP(*in, *out, st_ctim);
1859 CP(*in, *out, st_blksize);
1860 CP(*in, *out, st_blocks);
1861 CP(*in, *out, st_flags);
1862 CP(*in, *out, st_gen);
1867 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1873 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1876 copy_stat(&sb, &sb32);
1877 error = copyout(&sb32, uap->ub, sizeof (sb32));
1883 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1886 struct ostat32 sb32;
1889 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1892 copy_ostat(&sb, &sb32);
1893 error = copyout(&sb32, uap->ub, sizeof (sb32));
1899 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1905 error = kern_fstat(td, uap->fd, &ub);
1908 copy_stat(&ub, &ub32);
1909 error = copyout(&ub32, uap->ub, sizeof(ub32));
1915 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1918 struct ostat32 ub32;
1921 error = kern_fstat(td, uap->fd, &ub);
1924 copy_ostat(&ub, &ub32);
1925 error = copyout(&ub32, uap->ub, sizeof(ub32));
1931 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1937 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1940 copy_stat(&ub, &ub32);
1941 error = copyout(&ub32, uap->buf, sizeof(ub32));
1946 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1952 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1955 copy_stat(&sb, &sb32);
1956 error = copyout(&sb32, uap->ub, sizeof (sb32));
1962 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1965 struct ostat32 sb32;
1968 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1971 copy_ostat(&sb, &sb32);
1972 error = copyout(&sb32, uap->ub, sizeof (sb32));
1978 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1980 int error, name[CTL_MAXNAME];
1984 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1986 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1990 error = fueword32(uap->oldlenp, &tmp);
1997 error = userland_sysctl(td, name, uap->namelen,
1998 uap->old, &oldlen, 1,
1999 uap->new, uap->newlen, &j, SCTL_MASK32);
2000 if (error && error != ENOMEM)
2003 suword32(uap->oldlenp, j);
2008 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
2014 error = copyin(uap->jail, &version, sizeof(uint32_t));
2021 /* FreeBSD single IPv4 jails. */
2022 struct jail32_v0 j32_v0;
2024 bzero(&j, sizeof(struct jail));
2025 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
2028 CP(j32_v0, j, version);
2029 PTRIN_CP(j32_v0, j, path);
2030 PTRIN_CP(j32_v0, j, hostname);
2031 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
2037 * Version 1 was used by multi-IPv4 jail implementations
2038 * that never made it into the official kernel.
2042 case 2: /* JAIL_API_VERSION */
2044 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
2047 error = copyin(uap->jail, &j32, sizeof(struct jail32));
2050 CP(j32, j, version);
2051 PTRIN_CP(j32, j, path);
2052 PTRIN_CP(j32, j, hostname);
2053 PTRIN_CP(j32, j, jailname);
2056 PTRIN_CP(j32, j, ip4);
2057 PTRIN_CP(j32, j, ip6);
2062 /* Sci-Fi jails are not supported, sorry. */
2065 return (kern_jail(td, &j));
2069 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2074 /* Check that we have an even number of iovecs. */
2075 if (uap->iovcnt & 1)
2078 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2081 error = kern_jail_set(td, auio, uap->flags);
2087 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2089 struct iovec32 iov32;
2093 /* Check that we have an even number of iovecs. */
2094 if (uap->iovcnt & 1)
2097 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2100 error = kern_jail_get(td, auio, uap->flags);
2102 for (i = 0; i < uap->iovcnt; i++) {
2103 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2104 CP(auio->uio_iov[i], iov32, iov_len);
2105 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2114 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2116 struct sigaction32 s32;
2117 struct sigaction sa, osa, *sap;
2121 error = copyin(uap->act, &s32, sizeof(s32));
2124 sa.sa_handler = PTRIN(s32.sa_u);
2125 CP(s32, sa, sa_flags);
2126 CP(s32, sa, sa_mask);
2130 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2131 if (error == 0 && uap->oact != NULL) {
2132 s32.sa_u = PTROUT(osa.sa_handler);
2133 CP(osa, s32, sa_flags);
2134 CP(osa, s32, sa_mask);
2135 error = copyout(&s32, uap->oact, sizeof(s32));
2140 #ifdef COMPAT_FREEBSD4
2142 freebsd4_freebsd32_sigaction(struct thread *td,
2143 struct freebsd4_freebsd32_sigaction_args *uap)
2145 struct sigaction32 s32;
2146 struct sigaction sa, osa, *sap;
2150 error = copyin(uap->act, &s32, sizeof(s32));
2153 sa.sa_handler = PTRIN(s32.sa_u);
2154 CP(s32, sa, sa_flags);
2155 CP(s32, sa, sa_mask);
2159 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2160 if (error == 0 && uap->oact != NULL) {
2161 s32.sa_u = PTROUT(osa.sa_handler);
2162 CP(osa, s32, sa_flags);
2163 CP(osa, s32, sa_mask);
2164 error = copyout(&s32, uap->oact, sizeof(s32));
2171 struct osigaction32 {
2180 ofreebsd32_sigaction(struct thread *td,
2181 struct ofreebsd32_sigaction_args *uap)
2183 struct osigaction32 s32;
2184 struct sigaction sa, osa, *sap;
2187 if (uap->signum <= 0 || uap->signum >= ONSIG)
2191 error = copyin(uap->nsa, &s32, sizeof(s32));
2194 sa.sa_handler = PTRIN(s32.sa_u);
2195 CP(s32, sa, sa_flags);
2196 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2200 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2201 if (error == 0 && uap->osa != NULL) {
2202 s32.sa_u = PTROUT(osa.sa_handler);
2203 CP(osa, s32, sa_flags);
2204 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2205 error = copyout(&s32, uap->osa, sizeof(s32));
2211 ofreebsd32_sigprocmask(struct thread *td,
2212 struct ofreebsd32_sigprocmask_args *uap)
2217 OSIG2SIG(uap->mask, set);
2218 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2219 SIG2OSIG(oset, td->td_retval[0]);
2224 ofreebsd32_sigpending(struct thread *td,
2225 struct ofreebsd32_sigpending_args *uap)
2227 struct proc *p = td->td_proc;
2231 siglist = p->p_siglist;
2232 SIGSETOR(siglist, td->td_siglist);
2234 SIG2OSIG(siglist, td->td_retval[0]);
2239 u_int32_t sv_handler;
2245 ofreebsd32_sigvec(struct thread *td,
2246 struct ofreebsd32_sigvec_args *uap)
2248 struct sigvec32 vec;
2249 struct sigaction sa, osa, *sap;
2252 if (uap->signum <= 0 || uap->signum >= ONSIG)
2256 error = copyin(uap->nsv, &vec, sizeof(vec));
2259 sa.sa_handler = PTRIN(vec.sv_handler);
2260 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2261 sa.sa_flags = vec.sv_flags;
2262 sa.sa_flags ^= SA_RESTART;
2266 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2267 if (error == 0 && uap->osv != NULL) {
2268 vec.sv_handler = PTROUT(osa.sa_handler);
2269 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2270 vec.sv_flags = osa.sa_flags;
2271 vec.sv_flags &= ~SA_NOCLDWAIT;
2272 vec.sv_flags ^= SA_RESTART;
2273 error = copyout(&vec, uap->osv, sizeof(vec));
2279 ofreebsd32_sigblock(struct thread *td,
2280 struct ofreebsd32_sigblock_args *uap)
2284 OSIG2SIG(uap->mask, set);
2285 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2286 SIG2OSIG(oset, td->td_retval[0]);
2291 ofreebsd32_sigsetmask(struct thread *td,
2292 struct ofreebsd32_sigsetmask_args *uap)
2296 OSIG2SIG(uap->mask, set);
2297 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2298 SIG2OSIG(oset, td->td_retval[0]);
2303 ofreebsd32_sigsuspend(struct thread *td,
2304 struct ofreebsd32_sigsuspend_args *uap)
2308 OSIG2SIG(uap->mask, mask);
2309 return (kern_sigsuspend(td, mask));
2318 ofreebsd32_sigstack(struct thread *td,
2319 struct ofreebsd32_sigstack_args *uap)
2321 struct sigstack32 s32;
2322 struct sigstack nss, oss;
2323 int error = 0, unss;
2325 if (uap->nss != NULL) {
2326 error = copyin(uap->nss, &s32, sizeof(s32));
2329 nss.ss_sp = PTRIN(s32.ss_sp);
2330 CP(s32, nss, ss_onstack);
2335 oss.ss_sp = td->td_sigstk.ss_sp;
2336 oss.ss_onstack = sigonstack(cpu_getstack(td));
2338 td->td_sigstk.ss_sp = nss.ss_sp;
2339 td->td_sigstk.ss_size = 0;
2340 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2341 td->td_pflags |= TDP_ALTSTACK;
2343 if (uap->oss != NULL) {
2344 s32.ss_sp = PTROUT(oss.ss_sp);
2345 CP(oss, s32, ss_onstack);
2346 error = copyout(&s32, uap->oss, sizeof(s32));
2353 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2355 struct timespec32 rmt32, rqt32;
2356 struct timespec rmt, rqt;
2359 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2363 CP(rqt32, rqt, tv_sec);
2364 CP(rqt32, rqt, tv_nsec);
2367 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2369 error = kern_nanosleep(td, &rqt, &rmt);
2370 if (error == EINTR && uap->rmtp) {
2373 CP(rmt, rmt32, tv_sec);
2374 CP(rmt, rmt32, tv_nsec);
2376 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2384 freebsd32_clock_gettime(struct thread *td,
2385 struct freebsd32_clock_gettime_args *uap)
2387 struct timespec ats;
2388 struct timespec32 ats32;
2391 error = kern_clock_gettime(td, uap->clock_id, &ats);
2393 CP(ats, ats32, tv_sec);
2394 CP(ats, ats32, tv_nsec);
2395 error = copyout(&ats32, uap->tp, sizeof(ats32));
2401 freebsd32_clock_settime(struct thread *td,
2402 struct freebsd32_clock_settime_args *uap)
2404 struct timespec ats;
2405 struct timespec32 ats32;
2408 error = copyin(uap->tp, &ats32, sizeof(ats32));
2411 CP(ats32, ats, tv_sec);
2412 CP(ats32, ats, tv_nsec);
2414 return (kern_clock_settime(td, uap->clock_id, &ats));
2418 freebsd32_clock_getres(struct thread *td,
2419 struct freebsd32_clock_getres_args *uap)
2422 struct timespec32 ts32;
2425 if (uap->tp == NULL)
2427 error = kern_clock_getres(td, uap->clock_id, &ts);
2429 CP(ts, ts32, tv_sec);
2430 CP(ts, ts32, tv_nsec);
2431 error = copyout(&ts32, uap->tp, sizeof(ts32));
2436 int freebsd32_ktimer_create(struct thread *td,
2437 struct freebsd32_ktimer_create_args *uap)
2439 struct sigevent32 ev32;
2440 struct sigevent ev, *evp;
2443 if (uap->evp == NULL) {
2447 error = copyin(uap->evp, &ev32, sizeof(ev32));
2450 error = convert_sigevent32(&ev32, &ev);
2454 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2456 error = copyout(&id, uap->timerid, sizeof(int));
2458 kern_ktimer_delete(td, id);
2464 freebsd32_ktimer_settime(struct thread *td,
2465 struct freebsd32_ktimer_settime_args *uap)
2467 struct itimerspec32 val32, oval32;
2468 struct itimerspec val, oval, *ovalp;
2471 error = copyin(uap->value, &val32, sizeof(val32));
2475 ovalp = uap->ovalue != NULL ? &oval : NULL;
2476 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2477 if (error == 0 && uap->ovalue != NULL) {
2478 ITS_CP(oval, oval32);
2479 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2485 freebsd32_ktimer_gettime(struct thread *td,
2486 struct freebsd32_ktimer_gettime_args *uap)
2488 struct itimerspec32 val32;
2489 struct itimerspec val;
2492 error = kern_ktimer_gettime(td, uap->timerid, &val);
2495 error = copyout(&val32, uap->value, sizeof(val32));
2501 freebsd32_clock_getcpuclockid2(struct thread *td,
2502 struct freebsd32_clock_getcpuclockid2_args *uap)
2507 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2508 uap->which, &clk_id);
2510 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2515 freebsd32_thr_new(struct thread *td,
2516 struct freebsd32_thr_new_args *uap)
2518 struct thr_param32 param32;
2519 struct thr_param param;
2522 if (uap->param_size < 0 ||
2523 uap->param_size > sizeof(struct thr_param32))
2525 bzero(¶m, sizeof(struct thr_param));
2526 bzero(¶m32, sizeof(struct thr_param32));
2527 error = copyin(uap->param, ¶m32, uap->param_size);
2530 param.start_func = PTRIN(param32.start_func);
2531 param.arg = PTRIN(param32.arg);
2532 param.stack_base = PTRIN(param32.stack_base);
2533 param.stack_size = param32.stack_size;
2534 param.tls_base = PTRIN(param32.tls_base);
2535 param.tls_size = param32.tls_size;
2536 param.child_tid = PTRIN(param32.child_tid);
2537 param.parent_tid = PTRIN(param32.parent_tid);
2538 param.flags = param32.flags;
2539 param.rtp = PTRIN(param32.rtp);
2540 param.spare[0] = PTRIN(param32.spare[0]);
2541 param.spare[1] = PTRIN(param32.spare[1]);
2542 param.spare[2] = PTRIN(param32.spare[2]);
2544 return (kern_thr_new(td, ¶m));
2548 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2550 struct timespec32 ts32;
2551 struct timespec ts, *tsp;
2556 if (uap->timeout != NULL) {
2557 error = copyin((const void *)uap->timeout, (void *)&ts32,
2558 sizeof(struct timespec32));
2561 ts.tv_sec = ts32.tv_sec;
2562 ts.tv_nsec = ts32.tv_nsec;
2565 return (kern_thr_suspend(td, tsp));
2569 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2571 bzero(dst, sizeof(*dst));
2572 dst->si_signo = src->si_signo;
2573 dst->si_errno = src->si_errno;
2574 dst->si_code = src->si_code;
2575 dst->si_pid = src->si_pid;
2576 dst->si_uid = src->si_uid;
2577 dst->si_status = src->si_status;
2578 dst->si_addr = (uintptr_t)src->si_addr;
2579 dst->si_value.sival_int = src->si_value.sival_int;
2580 dst->si_timerid = src->si_timerid;
2581 dst->si_overrun = src->si_overrun;
2585 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2587 struct timespec32 ts32;
2589 struct timespec *timeout;
2592 struct siginfo32 si32;
2596 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2599 ts.tv_sec = ts32.tv_sec;
2600 ts.tv_nsec = ts32.tv_nsec;
2605 error = copyin(uap->set, &set, sizeof(set));
2609 error = kern_sigtimedwait(td, set, &ksi, timeout);
2614 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2615 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2619 td->td_retval[0] = ksi.ksi_signo;
2627 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2630 struct siginfo32 si32;
2634 error = copyin(uap->set, &set, sizeof(set));
2638 error = kern_sigtimedwait(td, set, &ksi, NULL);
2643 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2644 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2647 td->td_retval[0] = ksi.ksi_signo;
2652 freebsd32_cpuset_setid(struct thread *td,
2653 struct freebsd32_cpuset_setid_args *uap)
2655 struct cpuset_setid_args ap;
2657 ap.which = uap->which;
2658 ap.id = PAIR32TO64(id_t,uap->id);
2659 ap.setid = uap->setid;
2661 return (sys_cpuset_setid(td, &ap));
2665 freebsd32_cpuset_getid(struct thread *td,
2666 struct freebsd32_cpuset_getid_args *uap)
2668 struct cpuset_getid_args ap;
2670 ap.level = uap->level;
2671 ap.which = uap->which;
2672 ap.id = PAIR32TO64(id_t,uap->id);
2673 ap.setid = uap->setid;
2675 return (sys_cpuset_getid(td, &ap));
2679 freebsd32_cpuset_getaffinity(struct thread *td,
2680 struct freebsd32_cpuset_getaffinity_args *uap)
2682 struct cpuset_getaffinity_args ap;
2684 ap.level = uap->level;
2685 ap.which = uap->which;
2686 ap.id = PAIR32TO64(id_t,uap->id);
2687 ap.cpusetsize = uap->cpusetsize;
2688 ap.mask = uap->mask;
2690 return (sys_cpuset_getaffinity(td, &ap));
2694 freebsd32_cpuset_setaffinity(struct thread *td,
2695 struct freebsd32_cpuset_setaffinity_args *uap)
2697 struct cpuset_setaffinity_args ap;
2699 ap.level = uap->level;
2700 ap.which = uap->which;
2701 ap.id = PAIR32TO64(id_t,uap->id);
2702 ap.cpusetsize = uap->cpusetsize;
2703 ap.mask = uap->mask;
2705 return (sys_cpuset_setaffinity(td, &ap));
2709 freebsd32_nmount(struct thread *td,
2710 struct freebsd32_nmount_args /* {
2712 unsigned int iovcnt;
2721 * Mount flags are now 64-bits. On 32-bit archtectures only
2722 * 32-bits are passed in, but from here on everything handles
2723 * 64-bit flags correctly.
2727 AUDIT_ARG_FFLAGS(flags);
2730 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2731 * userspace to set this flag, but we must filter it out if we want
2732 * MNT_UPDATE on the root file system to work.
2733 * MNT_ROOTFS should only be set by the kernel when mounting its
2736 flags &= ~MNT_ROOTFS;
2739 * check that we have an even number of iovec's
2740 * and that we have at least two options.
2742 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2745 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2748 error = vfs_donmount(td, flags, auio);
2756 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2758 struct yyy32 *p32, s32;
2759 struct yyy *p = NULL, s;
2764 error = copyin(uap->zzz, &s32, sizeof(s32));
2770 error = kern_xxx(td, p);
2775 error = copyout(&s32, p32, sizeof(s32));
2782 syscall32_register(int *offset, struct sysent *new_sysent,
2783 struct sysent *old_sysent)
2785 if (*offset == NO_SYSCALL) {
2788 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2789 if (freebsd32_sysent[i].sy_call ==
2790 (sy_call_t *)lkmnosys)
2792 if (i == SYS_MAXSYSCALL)
2795 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2797 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2798 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2801 *old_sysent = freebsd32_sysent[*offset];
2802 freebsd32_sysent[*offset] = *new_sysent;
2807 syscall32_deregister(int *offset, struct sysent *old_sysent)
2811 freebsd32_sysent[*offset] = *old_sysent;
2816 syscall32_module_handler(struct module *mod, int what, void *arg)
2818 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2824 error = syscall32_register(data->offset, data->new_sysent,
2827 /* Leave a mark so we know to safely unload below. */
2828 data->offset = NULL;
2831 ms.intval = *data->offset;
2833 module_setspecific(mod, &ms);
2836 error = data->chainevh(mod, what, data->chainarg);
2840 * MOD_LOAD failed, so just return without calling the
2841 * chained handler since we didn't pass along the MOD_LOAD
2844 if (data->offset == NULL)
2846 if (data->chainevh) {
2847 error = data->chainevh(mod, what, data->chainarg);
2851 error = syscall32_deregister(data->offset, &data->old_sysent);
2856 error = data->chainevh(mod, what, data->chainarg);
2862 syscall32_helper_register(struct syscall_helper_data *sd)
2864 struct syscall_helper_data *sd1;
2867 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2868 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2871 syscall32_helper_unregister(sd);
2874 sd1->registered = 1;
2880 syscall32_helper_unregister(struct syscall_helper_data *sd)
2882 struct syscall_helper_data *sd1;
2884 for (sd1 = sd; sd1->registered != 0; sd1++) {
2885 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2886 sd1->registered = 0;
2892 freebsd32_copyout_strings(struct image_params *imgp)
2898 u_int32_t *stack_base;
2899 struct freebsd32_ps_strings *arginfo;
2900 char canary[sizeof(long) * 8];
2901 int32_t pagesizes32[MAXPAGESIZES];
2902 size_t execpath_len;
2906 * Calculate string base and vector table pointers.
2907 * Also deal with signal trampoline code for this exec type.
2909 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2910 execpath_len = strlen(imgp->execpath) + 1;
2913 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2915 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2916 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2919 destp = (uintptr_t)arginfo;
2924 if (szsigcode != 0) {
2926 destp = rounddown2(destp, sizeof(uint32_t));
2927 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2932 * Copy the image path for the rtld.
2934 if (execpath_len != 0) {
2935 destp -= execpath_len;
2936 imgp->execpathp = destp;
2937 copyout(imgp->execpath, (void *)destp, execpath_len);
2941 * Prepare the canary for SSP.
2943 arc4rand(canary, sizeof(canary), 0);
2944 destp -= sizeof(canary);
2945 imgp->canary = destp;
2946 copyout(canary, (void *)destp, sizeof(canary));
2947 imgp->canarylen = sizeof(canary);
2950 * Prepare the pagesizes array.
2952 for (i = 0; i < MAXPAGESIZES; i++)
2953 pagesizes32[i] = (uint32_t)pagesizes[i];
2954 destp -= sizeof(pagesizes32);
2955 destp = rounddown2(destp, sizeof(uint32_t));
2956 imgp->pagesizes = destp;
2957 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2958 imgp->pagesizeslen = sizeof(pagesizes32);
2960 destp -= ARG_MAX - imgp->args->stringspace;
2961 destp = rounddown2(destp, sizeof(uint32_t));
2964 * If we have a valid auxargs ptr, prepare some room
2967 if (imgp->auxargs) {
2969 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2970 * lower compatibility.
2972 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2975 * The '+ 2' is for the null pointers at the end of each of
2976 * the arg and env vector sets,and imgp->auxarg_size is room
2977 * for argument of Runtime loader.
2979 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2980 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2984 * The '+ 2' is for the null pointers at the end of each of
2985 * the arg and env vector sets
2987 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2988 imgp->args->envc + 2) * sizeof(u_int32_t));
2992 * vectp also becomes our initial stack base
2996 stringp = imgp->args->begin_argv;
2997 argc = imgp->args->argc;
2998 envc = imgp->args->envc;
3000 * Copy out strings - arguments and environment.
3002 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
3005 * Fill in "ps_strings" struct for ps, w, etc.
3007 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
3008 suword32(&arginfo->ps_nargvstr, argc);
3011 * Fill in argument portion of vector table.
3013 for (; argc > 0; --argc) {
3014 suword32(vectp++, (u_int32_t)(intptr_t)destp);
3015 while (*stringp++ != 0)
3020 /* a null vector table pointer separates the argp's from the envp's */
3021 suword32(vectp++, 0);
3023 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
3024 suword32(&arginfo->ps_nenvstr, envc);
3027 * Fill in environment portion of vector table.
3029 for (; envc > 0; --envc) {
3030 suword32(vectp++, (u_int32_t)(intptr_t)destp);
3031 while (*stringp++ != 0)
3036 /* end of vector table is a null pointer */
3039 return ((register_t *)stack_base);
3043 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
3045 struct kld_file_stat stat;
3046 struct kld32_file_stat stat32;
3049 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
3052 if (version != sizeof(struct kld32_file_stat_1) &&
3053 version != sizeof(struct kld32_file_stat))
3056 error = kern_kldstat(td, uap->fileid, &stat);
3060 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
3061 CP(stat, stat32, refs);
3062 CP(stat, stat32, id);
3063 PTROUT_CP(stat, stat32, address);
3064 CP(stat, stat32, size);
3065 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
3066 return (copyout(&stat32, uap->stat, version));
3070 freebsd32_posix_fallocate(struct thread *td,
3071 struct freebsd32_posix_fallocate_args *uap)
3074 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
3075 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3080 freebsd32_posix_fadvise(struct thread *td,
3081 struct freebsd32_posix_fadvise_args *uap)
3084 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
3085 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
3091 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3094 CP(*sig32, *sig, sigev_notify);
3095 switch (sig->sigev_notify) {
3098 case SIGEV_THREAD_ID:
3099 CP(*sig32, *sig, sigev_notify_thread_id);
3102 CP(*sig32, *sig, sigev_signo);
3103 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3106 CP(*sig32, *sig, sigev_notify_kqueue);
3107 CP(*sig32, *sig, sigev_notify_kevent_flags);
3108 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3117 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3121 struct procctl_reaper_status rs;
3122 struct procctl_reaper_pids rp;
3123 struct procctl_reaper_kill rk;
3126 struct procctl_reaper_pids32 rp;
3128 int error, error1, flags;
3132 case PROC_TRACE_CTL:
3133 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3138 case PROC_REAP_ACQUIRE:
3139 case PROC_REAP_RELEASE:
3140 if (uap->data != NULL)
3144 case PROC_REAP_STATUS:
3147 case PROC_REAP_GETPIDS:
3148 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3151 CP(x32.rp, x.rp, rp_count);
3152 PTRIN_CP(x32.rp, x.rp, rp_pids);
3155 case PROC_REAP_KILL:
3156 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3161 case PROC_TRACE_STATUS:
3167 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3170 case PROC_REAP_STATUS:
3172 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3174 case PROC_REAP_KILL:
3175 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3179 case PROC_TRACE_STATUS:
3181 error = copyout(&flags, uap->data, sizeof(flags));
3188 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3194 * Do unsigned conversion for arg when operation
3195 * interprets it as flags or pointer.
3197 case F_SETLK_REMOTE:
3206 tmp = (unsigned int)(uap->arg);
3212 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3216 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3218 struct timespec32 ts32;
3219 struct timespec ts, *tsp;
3223 if (uap->ts != NULL) {
3224 error = copyin(uap->ts, &ts32, sizeof(ts32));
3227 CP(ts32, ts, tv_sec);
3228 CP(ts32, ts, tv_nsec);
3232 if (uap->set != NULL) {
3233 error = copyin(uap->set, &set, sizeof(set));
3240 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));