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;
251 size_t count, size, copycount;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->flags);
260 while (copycount > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
270 td->td_retval[0] = count;
276 freebsd32_sigaltstack(struct thread *td,
277 struct freebsd32_sigaltstack_args *uap)
279 struct sigaltstack32 s32;
280 struct sigaltstack ss, oss, *ssp;
283 if (uap->ss != NULL) {
284 error = copyin(uap->ss, &s32, sizeof(s32));
287 PTRIN_CP(s32, ss, ss_sp);
288 CP(s32, ss, ss_size);
289 CP(s32, ss, ss_flags);
293 error = kern_sigaltstack(td, ssp, &oss);
294 if (error == 0 && uap->oss != NULL) {
295 PTROUT_CP(oss, s32, ss_sp);
296 CP(oss, s32, ss_size);
297 CP(oss, s32, ss_flags);
298 error = copyout(&s32, uap->oss, sizeof(s32));
304 * Custom version of exec_copyin_args() so that we can translate
308 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
309 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
316 bzero(args, sizeof(*args));
321 * Allocate demand-paged memory for the file name, argument, and
322 * environment strings.
324 error = exec_alloc_args(args);
329 * Copy the file name.
332 args->fname = args->buf;
333 error = (segflg == UIO_SYSSPACE) ?
334 copystr(fname, args->fname, PATH_MAX, &length) :
335 copyinstr(fname, args->fname, PATH_MAX, &length);
341 args->begin_argv = args->buf + length;
342 args->endp = args->begin_argv;
343 args->stringspace = ARG_MAX;
346 * extract arguments first
350 error = copyin(p32++, &arg, sizeof(arg));
356 error = copyinstr(argp, args->endp, args->stringspace, &length);
358 if (error == ENAMETOOLONG)
362 args->stringspace -= length;
363 args->endp += length;
367 args->begin_envv = args->endp;
370 * extract environment strings
375 error = copyin(p32++, &arg, sizeof(arg));
381 error = copyinstr(envp, args->endp, args->stringspace,
384 if (error == ENAMETOOLONG)
388 args->stringspace -= length;
389 args->endp += length;
397 exec_free_args(args);
402 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
404 struct image_args eargs;
407 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
408 uap->argv, uap->envv);
410 error = kern_execve(td, &eargs, NULL);
415 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
417 struct image_args eargs;
420 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
421 uap->argv, uap->envv);
424 error = kern_execve(td, &eargs, NULL);
430 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
432 struct mprotect_args ap;
434 ap.addr = PTRIN(uap->addr);
437 #if defined(__amd64__)
438 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
439 ap.prot |= PROT_EXEC;
441 return (sys_mprotect(td, &ap));
445 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
448 vm_offset_t addr = (vm_offset_t) uap->addr;
449 vm_size_t len = uap->len;
450 int prot = uap->prot;
451 int flags = uap->flags;
453 off_t pos = PAIR32TO64(off_t,uap->pos);
455 #if defined(__amd64__)
456 if (i386_read_exec && (prot & PROT_READ))
460 ap.addr = (void *) addr;
467 return (sys_mmap(td, &ap));
470 #ifdef COMPAT_FREEBSD6
472 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
474 struct freebsd32_mmap_args ap;
479 ap.flags = uap->flags;
484 return (freebsd32_mmap(td, &ap));
489 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
491 struct itimerval itv, oitv, *itvp;
492 struct itimerval32 i32;
495 if (uap->itv != NULL) {
496 error = copyin(uap->itv, &i32, sizeof(i32));
499 TV_CP(i32, itv, it_interval);
500 TV_CP(i32, itv, it_value);
504 error = kern_setitimer(td, uap->which, itvp, &oitv);
505 if (error || uap->oitv == NULL)
507 TV_CP(oitv, i32, it_interval);
508 TV_CP(oitv, i32, it_value);
509 return (copyout(&i32, uap->oitv, sizeof(i32)));
513 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
515 struct itimerval itv;
516 struct itimerval32 i32;
519 error = kern_getitimer(td, uap->which, &itv);
520 if (error || uap->itv == NULL)
522 TV_CP(itv, i32, it_interval);
523 TV_CP(itv, i32, it_value);
524 return (copyout(&i32, uap->itv, sizeof(i32)));
528 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
530 struct timeval32 tv32;
531 struct timeval tv, *tvp;
534 if (uap->tv != NULL) {
535 error = copyin(uap->tv, &tv32, sizeof(tv32));
538 CP(tv32, tv, tv_sec);
539 CP(tv32, tv, tv_usec);
544 * XXX Do pointers need PTRIN()?
546 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
547 sizeof(int32_t) * 8));
551 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
553 struct timespec32 ts32;
555 struct timeval tv, *tvp;
559 if (uap->ts != NULL) {
560 error = copyin(uap->ts, &ts32, sizeof(ts32));
563 CP(ts32, ts, tv_sec);
564 CP(ts32, ts, tv_nsec);
565 TIMESPEC_TO_TIMEVAL(&tv, &ts);
569 if (uap->sm != NULL) {
570 error = copyin(uap->sm, &set, sizeof(set));
577 * XXX Do pointers need PTRIN()?
579 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
580 uset, sizeof(int32_t) * 8);
585 * Copy 'count' items into the destination list pointed to by uap->eventlist.
588 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
590 struct freebsd32_kevent_args *uap;
591 struct kevent32 ks32[KQ_NEVENTS];
594 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
595 uap = (struct freebsd32_kevent_args *)arg;
597 for (i = 0; i < count; i++) {
598 CP(kevp[i], ks32[i], ident);
599 CP(kevp[i], ks32[i], filter);
600 CP(kevp[i], ks32[i], flags);
601 CP(kevp[i], ks32[i], fflags);
602 CP(kevp[i], ks32[i], data);
603 PTROUT_CP(kevp[i], ks32[i], udata);
605 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
607 uap->eventlist += count;
612 * Copy 'count' items from the list pointed to by uap->changelist.
615 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
617 struct freebsd32_kevent_args *uap;
618 struct kevent32 ks32[KQ_NEVENTS];
621 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
622 uap = (struct freebsd32_kevent_args *)arg;
624 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
627 uap->changelist += count;
629 for (i = 0; i < count; i++) {
630 CP(ks32[i], kevp[i], ident);
631 CP(ks32[i], kevp[i], filter);
632 CP(ks32[i], kevp[i], flags);
633 CP(ks32[i], kevp[i], fflags);
634 CP(ks32[i], kevp[i], data);
635 PTRIN_CP(ks32[i], kevp[i], udata);
642 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
644 struct timespec32 ts32;
645 struct timespec ts, *tsp;
646 struct kevent_copyops k_ops = { uap,
647 freebsd32_kevent_copyout,
648 freebsd32_kevent_copyin};
653 error = copyin(uap->timeout, &ts32, sizeof(ts32));
656 CP(ts32, ts, tv_sec);
657 CP(ts32, ts, tv_nsec);
661 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
667 freebsd32_gettimeofday(struct thread *td,
668 struct freebsd32_gettimeofday_args *uap)
671 struct timeval32 atv32;
677 CP(atv, atv32, tv_sec);
678 CP(atv, atv32, tv_usec);
679 error = copyout(&atv32, uap->tp, sizeof (atv32));
681 if (error == 0 && uap->tzp != NULL) {
682 rtz.tz_minuteswest = tz_minuteswest;
683 rtz.tz_dsttime = tz_dsttime;
684 error = copyout(&rtz, uap->tzp, sizeof (rtz));
690 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
696 error = kern_getrusage(td, uap->who, &s);
699 if (uap->rusage != NULL) {
700 freebsd32_rusage_out(&s, &s32);
701 error = copyout(&s32, uap->rusage, sizeof(s32));
707 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
709 struct iovec32 iov32;
716 if (iovcnt > UIO_MAXIOV)
718 iovlen = iovcnt * sizeof(struct iovec);
719 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
720 iov = (struct iovec *)(uio + 1);
721 for (i = 0; i < iovcnt; i++) {
722 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
727 iov[i].iov_base = PTRIN(iov32.iov_base);
728 iov[i].iov_len = iov32.iov_len;
731 uio->uio_iovcnt = iovcnt;
732 uio->uio_segflg = UIO_USERSPACE;
733 uio->uio_offset = -1;
735 for (i = 0; i < iovcnt; i++) {
736 if (iov->iov_len > INT_MAX - uio->uio_resid) {
740 uio->uio_resid += iov->iov_len;
748 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
753 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
756 error = kern_readv(td, uap->fd, auio);
762 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
767 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
770 error = kern_writev(td, uap->fd, auio);
776 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
781 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
784 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
790 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
795 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
798 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
804 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
807 struct iovec32 iov32;
813 if (iovcnt > UIO_MAXIOV)
815 iovlen = iovcnt * sizeof(struct iovec);
816 iov = malloc(iovlen, M_IOV, M_WAITOK);
817 for (i = 0; i < iovcnt; i++) {
818 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
823 iov[i].iov_base = PTRIN(iov32.iov_base);
824 iov[i].iov_len = iov32.iov_len;
831 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
836 error = copyin(msg32, &m32, sizeof(m32));
839 msg->msg_name = PTRIN(m32.msg_name);
840 msg->msg_namelen = m32.msg_namelen;
841 msg->msg_iov = PTRIN(m32.msg_iov);
842 msg->msg_iovlen = m32.msg_iovlen;
843 msg->msg_control = PTRIN(m32.msg_control);
844 msg->msg_controllen = m32.msg_controllen;
845 msg->msg_flags = m32.msg_flags;
850 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
855 m32.msg_name = PTROUT(msg->msg_name);
856 m32.msg_namelen = msg->msg_namelen;
857 m32.msg_iov = PTROUT(msg->msg_iov);
858 m32.msg_iovlen = msg->msg_iovlen;
859 m32.msg_control = PTROUT(msg->msg_control);
860 m32.msg_controllen = msg->msg_controllen;
861 m32.msg_flags = msg->msg_flags;
862 error = copyout(&m32, msg32, sizeof(m32));
867 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
869 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
871 #define FREEBSD32_ALIGN(p) \
872 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
873 #define FREEBSD32_CMSG_SPACE(l) \
874 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
876 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
877 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
879 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
883 socklen_t clen, datalen;
886 int len, maxlen, copylen;
890 len = msg->msg_controllen;
891 maxlen = msg->msg_controllen;
892 msg->msg_controllen = 0;
895 ctlbuf = msg->msg_control;
897 while (m && len > 0) {
898 cm = mtod(m, struct cmsghdr *);
903 if (sizeof(struct cmsghdr) > clen ||
904 cm->cmsg_len > clen) {
909 data = CMSG_DATA(cm);
910 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
912 /* Adjust message length */
913 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
918 copylen = sizeof(struct cmsghdr);
920 msg->msg_flags |= MSG_CTRUNC;
924 error = copyout(cm,ctlbuf,copylen);
928 ctlbuf += FREEBSD32_ALIGN(copylen);
929 len -= FREEBSD32_ALIGN(copylen);
937 msg->msg_flags |= MSG_CTRUNC;
941 error = copyout(data,ctlbuf,copylen);
945 ctlbuf += FREEBSD32_ALIGN(copylen);
946 len -= FREEBSD32_ALIGN(copylen);
948 if (CMSG_SPACE(datalen) < clen) {
949 clen -= CMSG_SPACE(datalen);
950 cm = (struct cmsghdr *)
951 ((caddr_t)cm + CMSG_SPACE(datalen));
960 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
968 freebsd32_recvmsg(td, uap)
970 struct freebsd32_recvmsg_args /* {
972 struct msghdr32 *msg;
978 struct iovec *uiov, *iov;
979 struct mbuf *control = NULL;
980 struct mbuf **controlp;
983 error = copyin(uap->msg, &m32, sizeof(m32));
986 error = freebsd32_copyinmsghdr(uap->msg, &msg);
989 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
993 msg.msg_flags = uap->flags;
997 controlp = (msg.msg_control != NULL) ? &control : NULL;
998 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1002 if (control != NULL)
1003 error = freebsd32_copy_msg_out(&msg, control);
1005 msg.msg_controllen = 0;
1008 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1012 if (control != NULL)
1019 * Copy-in the array of control messages constructed using alignment
1020 * and padding suitable for a 32-bit environment and construct an
1021 * mbuf using alignment and padding suitable for a 64-bit kernel.
1022 * The alignment and padding are defined indirectly by CMSG_DATA(),
1023 * CMSG_SPACE() and CMSG_LEN().
1026 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1030 u_int idx, len, msglen;
1033 buflen = FREEBSD32_ALIGN(buflen);
1035 if (buflen > MCLBYTES)
1039 * Iterate over the buffer and get the length of each message
1040 * in there. This has 32-bit alignment and padding. Use it to
1041 * determine the length of these messages when using 64-bit
1042 * alignment and padding.
1046 while (idx < buflen) {
1047 error = copyin(buf + idx, &msglen, sizeof(msglen));
1050 if (msglen < sizeof(struct cmsghdr))
1052 msglen = FREEBSD32_ALIGN(msglen);
1053 if (idx + msglen > buflen)
1056 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1057 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1058 len += CMSG_ALIGN(msglen);
1064 m = m_get(M_WAITOK, MT_CONTROL);
1066 MCLGET(m, M_WAITOK);
1069 md = mtod(m, void *);
1070 while (buflen > 0) {
1071 error = copyin(buf, md, sizeof(struct cmsghdr));
1074 msglen = *(u_int *)md;
1075 msglen = FREEBSD32_ALIGN(msglen);
1077 /* Modify the message length to account for alignment. */
1078 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1079 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1081 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1082 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1083 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1085 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1087 error = copyin(buf, md, msglen);
1090 md = (char *)md + CMSG_ALIGN(msglen);
1104 freebsd32_sendmsg(struct thread *td,
1105 struct freebsd32_sendmsg_args *uap)
1108 struct msghdr32 m32;
1110 struct mbuf *control = NULL;
1111 struct sockaddr *to = NULL;
1114 error = copyin(uap->msg, &m32, sizeof(m32));
1117 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1120 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1125 if (msg.msg_name != NULL) {
1126 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1134 if (msg.msg_control) {
1135 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1140 error = freebsd32_copyin_control(&control, msg.msg_control,
1141 msg.msg_controllen);
1145 msg.msg_control = NULL;
1146 msg.msg_controllen = 0;
1149 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1160 freebsd32_recvfrom(struct thread *td,
1161 struct freebsd32_recvfrom_args *uap)
1167 if (uap->fromlenaddr) {
1168 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1169 sizeof(msg.msg_namelen));
1173 msg.msg_namelen = 0;
1176 msg.msg_name = PTRIN(uap->from);
1177 msg.msg_iov = &aiov;
1179 aiov.iov_base = PTRIN(uap->buf);
1180 aiov.iov_len = uap->len;
1181 msg.msg_control = NULL;
1182 msg.msg_flags = uap->flags;
1183 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1184 if (error == 0 && uap->fromlenaddr)
1185 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1186 sizeof (msg.msg_namelen));
1191 freebsd32_settimeofday(struct thread *td,
1192 struct freebsd32_settimeofday_args *uap)
1194 struct timeval32 tv32;
1195 struct timeval tv, *tvp;
1196 struct timezone tz, *tzp;
1200 error = copyin(uap->tv, &tv32, sizeof(tv32));
1203 CP(tv32, tv, tv_sec);
1204 CP(tv32, tv, tv_usec);
1209 error = copyin(uap->tzp, &tz, sizeof(tz));
1215 return (kern_settimeofday(td, tvp, tzp));
1219 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1221 struct timeval32 s32[2];
1222 struct timeval s[2], *sp;
1225 if (uap->tptr != NULL) {
1226 error = copyin(uap->tptr, s32, sizeof(s32));
1229 CP(s32[0], s[0], tv_sec);
1230 CP(s32[0], s[0], tv_usec);
1231 CP(s32[1], s[1], tv_sec);
1232 CP(s32[1], s[1], tv_usec);
1236 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1241 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1243 struct timeval32 s32[2];
1244 struct timeval s[2], *sp;
1247 if (uap->tptr != NULL) {
1248 error = copyin(uap->tptr, s32, sizeof(s32));
1251 CP(s32[0], s[0], tv_sec);
1252 CP(s32[0], s[0], tv_usec);
1253 CP(s32[1], s[1], tv_sec);
1254 CP(s32[1], s[1], tv_usec);
1258 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1262 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1264 struct timeval32 s32[2];
1265 struct timeval s[2], *sp;
1268 if (uap->tptr != NULL) {
1269 error = copyin(uap->tptr, s32, sizeof(s32));
1272 CP(s32[0], s[0], tv_sec);
1273 CP(s32[0], s[0], tv_usec);
1274 CP(s32[1], s[1], tv_sec);
1275 CP(s32[1], s[1], tv_usec);
1279 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1283 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1285 struct timeval32 s32[2];
1286 struct timeval s[2], *sp;
1289 if (uap->times != NULL) {
1290 error = copyin(uap->times, s32, sizeof(s32));
1293 CP(s32[0], s[0], tv_sec);
1294 CP(s32[0], s[0], tv_usec);
1295 CP(s32[1], s[1], tv_sec);
1296 CP(s32[1], s[1], tv_usec);
1300 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1305 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1307 struct timespec32 ts32[2];
1308 struct timespec ts[2], *tsp;
1311 if (uap->times != NULL) {
1312 error = copyin(uap->times, ts32, sizeof(ts32));
1315 CP(ts32[0], ts[0], tv_sec);
1316 CP(ts32[0], ts[0], tv_nsec);
1317 CP(ts32[1], ts[1], tv_sec);
1318 CP(ts32[1], ts[1], tv_nsec);
1322 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1326 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1328 struct timespec32 ts32[2];
1329 struct timespec ts[2], *tsp;
1332 if (uap->times != NULL) {
1333 error = copyin(uap->times, ts32, sizeof(ts32));
1336 CP(ts32[0], ts[0], tv_sec);
1337 CP(ts32[0], ts[0], tv_nsec);
1338 CP(ts32[1], ts[1], tv_sec);
1339 CP(ts32[1], ts[1], tv_nsec);
1343 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1344 tsp, UIO_SYSSPACE, uap->flag));
1348 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1350 struct timeval32 tv32;
1351 struct timeval delta, olddelta, *deltap;
1355 error = copyin(uap->delta, &tv32, sizeof(tv32));
1358 CP(tv32, delta, tv_sec);
1359 CP(tv32, delta, tv_usec);
1363 error = kern_adjtime(td, deltap, &olddelta);
1364 if (uap->olddelta && error == 0) {
1365 CP(olddelta, tv32, tv_sec);
1366 CP(olddelta, tv32, tv_usec);
1367 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1372 #ifdef COMPAT_FREEBSD4
1374 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1376 struct statfs32 s32;
1380 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1383 copy_statfs(&s, &s32);
1384 return (copyout(&s32, uap->buf, sizeof(s32)));
1388 #ifdef COMPAT_FREEBSD4
1390 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1392 struct statfs32 s32;
1396 error = kern_fstatfs(td, uap->fd, &s);
1399 copy_statfs(&s, &s32);
1400 return (copyout(&s32, uap->buf, sizeof(s32)));
1404 #ifdef COMPAT_FREEBSD4
1406 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1408 struct statfs32 s32;
1413 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1415 error = kern_fhstatfs(td, fh, &s);
1418 copy_statfs(&s, &s32);
1419 return (copyout(&s32, uap->buf, sizeof(s32)));
1424 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1426 struct pread_args ap;
1430 ap.nbyte = uap->nbyte;
1431 ap.offset = PAIR32TO64(off_t,uap->offset);
1432 return (sys_pread(td, &ap));
1436 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1438 struct pwrite_args ap;
1442 ap.nbyte = uap->nbyte;
1443 ap.offset = PAIR32TO64(off_t,uap->offset);
1444 return (sys_pwrite(td, &ap));
1449 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1451 struct lseek_args nuap;
1454 nuap.offset = uap->offset;
1455 nuap.whence = uap->whence;
1456 return (sys_lseek(td, &nuap));
1461 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1464 struct lseek_args ap;
1468 ap.offset = PAIR32TO64(off_t,uap->offset);
1469 ap.whence = uap->whence;
1470 error = sys_lseek(td, &ap);
1471 /* Expand the quad return into two parts for eax and edx */
1472 pos = td->td_uretoff.tdu_off;
1473 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1474 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1479 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1481 struct truncate_args ap;
1483 ap.path = uap->path;
1484 ap.length = PAIR32TO64(off_t,uap->length);
1485 return (sys_truncate(td, &ap));
1489 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1491 struct ftruncate_args ap;
1494 ap.length = PAIR32TO64(off_t,uap->length);
1495 return (sys_ftruncate(td, &ap));
1500 ofreebsd32_getdirentries(struct thread *td,
1501 struct ofreebsd32_getdirentries_args *uap)
1503 struct ogetdirentries_args ap;
1510 ap.count = uap->count;
1512 error = kern_ogetdirentries(td, &ap, &loff);
1515 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1522 freebsd32_getdirentries(struct thread *td,
1523 struct freebsd32_getdirentries_args *uap)
1529 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1530 NULL, UIO_USERSPACE);
1533 if (uap->basep != NULL) {
1535 error = copyout(&base32, uap->basep, sizeof(int32_t));
1540 #ifdef COMPAT_FREEBSD6
1541 /* versions with the 'int pad' argument */
1543 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1545 struct pread_args ap;
1549 ap.nbyte = uap->nbyte;
1550 ap.offset = PAIR32TO64(off_t,uap->offset);
1551 return (sys_pread(td, &ap));
1555 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1557 struct pwrite_args ap;
1561 ap.nbyte = uap->nbyte;
1562 ap.offset = PAIR32TO64(off_t,uap->offset);
1563 return (sys_pwrite(td, &ap));
1567 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1570 struct lseek_args ap;
1574 ap.offset = PAIR32TO64(off_t,uap->offset);
1575 ap.whence = uap->whence;
1576 error = sys_lseek(td, &ap);
1577 /* Expand the quad return into two parts for eax and edx */
1578 pos = *(off_t *)(td->td_retval);
1579 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1580 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1585 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1587 struct truncate_args ap;
1589 ap.path = uap->path;
1590 ap.length = PAIR32TO64(off_t,uap->length);
1591 return (sys_truncate(td, &ap));
1595 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1597 struct ftruncate_args ap;
1600 ap.length = PAIR32TO64(off_t,uap->length);
1601 return (sys_ftruncate(td, &ap));
1603 #endif /* COMPAT_FREEBSD6 */
1613 freebsd32_do_sendfile(struct thread *td,
1614 struct freebsd32_sendfile_args *uap, int compat)
1616 struct sf_hdtr32 hdtr32;
1617 struct sf_hdtr hdtr;
1618 struct uio *hdr_uio, *trl_uio;
1620 cap_rights_t rights;
1621 struct iovec32 *iov32;
1622 off_t offset, sbytes;
1625 offset = PAIR32TO64(off_t, uap->offset);
1629 hdr_uio = trl_uio = NULL;
1631 if (uap->hdtr != NULL) {
1632 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1635 PTRIN_CP(hdtr32, hdtr, headers);
1636 CP(hdtr32, hdtr, hdr_cnt);
1637 PTRIN_CP(hdtr32, hdtr, trailers);
1638 CP(hdtr32, hdtr, trl_cnt);
1640 if (hdtr.headers != NULL) {
1641 iov32 = PTRIN(hdtr32.headers);
1642 error = freebsd32_copyinuio(iov32,
1643 hdtr32.hdr_cnt, &hdr_uio);
1647 if (hdtr.trailers != NULL) {
1648 iov32 = PTRIN(hdtr32.trailers);
1649 error = freebsd32_copyinuio(iov32,
1650 hdtr32.trl_cnt, &trl_uio);
1656 AUDIT_ARG_FD(uap->fd);
1658 if ((error = fget_read(td, uap->fd,
1659 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
1662 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1663 uap->nbytes, &sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1666 if (uap->sbytes != NULL)
1667 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1671 free(hdr_uio, M_IOV);
1673 free(trl_uio, M_IOV);
1677 #ifdef COMPAT_FREEBSD4
1679 freebsd4_freebsd32_sendfile(struct thread *td,
1680 struct freebsd4_freebsd32_sendfile_args *uap)
1682 return (freebsd32_do_sendfile(td,
1683 (struct freebsd32_sendfile_args *)uap, 1));
1688 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1691 return (freebsd32_do_sendfile(td, uap, 0));
1695 copy_stat(struct stat *in, struct stat32 *out)
1698 CP(*in, *out, st_dev);
1699 CP(*in, *out, st_ino);
1700 CP(*in, *out, st_mode);
1701 CP(*in, *out, st_nlink);
1702 CP(*in, *out, st_uid);
1703 CP(*in, *out, st_gid);
1704 CP(*in, *out, st_rdev);
1705 TS_CP(*in, *out, st_atim);
1706 TS_CP(*in, *out, st_mtim);
1707 TS_CP(*in, *out, st_ctim);
1708 CP(*in, *out, st_size);
1709 CP(*in, *out, st_blocks);
1710 CP(*in, *out, st_blksize);
1711 CP(*in, *out, st_flags);
1712 CP(*in, *out, st_gen);
1713 TS_CP(*in, *out, st_birthtim);
1718 copy_ostat(struct stat *in, struct ostat32 *out)
1721 CP(*in, *out, st_dev);
1722 CP(*in, *out, st_ino);
1723 CP(*in, *out, st_mode);
1724 CP(*in, *out, st_nlink);
1725 CP(*in, *out, st_uid);
1726 CP(*in, *out, st_gid);
1727 CP(*in, *out, st_rdev);
1728 CP(*in, *out, st_size);
1729 TS_CP(*in, *out, st_atim);
1730 TS_CP(*in, *out, st_mtim);
1731 TS_CP(*in, *out, st_ctim);
1732 CP(*in, *out, st_blksize);
1733 CP(*in, *out, st_blocks);
1734 CP(*in, *out, st_flags);
1735 CP(*in, *out, st_gen);
1740 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1746 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1750 copy_stat(&sb, &sb32);
1751 error = copyout(&sb32, uap->ub, sizeof (sb32));
1757 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1760 struct ostat32 sb32;
1763 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1767 copy_ostat(&sb, &sb32);
1768 error = copyout(&sb32, uap->ub, sizeof (sb32));
1774 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1780 error = kern_fstat(td, uap->fd, &ub);
1783 copy_stat(&ub, &ub32);
1784 error = copyout(&ub32, uap->ub, sizeof(ub32));
1790 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1793 struct ostat32 ub32;
1796 error = kern_fstat(td, uap->fd, &ub);
1799 copy_ostat(&ub, &ub32);
1800 error = copyout(&ub32, uap->ub, sizeof(ub32));
1806 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1812 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1816 copy_stat(&ub, &ub32);
1817 error = copyout(&ub32, uap->buf, sizeof(ub32));
1822 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1828 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1829 UIO_USERSPACE, &sb, NULL);
1832 copy_stat(&sb, &sb32);
1833 error = copyout(&sb32, uap->ub, sizeof (sb32));
1839 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1842 struct ostat32 sb32;
1845 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1846 UIO_USERSPACE, &sb, NULL);
1849 copy_ostat(&sb, &sb32);
1850 error = copyout(&sb32, uap->ub, sizeof (sb32));
1856 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1858 int error, name[CTL_MAXNAME];
1862 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1864 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1868 error = fueword32(uap->oldlenp, &tmp);
1875 error = userland_sysctl(td, name, uap->namelen,
1876 uap->old, &oldlen, 1,
1877 uap->new, uap->newlen, &j, SCTL_MASK32);
1878 if (error && error != ENOMEM)
1881 suword32(uap->oldlenp, j);
1886 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1892 error = copyin(uap->jail, &version, sizeof(uint32_t));
1899 /* FreeBSD single IPv4 jails. */
1900 struct jail32_v0 j32_v0;
1902 bzero(&j, sizeof(struct jail));
1903 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1906 CP(j32_v0, j, version);
1907 PTRIN_CP(j32_v0, j, path);
1908 PTRIN_CP(j32_v0, j, hostname);
1909 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1915 * Version 1 was used by multi-IPv4 jail implementations
1916 * that never made it into the official kernel.
1920 case 2: /* JAIL_API_VERSION */
1922 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1925 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1928 CP(j32, j, version);
1929 PTRIN_CP(j32, j, path);
1930 PTRIN_CP(j32, j, hostname);
1931 PTRIN_CP(j32, j, jailname);
1934 PTRIN_CP(j32, j, ip4);
1935 PTRIN_CP(j32, j, ip6);
1940 /* Sci-Fi jails are not supported, sorry. */
1943 return (kern_jail(td, &j));
1947 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1952 /* Check that we have an even number of iovecs. */
1953 if (uap->iovcnt & 1)
1956 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1959 error = kern_jail_set(td, auio, uap->flags);
1965 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1967 struct iovec32 iov32;
1971 /* Check that we have an even number of iovecs. */
1972 if (uap->iovcnt & 1)
1975 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1978 error = kern_jail_get(td, auio, uap->flags);
1980 for (i = 0; i < uap->iovcnt; i++) {
1981 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1982 CP(auio->uio_iov[i], iov32, iov_len);
1983 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
1992 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
1994 struct sigaction32 s32;
1995 struct sigaction sa, osa, *sap;
1999 error = copyin(uap->act, &s32, sizeof(s32));
2002 sa.sa_handler = PTRIN(s32.sa_u);
2003 CP(s32, sa, sa_flags);
2004 CP(s32, sa, sa_mask);
2008 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2009 if (error == 0 && uap->oact != NULL) {
2010 s32.sa_u = PTROUT(osa.sa_handler);
2011 CP(osa, s32, sa_flags);
2012 CP(osa, s32, sa_mask);
2013 error = copyout(&s32, uap->oact, sizeof(s32));
2018 #ifdef COMPAT_FREEBSD4
2020 freebsd4_freebsd32_sigaction(struct thread *td,
2021 struct freebsd4_freebsd32_sigaction_args *uap)
2023 struct sigaction32 s32;
2024 struct sigaction sa, osa, *sap;
2028 error = copyin(uap->act, &s32, sizeof(s32));
2031 sa.sa_handler = PTRIN(s32.sa_u);
2032 CP(s32, sa, sa_flags);
2033 CP(s32, sa, sa_mask);
2037 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2038 if (error == 0 && uap->oact != NULL) {
2039 s32.sa_u = PTROUT(osa.sa_handler);
2040 CP(osa, s32, sa_flags);
2041 CP(osa, s32, sa_mask);
2042 error = copyout(&s32, uap->oact, sizeof(s32));
2049 struct osigaction32 {
2058 ofreebsd32_sigaction(struct thread *td,
2059 struct ofreebsd32_sigaction_args *uap)
2061 struct osigaction32 s32;
2062 struct sigaction sa, osa, *sap;
2065 if (uap->signum <= 0 || uap->signum >= ONSIG)
2069 error = copyin(uap->nsa, &s32, sizeof(s32));
2072 sa.sa_handler = PTRIN(s32.sa_u);
2073 CP(s32, sa, sa_flags);
2074 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2078 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2079 if (error == 0 && uap->osa != NULL) {
2080 s32.sa_u = PTROUT(osa.sa_handler);
2081 CP(osa, s32, sa_flags);
2082 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2083 error = copyout(&s32, uap->osa, sizeof(s32));
2089 ofreebsd32_sigprocmask(struct thread *td,
2090 struct ofreebsd32_sigprocmask_args *uap)
2095 OSIG2SIG(uap->mask, set);
2096 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2097 SIG2OSIG(oset, td->td_retval[0]);
2102 ofreebsd32_sigpending(struct thread *td,
2103 struct ofreebsd32_sigpending_args *uap)
2105 struct proc *p = td->td_proc;
2109 siglist = p->p_siglist;
2110 SIGSETOR(siglist, td->td_siglist);
2112 SIG2OSIG(siglist, td->td_retval[0]);
2117 u_int32_t sv_handler;
2123 ofreebsd32_sigvec(struct thread *td,
2124 struct ofreebsd32_sigvec_args *uap)
2126 struct sigvec32 vec;
2127 struct sigaction sa, osa, *sap;
2130 if (uap->signum <= 0 || uap->signum >= ONSIG)
2134 error = copyin(uap->nsv, &vec, sizeof(vec));
2137 sa.sa_handler = PTRIN(vec.sv_handler);
2138 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2139 sa.sa_flags = vec.sv_flags;
2140 sa.sa_flags ^= SA_RESTART;
2144 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2145 if (error == 0 && uap->osv != NULL) {
2146 vec.sv_handler = PTROUT(osa.sa_handler);
2147 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2148 vec.sv_flags = osa.sa_flags;
2149 vec.sv_flags &= ~SA_NOCLDWAIT;
2150 vec.sv_flags ^= SA_RESTART;
2151 error = copyout(&vec, uap->osv, sizeof(vec));
2157 ofreebsd32_sigblock(struct thread *td,
2158 struct ofreebsd32_sigblock_args *uap)
2162 OSIG2SIG(uap->mask, set);
2163 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2164 SIG2OSIG(oset, td->td_retval[0]);
2169 ofreebsd32_sigsetmask(struct thread *td,
2170 struct ofreebsd32_sigsetmask_args *uap)
2174 OSIG2SIG(uap->mask, set);
2175 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2176 SIG2OSIG(oset, td->td_retval[0]);
2181 ofreebsd32_sigsuspend(struct thread *td,
2182 struct ofreebsd32_sigsuspend_args *uap)
2186 OSIG2SIG(uap->mask, mask);
2187 return (kern_sigsuspend(td, mask));
2196 ofreebsd32_sigstack(struct thread *td,
2197 struct ofreebsd32_sigstack_args *uap)
2199 struct sigstack32 s32;
2200 struct sigstack nss, oss;
2201 int error = 0, unss;
2203 if (uap->nss != NULL) {
2204 error = copyin(uap->nss, &s32, sizeof(s32));
2207 nss.ss_sp = PTRIN(s32.ss_sp);
2208 CP(s32, nss, ss_onstack);
2213 oss.ss_sp = td->td_sigstk.ss_sp;
2214 oss.ss_onstack = sigonstack(cpu_getstack(td));
2216 td->td_sigstk.ss_sp = nss.ss_sp;
2217 td->td_sigstk.ss_size = 0;
2218 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2219 td->td_pflags |= TDP_ALTSTACK;
2221 if (uap->oss != NULL) {
2222 s32.ss_sp = PTROUT(oss.ss_sp);
2223 CP(oss, s32, ss_onstack);
2224 error = copyout(&s32, uap->oss, sizeof(s32));
2231 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2233 struct timespec32 rmt32, rqt32;
2234 struct timespec rmt, rqt;
2237 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2241 CP(rqt32, rqt, tv_sec);
2242 CP(rqt32, rqt, tv_nsec);
2245 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2247 error = kern_nanosleep(td, &rqt, &rmt);
2248 if (error && uap->rmtp) {
2251 CP(rmt, rmt32, tv_sec);
2252 CP(rmt, rmt32, tv_nsec);
2254 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2262 freebsd32_clock_gettime(struct thread *td,
2263 struct freebsd32_clock_gettime_args *uap)
2265 struct timespec ats;
2266 struct timespec32 ats32;
2269 error = kern_clock_gettime(td, uap->clock_id, &ats);
2271 CP(ats, ats32, tv_sec);
2272 CP(ats, ats32, tv_nsec);
2273 error = copyout(&ats32, uap->tp, sizeof(ats32));
2279 freebsd32_clock_settime(struct thread *td,
2280 struct freebsd32_clock_settime_args *uap)
2282 struct timespec ats;
2283 struct timespec32 ats32;
2286 error = copyin(uap->tp, &ats32, sizeof(ats32));
2289 CP(ats32, ats, tv_sec);
2290 CP(ats32, ats, tv_nsec);
2292 return (kern_clock_settime(td, uap->clock_id, &ats));
2296 freebsd32_clock_getres(struct thread *td,
2297 struct freebsd32_clock_getres_args *uap)
2300 struct timespec32 ts32;
2303 if (uap->tp == NULL)
2305 error = kern_clock_getres(td, uap->clock_id, &ts);
2307 CP(ts, ts32, tv_sec);
2308 CP(ts, ts32, tv_nsec);
2309 error = copyout(&ts32, uap->tp, sizeof(ts32));
2314 int freebsd32_ktimer_create(struct thread *td,
2315 struct freebsd32_ktimer_create_args *uap)
2317 struct sigevent32 ev32;
2318 struct sigevent ev, *evp;
2321 if (uap->evp == NULL) {
2325 error = copyin(uap->evp, &ev32, sizeof(ev32));
2328 error = convert_sigevent32(&ev32, &ev);
2332 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2334 error = copyout(&id, uap->timerid, sizeof(int));
2336 kern_ktimer_delete(td, id);
2342 freebsd32_ktimer_settime(struct thread *td,
2343 struct freebsd32_ktimer_settime_args *uap)
2345 struct itimerspec32 val32, oval32;
2346 struct itimerspec val, oval, *ovalp;
2349 error = copyin(uap->value, &val32, sizeof(val32));
2353 ovalp = uap->ovalue != NULL ? &oval : NULL;
2354 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2355 if (error == 0 && uap->ovalue != NULL) {
2356 ITS_CP(oval, oval32);
2357 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2363 freebsd32_ktimer_gettime(struct thread *td,
2364 struct freebsd32_ktimer_gettime_args *uap)
2366 struct itimerspec32 val32;
2367 struct itimerspec val;
2370 error = kern_ktimer_gettime(td, uap->timerid, &val);
2373 error = copyout(&val32, uap->value, sizeof(val32));
2379 freebsd32_clock_getcpuclockid2(struct thread *td,
2380 struct freebsd32_clock_getcpuclockid2_args *uap)
2385 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2386 uap->which, &clk_id);
2388 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2393 freebsd32_thr_new(struct thread *td,
2394 struct freebsd32_thr_new_args *uap)
2396 struct thr_param32 param32;
2397 struct thr_param param;
2400 if (uap->param_size < 0 ||
2401 uap->param_size > sizeof(struct thr_param32))
2403 bzero(¶m, sizeof(struct thr_param));
2404 bzero(¶m32, sizeof(struct thr_param32));
2405 error = copyin(uap->param, ¶m32, uap->param_size);
2408 param.start_func = PTRIN(param32.start_func);
2409 param.arg = PTRIN(param32.arg);
2410 param.stack_base = PTRIN(param32.stack_base);
2411 param.stack_size = param32.stack_size;
2412 param.tls_base = PTRIN(param32.tls_base);
2413 param.tls_size = param32.tls_size;
2414 param.child_tid = PTRIN(param32.child_tid);
2415 param.parent_tid = PTRIN(param32.parent_tid);
2416 param.flags = param32.flags;
2417 param.rtp = PTRIN(param32.rtp);
2418 param.spare[0] = PTRIN(param32.spare[0]);
2419 param.spare[1] = PTRIN(param32.spare[1]);
2420 param.spare[2] = PTRIN(param32.spare[2]);
2422 return (kern_thr_new(td, ¶m));
2426 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2428 struct timespec32 ts32;
2429 struct timespec ts, *tsp;
2434 if (uap->timeout != NULL) {
2435 error = copyin((const void *)uap->timeout, (void *)&ts32,
2436 sizeof(struct timespec32));
2439 ts.tv_sec = ts32.tv_sec;
2440 ts.tv_nsec = ts32.tv_nsec;
2443 return (kern_thr_suspend(td, tsp));
2447 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2449 bzero(dst, sizeof(*dst));
2450 dst->si_signo = src->si_signo;
2451 dst->si_errno = src->si_errno;
2452 dst->si_code = src->si_code;
2453 dst->si_pid = src->si_pid;
2454 dst->si_uid = src->si_uid;
2455 dst->si_status = src->si_status;
2456 dst->si_addr = (uintptr_t)src->si_addr;
2457 dst->si_value.sival_int = src->si_value.sival_int;
2458 dst->si_timerid = src->si_timerid;
2459 dst->si_overrun = src->si_overrun;
2463 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2465 struct timespec32 ts32;
2467 struct timespec *timeout;
2470 struct siginfo32 si32;
2474 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2477 ts.tv_sec = ts32.tv_sec;
2478 ts.tv_nsec = ts32.tv_nsec;
2483 error = copyin(uap->set, &set, sizeof(set));
2487 error = kern_sigtimedwait(td, set, &ksi, timeout);
2492 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2493 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2497 td->td_retval[0] = ksi.ksi_signo;
2505 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2508 struct siginfo32 si32;
2512 error = copyin(uap->set, &set, sizeof(set));
2516 error = kern_sigtimedwait(td, set, &ksi, NULL);
2521 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2522 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2525 td->td_retval[0] = ksi.ksi_signo;
2530 freebsd32_cpuset_setid(struct thread *td,
2531 struct freebsd32_cpuset_setid_args *uap)
2533 struct cpuset_setid_args ap;
2535 ap.which = uap->which;
2536 ap.id = PAIR32TO64(id_t,uap->id);
2537 ap.setid = uap->setid;
2539 return (sys_cpuset_setid(td, &ap));
2543 freebsd32_cpuset_getid(struct thread *td,
2544 struct freebsd32_cpuset_getid_args *uap)
2546 struct cpuset_getid_args ap;
2548 ap.level = uap->level;
2549 ap.which = uap->which;
2550 ap.id = PAIR32TO64(id_t,uap->id);
2551 ap.setid = uap->setid;
2553 return (sys_cpuset_getid(td, &ap));
2557 freebsd32_cpuset_getaffinity(struct thread *td,
2558 struct freebsd32_cpuset_getaffinity_args *uap)
2560 struct cpuset_getaffinity_args ap;
2562 ap.level = uap->level;
2563 ap.which = uap->which;
2564 ap.id = PAIR32TO64(id_t,uap->id);
2565 ap.cpusetsize = uap->cpusetsize;
2566 ap.mask = uap->mask;
2568 return (sys_cpuset_getaffinity(td, &ap));
2572 freebsd32_cpuset_setaffinity(struct thread *td,
2573 struct freebsd32_cpuset_setaffinity_args *uap)
2575 struct cpuset_setaffinity_args ap;
2577 ap.level = uap->level;
2578 ap.which = uap->which;
2579 ap.id = PAIR32TO64(id_t,uap->id);
2580 ap.cpusetsize = uap->cpusetsize;
2581 ap.mask = uap->mask;
2583 return (sys_cpuset_setaffinity(td, &ap));
2587 freebsd32_nmount(struct thread *td,
2588 struct freebsd32_nmount_args /* {
2590 unsigned int iovcnt;
2599 * Mount flags are now 64-bits. On 32-bit archtectures only
2600 * 32-bits are passed in, but from here on everything handles
2601 * 64-bit flags correctly.
2605 AUDIT_ARG_FFLAGS(flags);
2608 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2609 * userspace to set this flag, but we must filter it out if we want
2610 * MNT_UPDATE on the root file system to work.
2611 * MNT_ROOTFS should only be set by the kernel when mounting its
2614 flags &= ~MNT_ROOTFS;
2617 * check that we have an even number of iovec's
2618 * and that we have at least two options.
2620 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2623 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2626 error = vfs_donmount(td, flags, auio);
2634 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2636 struct yyy32 *p32, s32;
2637 struct yyy *p = NULL, s;
2642 error = copyin(uap->zzz, &s32, sizeof(s32));
2648 error = kern_xxx(td, p);
2653 error = copyout(&s32, p32, sizeof(s32));
2660 syscall32_register(int *offset, struct sysent *new_sysent,
2661 struct sysent *old_sysent, int flags)
2664 if ((flags & ~SY_THR_STATIC) != 0)
2667 if (*offset == NO_SYSCALL) {
2670 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2671 if (freebsd32_sysent[i].sy_call ==
2672 (sy_call_t *)lkmnosys)
2674 if (i == SYS_MAXSYSCALL)
2677 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2679 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2680 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2683 *old_sysent = freebsd32_sysent[*offset];
2684 freebsd32_sysent[*offset] = *new_sysent;
2685 atomic_store_rel_32(&freebsd32_sysent[*offset].sy_thrcnt, flags);
2690 syscall32_deregister(int *offset, struct sysent *old_sysent)
2696 freebsd32_sysent[*offset] = *old_sysent;
2701 syscall32_module_handler(struct module *mod, int what, void *arg)
2703 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2709 error = syscall32_register(data->offset, data->new_sysent,
2710 &data->old_sysent, SY_THR_STATIC_KLD);
2712 /* Leave a mark so we know to safely unload below. */
2713 data->offset = NULL;
2716 ms.intval = *data->offset;
2718 module_setspecific(mod, &ms);
2721 error = data->chainevh(mod, what, data->chainarg);
2725 * MOD_LOAD failed, so just return without calling the
2726 * chained handler since we didn't pass along the MOD_LOAD
2729 if (data->offset == NULL)
2731 if (data->chainevh) {
2732 error = data->chainevh(mod, what, data->chainarg);
2736 error = syscall32_deregister(data->offset, &data->old_sysent);
2741 error = data->chainevh(mod, what, data->chainarg);
2747 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
2749 struct syscall_helper_data *sd1;
2752 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2753 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2754 &sd1->old_sysent, flags);
2756 syscall32_helper_unregister(sd);
2759 sd1->registered = 1;
2765 syscall32_helper_unregister(struct syscall_helper_data *sd)
2767 struct syscall_helper_data *sd1;
2769 for (sd1 = sd; sd1->registered != 0; sd1++) {
2770 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2771 sd1->registered = 0;
2777 freebsd32_copyout_strings(struct image_params *imgp)
2783 u_int32_t *stack_base;
2784 struct freebsd32_ps_strings *arginfo;
2785 char canary[sizeof(long) * 8];
2786 int32_t pagesizes32[MAXPAGESIZES];
2787 size_t execpath_len;
2791 * Calculate string base and vector table pointers.
2792 * Also deal with signal trampoline code for this exec type.
2794 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2795 execpath_len = strlen(imgp->execpath) + 1;
2798 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2800 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2801 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2804 destp = (uintptr_t)arginfo;
2809 if (szsigcode != 0) {
2811 destp = rounddown2(destp, sizeof(uint32_t));
2812 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2817 * Copy the image path for the rtld.
2819 if (execpath_len != 0) {
2820 destp -= execpath_len;
2821 imgp->execpathp = destp;
2822 copyout(imgp->execpath, (void *)destp, execpath_len);
2826 * Prepare the canary for SSP.
2828 arc4rand(canary, sizeof(canary), 0);
2829 destp -= sizeof(canary);
2830 imgp->canary = destp;
2831 copyout(canary, (void *)destp, sizeof(canary));
2832 imgp->canarylen = sizeof(canary);
2835 * Prepare the pagesizes array.
2837 for (i = 0; i < MAXPAGESIZES; i++)
2838 pagesizes32[i] = (uint32_t)pagesizes[i];
2839 destp -= sizeof(pagesizes32);
2840 destp = rounddown2(destp, sizeof(uint32_t));
2841 imgp->pagesizes = destp;
2842 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2843 imgp->pagesizeslen = sizeof(pagesizes32);
2845 destp -= ARG_MAX - imgp->args->stringspace;
2846 destp = rounddown2(destp, sizeof(uint32_t));
2849 * If we have a valid auxargs ptr, prepare some room
2852 if (imgp->auxargs) {
2854 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2855 * lower compatibility.
2857 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2860 * The '+ 2' is for the null pointers at the end of each of
2861 * the arg and env vector sets,and imgp->auxarg_size is room
2862 * for argument of Runtime loader.
2864 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2865 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2869 * The '+ 2' is for the null pointers at the end of each of
2870 * the arg and env vector sets
2872 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2873 imgp->args->envc + 2) * sizeof(u_int32_t));
2877 * vectp also becomes our initial stack base
2881 stringp = imgp->args->begin_argv;
2882 argc = imgp->args->argc;
2883 envc = imgp->args->envc;
2885 * Copy out strings - arguments and environment.
2887 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2890 * Fill in "ps_strings" struct for ps, w, etc.
2892 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2893 suword32(&arginfo->ps_nargvstr, argc);
2896 * Fill in argument portion of vector table.
2898 for (; argc > 0; --argc) {
2899 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2900 while (*stringp++ != 0)
2905 /* a null vector table pointer separates the argp's from the envp's */
2906 suword32(vectp++, 0);
2908 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2909 suword32(&arginfo->ps_nenvstr, envc);
2912 * Fill in environment portion of vector table.
2914 for (; envc > 0; --envc) {
2915 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2916 while (*stringp++ != 0)
2921 /* end of vector table is a null pointer */
2924 return ((register_t *)stack_base);
2928 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2930 struct kld_file_stat stat;
2931 struct kld32_file_stat stat32;
2934 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2937 if (version != sizeof(struct kld32_file_stat_1) &&
2938 version != sizeof(struct kld32_file_stat))
2941 error = kern_kldstat(td, uap->fileid, &stat);
2945 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2946 CP(stat, stat32, refs);
2947 CP(stat, stat32, id);
2948 PTROUT_CP(stat, stat32, address);
2949 CP(stat, stat32, size);
2950 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2951 return (copyout(&stat32, uap->stat, version));
2955 freebsd32_posix_fallocate(struct thread *td,
2956 struct freebsd32_posix_fallocate_args *uap)
2959 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
2960 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
2965 freebsd32_posix_fadvise(struct thread *td,
2966 struct freebsd32_posix_fadvise_args *uap)
2969 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
2970 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
2976 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
2979 CP(*sig32, *sig, sigev_notify);
2980 switch (sig->sigev_notify) {
2983 case SIGEV_THREAD_ID:
2984 CP(*sig32, *sig, sigev_notify_thread_id);
2987 CP(*sig32, *sig, sigev_signo);
2988 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2991 CP(*sig32, *sig, sigev_notify_kqueue);
2992 CP(*sig32, *sig, sigev_notify_kevent_flags);
2993 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3002 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3006 struct procctl_reaper_status rs;
3007 struct procctl_reaper_pids rp;
3008 struct procctl_reaper_kill rk;
3011 struct procctl_reaper_pids32 rp;
3013 int error, error1, flags;
3017 case PROC_TRACE_CTL:
3018 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3023 case PROC_REAP_ACQUIRE:
3024 case PROC_REAP_RELEASE:
3025 if (uap->data != NULL)
3029 case PROC_REAP_STATUS:
3032 case PROC_REAP_GETPIDS:
3033 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3036 CP(x32.rp, x.rp, rp_count);
3037 PTRIN_CP(x32.rp, x.rp, rp_pids);
3040 case PROC_REAP_KILL:
3041 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3046 case PROC_TRACE_STATUS:
3052 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3055 case PROC_REAP_STATUS:
3057 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3059 case PROC_REAP_KILL:
3060 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3064 case PROC_TRACE_STATUS:
3066 error = copyout(&flags, uap->data, sizeof(flags));
3073 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3079 * Do unsigned conversion for arg when operation
3080 * interprets it as flags or pointer.
3082 case F_SETLK_REMOTE:
3091 tmp = (unsigned int)(uap->arg);
3097 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3101 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3103 struct timespec32 ts32;
3104 struct timespec ts, *tsp;
3108 if (uap->ts != NULL) {
3109 error = copyin(uap->ts, &ts32, sizeof(ts32));
3112 CP(ts32, ts, tv_sec);
3113 CP(ts32, ts, tv_nsec);
3117 if (uap->set != NULL) {
3118 error = copyin(uap->set, &set, sizeof(set));
3125 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));