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, 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;
403 struct vmspace *oldvmspace;
406 error = pre_execve(td, &oldvmspace);
409 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
410 uap->argv, uap->envv);
412 error = kern_execve(td, &eargs, NULL);
413 post_execve(td, error, oldvmspace);
418 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
420 struct image_args eargs;
421 struct vmspace *oldvmspace;
424 error = pre_execve(td, &oldvmspace);
427 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
428 uap->argv, uap->envv);
431 error = kern_execve(td, &eargs, NULL);
433 post_execve(td, error, oldvmspace);
439 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
440 int prot, int fd, off_t pos)
443 vm_map_entry_t entry;
446 map = &td->td_proc->p_vmspace->vm_map;
448 prot |= VM_PROT_WRITE;
450 if (vm_map_lookup_entry(map, start, &entry)) {
451 if ((entry->protection & prot) != prot) {
452 rv = vm_map_protect(map,
455 entry->protection | prot,
457 if (rv != KERN_SUCCESS)
461 vm_offset_t addr = trunc_page(start);
462 rv = vm_map_find(map, NULL, 0, &addr, PAGE_SIZE, 0,
463 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
464 if (rv != KERN_SUCCESS)
471 r.buf = (void *) start;
472 r.nbyte = end - start;
474 return (sys_pread(td, &r));
476 while (start < end) {
477 subyte((void *) start, 0);
486 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
488 struct mprotect_args ap;
490 ap.addr = PTRIN(uap->addr);
493 #if defined(__amd64__) || defined(__ia64__)
494 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
495 ap.prot |= PROT_EXEC;
497 return (sys_mprotect(td, &ap));
501 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
504 vm_offset_t addr = (vm_offset_t) uap->addr;
505 vm_size_t len = uap->len;
506 int prot = uap->prot;
507 int flags = uap->flags;
509 off_t pos = PAIR32TO64(off_t,uap->pos);
515 * Attempt to handle page size hassles.
517 pageoff = (pos & PAGE_MASK);
518 if (flags & MAP_FIXED) {
519 vm_offset_t start, end;
523 if (start != trunc_page(start)) {
524 error = freebsd32_mmap_partial(td, start,
525 round_page(start), prot,
528 pos += round_page(start) - start;
529 start = round_page(start);
531 if (end != round_page(end)) {
532 vm_offset_t t = trunc_page(end);
533 error = freebsd32_mmap_partial(td, t, end,
536 end = trunc_page(end);
538 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
540 * We can't map this region at all. The specified
541 * address doesn't have the same alignment as the file
542 * position. Fake the mapping by simply reading the
543 * entire region into memory. First we need to make
544 * sure the region exists.
550 prot |= VM_PROT_WRITE;
551 map = &td->td_proc->p_vmspace->vm_map;
552 rv = vm_map_remove(map, start, end);
553 if (rv != KERN_SUCCESS)
555 rv = vm_map_find(map, NULL, 0, &start, end - start,
556 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
557 if (rv != KERN_SUCCESS)
560 r.buf = (void *) start;
561 r.nbyte = end - start;
563 error = sys_pread(td, &r);
567 td->td_retval[0] = addr;
572 * After dealing with the ragged ends, there
573 * might be none left.
575 td->td_retval[0] = addr;
583 #if defined(__amd64__) || defined(__ia64__)
584 if (i386_read_exec && (prot & PROT_READ))
588 ap.addr = (void *) addr;
595 return (sys_mmap(td, &ap));
598 #ifdef COMPAT_FREEBSD6
600 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
602 struct freebsd32_mmap_args ap;
607 ap.flags = uap->flags;
612 return (freebsd32_mmap(td, &ap));
617 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
619 struct itimerval itv, oitv, *itvp;
620 struct itimerval32 i32;
623 if (uap->itv != NULL) {
624 error = copyin(uap->itv, &i32, sizeof(i32));
627 TV_CP(i32, itv, it_interval);
628 TV_CP(i32, itv, it_value);
632 error = kern_setitimer(td, uap->which, itvp, &oitv);
633 if (error || uap->oitv == NULL)
635 TV_CP(oitv, i32, it_interval);
636 TV_CP(oitv, i32, it_value);
637 return (copyout(&i32, uap->oitv, sizeof(i32)));
641 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
643 struct itimerval itv;
644 struct itimerval32 i32;
647 error = kern_getitimer(td, uap->which, &itv);
648 if (error || uap->itv == NULL)
650 TV_CP(itv, i32, it_interval);
651 TV_CP(itv, i32, it_value);
652 return (copyout(&i32, uap->itv, sizeof(i32)));
656 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
658 struct timeval32 tv32;
659 struct timeval tv, *tvp;
662 if (uap->tv != NULL) {
663 error = copyin(uap->tv, &tv32, sizeof(tv32));
666 CP(tv32, tv, tv_sec);
667 CP(tv32, tv, tv_usec);
672 * XXX Do pointers need PTRIN()?
674 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
675 sizeof(int32_t) * 8));
679 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
681 struct timespec32 ts32;
683 struct timeval tv, *tvp;
687 if (uap->ts != NULL) {
688 error = copyin(uap->ts, &ts32, sizeof(ts32));
691 CP(ts32, ts, tv_sec);
692 CP(ts32, ts, tv_nsec);
693 TIMESPEC_TO_TIMEVAL(&tv, &ts);
697 if (uap->sm != NULL) {
698 error = copyin(uap->sm, &set, sizeof(set));
705 * XXX Do pointers need PTRIN()?
707 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
708 uset, sizeof(int32_t) * 8);
713 * Copy 'count' items into the destination list pointed to by uap->eventlist.
716 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
718 struct freebsd32_kevent_args *uap;
719 struct kevent32 ks32[KQ_NEVENTS];
722 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
723 uap = (struct freebsd32_kevent_args *)arg;
725 for (i = 0; i < count; i++) {
726 CP(kevp[i], ks32[i], ident);
727 CP(kevp[i], ks32[i], filter);
728 CP(kevp[i], ks32[i], flags);
729 CP(kevp[i], ks32[i], fflags);
730 CP(kevp[i], ks32[i], data);
731 PTROUT_CP(kevp[i], ks32[i], udata);
733 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
735 uap->eventlist += count;
740 * Copy 'count' items from the list pointed to by uap->changelist.
743 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
745 struct freebsd32_kevent_args *uap;
746 struct kevent32 ks32[KQ_NEVENTS];
749 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
750 uap = (struct freebsd32_kevent_args *)arg;
752 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
755 uap->changelist += count;
757 for (i = 0; i < count; i++) {
758 CP(ks32[i], kevp[i], ident);
759 CP(ks32[i], kevp[i], filter);
760 CP(ks32[i], kevp[i], flags);
761 CP(ks32[i], kevp[i], fflags);
762 CP(ks32[i], kevp[i], data);
763 PTRIN_CP(ks32[i], kevp[i], udata);
770 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
772 struct timespec32 ts32;
773 struct timespec ts, *tsp;
774 struct kevent_copyops k_ops = { uap,
775 freebsd32_kevent_copyout,
776 freebsd32_kevent_copyin};
781 error = copyin(uap->timeout, &ts32, sizeof(ts32));
784 CP(ts32, ts, tv_sec);
785 CP(ts32, ts, tv_nsec);
789 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
795 freebsd32_gettimeofday(struct thread *td,
796 struct freebsd32_gettimeofday_args *uap)
799 struct timeval32 atv32;
805 CP(atv, atv32, tv_sec);
806 CP(atv, atv32, tv_usec);
807 error = copyout(&atv32, uap->tp, sizeof (atv32));
809 if (error == 0 && uap->tzp != NULL) {
810 rtz.tz_minuteswest = tz_minuteswest;
811 rtz.tz_dsttime = tz_dsttime;
812 error = copyout(&rtz, uap->tzp, sizeof (rtz));
818 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
824 error = kern_getrusage(td, uap->who, &s);
827 if (uap->rusage != NULL) {
828 freebsd32_rusage_out(&s, &s32);
829 error = copyout(&s32, uap->rusage, sizeof(s32));
835 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
837 struct iovec32 iov32;
844 if (iovcnt > UIO_MAXIOV)
846 iovlen = iovcnt * sizeof(struct iovec);
847 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
848 iov = (struct iovec *)(uio + 1);
849 for (i = 0; i < iovcnt; i++) {
850 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
855 iov[i].iov_base = PTRIN(iov32.iov_base);
856 iov[i].iov_len = iov32.iov_len;
859 uio->uio_iovcnt = iovcnt;
860 uio->uio_segflg = UIO_USERSPACE;
861 uio->uio_offset = -1;
863 for (i = 0; i < iovcnt; i++) {
864 if (iov->iov_len > INT_MAX - uio->uio_resid) {
868 uio->uio_resid += iov->iov_len;
876 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
881 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
884 error = kern_readv(td, uap->fd, auio);
890 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
895 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
898 error = kern_writev(td, uap->fd, auio);
904 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
909 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
912 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
918 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
923 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
926 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
932 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
935 struct iovec32 iov32;
941 if (iovcnt > UIO_MAXIOV)
943 iovlen = iovcnt * sizeof(struct iovec);
944 iov = malloc(iovlen, M_IOV, M_WAITOK);
945 for (i = 0; i < iovcnt; i++) {
946 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
951 iov[i].iov_base = PTRIN(iov32.iov_base);
952 iov[i].iov_len = iov32.iov_len;
959 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
964 error = copyin(msg32, &m32, sizeof(m32));
967 msg->msg_name = PTRIN(m32.msg_name);
968 msg->msg_namelen = m32.msg_namelen;
969 msg->msg_iov = PTRIN(m32.msg_iov);
970 msg->msg_iovlen = m32.msg_iovlen;
971 msg->msg_control = PTRIN(m32.msg_control);
972 msg->msg_controllen = m32.msg_controllen;
973 msg->msg_flags = m32.msg_flags;
978 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
983 m32.msg_name = PTROUT(msg->msg_name);
984 m32.msg_namelen = msg->msg_namelen;
985 m32.msg_iov = PTROUT(msg->msg_iov);
986 m32.msg_iovlen = msg->msg_iovlen;
987 m32.msg_control = PTROUT(msg->msg_control);
988 m32.msg_controllen = msg->msg_controllen;
989 m32.msg_flags = msg->msg_flags;
990 error = copyout(&m32, msg32, sizeof(m32));
995 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
997 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
999 #define FREEBSD32_ALIGN(p) \
1000 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
1001 #define FREEBSD32_CMSG_SPACE(l) \
1002 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
1004 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1005 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1007 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1011 socklen_t clen, datalen;
1014 int len, maxlen, copylen;
1018 len = msg->msg_controllen;
1019 maxlen = msg->msg_controllen;
1020 msg->msg_controllen = 0;
1023 ctlbuf = msg->msg_control;
1025 while (m && len > 0) {
1026 cm = mtod(m, struct cmsghdr *);
1029 while (cm != NULL) {
1031 if (sizeof(struct cmsghdr) > clen ||
1032 cm->cmsg_len > clen) {
1037 data = CMSG_DATA(cm);
1038 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1040 /* Adjust message length */
1041 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1046 copylen = sizeof(struct cmsghdr);
1047 if (len < copylen) {
1048 msg->msg_flags |= MSG_CTRUNC;
1052 error = copyout(cm,ctlbuf,copylen);
1056 ctlbuf += FREEBSD32_ALIGN(copylen);
1057 len -= FREEBSD32_ALIGN(copylen);
1064 if (len < copylen) {
1065 msg->msg_flags |= MSG_CTRUNC;
1069 error = copyout(data,ctlbuf,copylen);
1073 ctlbuf += FREEBSD32_ALIGN(copylen);
1074 len -= FREEBSD32_ALIGN(copylen);
1076 if (CMSG_SPACE(datalen) < clen) {
1077 clen -= CMSG_SPACE(datalen);
1078 cm = (struct cmsghdr *)
1079 ((caddr_t)cm + CMSG_SPACE(datalen));
1088 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1096 freebsd32_recvmsg(td, uap)
1098 struct freebsd32_recvmsg_args /* {
1100 struct msghdr32 *msg;
1105 struct msghdr32 m32;
1106 struct iovec *uiov, *iov;
1107 struct mbuf *control = NULL;
1108 struct mbuf **controlp;
1111 error = copyin(uap->msg, &m32, sizeof(m32));
1114 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1117 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1121 msg.msg_flags = uap->flags;
1125 controlp = (msg.msg_control != NULL) ? &control : NULL;
1126 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1130 if (control != NULL)
1131 error = freebsd32_copy_msg_out(&msg, control);
1133 msg.msg_controllen = 0;
1136 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1140 if (control != NULL)
1147 * Copy-in the array of control messages constructed using alignment
1148 * and padding suitable for a 32-bit environment and construct an
1149 * mbuf using alignment and padding suitable for a 64-bit kernel.
1150 * The alignment and padding are defined indirectly by CMSG_DATA(),
1151 * CMSG_SPACE() and CMSG_LEN().
1154 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1158 u_int idx, len, msglen;
1161 buflen = FREEBSD32_ALIGN(buflen);
1163 if (buflen > MCLBYTES)
1167 * Iterate over the buffer and get the length of each message
1168 * in there. This has 32-bit alignment and padding. Use it to
1169 * determine the length of these messages when using 64-bit
1170 * alignment and padding.
1174 while (idx < buflen) {
1175 error = copyin(buf + idx, &msglen, sizeof(msglen));
1178 if (msglen < sizeof(struct cmsghdr))
1180 msglen = FREEBSD32_ALIGN(msglen);
1181 if (idx + msglen > buflen)
1184 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1185 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1186 len += CMSG_ALIGN(msglen);
1192 m = m_get(M_WAITOK, MT_CONTROL);
1194 MCLGET(m, M_WAITOK);
1197 md = mtod(m, void *);
1198 while (buflen > 0) {
1199 error = copyin(buf, md, sizeof(struct cmsghdr));
1202 msglen = *(u_int *)md;
1203 msglen = FREEBSD32_ALIGN(msglen);
1205 /* Modify the message length to account for alignment. */
1206 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1207 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1209 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1210 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1211 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1213 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1215 error = copyin(buf, md, msglen);
1218 md = (char *)md + CMSG_ALIGN(msglen);
1232 freebsd32_sendmsg(struct thread *td,
1233 struct freebsd32_sendmsg_args *uap)
1236 struct msghdr32 m32;
1238 struct mbuf *control = NULL;
1239 struct sockaddr *to = NULL;
1242 error = copyin(uap->msg, &m32, sizeof(m32));
1245 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1248 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1253 if (msg.msg_name != NULL) {
1254 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1262 if (msg.msg_control) {
1263 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1268 error = freebsd32_copyin_control(&control, msg.msg_control,
1269 msg.msg_controllen);
1273 msg.msg_control = NULL;
1274 msg.msg_controllen = 0;
1277 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1288 freebsd32_recvfrom(struct thread *td,
1289 struct freebsd32_recvfrom_args *uap)
1295 if (uap->fromlenaddr) {
1296 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1297 sizeof(msg.msg_namelen));
1301 msg.msg_namelen = 0;
1304 msg.msg_name = PTRIN(uap->from);
1305 msg.msg_iov = &aiov;
1307 aiov.iov_base = PTRIN(uap->buf);
1308 aiov.iov_len = uap->len;
1309 msg.msg_control = NULL;
1310 msg.msg_flags = uap->flags;
1311 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1312 if (error == 0 && uap->fromlenaddr)
1313 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1314 sizeof (msg.msg_namelen));
1319 freebsd32_settimeofday(struct thread *td,
1320 struct freebsd32_settimeofday_args *uap)
1322 struct timeval32 tv32;
1323 struct timeval tv, *tvp;
1324 struct timezone tz, *tzp;
1328 error = copyin(uap->tv, &tv32, sizeof(tv32));
1331 CP(tv32, tv, tv_sec);
1332 CP(tv32, tv, tv_usec);
1337 error = copyin(uap->tzp, &tz, sizeof(tz));
1343 return (kern_settimeofday(td, tvp, tzp));
1347 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1349 struct timeval32 s32[2];
1350 struct timeval s[2], *sp;
1353 if (uap->tptr != NULL) {
1354 error = copyin(uap->tptr, s32, sizeof(s32));
1357 CP(s32[0], s[0], tv_sec);
1358 CP(s32[0], s[0], tv_usec);
1359 CP(s32[1], s[1], tv_sec);
1360 CP(s32[1], s[1], tv_usec);
1364 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1368 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1370 struct timeval32 s32[2];
1371 struct timeval s[2], *sp;
1374 if (uap->tptr != NULL) {
1375 error = copyin(uap->tptr, s32, sizeof(s32));
1378 CP(s32[0], s[0], tv_sec);
1379 CP(s32[0], s[0], tv_usec);
1380 CP(s32[1], s[1], tv_sec);
1381 CP(s32[1], s[1], tv_usec);
1385 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1389 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1391 struct timeval32 s32[2];
1392 struct timeval s[2], *sp;
1395 if (uap->tptr != NULL) {
1396 error = copyin(uap->tptr, s32, sizeof(s32));
1399 CP(s32[0], s[0], tv_sec);
1400 CP(s32[0], s[0], tv_usec);
1401 CP(s32[1], s[1], tv_sec);
1402 CP(s32[1], s[1], tv_usec);
1406 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1410 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1412 struct timeval32 s32[2];
1413 struct timeval s[2], *sp;
1416 if (uap->times != NULL) {
1417 error = copyin(uap->times, s32, sizeof(s32));
1420 CP(s32[0], s[0], tv_sec);
1421 CP(s32[0], s[0], tv_usec);
1422 CP(s32[1], s[1], tv_sec);
1423 CP(s32[1], s[1], tv_usec);
1427 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1432 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1434 struct timespec32 ts32[2];
1435 struct timespec ts[2], *tsp;
1438 if (uap->times != NULL) {
1439 error = copyin(uap->times, ts32, sizeof(ts32));
1442 CP(ts32[0], ts[0], tv_sec);
1443 CP(ts32[0], ts[0], tv_nsec);
1444 CP(ts32[1], ts[1], tv_sec);
1445 CP(ts32[1], ts[1], tv_nsec);
1449 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1453 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1455 struct timespec32 ts32[2];
1456 struct timespec ts[2], *tsp;
1459 if (uap->times != NULL) {
1460 error = copyin(uap->times, ts32, sizeof(ts32));
1463 CP(ts32[0], ts[0], tv_sec);
1464 CP(ts32[0], ts[0], tv_nsec);
1465 CP(ts32[1], ts[1], tv_sec);
1466 CP(ts32[1], ts[1], tv_nsec);
1470 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1471 tsp, UIO_SYSSPACE, uap->flag));
1475 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1477 struct timeval32 tv32;
1478 struct timeval delta, olddelta, *deltap;
1482 error = copyin(uap->delta, &tv32, sizeof(tv32));
1485 CP(tv32, delta, tv_sec);
1486 CP(tv32, delta, tv_usec);
1490 error = kern_adjtime(td, deltap, &olddelta);
1491 if (uap->olddelta && error == 0) {
1492 CP(olddelta, tv32, tv_sec);
1493 CP(olddelta, tv32, tv_usec);
1494 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1499 #ifdef COMPAT_FREEBSD4
1501 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1503 struct statfs32 s32;
1507 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1510 copy_statfs(&s, &s32);
1511 return (copyout(&s32, uap->buf, sizeof(s32)));
1515 #ifdef COMPAT_FREEBSD4
1517 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1519 struct statfs32 s32;
1523 error = kern_fstatfs(td, uap->fd, &s);
1526 copy_statfs(&s, &s32);
1527 return (copyout(&s32, uap->buf, sizeof(s32)));
1531 #ifdef COMPAT_FREEBSD4
1533 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1535 struct statfs32 s32;
1540 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1542 error = kern_fhstatfs(td, fh, &s);
1545 copy_statfs(&s, &s32);
1546 return (copyout(&s32, uap->buf, sizeof(s32)));
1551 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1553 struct pread_args ap;
1557 ap.nbyte = uap->nbyte;
1558 ap.offset = PAIR32TO64(off_t,uap->offset);
1559 return (sys_pread(td, &ap));
1563 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1565 struct pwrite_args ap;
1569 ap.nbyte = uap->nbyte;
1570 ap.offset = PAIR32TO64(off_t,uap->offset);
1571 return (sys_pwrite(td, &ap));
1576 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1578 struct lseek_args nuap;
1581 nuap.offset = uap->offset;
1582 nuap.whence = uap->whence;
1583 return (sys_lseek(td, &nuap));
1588 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1591 struct lseek_args ap;
1595 ap.offset = PAIR32TO64(off_t,uap->offset);
1596 ap.whence = uap->whence;
1597 error = sys_lseek(td, &ap);
1598 /* Expand the quad return into two parts for eax and edx */
1599 pos = *(off_t *)(td->td_retval);
1600 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1601 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1606 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1608 struct truncate_args ap;
1610 ap.path = uap->path;
1611 ap.length = PAIR32TO64(off_t,uap->length);
1612 return (sys_truncate(td, &ap));
1616 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1618 struct ftruncate_args ap;
1621 ap.length = PAIR32TO64(off_t,uap->length);
1622 return (sys_ftruncate(td, &ap));
1627 ofreebsd32_getdirentries(struct thread *td,
1628 struct ofreebsd32_getdirentries_args *uap)
1630 struct ogetdirentries_args ap;
1637 ap.count = uap->count;
1639 error = kern_ogetdirentries(td, &ap, &loff);
1642 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1649 freebsd32_getdirentries(struct thread *td,
1650 struct freebsd32_getdirentries_args *uap)
1656 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1657 NULL, UIO_USERSPACE);
1660 if (uap->basep != NULL) {
1662 error = copyout(&base32, uap->basep, sizeof(int32_t));
1667 #ifdef COMPAT_FREEBSD6
1668 /* versions with the 'int pad' argument */
1670 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1672 struct pread_args ap;
1676 ap.nbyte = uap->nbyte;
1677 ap.offset = PAIR32TO64(off_t,uap->offset);
1678 return (sys_pread(td, &ap));
1682 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1684 struct pwrite_args ap;
1688 ap.nbyte = uap->nbyte;
1689 ap.offset = PAIR32TO64(off_t,uap->offset);
1690 return (sys_pwrite(td, &ap));
1694 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1697 struct lseek_args ap;
1701 ap.offset = PAIR32TO64(off_t,uap->offset);
1702 ap.whence = uap->whence;
1703 error = sys_lseek(td, &ap);
1704 /* Expand the quad return into two parts for eax and edx */
1705 pos = *(off_t *)(td->td_retval);
1706 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1707 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1712 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1714 struct truncate_args ap;
1716 ap.path = uap->path;
1717 ap.length = PAIR32TO64(off_t,uap->length);
1718 return (sys_truncate(td, &ap));
1722 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1724 struct ftruncate_args ap;
1727 ap.length = PAIR32TO64(off_t,uap->length);
1728 return (sys_ftruncate(td, &ap));
1730 #endif /* COMPAT_FREEBSD6 */
1740 freebsd32_do_sendfile(struct thread *td,
1741 struct freebsd32_sendfile_args *uap, int compat)
1743 struct sf_hdtr32 hdtr32;
1744 struct sf_hdtr hdtr;
1745 struct uio *hdr_uio, *trl_uio;
1746 struct iovec32 *iov32;
1748 cap_rights_t rights;
1752 offset = PAIR32TO64(off_t, uap->offset);
1756 hdr_uio = trl_uio = NULL;
1758 if (uap->hdtr != NULL) {
1759 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1762 PTRIN_CP(hdtr32, hdtr, headers);
1763 CP(hdtr32, hdtr, hdr_cnt);
1764 PTRIN_CP(hdtr32, hdtr, trailers);
1765 CP(hdtr32, hdtr, trl_cnt);
1767 if (hdtr.headers != NULL) {
1768 iov32 = PTRIN(hdtr32.headers);
1769 error = freebsd32_copyinuio(iov32,
1770 hdtr32.hdr_cnt, &hdr_uio);
1774 if (hdtr.trailers != NULL) {
1775 iov32 = PTRIN(hdtr32.trailers);
1776 error = freebsd32_copyinuio(iov32,
1777 hdtr32.trl_cnt, &trl_uio);
1783 AUDIT_ARG_FD(uap->fd);
1785 if ((error = fget_read(td, uap->fd,
1786 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0) {
1790 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1791 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1796 free(hdr_uio, M_IOV);
1798 free(trl_uio, M_IOV);
1802 #ifdef COMPAT_FREEBSD4
1804 freebsd4_freebsd32_sendfile(struct thread *td,
1805 struct freebsd4_freebsd32_sendfile_args *uap)
1807 return (freebsd32_do_sendfile(td,
1808 (struct freebsd32_sendfile_args *)uap, 1));
1813 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1816 return (freebsd32_do_sendfile(td, uap, 0));
1820 copy_stat(struct stat *in, struct stat32 *out)
1823 CP(*in, *out, st_dev);
1824 CP(*in, *out, st_ino);
1825 CP(*in, *out, st_mode);
1826 CP(*in, *out, st_nlink);
1827 CP(*in, *out, st_uid);
1828 CP(*in, *out, st_gid);
1829 CP(*in, *out, st_rdev);
1830 TS_CP(*in, *out, st_atim);
1831 TS_CP(*in, *out, st_mtim);
1832 TS_CP(*in, *out, st_ctim);
1833 CP(*in, *out, st_size);
1834 CP(*in, *out, st_blocks);
1835 CP(*in, *out, st_blksize);
1836 CP(*in, *out, st_flags);
1837 CP(*in, *out, st_gen);
1838 TS_CP(*in, *out, st_birthtim);
1843 copy_ostat(struct stat *in, struct ostat32 *out)
1846 CP(*in, *out, st_dev);
1847 CP(*in, *out, st_ino);
1848 CP(*in, *out, st_mode);
1849 CP(*in, *out, st_nlink);
1850 CP(*in, *out, st_uid);
1851 CP(*in, *out, st_gid);
1852 CP(*in, *out, st_rdev);
1853 CP(*in, *out, st_size);
1854 TS_CP(*in, *out, st_atim);
1855 TS_CP(*in, *out, st_mtim);
1856 TS_CP(*in, *out, st_ctim);
1857 CP(*in, *out, st_blksize);
1858 CP(*in, *out, st_blocks);
1859 CP(*in, *out, st_flags);
1860 CP(*in, *out, st_gen);
1865 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1871 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1874 copy_stat(&sb, &sb32);
1875 error = copyout(&sb32, uap->ub, sizeof (sb32));
1881 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1884 struct ostat32 sb32;
1887 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1890 copy_ostat(&sb, &sb32);
1891 error = copyout(&sb32, uap->ub, sizeof (sb32));
1897 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1903 error = kern_fstat(td, uap->fd, &ub);
1906 copy_stat(&ub, &ub32);
1907 error = copyout(&ub32, uap->ub, sizeof(ub32));
1913 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1916 struct ostat32 ub32;
1919 error = kern_fstat(td, uap->fd, &ub);
1922 copy_ostat(&ub, &ub32);
1923 error = copyout(&ub32, uap->ub, sizeof(ub32));
1929 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1935 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1938 copy_stat(&ub, &ub32);
1939 error = copyout(&ub32, uap->buf, sizeof(ub32));
1944 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1950 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1953 copy_stat(&sb, &sb32);
1954 error = copyout(&sb32, uap->ub, sizeof (sb32));
1960 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1963 struct ostat32 sb32;
1966 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1969 copy_ostat(&sb, &sb32);
1970 error = copyout(&sb32, uap->ub, sizeof (sb32));
1976 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1978 int error, name[CTL_MAXNAME];
1982 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1984 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1988 error = fueword32(uap->oldlenp, &tmp);
1995 error = userland_sysctl(td, name, uap->namelen,
1996 uap->old, &oldlen, 1,
1997 uap->new, uap->newlen, &j, SCTL_MASK32);
1998 if (error && error != ENOMEM)
2001 suword32(uap->oldlenp, j);
2006 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
2012 error = copyin(uap->jail, &version, sizeof(uint32_t));
2019 /* FreeBSD single IPv4 jails. */
2020 struct jail32_v0 j32_v0;
2022 bzero(&j, sizeof(struct jail));
2023 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
2026 CP(j32_v0, j, version);
2027 PTRIN_CP(j32_v0, j, path);
2028 PTRIN_CP(j32_v0, j, hostname);
2029 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
2035 * Version 1 was used by multi-IPv4 jail implementations
2036 * that never made it into the official kernel.
2040 case 2: /* JAIL_API_VERSION */
2042 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
2045 error = copyin(uap->jail, &j32, sizeof(struct jail32));
2048 CP(j32, j, version);
2049 PTRIN_CP(j32, j, path);
2050 PTRIN_CP(j32, j, hostname);
2051 PTRIN_CP(j32, j, jailname);
2054 PTRIN_CP(j32, j, ip4);
2055 PTRIN_CP(j32, j, ip6);
2060 /* Sci-Fi jails are not supported, sorry. */
2063 return (kern_jail(td, &j));
2067 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2072 /* Check that we have an even number of iovecs. */
2073 if (uap->iovcnt & 1)
2076 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2079 error = kern_jail_set(td, auio, uap->flags);
2085 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2087 struct iovec32 iov32;
2091 /* Check that we have an even number of iovecs. */
2092 if (uap->iovcnt & 1)
2095 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2098 error = kern_jail_get(td, auio, uap->flags);
2100 for (i = 0; i < uap->iovcnt; i++) {
2101 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2102 CP(auio->uio_iov[i], iov32, iov_len);
2103 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2112 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2114 struct sigaction32 s32;
2115 struct sigaction sa, osa, *sap;
2119 error = copyin(uap->act, &s32, sizeof(s32));
2122 sa.sa_handler = PTRIN(s32.sa_u);
2123 CP(s32, sa, sa_flags);
2124 CP(s32, sa, sa_mask);
2128 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2129 if (error == 0 && uap->oact != NULL) {
2130 s32.sa_u = PTROUT(osa.sa_handler);
2131 CP(osa, s32, sa_flags);
2132 CP(osa, s32, sa_mask);
2133 error = copyout(&s32, uap->oact, sizeof(s32));
2138 #ifdef COMPAT_FREEBSD4
2140 freebsd4_freebsd32_sigaction(struct thread *td,
2141 struct freebsd4_freebsd32_sigaction_args *uap)
2143 struct sigaction32 s32;
2144 struct sigaction sa, osa, *sap;
2148 error = copyin(uap->act, &s32, sizeof(s32));
2151 sa.sa_handler = PTRIN(s32.sa_u);
2152 CP(s32, sa, sa_flags);
2153 CP(s32, sa, sa_mask);
2157 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2158 if (error == 0 && uap->oact != NULL) {
2159 s32.sa_u = PTROUT(osa.sa_handler);
2160 CP(osa, s32, sa_flags);
2161 CP(osa, s32, sa_mask);
2162 error = copyout(&s32, uap->oact, sizeof(s32));
2169 struct osigaction32 {
2178 ofreebsd32_sigaction(struct thread *td,
2179 struct ofreebsd32_sigaction_args *uap)
2181 struct osigaction32 s32;
2182 struct sigaction sa, osa, *sap;
2185 if (uap->signum <= 0 || uap->signum >= ONSIG)
2189 error = copyin(uap->nsa, &s32, sizeof(s32));
2192 sa.sa_handler = PTRIN(s32.sa_u);
2193 CP(s32, sa, sa_flags);
2194 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2198 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2199 if (error == 0 && uap->osa != NULL) {
2200 s32.sa_u = PTROUT(osa.sa_handler);
2201 CP(osa, s32, sa_flags);
2202 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2203 error = copyout(&s32, uap->osa, sizeof(s32));
2209 ofreebsd32_sigprocmask(struct thread *td,
2210 struct ofreebsd32_sigprocmask_args *uap)
2215 OSIG2SIG(uap->mask, set);
2216 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2217 SIG2OSIG(oset, td->td_retval[0]);
2222 ofreebsd32_sigpending(struct thread *td,
2223 struct ofreebsd32_sigpending_args *uap)
2225 struct proc *p = td->td_proc;
2229 siglist = p->p_siglist;
2230 SIGSETOR(siglist, td->td_siglist);
2232 SIG2OSIG(siglist, td->td_retval[0]);
2237 u_int32_t sv_handler;
2243 ofreebsd32_sigvec(struct thread *td,
2244 struct ofreebsd32_sigvec_args *uap)
2246 struct sigvec32 vec;
2247 struct sigaction sa, osa, *sap;
2250 if (uap->signum <= 0 || uap->signum >= ONSIG)
2254 error = copyin(uap->nsv, &vec, sizeof(vec));
2257 sa.sa_handler = PTRIN(vec.sv_handler);
2258 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2259 sa.sa_flags = vec.sv_flags;
2260 sa.sa_flags ^= SA_RESTART;
2264 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2265 if (error == 0 && uap->osv != NULL) {
2266 vec.sv_handler = PTROUT(osa.sa_handler);
2267 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2268 vec.sv_flags = osa.sa_flags;
2269 vec.sv_flags &= ~SA_NOCLDWAIT;
2270 vec.sv_flags ^= SA_RESTART;
2271 error = copyout(&vec, uap->osv, sizeof(vec));
2277 ofreebsd32_sigblock(struct thread *td,
2278 struct ofreebsd32_sigblock_args *uap)
2282 OSIG2SIG(uap->mask, set);
2283 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2284 SIG2OSIG(oset, td->td_retval[0]);
2289 ofreebsd32_sigsetmask(struct thread *td,
2290 struct ofreebsd32_sigsetmask_args *uap)
2294 OSIG2SIG(uap->mask, set);
2295 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2296 SIG2OSIG(oset, td->td_retval[0]);
2301 ofreebsd32_sigsuspend(struct thread *td,
2302 struct ofreebsd32_sigsuspend_args *uap)
2306 OSIG2SIG(uap->mask, mask);
2307 return (kern_sigsuspend(td, mask));
2316 ofreebsd32_sigstack(struct thread *td,
2317 struct ofreebsd32_sigstack_args *uap)
2319 struct sigstack32 s32;
2320 struct sigstack nss, oss;
2321 int error = 0, unss;
2323 if (uap->nss != NULL) {
2324 error = copyin(uap->nss, &s32, sizeof(s32));
2327 nss.ss_sp = PTRIN(s32.ss_sp);
2328 CP(s32, nss, ss_onstack);
2333 oss.ss_sp = td->td_sigstk.ss_sp;
2334 oss.ss_onstack = sigonstack(cpu_getstack(td));
2336 td->td_sigstk.ss_sp = nss.ss_sp;
2337 td->td_sigstk.ss_size = 0;
2338 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2339 td->td_pflags |= TDP_ALTSTACK;
2341 if (uap->oss != NULL) {
2342 s32.ss_sp = PTROUT(oss.ss_sp);
2343 CP(oss, s32, ss_onstack);
2344 error = copyout(&s32, uap->oss, sizeof(s32));
2351 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2353 struct timespec32 rmt32, rqt32;
2354 struct timespec rmt, rqt;
2357 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2361 CP(rqt32, rqt, tv_sec);
2362 CP(rqt32, rqt, tv_nsec);
2365 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2367 error = kern_nanosleep(td, &rqt, &rmt);
2368 if (error && uap->rmtp) {
2371 CP(rmt, rmt32, tv_sec);
2372 CP(rmt, rmt32, tv_nsec);
2374 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2382 freebsd32_clock_gettime(struct thread *td,
2383 struct freebsd32_clock_gettime_args *uap)
2385 struct timespec ats;
2386 struct timespec32 ats32;
2389 error = kern_clock_gettime(td, uap->clock_id, &ats);
2391 CP(ats, ats32, tv_sec);
2392 CP(ats, ats32, tv_nsec);
2393 error = copyout(&ats32, uap->tp, sizeof(ats32));
2399 freebsd32_clock_settime(struct thread *td,
2400 struct freebsd32_clock_settime_args *uap)
2402 struct timespec ats;
2403 struct timespec32 ats32;
2406 error = copyin(uap->tp, &ats32, sizeof(ats32));
2409 CP(ats32, ats, tv_sec);
2410 CP(ats32, ats, tv_nsec);
2412 return (kern_clock_settime(td, uap->clock_id, &ats));
2416 freebsd32_clock_getres(struct thread *td,
2417 struct freebsd32_clock_getres_args *uap)
2420 struct timespec32 ts32;
2423 if (uap->tp == NULL)
2425 error = kern_clock_getres(td, uap->clock_id, &ts);
2427 CP(ts, ts32, tv_sec);
2428 CP(ts, ts32, tv_nsec);
2429 error = copyout(&ts32, uap->tp, sizeof(ts32));
2434 int freebsd32_ktimer_create(struct thread *td,
2435 struct freebsd32_ktimer_create_args *uap)
2437 struct sigevent32 ev32;
2438 struct sigevent ev, *evp;
2441 if (uap->evp == NULL) {
2445 error = copyin(uap->evp, &ev32, sizeof(ev32));
2448 error = convert_sigevent32(&ev32, &ev);
2452 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2454 error = copyout(&id, uap->timerid, sizeof(int));
2456 kern_ktimer_delete(td, id);
2462 freebsd32_ktimer_settime(struct thread *td,
2463 struct freebsd32_ktimer_settime_args *uap)
2465 struct itimerspec32 val32, oval32;
2466 struct itimerspec val, oval, *ovalp;
2469 error = copyin(uap->value, &val32, sizeof(val32));
2473 ovalp = uap->ovalue != NULL ? &oval : NULL;
2474 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2475 if (error == 0 && uap->ovalue != NULL) {
2476 ITS_CP(oval, oval32);
2477 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2483 freebsd32_ktimer_gettime(struct thread *td,
2484 struct freebsd32_ktimer_gettime_args *uap)
2486 struct itimerspec32 val32;
2487 struct itimerspec val;
2490 error = kern_ktimer_gettime(td, uap->timerid, &val);
2493 error = copyout(&val32, uap->value, sizeof(val32));
2499 freebsd32_clock_getcpuclockid2(struct thread *td,
2500 struct freebsd32_clock_getcpuclockid2_args *uap)
2505 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2506 uap->which, &clk_id);
2508 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2513 freebsd32_thr_new(struct thread *td,
2514 struct freebsd32_thr_new_args *uap)
2516 struct thr_param32 param32;
2517 struct thr_param param;
2520 if (uap->param_size < 0 ||
2521 uap->param_size > sizeof(struct thr_param32))
2523 bzero(¶m, sizeof(struct thr_param));
2524 bzero(¶m32, sizeof(struct thr_param32));
2525 error = copyin(uap->param, ¶m32, uap->param_size);
2528 param.start_func = PTRIN(param32.start_func);
2529 param.arg = PTRIN(param32.arg);
2530 param.stack_base = PTRIN(param32.stack_base);
2531 param.stack_size = param32.stack_size;
2532 param.tls_base = PTRIN(param32.tls_base);
2533 param.tls_size = param32.tls_size;
2534 param.child_tid = PTRIN(param32.child_tid);
2535 param.parent_tid = PTRIN(param32.parent_tid);
2536 param.flags = param32.flags;
2537 param.rtp = PTRIN(param32.rtp);
2538 param.spare[0] = PTRIN(param32.spare[0]);
2539 param.spare[1] = PTRIN(param32.spare[1]);
2540 param.spare[2] = PTRIN(param32.spare[2]);
2542 return (kern_thr_new(td, ¶m));
2546 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2548 struct timespec32 ts32;
2549 struct timespec ts, *tsp;
2554 if (uap->timeout != NULL) {
2555 error = copyin((const void *)uap->timeout, (void *)&ts32,
2556 sizeof(struct timespec32));
2559 ts.tv_sec = ts32.tv_sec;
2560 ts.tv_nsec = ts32.tv_nsec;
2563 return (kern_thr_suspend(td, tsp));
2567 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2569 bzero(dst, sizeof(*dst));
2570 dst->si_signo = src->si_signo;
2571 dst->si_errno = src->si_errno;
2572 dst->si_code = src->si_code;
2573 dst->si_pid = src->si_pid;
2574 dst->si_uid = src->si_uid;
2575 dst->si_status = src->si_status;
2576 dst->si_addr = (uintptr_t)src->si_addr;
2577 dst->si_value.sival_int = src->si_value.sival_int;
2578 dst->si_timerid = src->si_timerid;
2579 dst->si_overrun = src->si_overrun;
2583 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2585 struct timespec32 ts32;
2587 struct timespec *timeout;
2590 struct siginfo32 si32;
2594 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2597 ts.tv_sec = ts32.tv_sec;
2598 ts.tv_nsec = ts32.tv_nsec;
2603 error = copyin(uap->set, &set, sizeof(set));
2607 error = kern_sigtimedwait(td, set, &ksi, timeout);
2612 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2613 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2617 td->td_retval[0] = ksi.ksi_signo;
2625 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2628 struct siginfo32 si32;
2632 error = copyin(uap->set, &set, sizeof(set));
2636 error = kern_sigtimedwait(td, set, &ksi, NULL);
2641 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2642 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2645 td->td_retval[0] = ksi.ksi_signo;
2650 freebsd32_cpuset_setid(struct thread *td,
2651 struct freebsd32_cpuset_setid_args *uap)
2653 struct cpuset_setid_args ap;
2655 ap.which = uap->which;
2656 ap.id = PAIR32TO64(id_t,uap->id);
2657 ap.setid = uap->setid;
2659 return (sys_cpuset_setid(td, &ap));
2663 freebsd32_cpuset_getid(struct thread *td,
2664 struct freebsd32_cpuset_getid_args *uap)
2666 struct cpuset_getid_args ap;
2668 ap.level = uap->level;
2669 ap.which = uap->which;
2670 ap.id = PAIR32TO64(id_t,uap->id);
2671 ap.setid = uap->setid;
2673 return (sys_cpuset_getid(td, &ap));
2677 freebsd32_cpuset_getaffinity(struct thread *td,
2678 struct freebsd32_cpuset_getaffinity_args *uap)
2680 struct cpuset_getaffinity_args ap;
2682 ap.level = uap->level;
2683 ap.which = uap->which;
2684 ap.id = PAIR32TO64(id_t,uap->id);
2685 ap.cpusetsize = uap->cpusetsize;
2686 ap.mask = uap->mask;
2688 return (sys_cpuset_getaffinity(td, &ap));
2692 freebsd32_cpuset_setaffinity(struct thread *td,
2693 struct freebsd32_cpuset_setaffinity_args *uap)
2695 struct cpuset_setaffinity_args ap;
2697 ap.level = uap->level;
2698 ap.which = uap->which;
2699 ap.id = PAIR32TO64(id_t,uap->id);
2700 ap.cpusetsize = uap->cpusetsize;
2701 ap.mask = uap->mask;
2703 return (sys_cpuset_setaffinity(td, &ap));
2707 freebsd32_nmount(struct thread *td,
2708 struct freebsd32_nmount_args /* {
2710 unsigned int iovcnt;
2719 * Mount flags are now 64-bits. On 32-bit archtectures only
2720 * 32-bits are passed in, but from here on everything handles
2721 * 64-bit flags correctly.
2725 AUDIT_ARG_FFLAGS(flags);
2728 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2729 * userspace to set this flag, but we must filter it out if we want
2730 * MNT_UPDATE on the root file system to work.
2731 * MNT_ROOTFS should only be set by the kernel when mounting its
2734 flags &= ~MNT_ROOTFS;
2737 * check that we have an even number of iovec's
2738 * and that we have at least two options.
2740 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2743 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2746 error = vfs_donmount(td, flags, auio);
2754 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2756 struct yyy32 *p32, s32;
2757 struct yyy *p = NULL, s;
2762 error = copyin(uap->zzz, &s32, sizeof(s32));
2768 error = kern_xxx(td, p);
2773 error = copyout(&s32, p32, sizeof(s32));
2780 syscall32_register(int *offset, struct sysent *new_sysent,
2781 struct sysent *old_sysent)
2783 if (*offset == NO_SYSCALL) {
2786 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2787 if (freebsd32_sysent[i].sy_call ==
2788 (sy_call_t *)lkmnosys)
2790 if (i == SYS_MAXSYSCALL)
2793 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2795 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2796 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2799 *old_sysent = freebsd32_sysent[*offset];
2800 freebsd32_sysent[*offset] = *new_sysent;
2805 syscall32_deregister(int *offset, struct sysent *old_sysent)
2809 freebsd32_sysent[*offset] = *old_sysent;
2814 syscall32_module_handler(struct module *mod, int what, void *arg)
2816 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2822 error = syscall32_register(data->offset, data->new_sysent,
2825 /* Leave a mark so we know to safely unload below. */
2826 data->offset = NULL;
2829 ms.intval = *data->offset;
2831 module_setspecific(mod, &ms);
2834 error = data->chainevh(mod, what, data->chainarg);
2838 * MOD_LOAD failed, so just return without calling the
2839 * chained handler since we didn't pass along the MOD_LOAD
2842 if (data->offset == NULL)
2844 if (data->chainevh) {
2845 error = data->chainevh(mod, what, data->chainarg);
2849 error = syscall32_deregister(data->offset, &data->old_sysent);
2854 error = data->chainevh(mod, what, data->chainarg);
2860 syscall32_helper_register(struct syscall_helper_data *sd)
2862 struct syscall_helper_data *sd1;
2865 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2866 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2869 syscall32_helper_unregister(sd);
2872 sd1->registered = 1;
2878 syscall32_helper_unregister(struct syscall_helper_data *sd)
2880 struct syscall_helper_data *sd1;
2882 for (sd1 = sd; sd1->registered != 0; sd1++) {
2883 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2884 sd1->registered = 0;
2890 freebsd32_copyout_strings(struct image_params *imgp)
2896 u_int32_t *stack_base;
2897 struct freebsd32_ps_strings *arginfo;
2898 char canary[sizeof(long) * 8];
2899 int32_t pagesizes32[MAXPAGESIZES];
2900 size_t execpath_len;
2904 * Calculate string base and vector table pointers.
2905 * Also deal with signal trampoline code for this exec type.
2907 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2908 execpath_len = strlen(imgp->execpath) + 1;
2911 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2913 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2914 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2917 destp = (uintptr_t)arginfo;
2922 if (szsigcode != 0) {
2924 destp = rounddown2(destp, sizeof(uint32_t));
2925 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2930 * Copy the image path for the rtld.
2932 if (execpath_len != 0) {
2933 destp -= execpath_len;
2934 imgp->execpathp = destp;
2935 copyout(imgp->execpath, (void *)destp, execpath_len);
2939 * Prepare the canary for SSP.
2941 arc4rand(canary, sizeof(canary), 0);
2942 destp -= sizeof(canary);
2943 imgp->canary = destp;
2944 copyout(canary, (void *)destp, sizeof(canary));
2945 imgp->canarylen = sizeof(canary);
2948 * Prepare the pagesizes array.
2950 for (i = 0; i < MAXPAGESIZES; i++)
2951 pagesizes32[i] = (uint32_t)pagesizes[i];
2952 destp -= sizeof(pagesizes32);
2953 destp = rounddown2(destp, sizeof(uint32_t));
2954 imgp->pagesizes = destp;
2955 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2956 imgp->pagesizeslen = sizeof(pagesizes32);
2958 destp -= ARG_MAX - imgp->args->stringspace;
2959 destp = rounddown2(destp, sizeof(uint32_t));
2962 * If we have a valid auxargs ptr, prepare some room
2965 if (imgp->auxargs) {
2967 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2968 * lower compatibility.
2970 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2973 * The '+ 2' is for the null pointers at the end of each of
2974 * the arg and env vector sets,and imgp->auxarg_size is room
2975 * for argument of Runtime loader.
2977 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2978 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2982 * The '+ 2' is for the null pointers at the end of each of
2983 * the arg and env vector sets
2985 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2986 imgp->args->envc + 2) * sizeof(u_int32_t));
2990 * vectp also becomes our initial stack base
2994 stringp = imgp->args->begin_argv;
2995 argc = imgp->args->argc;
2996 envc = imgp->args->envc;
2998 * Copy out strings - arguments and environment.
3000 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
3003 * Fill in "ps_strings" struct for ps, w, etc.
3005 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
3006 suword32(&arginfo->ps_nargvstr, argc);
3009 * Fill in argument portion of vector table.
3011 for (; argc > 0; --argc) {
3012 suword32(vectp++, (u_int32_t)(intptr_t)destp);
3013 while (*stringp++ != 0)
3018 /* a null vector table pointer separates the argp's from the envp's */
3019 suword32(vectp++, 0);
3021 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
3022 suword32(&arginfo->ps_nenvstr, envc);
3025 * Fill in environment portion of vector table.
3027 for (; envc > 0; --envc) {
3028 suword32(vectp++, (u_int32_t)(intptr_t)destp);
3029 while (*stringp++ != 0)
3034 /* end of vector table is a null pointer */
3037 return ((register_t *)stack_base);
3041 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
3043 struct kld_file_stat *stat;
3044 struct kld32_file_stat *stat32;
3047 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
3050 if (version != sizeof(struct kld32_file_stat_1) &&
3051 version != sizeof(struct kld32_file_stat))
3054 stat = malloc(sizeof(*stat), M_TEMP, M_WAITOK | M_ZERO);
3055 stat32 = malloc(sizeof(*stat32), M_TEMP, M_WAITOK | M_ZERO);
3056 error = kern_kldstat(td, uap->fileid, stat);
3058 bcopy(&stat->name[0], &stat32->name[0], sizeof(stat->name));
3059 CP(*stat, *stat32, refs);
3060 CP(*stat, *stat32, id);
3061 PTROUT_CP(*stat, *stat32, address);
3062 CP(*stat, *stat32, size);
3063 bcopy(&stat->pathname[0], &stat32->pathname[0],
3064 sizeof(stat->pathname));
3065 error = copyout(stat32, uap->stat, version);
3068 free(stat32, M_TEMP);
3073 freebsd32_posix_fallocate(struct thread *td,
3074 struct freebsd32_posix_fallocate_args *uap)
3077 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
3078 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3083 freebsd32_posix_fadvise(struct thread *td,
3084 struct freebsd32_posix_fadvise_args *uap)
3087 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
3088 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
3094 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3097 CP(*sig32, *sig, sigev_notify);
3098 switch (sig->sigev_notify) {
3101 case SIGEV_THREAD_ID:
3102 CP(*sig32, *sig, sigev_notify_thread_id);
3105 CP(*sig32, *sig, sigev_signo);
3106 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3109 CP(*sig32, *sig, sigev_notify_kqueue);
3110 CP(*sig32, *sig, sigev_notify_kevent_flags);
3111 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3120 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3124 struct procctl_reaper_status rs;
3125 struct procctl_reaper_pids rp;
3126 struct procctl_reaper_kill rk;
3129 struct procctl_reaper_pids32 rp;
3131 int error, error1, flags;
3135 case PROC_TRACE_CTL:
3136 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3141 case PROC_REAP_ACQUIRE:
3142 case PROC_REAP_RELEASE:
3143 if (uap->data != NULL)
3147 case PROC_REAP_STATUS:
3150 case PROC_REAP_GETPIDS:
3151 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3154 CP(x32.rp, x.rp, rp_count);
3155 PTRIN_CP(x32.rp, x.rp, rp_pids);
3158 case PROC_REAP_KILL:
3159 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3164 case PROC_TRACE_STATUS:
3170 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3173 case PROC_REAP_STATUS:
3175 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3177 case PROC_REAP_KILL:
3178 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3182 case PROC_TRACE_STATUS:
3184 error = copyout(&flags, uap->data, sizeof(flags));
3191 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3197 * Do unsigned conversion for arg when operation
3198 * interprets it as flags or pointer.
3200 case F_SETLK_REMOTE:
3209 tmp = (unsigned int)(uap->arg);
3215 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3219 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3221 struct timespec32 ts32;
3222 struct timespec ts, *tsp;
3226 if (uap->ts != NULL) {
3227 error = copyin(uap->ts, &ts32, sizeof(ts32));
3230 CP(ts32, ts, tv_sec);
3231 CP(ts32, ts, tv_nsec);
3235 if (uap->set != NULL) {
3236 error = copyin(uap->set, &set, sizeof(set));
3243 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));