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"
33 #include "opt_ktrace.h"
35 #define __ELF_WORD_SIZE 32
37 #include <sys/param.h>
39 #include <sys/capsicum.h>
40 #include <sys/clock.h>
42 #include <sys/fcntl.h>
43 #include <sys/filedesc.h>
44 #include <sys/imgact.h>
46 #include <sys/kernel.h>
47 #include <sys/limits.h>
48 #include <sys/linker.h>
50 #include <sys/malloc.h>
51 #include <sys/file.h> /* Must come after sys/malloc.h */
52 #include <sys/imgact.h>
55 #include <sys/module.h>
56 #include <sys/mount.h>
57 #include <sys/mutex.h>
58 #include <sys/namei.h>
60 #include <sys/procctl.h>
61 #include <sys/reboot.h>
62 #include <sys/resource.h>
63 #include <sys/resourcevar.h>
64 #include <sys/selinfo.h>
65 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
66 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
67 #include <sys/signal.h>
68 #include <sys/signalvar.h>
69 #include <sys/socket.h>
70 #include <sys/socketvar.h>
72 #include <sys/syscall.h>
73 #include <sys/syscallsubr.h>
74 #include <sys/sysctl.h>
75 #include <sys/sysent.h>
76 #include <sys/sysproto.h>
77 #include <sys/systm.h>
79 #include <sys/unistd.h>
80 #include <sys/ucontext.h>
81 #include <sys/vnode.h>
88 #include <sys/ktrace.h>
92 #include <netinet/in.h>
96 #include <vm/vm_param.h>
98 #include <vm/vm_map.h>
99 #include <vm/vm_object.h>
100 #include <vm/vm_extern.h>
102 #include <machine/cpu.h>
103 #include <machine/elf.h>
105 #include <security/audit/audit.h>
107 #include <compat/freebsd32/freebsd32_util.h>
108 #include <compat/freebsd32/freebsd32.h>
109 #include <compat/freebsd32/freebsd32_ipc.h>
110 #include <compat/freebsd32/freebsd32_misc.h>
111 #include <compat/freebsd32/freebsd32_signal.h>
112 #include <compat/freebsd32/freebsd32_proto.h>
114 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
117 CTASSERT(sizeof(struct timeval32) == 8);
118 CTASSERT(sizeof(struct timespec32) == 8);
119 CTASSERT(sizeof(struct itimerval32) == 16);
121 CTASSERT(sizeof(struct statfs32) == 256);
123 CTASSERT(sizeof(struct rusage32) == 72);
125 CTASSERT(sizeof(struct sigaltstack32) == 12);
126 CTASSERT(sizeof(struct kevent32) == 20);
127 CTASSERT(sizeof(struct iovec32) == 8);
128 CTASSERT(sizeof(struct msghdr32) == 28);
130 CTASSERT(sizeof(struct stat32) == 96);
132 CTASSERT(sizeof(struct sigaction32) == 24);
134 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
135 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
136 static int freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
137 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp);
140 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
143 TV_CP(*s, *s32, ru_utime);
144 TV_CP(*s, *s32, ru_stime);
145 CP(*s, *s32, ru_maxrss);
146 CP(*s, *s32, ru_ixrss);
147 CP(*s, *s32, ru_idrss);
148 CP(*s, *s32, ru_isrss);
149 CP(*s, *s32, ru_minflt);
150 CP(*s, *s32, ru_majflt);
151 CP(*s, *s32, ru_nswap);
152 CP(*s, *s32, ru_inblock);
153 CP(*s, *s32, ru_oublock);
154 CP(*s, *s32, ru_msgsnd);
155 CP(*s, *s32, ru_msgrcv);
156 CP(*s, *s32, ru_nsignals);
157 CP(*s, *s32, ru_nvcsw);
158 CP(*s, *s32, ru_nivcsw);
162 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
165 struct rusage32 ru32;
166 struct rusage ru, *rup;
168 if (uap->rusage != NULL)
172 error = kern_wait(td, uap->pid, &status, uap->options, rup);
175 if (uap->status != NULL)
176 error = copyout(&status, uap->status, sizeof(status));
177 if (uap->rusage != NULL && error == 0) {
178 freebsd32_rusage_out(&ru, &ru32);
179 error = copyout(&ru32, uap->rusage, sizeof(ru32));
185 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
187 struct wrusage32 wru32;
188 struct __wrusage wru, *wrup;
189 struct siginfo32 si32;
190 struct __siginfo si, *sip;
193 if (uap->wrusage != NULL)
197 if (uap->info != NULL) {
199 bzero(sip, sizeof(*sip));
202 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
203 &status, uap->options, wrup, sip);
206 if (uap->status != NULL)
207 error = copyout(&status, uap->status, sizeof(status));
208 if (uap->wrusage != NULL && error == 0) {
209 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
210 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
211 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
213 if (uap->info != NULL && error == 0) {
214 siginfo_to_siginfo32 (&si, &si32);
215 error = copyout(&si32, uap->info, sizeof(si32));
220 #ifdef COMPAT_FREEBSD4
222 copy_statfs(struct statfs *in, struct statfs32 *out)
225 statfs_scale_blocks(in, INT32_MAX);
226 bzero(out, sizeof(*out));
227 CP(*in, *out, f_bsize);
228 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
229 CP(*in, *out, f_blocks);
230 CP(*in, *out, f_bfree);
231 CP(*in, *out, f_bavail);
232 out->f_files = MIN(in->f_files, INT32_MAX);
233 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
234 CP(*in, *out, f_fsid);
235 CP(*in, *out, f_owner);
236 CP(*in, *out, f_type);
237 CP(*in, *out, f_flags);
238 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
239 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
240 strlcpy(out->f_fstypename,
241 in->f_fstypename, MFSNAMELEN);
242 strlcpy(out->f_mntonname,
243 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
244 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
245 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
246 strlcpy(out->f_mntfromname,
247 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
251 #ifdef COMPAT_FREEBSD4
253 freebsd4_freebsd32_getfsstat(struct thread *td,
254 struct freebsd4_freebsd32_getfsstat_args *uap)
256 struct statfs *buf, *sp;
257 struct statfs32 stat32;
258 size_t count, size, copycount;
261 count = uap->bufsize / sizeof(struct statfs32);
262 size = count * sizeof(struct statfs);
263 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
267 while (copycount > 0 && error == 0) {
268 copy_statfs(sp, &stat32);
269 error = copyout(&stat32, uap->buf, sizeof(stat32));
277 td->td_retval[0] = count;
282 #ifdef COMPAT_FREEBSD10
284 freebsd10_freebsd32_pipe(struct thread *td,
285 struct freebsd10_freebsd32_pipe_args *uap) {
287 return (freebsd10_pipe(td, (struct freebsd10_pipe_args*)uap));
292 freebsd32_sigaltstack(struct thread *td,
293 struct freebsd32_sigaltstack_args *uap)
295 struct sigaltstack32 s32;
296 struct sigaltstack ss, oss, *ssp;
299 if (uap->ss != NULL) {
300 error = copyin(uap->ss, &s32, sizeof(s32));
303 PTRIN_CP(s32, ss, ss_sp);
304 CP(s32, ss, ss_size);
305 CP(s32, ss, ss_flags);
309 error = kern_sigaltstack(td, ssp, &oss);
310 if (error == 0 && uap->oss != NULL) {
311 PTROUT_CP(oss, s32, ss_sp);
312 CP(oss, s32, ss_size);
313 CP(oss, s32, ss_flags);
314 error = copyout(&s32, uap->oss, sizeof(s32));
320 * Custom version of exec_copyin_args() so that we can translate
324 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
325 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
332 bzero(args, sizeof(*args));
337 * Allocate demand-paged memory for the file name, argument, and
338 * environment strings.
340 error = exec_alloc_args(args);
345 * Copy the file name.
348 args->fname = args->buf;
349 error = (segflg == UIO_SYSSPACE) ?
350 copystr(fname, args->fname, PATH_MAX, &length) :
351 copyinstr(fname, args->fname, PATH_MAX, &length);
357 args->begin_argv = args->buf + length;
358 args->endp = args->begin_argv;
359 args->stringspace = ARG_MAX;
362 * extract arguments first
366 error = copyin(p32++, &arg, sizeof(arg));
372 error = copyinstr(argp, args->endp, args->stringspace, &length);
374 if (error == ENAMETOOLONG)
378 args->stringspace -= length;
379 args->endp += length;
383 args->begin_envv = args->endp;
386 * extract environment strings
391 error = copyin(p32++, &arg, sizeof(arg));
397 error = copyinstr(envp, args->endp, args->stringspace,
400 if (error == ENAMETOOLONG)
404 args->stringspace -= length;
405 args->endp += length;
413 exec_free_args(args);
418 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
420 struct image_args eargs;
421 struct vmspace *oldvmspace;
424 error = pre_execve(td, &oldvmspace);
427 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
428 uap->argv, uap->envv);
430 error = kern_execve(td, &eargs, NULL);
431 post_execve(td, error, oldvmspace);
436 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
438 struct image_args eargs;
439 struct vmspace *oldvmspace;
442 error = pre_execve(td, &oldvmspace);
445 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
446 uap->argv, uap->envv);
449 error = kern_execve(td, &eargs, NULL);
451 post_execve(td, error, oldvmspace);
456 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
461 #if defined(__amd64__)
462 if (i386_read_exec && (prot & PROT_READ) != 0)
465 return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len,
470 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
475 #if defined(__amd64__)
476 if (i386_read_exec && (prot & PROT_READ))
480 return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
481 uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
484 #ifdef COMPAT_FREEBSD6
486 freebsd6_freebsd32_mmap(struct thread *td,
487 struct freebsd6_freebsd32_mmap_args *uap)
492 #if defined(__amd64__)
493 if (i386_read_exec && (prot & PROT_READ))
497 return (kern_mmap(td, (uintptr_t)uap->addr, uap->len, prot,
498 uap->flags, uap->fd, PAIR32TO64(off_t, uap->pos)));
503 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
505 struct itimerval itv, oitv, *itvp;
506 struct itimerval32 i32;
509 if (uap->itv != NULL) {
510 error = copyin(uap->itv, &i32, sizeof(i32));
513 TV_CP(i32, itv, it_interval);
514 TV_CP(i32, itv, it_value);
518 error = kern_setitimer(td, uap->which, itvp, &oitv);
519 if (error || uap->oitv == NULL)
521 TV_CP(oitv, i32, it_interval);
522 TV_CP(oitv, i32, it_value);
523 return (copyout(&i32, uap->oitv, sizeof(i32)));
527 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
529 struct itimerval itv;
530 struct itimerval32 i32;
533 error = kern_getitimer(td, uap->which, &itv);
534 if (error || uap->itv == NULL)
536 TV_CP(itv, i32, it_interval);
537 TV_CP(itv, i32, it_value);
538 return (copyout(&i32, uap->itv, sizeof(i32)));
542 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
544 struct timeval32 tv32;
545 struct timeval tv, *tvp;
548 if (uap->tv != NULL) {
549 error = copyin(uap->tv, &tv32, sizeof(tv32));
552 CP(tv32, tv, tv_sec);
553 CP(tv32, tv, tv_usec);
558 * XXX Do pointers need PTRIN()?
560 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
561 sizeof(int32_t) * 8));
565 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
567 struct timespec32 ts32;
569 struct timeval tv, *tvp;
573 if (uap->ts != NULL) {
574 error = copyin(uap->ts, &ts32, sizeof(ts32));
577 CP(ts32, ts, tv_sec);
578 CP(ts32, ts, tv_nsec);
579 TIMESPEC_TO_TIMEVAL(&tv, &ts);
583 if (uap->sm != NULL) {
584 error = copyin(uap->sm, &set, sizeof(set));
591 * XXX Do pointers need PTRIN()?
593 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
594 uset, sizeof(int32_t) * 8);
599 * Copy 'count' items into the destination list pointed to by uap->eventlist.
602 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
604 struct freebsd32_kevent_args *uap;
605 struct kevent32 ks32[KQ_NEVENTS];
608 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
609 uap = (struct freebsd32_kevent_args *)arg;
611 for (i = 0; i < count; i++) {
612 CP(kevp[i], ks32[i], ident);
613 CP(kevp[i], ks32[i], filter);
614 CP(kevp[i], ks32[i], flags);
615 CP(kevp[i], ks32[i], fflags);
616 CP(kevp[i], ks32[i], data);
617 PTROUT_CP(kevp[i], ks32[i], udata);
619 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
621 uap->eventlist += count;
626 * Copy 'count' items from the list pointed to by uap->changelist.
629 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
631 struct freebsd32_kevent_args *uap;
632 struct kevent32 ks32[KQ_NEVENTS];
635 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
636 uap = (struct freebsd32_kevent_args *)arg;
638 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
641 uap->changelist += count;
643 for (i = 0; i < count; i++) {
644 CP(ks32[i], kevp[i], ident);
645 CP(ks32[i], kevp[i], filter);
646 CP(ks32[i], kevp[i], flags);
647 CP(ks32[i], kevp[i], fflags);
648 CP(ks32[i], kevp[i], data);
649 PTRIN_CP(ks32[i], kevp[i], udata);
656 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
658 struct timespec32 ts32;
659 struct timespec ts, *tsp;
660 struct kevent_copyops k_ops = {
662 .k_copyout = freebsd32_kevent_copyout,
663 .k_copyin = freebsd32_kevent_copyin,
666 struct kevent32 *eventlist = uap->eventlist;
672 error = copyin(uap->timeout, &ts32, sizeof(ts32));
675 CP(ts32, ts, tv_sec);
676 CP(ts32, ts, tv_nsec);
681 if (KTRPOINT(td, KTR_STRUCT_ARRAY))
682 ktrstructarray("kevent32", UIO_USERSPACE, uap->changelist,
683 uap->nchanges, sizeof(struct kevent32));
685 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
688 if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
689 ktrstructarray("kevent32", UIO_USERSPACE, eventlist,
690 td->td_retval[0], sizeof(struct kevent32));
696 freebsd32_gettimeofday(struct thread *td,
697 struct freebsd32_gettimeofday_args *uap)
700 struct timeval32 atv32;
706 CP(atv, atv32, tv_sec);
707 CP(atv, atv32, tv_usec);
708 error = copyout(&atv32, uap->tp, sizeof (atv32));
710 if (error == 0 && uap->tzp != NULL) {
711 rtz.tz_minuteswest = tz_minuteswest;
712 rtz.tz_dsttime = tz_dsttime;
713 error = copyout(&rtz, uap->tzp, sizeof (rtz));
719 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
725 error = kern_getrusage(td, uap->who, &s);
728 if (uap->rusage != NULL) {
729 freebsd32_rusage_out(&s, &s32);
730 error = copyout(&s32, uap->rusage, sizeof(s32));
736 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
738 struct iovec32 iov32;
745 if (iovcnt > UIO_MAXIOV)
747 iovlen = iovcnt * sizeof(struct iovec);
748 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
749 iov = (struct iovec *)(uio + 1);
750 for (i = 0; i < iovcnt; i++) {
751 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
756 iov[i].iov_base = PTRIN(iov32.iov_base);
757 iov[i].iov_len = iov32.iov_len;
760 uio->uio_iovcnt = iovcnt;
761 uio->uio_segflg = UIO_USERSPACE;
762 uio->uio_offset = -1;
764 for (i = 0; i < iovcnt; i++) {
765 if (iov->iov_len > INT_MAX - uio->uio_resid) {
769 uio->uio_resid += iov->iov_len;
777 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
782 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
785 error = kern_readv(td, uap->fd, auio);
791 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
796 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
799 error = kern_writev(td, uap->fd, auio);
805 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
810 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
813 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
819 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
824 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
827 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
833 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
836 struct iovec32 iov32;
842 if (iovcnt > UIO_MAXIOV)
844 iovlen = iovcnt * sizeof(struct iovec);
845 iov = malloc(iovlen, M_IOV, M_WAITOK);
846 for (i = 0; i < iovcnt; i++) {
847 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
852 iov[i].iov_base = PTRIN(iov32.iov_base);
853 iov[i].iov_len = iov32.iov_len;
860 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
865 error = copyin(msg32, &m32, sizeof(m32));
868 msg->msg_name = PTRIN(m32.msg_name);
869 msg->msg_namelen = m32.msg_namelen;
870 msg->msg_iov = PTRIN(m32.msg_iov);
871 msg->msg_iovlen = m32.msg_iovlen;
872 msg->msg_control = PTRIN(m32.msg_control);
873 msg->msg_controllen = m32.msg_controllen;
874 msg->msg_flags = m32.msg_flags;
879 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
884 m32.msg_name = PTROUT(msg->msg_name);
885 m32.msg_namelen = msg->msg_namelen;
886 m32.msg_iov = PTROUT(msg->msg_iov);
887 m32.msg_iovlen = msg->msg_iovlen;
888 m32.msg_control = PTROUT(msg->msg_control);
889 m32.msg_controllen = msg->msg_controllen;
890 m32.msg_flags = msg->msg_flags;
891 error = copyout(&m32, msg32, sizeof(m32));
896 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
898 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
900 #define FREEBSD32_ALIGN(p) \
901 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
902 #define FREEBSD32_CMSG_SPACE(l) \
903 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
905 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
906 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
908 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
912 socklen_t clen, datalen;
915 int len, maxlen, copylen;
919 len = msg->msg_controllen;
920 maxlen = msg->msg_controllen;
921 msg->msg_controllen = 0;
924 ctlbuf = msg->msg_control;
926 while (m && len > 0) {
927 cm = mtod(m, struct cmsghdr *);
932 if (sizeof(struct cmsghdr) > clen ||
933 cm->cmsg_len > clen) {
938 data = CMSG_DATA(cm);
939 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
941 /* Adjust message length */
942 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
947 copylen = sizeof(struct cmsghdr);
949 msg->msg_flags |= MSG_CTRUNC;
953 error = copyout(cm,ctlbuf,copylen);
957 ctlbuf += FREEBSD32_ALIGN(copylen);
958 len -= FREEBSD32_ALIGN(copylen);
966 msg->msg_flags |= MSG_CTRUNC;
970 error = copyout(data,ctlbuf,copylen);
974 ctlbuf += FREEBSD32_ALIGN(copylen);
975 len -= FREEBSD32_ALIGN(copylen);
977 if (CMSG_SPACE(datalen) < clen) {
978 clen -= CMSG_SPACE(datalen);
979 cm = (struct cmsghdr *)
980 ((caddr_t)cm + CMSG_SPACE(datalen));
989 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
997 freebsd32_recvmsg(td, uap)
999 struct freebsd32_recvmsg_args /* {
1001 struct msghdr32 *msg;
1006 struct msghdr32 m32;
1007 struct iovec *uiov, *iov;
1008 struct mbuf *control = NULL;
1009 struct mbuf **controlp;
1012 error = copyin(uap->msg, &m32, sizeof(m32));
1015 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1018 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1022 msg.msg_flags = uap->flags;
1026 controlp = (msg.msg_control != NULL) ? &control : NULL;
1027 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1031 if (control != NULL)
1032 error = freebsd32_copy_msg_out(&msg, control);
1034 msg.msg_controllen = 0;
1037 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1041 if (control != NULL)
1048 * Copy-in the array of control messages constructed using alignment
1049 * and padding suitable for a 32-bit environment and construct an
1050 * mbuf using alignment and padding suitable for a 64-bit kernel.
1051 * The alignment and padding are defined indirectly by CMSG_DATA(),
1052 * CMSG_SPACE() and CMSG_LEN().
1055 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1059 u_int idx, len, msglen;
1062 buflen = FREEBSD32_ALIGN(buflen);
1064 if (buflen > MCLBYTES)
1068 * Iterate over the buffer and get the length of each message
1069 * in there. This has 32-bit alignment and padding. Use it to
1070 * determine the length of these messages when using 64-bit
1071 * alignment and padding.
1075 while (idx < buflen) {
1076 error = copyin(buf + idx, &msglen, sizeof(msglen));
1079 if (msglen < sizeof(struct cmsghdr))
1081 msglen = FREEBSD32_ALIGN(msglen);
1082 if (idx + msglen > buflen)
1085 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1086 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1087 len += CMSG_ALIGN(msglen);
1093 m = m_get(M_WAITOK, MT_CONTROL);
1095 MCLGET(m, M_WAITOK);
1098 md = mtod(m, void *);
1099 while (buflen > 0) {
1100 error = copyin(buf, md, sizeof(struct cmsghdr));
1103 msglen = *(u_int *)md;
1104 msglen = FREEBSD32_ALIGN(msglen);
1106 /* Modify the message length to account for alignment. */
1107 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1108 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1110 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1111 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1112 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1114 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1116 error = copyin(buf, md, msglen);
1119 md = (char *)md + CMSG_ALIGN(msglen);
1133 freebsd32_sendmsg(struct thread *td,
1134 struct freebsd32_sendmsg_args *uap)
1137 struct msghdr32 m32;
1139 struct mbuf *control = NULL;
1140 struct sockaddr *to = NULL;
1143 error = copyin(uap->msg, &m32, sizeof(m32));
1146 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1149 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1154 if (msg.msg_name != NULL) {
1155 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1163 if (msg.msg_control) {
1164 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1169 error = freebsd32_copyin_control(&control, msg.msg_control,
1170 msg.msg_controllen);
1174 msg.msg_control = NULL;
1175 msg.msg_controllen = 0;
1178 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1189 freebsd32_recvfrom(struct thread *td,
1190 struct freebsd32_recvfrom_args *uap)
1196 if (uap->fromlenaddr) {
1197 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1198 sizeof(msg.msg_namelen));
1202 msg.msg_namelen = 0;
1205 msg.msg_name = PTRIN(uap->from);
1206 msg.msg_iov = &aiov;
1208 aiov.iov_base = PTRIN(uap->buf);
1209 aiov.iov_len = uap->len;
1210 msg.msg_control = NULL;
1211 msg.msg_flags = uap->flags;
1212 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1213 if (error == 0 && uap->fromlenaddr)
1214 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1215 sizeof (msg.msg_namelen));
1220 freebsd32_settimeofday(struct thread *td,
1221 struct freebsd32_settimeofday_args *uap)
1223 struct timeval32 tv32;
1224 struct timeval tv, *tvp;
1225 struct timezone tz, *tzp;
1229 error = copyin(uap->tv, &tv32, sizeof(tv32));
1232 CP(tv32, tv, tv_sec);
1233 CP(tv32, tv, tv_usec);
1238 error = copyin(uap->tzp, &tz, sizeof(tz));
1244 return (kern_settimeofday(td, tvp, tzp));
1248 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1250 struct timeval32 s32[2];
1251 struct timeval s[2], *sp;
1254 if (uap->tptr != NULL) {
1255 error = copyin(uap->tptr, s32, sizeof(s32));
1258 CP(s32[0], s[0], tv_sec);
1259 CP(s32[0], s[0], tv_usec);
1260 CP(s32[1], s[1], tv_sec);
1261 CP(s32[1], s[1], tv_usec);
1265 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1270 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1272 struct timeval32 s32[2];
1273 struct timeval s[2], *sp;
1276 if (uap->tptr != NULL) {
1277 error = copyin(uap->tptr, s32, sizeof(s32));
1280 CP(s32[0], s[0], tv_sec);
1281 CP(s32[0], s[0], tv_usec);
1282 CP(s32[1], s[1], tv_sec);
1283 CP(s32[1], s[1], tv_usec);
1287 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1291 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1293 struct timeval32 s32[2];
1294 struct timeval s[2], *sp;
1297 if (uap->tptr != NULL) {
1298 error = copyin(uap->tptr, s32, sizeof(s32));
1301 CP(s32[0], s[0], tv_sec);
1302 CP(s32[0], s[0], tv_usec);
1303 CP(s32[1], s[1], tv_sec);
1304 CP(s32[1], s[1], tv_usec);
1308 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1312 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1314 struct timeval32 s32[2];
1315 struct timeval s[2], *sp;
1318 if (uap->times != NULL) {
1319 error = copyin(uap->times, s32, sizeof(s32));
1322 CP(s32[0], s[0], tv_sec);
1323 CP(s32[0], s[0], tv_usec);
1324 CP(s32[1], s[1], tv_sec);
1325 CP(s32[1], s[1], tv_usec);
1329 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1334 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1336 struct timespec32 ts32[2];
1337 struct timespec ts[2], *tsp;
1340 if (uap->times != NULL) {
1341 error = copyin(uap->times, ts32, sizeof(ts32));
1344 CP(ts32[0], ts[0], tv_sec);
1345 CP(ts32[0], ts[0], tv_nsec);
1346 CP(ts32[1], ts[1], tv_sec);
1347 CP(ts32[1], ts[1], tv_nsec);
1351 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1355 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1357 struct timespec32 ts32[2];
1358 struct timespec ts[2], *tsp;
1361 if (uap->times != NULL) {
1362 error = copyin(uap->times, ts32, sizeof(ts32));
1365 CP(ts32[0], ts[0], tv_sec);
1366 CP(ts32[0], ts[0], tv_nsec);
1367 CP(ts32[1], ts[1], tv_sec);
1368 CP(ts32[1], ts[1], tv_nsec);
1372 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1373 tsp, UIO_SYSSPACE, uap->flag));
1377 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1379 struct timeval32 tv32;
1380 struct timeval delta, olddelta, *deltap;
1384 error = copyin(uap->delta, &tv32, sizeof(tv32));
1387 CP(tv32, delta, tv_sec);
1388 CP(tv32, delta, tv_usec);
1392 error = kern_adjtime(td, deltap, &olddelta);
1393 if (uap->olddelta && error == 0) {
1394 CP(olddelta, tv32, tv_sec);
1395 CP(olddelta, tv32, tv_usec);
1396 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1401 #ifdef COMPAT_FREEBSD4
1403 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1405 struct statfs32 s32;
1409 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1410 error = kern_statfs(td, uap->path, UIO_USERSPACE, sp);
1412 copy_statfs(sp, &s32);
1413 error = copyout(&s32, uap->buf, sizeof(s32));
1420 #ifdef COMPAT_FREEBSD4
1422 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1424 struct statfs32 s32;
1428 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1429 error = kern_fstatfs(td, uap->fd, sp);
1431 copy_statfs(sp, &s32);
1432 error = copyout(&s32, uap->buf, sizeof(s32));
1439 #ifdef COMPAT_FREEBSD4
1441 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1443 struct statfs32 s32;
1448 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1450 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1451 error = kern_fhstatfs(td, fh, sp);
1453 copy_statfs(sp, &s32);
1454 error = copyout(&s32, uap->buf, sizeof(s32));
1462 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1465 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1466 PAIR32TO64(off_t, uap->offset)));
1470 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1473 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1474 PAIR32TO64(off_t, uap->offset)));
1479 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1482 return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
1487 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1492 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1494 /* Expand the quad return into two parts for eax and edx */
1495 pos = td->td_uretoff.tdu_off;
1496 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1497 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1502 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1505 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1506 PAIR32TO64(off_t, uap->length)));
1510 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1513 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
1518 ofreebsd32_getdirentries(struct thread *td,
1519 struct ofreebsd32_getdirentries_args *uap)
1521 struct ogetdirentries_args ap;
1528 ap.count = uap->count;
1530 error = kern_ogetdirentries(td, &ap, &loff);
1533 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1540 freebsd32_getdirentries(struct thread *td,
1541 struct freebsd32_getdirentries_args *uap)
1547 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1548 NULL, UIO_USERSPACE);
1551 if (uap->basep != NULL) {
1553 error = copyout(&base32, uap->basep, sizeof(int32_t));
1558 #ifdef COMPAT_FREEBSD6
1559 /* versions with the 'int pad' argument */
1561 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1564 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1565 PAIR32TO64(off_t, uap->offset)));
1569 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1572 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1573 PAIR32TO64(off_t, uap->offset)));
1577 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1582 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1584 /* Expand the quad return into two parts for eax and edx */
1585 pos = *(off_t *)(td->td_retval);
1586 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1587 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1592 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1595 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1596 PAIR32TO64(off_t, uap->length)));
1600 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1603 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
1605 #endif /* COMPAT_FREEBSD6 */
1615 freebsd32_do_sendfile(struct thread *td,
1616 struct freebsd32_sendfile_args *uap, int compat)
1618 struct sf_hdtr32 hdtr32;
1619 struct sf_hdtr hdtr;
1620 struct uio *hdr_uio, *trl_uio;
1622 cap_rights_t rights;
1623 struct iovec32 *iov32;
1624 off_t offset, sbytes;
1627 offset = PAIR32TO64(off_t, uap->offset);
1631 hdr_uio = trl_uio = NULL;
1633 if (uap->hdtr != NULL) {
1634 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1637 PTRIN_CP(hdtr32, hdtr, headers);
1638 CP(hdtr32, hdtr, hdr_cnt);
1639 PTRIN_CP(hdtr32, hdtr, trailers);
1640 CP(hdtr32, hdtr, trl_cnt);
1642 if (hdtr.headers != NULL) {
1643 iov32 = PTRIN(hdtr32.headers);
1644 error = freebsd32_copyinuio(iov32,
1645 hdtr32.hdr_cnt, &hdr_uio);
1648 #ifdef COMPAT_FREEBSD4
1650 * In FreeBSD < 5.0 the nbytes to send also included
1651 * the header. If compat is specified subtract the
1652 * header size from nbytes.
1655 if (uap->nbytes > hdr_uio->uio_resid)
1656 uap->nbytes -= hdr_uio->uio_resid;
1662 if (hdtr.trailers != NULL) {
1663 iov32 = PTRIN(hdtr32.trailers);
1664 error = freebsd32_copyinuio(iov32,
1665 hdtr32.trl_cnt, &trl_uio);
1671 AUDIT_ARG_FD(uap->fd);
1673 if ((error = fget_read(td, uap->fd,
1674 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
1677 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1678 uap->nbytes, &sbytes, uap->flags, td);
1681 if (uap->sbytes != NULL)
1682 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1686 free(hdr_uio, M_IOV);
1688 free(trl_uio, M_IOV);
1692 #ifdef COMPAT_FREEBSD4
1694 freebsd4_freebsd32_sendfile(struct thread *td,
1695 struct freebsd4_freebsd32_sendfile_args *uap)
1697 return (freebsd32_do_sendfile(td,
1698 (struct freebsd32_sendfile_args *)uap, 1));
1703 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1706 return (freebsd32_do_sendfile(td, uap, 0));
1710 copy_stat(struct stat *in, struct stat32 *out)
1713 CP(*in, *out, st_dev);
1714 CP(*in, *out, st_ino);
1715 CP(*in, *out, st_mode);
1716 CP(*in, *out, st_nlink);
1717 CP(*in, *out, st_uid);
1718 CP(*in, *out, st_gid);
1719 CP(*in, *out, st_rdev);
1720 TS_CP(*in, *out, st_atim);
1721 TS_CP(*in, *out, st_mtim);
1722 TS_CP(*in, *out, st_ctim);
1723 CP(*in, *out, st_size);
1724 CP(*in, *out, st_blocks);
1725 CP(*in, *out, st_blksize);
1726 CP(*in, *out, st_flags);
1727 CP(*in, *out, st_gen);
1728 TS_CP(*in, *out, st_birthtim);
1733 copy_ostat(struct stat *in, struct ostat32 *out)
1736 CP(*in, *out, st_dev);
1737 CP(*in, *out, st_ino);
1738 CP(*in, *out, st_mode);
1739 CP(*in, *out, st_nlink);
1740 CP(*in, *out, st_uid);
1741 CP(*in, *out, st_gid);
1742 CP(*in, *out, st_rdev);
1743 CP(*in, *out, st_size);
1744 TS_CP(*in, *out, st_atim);
1745 TS_CP(*in, *out, st_mtim);
1746 TS_CP(*in, *out, st_ctim);
1747 CP(*in, *out, st_blksize);
1748 CP(*in, *out, st_blocks);
1749 CP(*in, *out, st_flags);
1750 CP(*in, *out, st_gen);
1755 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1761 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1765 copy_stat(&sb, &sb32);
1766 error = copyout(&sb32, uap->ub, sizeof (sb32));
1772 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1775 struct ostat32 sb32;
1778 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1782 copy_ostat(&sb, &sb32);
1783 error = copyout(&sb32, uap->ub, sizeof (sb32));
1789 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1795 error = kern_fstat(td, uap->fd, &ub);
1798 copy_stat(&ub, &ub32);
1799 error = copyout(&ub32, uap->ub, sizeof(ub32));
1805 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1808 struct ostat32 ub32;
1811 error = kern_fstat(td, uap->fd, &ub);
1814 copy_ostat(&ub, &ub32);
1815 error = copyout(&ub32, uap->ub, sizeof(ub32));
1821 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1827 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1831 copy_stat(&ub, &ub32);
1832 error = copyout(&ub32, uap->buf, sizeof(ub32));
1837 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1843 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1844 UIO_USERSPACE, &sb, NULL);
1847 copy_stat(&sb, &sb32);
1848 error = copyout(&sb32, uap->ub, sizeof (sb32));
1854 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1857 struct ostat32 sb32;
1860 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1861 UIO_USERSPACE, &sb, NULL);
1864 copy_ostat(&sb, &sb32);
1865 error = copyout(&sb32, uap->ub, sizeof (sb32));
1871 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1873 int error, name[CTL_MAXNAME];
1877 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1879 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1883 error = fueword32(uap->oldlenp, &tmp);
1890 error = userland_sysctl(td, name, uap->namelen,
1891 uap->old, &oldlen, 1,
1892 uap->new, uap->newlen, &j, SCTL_MASK32);
1893 if (error && error != ENOMEM)
1896 suword32(uap->oldlenp, j);
1901 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1907 error = copyin(uap->jail, &version, sizeof(uint32_t));
1914 /* FreeBSD single IPv4 jails. */
1915 struct jail32_v0 j32_v0;
1917 bzero(&j, sizeof(struct jail));
1918 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1921 CP(j32_v0, j, version);
1922 PTRIN_CP(j32_v0, j, path);
1923 PTRIN_CP(j32_v0, j, hostname);
1924 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1930 * Version 1 was used by multi-IPv4 jail implementations
1931 * that never made it into the official kernel.
1935 case 2: /* JAIL_API_VERSION */
1937 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1940 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1943 CP(j32, j, version);
1944 PTRIN_CP(j32, j, path);
1945 PTRIN_CP(j32, j, hostname);
1946 PTRIN_CP(j32, j, jailname);
1949 PTRIN_CP(j32, j, ip4);
1950 PTRIN_CP(j32, j, ip6);
1955 /* Sci-Fi jails are not supported, sorry. */
1958 return (kern_jail(td, &j));
1962 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1967 /* Check that we have an even number of iovecs. */
1968 if (uap->iovcnt & 1)
1971 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1974 error = kern_jail_set(td, auio, uap->flags);
1980 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1982 struct iovec32 iov32;
1986 /* Check that we have an even number of iovecs. */
1987 if (uap->iovcnt & 1)
1990 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1993 error = kern_jail_get(td, auio, uap->flags);
1995 for (i = 0; i < uap->iovcnt; i++) {
1996 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1997 CP(auio->uio_iov[i], iov32, iov_len);
1998 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2007 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2009 struct sigaction32 s32;
2010 struct sigaction sa, osa, *sap;
2014 error = copyin(uap->act, &s32, sizeof(s32));
2017 sa.sa_handler = PTRIN(s32.sa_u);
2018 CP(s32, sa, sa_flags);
2019 CP(s32, sa, sa_mask);
2023 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2024 if (error == 0 && uap->oact != NULL) {
2025 s32.sa_u = PTROUT(osa.sa_handler);
2026 CP(osa, s32, sa_flags);
2027 CP(osa, s32, sa_mask);
2028 error = copyout(&s32, uap->oact, sizeof(s32));
2033 #ifdef COMPAT_FREEBSD4
2035 freebsd4_freebsd32_sigaction(struct thread *td,
2036 struct freebsd4_freebsd32_sigaction_args *uap)
2038 struct sigaction32 s32;
2039 struct sigaction sa, osa, *sap;
2043 error = copyin(uap->act, &s32, sizeof(s32));
2046 sa.sa_handler = PTRIN(s32.sa_u);
2047 CP(s32, sa, sa_flags);
2048 CP(s32, sa, sa_mask);
2052 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2053 if (error == 0 && uap->oact != NULL) {
2054 s32.sa_u = PTROUT(osa.sa_handler);
2055 CP(osa, s32, sa_flags);
2056 CP(osa, s32, sa_mask);
2057 error = copyout(&s32, uap->oact, sizeof(s32));
2064 struct osigaction32 {
2073 ofreebsd32_sigaction(struct thread *td,
2074 struct ofreebsd32_sigaction_args *uap)
2076 struct osigaction32 s32;
2077 struct sigaction sa, osa, *sap;
2080 if (uap->signum <= 0 || uap->signum >= ONSIG)
2084 error = copyin(uap->nsa, &s32, sizeof(s32));
2087 sa.sa_handler = PTRIN(s32.sa_u);
2088 CP(s32, sa, sa_flags);
2089 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2093 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2094 if (error == 0 && uap->osa != NULL) {
2095 s32.sa_u = PTROUT(osa.sa_handler);
2096 CP(osa, s32, sa_flags);
2097 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2098 error = copyout(&s32, uap->osa, sizeof(s32));
2104 ofreebsd32_sigprocmask(struct thread *td,
2105 struct ofreebsd32_sigprocmask_args *uap)
2110 OSIG2SIG(uap->mask, set);
2111 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2112 SIG2OSIG(oset, td->td_retval[0]);
2117 ofreebsd32_sigpending(struct thread *td,
2118 struct ofreebsd32_sigpending_args *uap)
2120 struct proc *p = td->td_proc;
2124 siglist = p->p_siglist;
2125 SIGSETOR(siglist, td->td_siglist);
2127 SIG2OSIG(siglist, td->td_retval[0]);
2132 u_int32_t sv_handler;
2138 ofreebsd32_sigvec(struct thread *td,
2139 struct ofreebsd32_sigvec_args *uap)
2141 struct sigvec32 vec;
2142 struct sigaction sa, osa, *sap;
2145 if (uap->signum <= 0 || uap->signum >= ONSIG)
2149 error = copyin(uap->nsv, &vec, sizeof(vec));
2152 sa.sa_handler = PTRIN(vec.sv_handler);
2153 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2154 sa.sa_flags = vec.sv_flags;
2155 sa.sa_flags ^= SA_RESTART;
2159 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2160 if (error == 0 && uap->osv != NULL) {
2161 vec.sv_handler = PTROUT(osa.sa_handler);
2162 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2163 vec.sv_flags = osa.sa_flags;
2164 vec.sv_flags &= ~SA_NOCLDWAIT;
2165 vec.sv_flags ^= SA_RESTART;
2166 error = copyout(&vec, uap->osv, sizeof(vec));
2172 ofreebsd32_sigblock(struct thread *td,
2173 struct ofreebsd32_sigblock_args *uap)
2177 OSIG2SIG(uap->mask, set);
2178 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2179 SIG2OSIG(oset, td->td_retval[0]);
2184 ofreebsd32_sigsetmask(struct thread *td,
2185 struct ofreebsd32_sigsetmask_args *uap)
2189 OSIG2SIG(uap->mask, set);
2190 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2191 SIG2OSIG(oset, td->td_retval[0]);
2196 ofreebsd32_sigsuspend(struct thread *td,
2197 struct ofreebsd32_sigsuspend_args *uap)
2201 OSIG2SIG(uap->mask, mask);
2202 return (kern_sigsuspend(td, mask));
2211 ofreebsd32_sigstack(struct thread *td,
2212 struct ofreebsd32_sigstack_args *uap)
2214 struct sigstack32 s32;
2215 struct sigstack nss, oss;
2216 int error = 0, unss;
2218 if (uap->nss != NULL) {
2219 error = copyin(uap->nss, &s32, sizeof(s32));
2222 nss.ss_sp = PTRIN(s32.ss_sp);
2223 CP(s32, nss, ss_onstack);
2228 oss.ss_sp = td->td_sigstk.ss_sp;
2229 oss.ss_onstack = sigonstack(cpu_getstack(td));
2231 td->td_sigstk.ss_sp = nss.ss_sp;
2232 td->td_sigstk.ss_size = 0;
2233 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2234 td->td_pflags |= TDP_ALTSTACK;
2236 if (uap->oss != NULL) {
2237 s32.ss_sp = PTROUT(oss.ss_sp);
2238 CP(oss, s32, ss_onstack);
2239 error = copyout(&s32, uap->oss, sizeof(s32));
2246 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2249 return (freebsd32_user_clock_nanosleep(td, CLOCK_REALTIME,
2250 TIMER_RELTIME, uap->rqtp, uap->rmtp));
2254 freebsd32_clock_nanosleep(struct thread *td,
2255 struct freebsd32_clock_nanosleep_args *uap)
2259 error = freebsd32_user_clock_nanosleep(td, uap->clock_id, uap->flags,
2260 uap->rqtp, uap->rmtp);
2261 return (kern_posix_error(td, error));
2265 freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
2266 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp)
2268 struct timespec32 rmt32, rqt32;
2269 struct timespec rmt, rqt;
2272 error = copyin(ua_rqtp, &rqt32, sizeof(rqt32));
2276 CP(rqt32, rqt, tv_sec);
2277 CP(rqt32, rqt, tv_nsec);
2279 if (ua_rmtp != NULL && (flags & TIMER_ABSTIME) == 0 &&
2280 !useracc(ua_rmtp, sizeof(rmt32), VM_PROT_WRITE))
2282 error = kern_clock_nanosleep(td, clock_id, flags, &rqt, &rmt);
2283 if (error == EINTR && ua_rmtp != NULL && (flags & TIMER_ABSTIME) == 0) {
2286 CP(rmt, rmt32, tv_sec);
2287 CP(rmt, rmt32, tv_nsec);
2289 error2 = copyout(&rmt32, ua_rmtp, sizeof(rmt32));
2297 freebsd32_clock_gettime(struct thread *td,
2298 struct freebsd32_clock_gettime_args *uap)
2300 struct timespec ats;
2301 struct timespec32 ats32;
2304 error = kern_clock_gettime(td, uap->clock_id, &ats);
2306 CP(ats, ats32, tv_sec);
2307 CP(ats, ats32, tv_nsec);
2308 error = copyout(&ats32, uap->tp, sizeof(ats32));
2314 freebsd32_clock_settime(struct thread *td,
2315 struct freebsd32_clock_settime_args *uap)
2317 struct timespec ats;
2318 struct timespec32 ats32;
2321 error = copyin(uap->tp, &ats32, sizeof(ats32));
2324 CP(ats32, ats, tv_sec);
2325 CP(ats32, ats, tv_nsec);
2327 return (kern_clock_settime(td, uap->clock_id, &ats));
2331 freebsd32_clock_getres(struct thread *td,
2332 struct freebsd32_clock_getres_args *uap)
2335 struct timespec32 ts32;
2338 if (uap->tp == NULL)
2340 error = kern_clock_getres(td, uap->clock_id, &ts);
2342 CP(ts, ts32, tv_sec);
2343 CP(ts, ts32, tv_nsec);
2344 error = copyout(&ts32, uap->tp, sizeof(ts32));
2349 int freebsd32_ktimer_create(struct thread *td,
2350 struct freebsd32_ktimer_create_args *uap)
2352 struct sigevent32 ev32;
2353 struct sigevent ev, *evp;
2356 if (uap->evp == NULL) {
2360 error = copyin(uap->evp, &ev32, sizeof(ev32));
2363 error = convert_sigevent32(&ev32, &ev);
2367 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2369 error = copyout(&id, uap->timerid, sizeof(int));
2371 kern_ktimer_delete(td, id);
2377 freebsd32_ktimer_settime(struct thread *td,
2378 struct freebsd32_ktimer_settime_args *uap)
2380 struct itimerspec32 val32, oval32;
2381 struct itimerspec val, oval, *ovalp;
2384 error = copyin(uap->value, &val32, sizeof(val32));
2388 ovalp = uap->ovalue != NULL ? &oval : NULL;
2389 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2390 if (error == 0 && uap->ovalue != NULL) {
2391 ITS_CP(oval, oval32);
2392 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2398 freebsd32_ktimer_gettime(struct thread *td,
2399 struct freebsd32_ktimer_gettime_args *uap)
2401 struct itimerspec32 val32;
2402 struct itimerspec val;
2405 error = kern_ktimer_gettime(td, uap->timerid, &val);
2408 error = copyout(&val32, uap->value, sizeof(val32));
2414 freebsd32_clock_getcpuclockid2(struct thread *td,
2415 struct freebsd32_clock_getcpuclockid2_args *uap)
2420 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2421 uap->which, &clk_id);
2423 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2428 freebsd32_thr_new(struct thread *td,
2429 struct freebsd32_thr_new_args *uap)
2431 struct thr_param32 param32;
2432 struct thr_param param;
2435 if (uap->param_size < 0 ||
2436 uap->param_size > sizeof(struct thr_param32))
2438 bzero(¶m, sizeof(struct thr_param));
2439 bzero(¶m32, sizeof(struct thr_param32));
2440 error = copyin(uap->param, ¶m32, uap->param_size);
2443 param.start_func = PTRIN(param32.start_func);
2444 param.arg = PTRIN(param32.arg);
2445 param.stack_base = PTRIN(param32.stack_base);
2446 param.stack_size = param32.stack_size;
2447 param.tls_base = PTRIN(param32.tls_base);
2448 param.tls_size = param32.tls_size;
2449 param.child_tid = PTRIN(param32.child_tid);
2450 param.parent_tid = PTRIN(param32.parent_tid);
2451 param.flags = param32.flags;
2452 param.rtp = PTRIN(param32.rtp);
2453 param.spare[0] = PTRIN(param32.spare[0]);
2454 param.spare[1] = PTRIN(param32.spare[1]);
2455 param.spare[2] = PTRIN(param32.spare[2]);
2457 return (kern_thr_new(td, ¶m));
2461 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2463 struct timespec32 ts32;
2464 struct timespec ts, *tsp;
2469 if (uap->timeout != NULL) {
2470 error = copyin((const void *)uap->timeout, (void *)&ts32,
2471 sizeof(struct timespec32));
2474 ts.tv_sec = ts32.tv_sec;
2475 ts.tv_nsec = ts32.tv_nsec;
2478 return (kern_thr_suspend(td, tsp));
2482 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2484 bzero(dst, sizeof(*dst));
2485 dst->si_signo = src->si_signo;
2486 dst->si_errno = src->si_errno;
2487 dst->si_code = src->si_code;
2488 dst->si_pid = src->si_pid;
2489 dst->si_uid = src->si_uid;
2490 dst->si_status = src->si_status;
2491 dst->si_addr = (uintptr_t)src->si_addr;
2492 dst->si_value.sival_int = src->si_value.sival_int;
2493 dst->si_timerid = src->si_timerid;
2494 dst->si_overrun = src->si_overrun;
2497 #ifndef _FREEBSD32_SYSPROTO_H_
2498 struct freebsd32_sigqueue_args {
2501 /* union sigval32 */ int value;
2505 freebsd32_sigqueue(struct thread *td, struct freebsd32_sigqueue_args *uap)
2510 * On 32-bit ABIs, sival_int and sival_ptr are the same.
2511 * On 64-bit little-endian ABIs, the low bits are the same.
2512 * In 64-bit big-endian ABIs, sival_int overlaps with
2513 * sival_ptr's HIGH bits. We choose to support sival_int
2514 * rather than sival_ptr in this case as it seems to be
2517 bzero(&sv, sizeof(sv));
2518 sv.sival_int = uap->value;
2520 return (kern_sigqueue(td, uap->pid, uap->signum, &sv));
2524 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2526 struct timespec32 ts32;
2528 struct timespec *timeout;
2531 struct siginfo32 si32;
2535 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2538 ts.tv_sec = ts32.tv_sec;
2539 ts.tv_nsec = ts32.tv_nsec;
2544 error = copyin(uap->set, &set, sizeof(set));
2548 error = kern_sigtimedwait(td, set, &ksi, timeout);
2553 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2554 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2558 td->td_retval[0] = ksi.ksi_signo;
2566 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2569 struct siginfo32 si32;
2573 error = copyin(uap->set, &set, sizeof(set));
2577 error = kern_sigtimedwait(td, set, &ksi, NULL);
2582 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2583 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2586 td->td_retval[0] = ksi.ksi_signo;
2591 freebsd32_cpuset_setid(struct thread *td,
2592 struct freebsd32_cpuset_setid_args *uap)
2595 return (kern_cpuset_setid(td, uap->which,
2596 PAIR32TO64(id_t, uap->id), uap->setid));
2600 freebsd32_cpuset_getid(struct thread *td,
2601 struct freebsd32_cpuset_getid_args *uap)
2604 return (kern_cpuset_getid(td, uap->level, uap->which,
2605 PAIR32TO64(id_t, uap->id), uap->setid));
2609 freebsd32_cpuset_getaffinity(struct thread *td,
2610 struct freebsd32_cpuset_getaffinity_args *uap)
2613 return (kern_cpuset_getaffinity(td, uap->level, uap->which,
2614 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
2618 freebsd32_cpuset_setaffinity(struct thread *td,
2619 struct freebsd32_cpuset_setaffinity_args *uap)
2622 return (kern_cpuset_setaffinity(td, uap->level, uap->which,
2623 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask));
2627 freebsd32_nmount(struct thread *td,
2628 struct freebsd32_nmount_args /* {
2630 unsigned int iovcnt;
2639 * Mount flags are now 64-bits. On 32-bit archtectures only
2640 * 32-bits are passed in, but from here on everything handles
2641 * 64-bit flags correctly.
2645 AUDIT_ARG_FFLAGS(flags);
2648 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2649 * userspace to set this flag, but we must filter it out if we want
2650 * MNT_UPDATE on the root file system to work.
2651 * MNT_ROOTFS should only be set by the kernel when mounting its
2654 flags &= ~MNT_ROOTFS;
2657 * check that we have an even number of iovec's
2658 * and that we have at least two options.
2660 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2663 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2666 error = vfs_donmount(td, flags, auio);
2674 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2676 struct yyy32 *p32, s32;
2677 struct yyy *p = NULL, s;
2682 error = copyin(uap->zzz, &s32, sizeof(s32));
2688 error = kern_xxx(td, p);
2693 error = copyout(&s32, p32, sizeof(s32));
2700 syscall32_register(int *offset, struct sysent *new_sysent,
2701 struct sysent *old_sysent, int flags)
2704 if ((flags & ~SY_THR_STATIC) != 0)
2707 if (*offset == NO_SYSCALL) {
2710 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2711 if (freebsd32_sysent[i].sy_call ==
2712 (sy_call_t *)lkmnosys)
2714 if (i == SYS_MAXSYSCALL)
2717 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2719 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2720 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2723 *old_sysent = freebsd32_sysent[*offset];
2724 freebsd32_sysent[*offset] = *new_sysent;
2725 atomic_store_rel_32(&freebsd32_sysent[*offset].sy_thrcnt, flags);
2730 syscall32_deregister(int *offset, struct sysent *old_sysent)
2736 freebsd32_sysent[*offset] = *old_sysent;
2741 syscall32_module_handler(struct module *mod, int what, void *arg)
2743 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2749 error = syscall32_register(data->offset, data->new_sysent,
2750 &data->old_sysent, SY_THR_STATIC_KLD);
2752 /* Leave a mark so we know to safely unload below. */
2753 data->offset = NULL;
2756 ms.intval = *data->offset;
2758 module_setspecific(mod, &ms);
2761 error = data->chainevh(mod, what, data->chainarg);
2765 * MOD_LOAD failed, so just return without calling the
2766 * chained handler since we didn't pass along the MOD_LOAD
2769 if (data->offset == NULL)
2771 if (data->chainevh) {
2772 error = data->chainevh(mod, what, data->chainarg);
2776 error = syscall32_deregister(data->offset, &data->old_sysent);
2781 error = data->chainevh(mod, what, data->chainarg);
2787 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
2789 struct syscall_helper_data *sd1;
2792 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2793 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2794 &sd1->old_sysent, flags);
2796 syscall32_helper_unregister(sd);
2799 sd1->registered = 1;
2805 syscall32_helper_unregister(struct syscall_helper_data *sd)
2807 struct syscall_helper_data *sd1;
2809 for (sd1 = sd; sd1->registered != 0; sd1++) {
2810 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2811 sd1->registered = 0;
2817 freebsd32_copyout_strings(struct image_params *imgp)
2823 u_int32_t *stack_base;
2824 struct freebsd32_ps_strings *arginfo;
2825 char canary[sizeof(long) * 8];
2826 int32_t pagesizes32[MAXPAGESIZES];
2827 size_t execpath_len;
2831 * Calculate string base and vector table pointers.
2832 * Also deal with signal trampoline code for this exec type.
2834 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2835 execpath_len = strlen(imgp->execpath) + 1;
2838 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2840 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2841 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2844 destp = (uintptr_t)arginfo;
2849 if (szsigcode != 0) {
2851 destp = rounddown2(destp, sizeof(uint32_t));
2852 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2857 * Copy the image path for the rtld.
2859 if (execpath_len != 0) {
2860 destp -= execpath_len;
2861 imgp->execpathp = destp;
2862 copyout(imgp->execpath, (void *)destp, execpath_len);
2866 * Prepare the canary for SSP.
2868 arc4rand(canary, sizeof(canary), 0);
2869 destp -= sizeof(canary);
2870 imgp->canary = destp;
2871 copyout(canary, (void *)destp, sizeof(canary));
2872 imgp->canarylen = sizeof(canary);
2875 * Prepare the pagesizes array.
2877 for (i = 0; i < MAXPAGESIZES; i++)
2878 pagesizes32[i] = (uint32_t)pagesizes[i];
2879 destp -= sizeof(pagesizes32);
2880 destp = rounddown2(destp, sizeof(uint32_t));
2881 imgp->pagesizes = destp;
2882 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2883 imgp->pagesizeslen = sizeof(pagesizes32);
2885 destp -= ARG_MAX - imgp->args->stringspace;
2886 destp = rounddown2(destp, sizeof(uint32_t));
2889 * If we have a valid auxargs ptr, prepare some room
2892 if (imgp->auxargs) {
2894 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2895 * lower compatibility.
2897 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2900 * The '+ 2' is for the null pointers at the end of each of
2901 * the arg and env vector sets,and imgp->auxarg_size is room
2902 * for argument of Runtime loader.
2904 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2905 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2909 * The '+ 2' is for the null pointers at the end of each of
2910 * the arg and env vector sets
2912 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2913 imgp->args->envc + 2) * sizeof(u_int32_t));
2917 * vectp also becomes our initial stack base
2921 stringp = imgp->args->begin_argv;
2922 argc = imgp->args->argc;
2923 envc = imgp->args->envc;
2925 * Copy out strings - arguments and environment.
2927 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2930 * Fill in "ps_strings" struct for ps, w, etc.
2932 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2933 suword32(&arginfo->ps_nargvstr, argc);
2936 * Fill in argument portion of vector table.
2938 for (; argc > 0; --argc) {
2939 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2940 while (*stringp++ != 0)
2945 /* a null vector table pointer separates the argp's from the envp's */
2946 suword32(vectp++, 0);
2948 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2949 suword32(&arginfo->ps_nenvstr, envc);
2952 * Fill in environment portion of vector table.
2954 for (; envc > 0; --envc) {
2955 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2956 while (*stringp++ != 0)
2961 /* end of vector table is a null pointer */
2964 return ((register_t *)stack_base);
2968 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2970 struct kld_file_stat *stat;
2971 struct kld32_file_stat *stat32;
2974 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2977 if (version != sizeof(struct kld32_file_stat_1) &&
2978 version != sizeof(struct kld32_file_stat))
2981 stat = malloc(sizeof(*stat), M_TEMP, M_WAITOK | M_ZERO);
2982 stat32 = malloc(sizeof(*stat32), M_TEMP, M_WAITOK | M_ZERO);
2983 error = kern_kldstat(td, uap->fileid, stat);
2985 bcopy(&stat->name[0], &stat32->name[0], sizeof(stat->name));
2986 CP(*stat, *stat32, refs);
2987 CP(*stat, *stat32, id);
2988 PTROUT_CP(*stat, *stat32, address);
2989 CP(*stat, *stat32, size);
2990 bcopy(&stat->pathname[0], &stat32->pathname[0],
2991 sizeof(stat->pathname));
2992 stat32->version = version;
2993 error = copyout(stat32, uap->stat, version);
2996 free(stat32, M_TEMP);
3001 freebsd32_posix_fallocate(struct thread *td,
3002 struct freebsd32_posix_fallocate_args *uap)
3006 error = kern_posix_fallocate(td, uap->fd,
3007 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3008 return (kern_posix_error(td, error));
3012 freebsd32_posix_fadvise(struct thread *td,
3013 struct freebsd32_posix_fadvise_args *uap)
3017 error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
3018 PAIR32TO64(off_t, uap->len), uap->advice);
3019 return (kern_posix_error(td, error));
3023 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3026 CP(*sig32, *sig, sigev_notify);
3027 switch (sig->sigev_notify) {
3030 case SIGEV_THREAD_ID:
3031 CP(*sig32, *sig, sigev_notify_thread_id);
3034 CP(*sig32, *sig, sigev_signo);
3035 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3038 CP(*sig32, *sig, sigev_notify_kqueue);
3039 CP(*sig32, *sig, sigev_notify_kevent_flags);
3040 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3049 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3053 struct procctl_reaper_status rs;
3054 struct procctl_reaper_pids rp;
3055 struct procctl_reaper_kill rk;
3058 struct procctl_reaper_pids32 rp;
3060 int error, error1, flags;
3064 case PROC_TRACE_CTL:
3065 case PROC_TRAPCAP_CTL:
3066 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3071 case PROC_REAP_ACQUIRE:
3072 case PROC_REAP_RELEASE:
3073 if (uap->data != NULL)
3077 case PROC_REAP_STATUS:
3080 case PROC_REAP_GETPIDS:
3081 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3084 CP(x32.rp, x.rp, rp_count);
3085 PTRIN_CP(x32.rp, x.rp, rp_pids);
3088 case PROC_REAP_KILL:
3089 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3094 case PROC_TRACE_STATUS:
3095 case PROC_TRAPCAP_STATUS:
3101 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3104 case PROC_REAP_STATUS:
3106 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3108 case PROC_REAP_KILL:
3109 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3113 case PROC_TRACE_STATUS:
3114 case PROC_TRAPCAP_STATUS:
3116 error = copyout(&flags, uap->data, sizeof(flags));
3123 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3129 * Do unsigned conversion for arg when operation
3130 * interprets it as flags or pointer.
3132 case F_SETLK_REMOTE:
3141 tmp = (unsigned int)(uap->arg);
3147 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3151 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3153 struct timespec32 ts32;
3154 struct timespec ts, *tsp;
3158 if (uap->ts != NULL) {
3159 error = copyin(uap->ts, &ts32, sizeof(ts32));
3162 CP(ts32, ts, tv_sec);
3163 CP(ts32, ts, tv_nsec);
3167 if (uap->set != NULL) {
3168 error = copyin(uap->set, &set, sizeof(set));
3175 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));