2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include "opt_inet6.h"
34 #define __ELF_WORD_SIZE 32
36 #include <sys/param.h>
38 #include <sys/capsicum.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.h>
59 #include <sys/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
249 struct statfs *buf, *sp;
250 struct statfs32 stat32;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
258 count = td->td_retval[0];
260 while (count > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
274 freebsd32_sigaltstack(struct thread *td,
275 struct freebsd32_sigaltstack_args *uap)
277 struct sigaltstack32 s32;
278 struct sigaltstack ss, oss, *ssp;
281 if (uap->ss != NULL) {
282 error = copyin(uap->ss, &s32, sizeof(s32));
285 PTRIN_CP(s32, ss, ss_sp);
286 CP(s32, ss, ss_size);
287 CP(s32, ss, ss_flags);
291 error = kern_sigaltstack(td, ssp, &oss);
292 if (error == 0 && uap->oss != NULL) {
293 PTROUT_CP(oss, s32, ss_sp);
294 CP(oss, s32, ss_size);
295 CP(oss, s32, ss_flags);
296 error = copyout(&s32, uap->oss, sizeof(s32));
302 * Custom version of exec_copyin_args() so that we can translate
306 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
307 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
314 bzero(args, sizeof(*args));
319 * Allocate demand-paged memory for the file name, argument, and
320 * environment strings.
322 error = exec_alloc_args(args);
327 * Copy the file name.
330 args->fname = args->buf;
331 error = (segflg == UIO_SYSSPACE) ?
332 copystr(fname, args->fname, PATH_MAX, &length) :
333 copyinstr(fname, args->fname, PATH_MAX, &length);
339 args->begin_argv = args->buf + length;
340 args->endp = args->begin_argv;
341 args->stringspace = ARG_MAX;
344 * extract arguments first
348 error = copyin(p32++, &arg, sizeof(arg));
354 error = copyinstr(argp, args->endp, args->stringspace, &length);
356 if (error == ENAMETOOLONG)
360 args->stringspace -= length;
361 args->endp += length;
365 args->begin_envv = args->endp;
368 * extract environment strings
373 error = copyin(p32++, &arg, sizeof(arg));
379 error = copyinstr(envp, args->endp, args->stringspace,
382 if (error == ENAMETOOLONG)
386 args->stringspace -= length;
387 args->endp += length;
395 exec_free_args(args);
400 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
402 struct image_args eargs;
405 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
406 uap->argv, uap->envv);
408 error = kern_execve(td, &eargs, NULL);
413 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
415 struct image_args eargs;
418 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
419 uap->argv, uap->envv);
422 error = kern_execve(td, &eargs, NULL);
428 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
430 struct mprotect_args ap;
432 ap.addr = PTRIN(uap->addr);
435 #if defined(__amd64__)
436 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
437 ap.prot |= PROT_EXEC;
439 return (sys_mprotect(td, &ap));
443 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
446 vm_offset_t addr = (vm_offset_t) uap->addr;
447 vm_size_t len = uap->len;
448 int prot = uap->prot;
449 int flags = uap->flags;
451 off_t pos = PAIR32TO64(off_t,uap->pos);
453 #if defined(__amd64__)
454 if (i386_read_exec && (prot & PROT_READ))
458 ap.addr = (void *) addr;
465 return (sys_mmap(td, &ap));
468 #ifdef COMPAT_FREEBSD6
470 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
472 struct freebsd32_mmap_args ap;
477 ap.flags = uap->flags;
482 return (freebsd32_mmap(td, &ap));
487 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
489 struct itimerval itv, oitv, *itvp;
490 struct itimerval32 i32;
493 if (uap->itv != NULL) {
494 error = copyin(uap->itv, &i32, sizeof(i32));
497 TV_CP(i32, itv, it_interval);
498 TV_CP(i32, itv, it_value);
502 error = kern_setitimer(td, uap->which, itvp, &oitv);
503 if (error || uap->oitv == NULL)
505 TV_CP(oitv, i32, it_interval);
506 TV_CP(oitv, i32, it_value);
507 return (copyout(&i32, uap->oitv, sizeof(i32)));
511 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
513 struct itimerval itv;
514 struct itimerval32 i32;
517 error = kern_getitimer(td, uap->which, &itv);
518 if (error || uap->itv == NULL)
520 TV_CP(itv, i32, it_interval);
521 TV_CP(itv, i32, it_value);
522 return (copyout(&i32, uap->itv, sizeof(i32)));
526 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
528 struct timeval32 tv32;
529 struct timeval tv, *tvp;
532 if (uap->tv != NULL) {
533 error = copyin(uap->tv, &tv32, sizeof(tv32));
536 CP(tv32, tv, tv_sec);
537 CP(tv32, tv, tv_usec);
542 * XXX Do pointers need PTRIN()?
544 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
545 sizeof(int32_t) * 8));
549 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
551 struct timespec32 ts32;
553 struct timeval tv, *tvp;
557 if (uap->ts != NULL) {
558 error = copyin(uap->ts, &ts32, sizeof(ts32));
561 CP(ts32, ts, tv_sec);
562 CP(ts32, ts, tv_nsec);
563 TIMESPEC_TO_TIMEVAL(&tv, &ts);
567 if (uap->sm != NULL) {
568 error = copyin(uap->sm, &set, sizeof(set));
575 * XXX Do pointers need PTRIN()?
577 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
578 uset, sizeof(int32_t) * 8);
583 * Copy 'count' items into the destination list pointed to by uap->eventlist.
586 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
588 struct freebsd32_kevent_args *uap;
589 struct kevent32 ks32[KQ_NEVENTS];
592 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
593 uap = (struct freebsd32_kevent_args *)arg;
595 for (i = 0; i < count; i++) {
596 CP(kevp[i], ks32[i], ident);
597 CP(kevp[i], ks32[i], filter);
598 CP(kevp[i], ks32[i], flags);
599 CP(kevp[i], ks32[i], fflags);
600 CP(kevp[i], ks32[i], data);
601 PTROUT_CP(kevp[i], ks32[i], udata);
603 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
605 uap->eventlist += count;
610 * Copy 'count' items from the list pointed to by uap->changelist.
613 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
615 struct freebsd32_kevent_args *uap;
616 struct kevent32 ks32[KQ_NEVENTS];
619 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
620 uap = (struct freebsd32_kevent_args *)arg;
622 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
625 uap->changelist += count;
627 for (i = 0; i < count; i++) {
628 CP(ks32[i], kevp[i], ident);
629 CP(ks32[i], kevp[i], filter);
630 CP(ks32[i], kevp[i], flags);
631 CP(ks32[i], kevp[i], fflags);
632 CP(ks32[i], kevp[i], data);
633 PTRIN_CP(ks32[i], kevp[i], udata);
640 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
642 struct timespec32 ts32;
643 struct timespec ts, *tsp;
644 struct kevent_copyops k_ops = { uap,
645 freebsd32_kevent_copyout,
646 freebsd32_kevent_copyin};
651 error = copyin(uap->timeout, &ts32, sizeof(ts32));
654 CP(ts32, ts, tv_sec);
655 CP(ts32, ts, tv_nsec);
659 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
665 freebsd32_gettimeofday(struct thread *td,
666 struct freebsd32_gettimeofday_args *uap)
669 struct timeval32 atv32;
675 CP(atv, atv32, tv_sec);
676 CP(atv, atv32, tv_usec);
677 error = copyout(&atv32, uap->tp, sizeof (atv32));
679 if (error == 0 && uap->tzp != NULL) {
680 rtz.tz_minuteswest = tz_minuteswest;
681 rtz.tz_dsttime = tz_dsttime;
682 error = copyout(&rtz, uap->tzp, sizeof (rtz));
688 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
694 error = kern_getrusage(td, uap->who, &s);
697 if (uap->rusage != NULL) {
698 freebsd32_rusage_out(&s, &s32);
699 error = copyout(&s32, uap->rusage, sizeof(s32));
705 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
707 struct iovec32 iov32;
714 if (iovcnt > UIO_MAXIOV)
716 iovlen = iovcnt * sizeof(struct iovec);
717 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
718 iov = (struct iovec *)(uio + 1);
719 for (i = 0; i < iovcnt; i++) {
720 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
725 iov[i].iov_base = PTRIN(iov32.iov_base);
726 iov[i].iov_len = iov32.iov_len;
729 uio->uio_iovcnt = iovcnt;
730 uio->uio_segflg = UIO_USERSPACE;
731 uio->uio_offset = -1;
733 for (i = 0; i < iovcnt; i++) {
734 if (iov->iov_len > INT_MAX - uio->uio_resid) {
738 uio->uio_resid += iov->iov_len;
746 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
751 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
754 error = kern_readv(td, uap->fd, auio);
760 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
765 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
768 error = kern_writev(td, uap->fd, auio);
774 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
779 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
782 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
788 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
793 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
796 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
802 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
805 struct iovec32 iov32;
811 if (iovcnt > UIO_MAXIOV)
813 iovlen = iovcnt * sizeof(struct iovec);
814 iov = malloc(iovlen, M_IOV, M_WAITOK);
815 for (i = 0; i < iovcnt; i++) {
816 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
821 iov[i].iov_base = PTRIN(iov32.iov_base);
822 iov[i].iov_len = iov32.iov_len;
829 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
834 error = copyin(msg32, &m32, sizeof(m32));
837 msg->msg_name = PTRIN(m32.msg_name);
838 msg->msg_namelen = m32.msg_namelen;
839 msg->msg_iov = PTRIN(m32.msg_iov);
840 msg->msg_iovlen = m32.msg_iovlen;
841 msg->msg_control = PTRIN(m32.msg_control);
842 msg->msg_controllen = m32.msg_controllen;
843 msg->msg_flags = m32.msg_flags;
848 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
853 m32.msg_name = PTROUT(msg->msg_name);
854 m32.msg_namelen = msg->msg_namelen;
855 m32.msg_iov = PTROUT(msg->msg_iov);
856 m32.msg_iovlen = msg->msg_iovlen;
857 m32.msg_control = PTROUT(msg->msg_control);
858 m32.msg_controllen = msg->msg_controllen;
859 m32.msg_flags = msg->msg_flags;
860 error = copyout(&m32, msg32, sizeof(m32));
865 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
867 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
869 #define FREEBSD32_ALIGN(p) \
870 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
871 #define FREEBSD32_CMSG_SPACE(l) \
872 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
874 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
875 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
877 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
881 socklen_t clen, datalen;
884 int len, maxlen, copylen;
888 len = msg->msg_controllen;
889 maxlen = msg->msg_controllen;
890 msg->msg_controllen = 0;
893 ctlbuf = msg->msg_control;
895 while (m && len > 0) {
896 cm = mtod(m, struct cmsghdr *);
901 if (sizeof(struct cmsghdr) > clen ||
902 cm->cmsg_len > clen) {
907 data = CMSG_DATA(cm);
908 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
910 /* Adjust message length */
911 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
916 copylen = sizeof(struct cmsghdr);
918 msg->msg_flags |= MSG_CTRUNC;
922 error = copyout(cm,ctlbuf,copylen);
926 ctlbuf += FREEBSD32_ALIGN(copylen);
927 len -= FREEBSD32_ALIGN(copylen);
935 msg->msg_flags |= MSG_CTRUNC;
939 error = copyout(data,ctlbuf,copylen);
943 ctlbuf += FREEBSD32_ALIGN(copylen);
944 len -= FREEBSD32_ALIGN(copylen);
946 if (CMSG_SPACE(datalen) < clen) {
947 clen -= CMSG_SPACE(datalen);
948 cm = (struct cmsghdr *)
949 ((caddr_t)cm + CMSG_SPACE(datalen));
958 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
966 freebsd32_recvmsg(td, uap)
968 struct freebsd32_recvmsg_args /* {
970 struct msghdr32 *msg;
976 struct iovec *uiov, *iov;
977 struct mbuf *control = NULL;
978 struct mbuf **controlp;
981 error = copyin(uap->msg, &m32, sizeof(m32));
984 error = freebsd32_copyinmsghdr(uap->msg, &msg);
987 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
991 msg.msg_flags = uap->flags;
995 controlp = (msg.msg_control != NULL) ? &control : NULL;
996 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1000 if (control != NULL)
1001 error = freebsd32_copy_msg_out(&msg, control);
1003 msg.msg_controllen = 0;
1006 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1010 if (control != NULL)
1017 * Copy-in the array of control messages constructed using alignment
1018 * and padding suitable for a 32-bit environment and construct an
1019 * mbuf using alignment and padding suitable for a 64-bit kernel.
1020 * The alignment and padding are defined indirectly by CMSG_DATA(),
1021 * CMSG_SPACE() and CMSG_LEN().
1024 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1028 u_int idx, len, msglen;
1031 buflen = FREEBSD32_ALIGN(buflen);
1033 if (buflen > MCLBYTES)
1037 * Iterate over the buffer and get the length of each message
1038 * in there. This has 32-bit alignment and padding. Use it to
1039 * determine the length of these messages when using 64-bit
1040 * alignment and padding.
1044 while (idx < buflen) {
1045 error = copyin(buf + idx, &msglen, sizeof(msglen));
1048 if (msglen < sizeof(struct cmsghdr))
1050 msglen = FREEBSD32_ALIGN(msglen);
1051 if (idx + msglen > buflen)
1054 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1055 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1056 len += CMSG_ALIGN(msglen);
1062 m = m_get(M_WAITOK, MT_CONTROL);
1064 MCLGET(m, M_WAITOK);
1067 md = mtod(m, void *);
1068 while (buflen > 0) {
1069 error = copyin(buf, md, sizeof(struct cmsghdr));
1072 msglen = *(u_int *)md;
1073 msglen = FREEBSD32_ALIGN(msglen);
1075 /* Modify the message length to account for alignment. */
1076 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1077 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1079 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1080 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1081 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1083 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1085 error = copyin(buf, md, msglen);
1088 md = (char *)md + CMSG_ALIGN(msglen);
1102 freebsd32_sendmsg(struct thread *td,
1103 struct freebsd32_sendmsg_args *uap)
1106 struct msghdr32 m32;
1108 struct mbuf *control = NULL;
1109 struct sockaddr *to = NULL;
1112 error = copyin(uap->msg, &m32, sizeof(m32));
1115 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1118 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1123 if (msg.msg_name != NULL) {
1124 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1132 if (msg.msg_control) {
1133 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1138 error = freebsd32_copyin_control(&control, msg.msg_control,
1139 msg.msg_controllen);
1143 msg.msg_control = NULL;
1144 msg.msg_controllen = 0;
1147 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1158 freebsd32_recvfrom(struct thread *td,
1159 struct freebsd32_recvfrom_args *uap)
1165 if (uap->fromlenaddr) {
1166 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1167 sizeof(msg.msg_namelen));
1171 msg.msg_namelen = 0;
1174 msg.msg_name = PTRIN(uap->from);
1175 msg.msg_iov = &aiov;
1177 aiov.iov_base = PTRIN(uap->buf);
1178 aiov.iov_len = uap->len;
1179 msg.msg_control = NULL;
1180 msg.msg_flags = uap->flags;
1181 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1182 if (error == 0 && uap->fromlenaddr)
1183 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1184 sizeof (msg.msg_namelen));
1189 freebsd32_settimeofday(struct thread *td,
1190 struct freebsd32_settimeofday_args *uap)
1192 struct timeval32 tv32;
1193 struct timeval tv, *tvp;
1194 struct timezone tz, *tzp;
1198 error = copyin(uap->tv, &tv32, sizeof(tv32));
1201 CP(tv32, tv, tv_sec);
1202 CP(tv32, tv, tv_usec);
1207 error = copyin(uap->tzp, &tz, sizeof(tz));
1213 return (kern_settimeofday(td, tvp, tzp));
1217 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1219 struct timeval32 s32[2];
1220 struct timeval s[2], *sp;
1223 if (uap->tptr != NULL) {
1224 error = copyin(uap->tptr, s32, sizeof(s32));
1227 CP(s32[0], s[0], tv_sec);
1228 CP(s32[0], s[0], tv_usec);
1229 CP(s32[1], s[1], tv_sec);
1230 CP(s32[1], s[1], tv_usec);
1234 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1239 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1241 struct timeval32 s32[2];
1242 struct timeval s[2], *sp;
1245 if (uap->tptr != NULL) {
1246 error = copyin(uap->tptr, s32, sizeof(s32));
1249 CP(s32[0], s[0], tv_sec);
1250 CP(s32[0], s[0], tv_usec);
1251 CP(s32[1], s[1], tv_sec);
1252 CP(s32[1], s[1], tv_usec);
1256 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1260 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1262 struct timeval32 s32[2];
1263 struct timeval s[2], *sp;
1266 if (uap->tptr != NULL) {
1267 error = copyin(uap->tptr, s32, sizeof(s32));
1270 CP(s32[0], s[0], tv_sec);
1271 CP(s32[0], s[0], tv_usec);
1272 CP(s32[1], s[1], tv_sec);
1273 CP(s32[1], s[1], tv_usec);
1277 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1281 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1283 struct timeval32 s32[2];
1284 struct timeval s[2], *sp;
1287 if (uap->times != NULL) {
1288 error = copyin(uap->times, s32, sizeof(s32));
1291 CP(s32[0], s[0], tv_sec);
1292 CP(s32[0], s[0], tv_usec);
1293 CP(s32[1], s[1], tv_sec);
1294 CP(s32[1], s[1], tv_usec);
1298 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1303 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1305 struct timeval32 tv32;
1306 struct timeval delta, olddelta, *deltap;
1310 error = copyin(uap->delta, &tv32, sizeof(tv32));
1313 CP(tv32, delta, tv_sec);
1314 CP(tv32, delta, tv_usec);
1318 error = kern_adjtime(td, deltap, &olddelta);
1319 if (uap->olddelta && error == 0) {
1320 CP(olddelta, tv32, tv_sec);
1321 CP(olddelta, tv32, tv_usec);
1322 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1327 #ifdef COMPAT_FREEBSD4
1329 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1331 struct statfs32 s32;
1335 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1338 copy_statfs(&s, &s32);
1339 return (copyout(&s32, uap->buf, sizeof(s32)));
1343 #ifdef COMPAT_FREEBSD4
1345 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1347 struct statfs32 s32;
1351 error = kern_fstatfs(td, uap->fd, &s);
1354 copy_statfs(&s, &s32);
1355 return (copyout(&s32, uap->buf, sizeof(s32)));
1359 #ifdef COMPAT_FREEBSD4
1361 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1363 struct statfs32 s32;
1368 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1370 error = kern_fhstatfs(td, fh, &s);
1373 copy_statfs(&s, &s32);
1374 return (copyout(&s32, uap->buf, sizeof(s32)));
1379 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1381 struct pread_args ap;
1385 ap.nbyte = uap->nbyte;
1386 ap.offset = PAIR32TO64(off_t,uap->offset);
1387 return (sys_pread(td, &ap));
1391 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1393 struct pwrite_args ap;
1397 ap.nbyte = uap->nbyte;
1398 ap.offset = PAIR32TO64(off_t,uap->offset);
1399 return (sys_pwrite(td, &ap));
1404 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1406 struct lseek_args nuap;
1409 nuap.offset = uap->offset;
1410 nuap.whence = uap->whence;
1411 return (sys_lseek(td, &nuap));
1416 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1419 struct lseek_args ap;
1423 ap.offset = PAIR32TO64(off_t,uap->offset);
1424 ap.whence = uap->whence;
1425 error = sys_lseek(td, &ap);
1426 /* Expand the quad return into two parts for eax and edx */
1427 pos = td->td_uretoff.tdu_off;
1428 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1429 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1434 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1436 struct truncate_args ap;
1438 ap.path = uap->path;
1439 ap.length = PAIR32TO64(off_t,uap->length);
1440 return (sys_truncate(td, &ap));
1444 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1446 struct ftruncate_args ap;
1449 ap.length = PAIR32TO64(off_t,uap->length);
1450 return (sys_ftruncate(td, &ap));
1455 ofreebsd32_getdirentries(struct thread *td,
1456 struct ofreebsd32_getdirentries_args *uap)
1458 struct ogetdirentries_args ap;
1465 ap.count = uap->count;
1467 error = kern_ogetdirentries(td, &ap, &loff);
1470 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1477 freebsd32_getdirentries(struct thread *td,
1478 struct freebsd32_getdirentries_args *uap)
1484 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1485 NULL, UIO_USERSPACE);
1488 if (uap->basep != NULL) {
1490 error = copyout(&base32, uap->basep, sizeof(int32_t));
1495 #ifdef COMPAT_FREEBSD6
1496 /* versions with the 'int pad' argument */
1498 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1500 struct pread_args ap;
1504 ap.nbyte = uap->nbyte;
1505 ap.offset = PAIR32TO64(off_t,uap->offset);
1506 return (sys_pread(td, &ap));
1510 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1512 struct pwrite_args ap;
1516 ap.nbyte = uap->nbyte;
1517 ap.offset = PAIR32TO64(off_t,uap->offset);
1518 return (sys_pwrite(td, &ap));
1522 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1525 struct lseek_args ap;
1529 ap.offset = PAIR32TO64(off_t,uap->offset);
1530 ap.whence = uap->whence;
1531 error = sys_lseek(td, &ap);
1532 /* Expand the quad return into two parts for eax and edx */
1533 pos = *(off_t *)(td->td_retval);
1534 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1535 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1540 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1542 struct truncate_args ap;
1544 ap.path = uap->path;
1545 ap.length = PAIR32TO64(off_t,uap->length);
1546 return (sys_truncate(td, &ap));
1550 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1552 struct ftruncate_args ap;
1555 ap.length = PAIR32TO64(off_t,uap->length);
1556 return (sys_ftruncate(td, &ap));
1558 #endif /* COMPAT_FREEBSD6 */
1568 freebsd32_do_sendfile(struct thread *td,
1569 struct freebsd32_sendfile_args *uap, int compat)
1571 struct sf_hdtr32 hdtr32;
1572 struct sf_hdtr hdtr;
1573 struct uio *hdr_uio, *trl_uio;
1575 cap_rights_t rights;
1576 struct iovec32 *iov32;
1577 off_t offset, sbytes;
1580 offset = PAIR32TO64(off_t, uap->offset);
1584 hdr_uio = trl_uio = NULL;
1586 if (uap->hdtr != NULL) {
1587 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1590 PTRIN_CP(hdtr32, hdtr, headers);
1591 CP(hdtr32, hdtr, hdr_cnt);
1592 PTRIN_CP(hdtr32, hdtr, trailers);
1593 CP(hdtr32, hdtr, trl_cnt);
1595 if (hdtr.headers != NULL) {
1596 iov32 = PTRIN(hdtr32.headers);
1597 error = freebsd32_copyinuio(iov32,
1598 hdtr32.hdr_cnt, &hdr_uio);
1602 if (hdtr.trailers != NULL) {
1603 iov32 = PTRIN(hdtr32.trailers);
1604 error = freebsd32_copyinuio(iov32,
1605 hdtr32.trl_cnt, &trl_uio);
1611 AUDIT_ARG_FD(uap->fd);
1613 if ((error = fget_read(td, uap->fd,
1614 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
1617 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1618 uap->nbytes, &sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1621 if (uap->sbytes != NULL)
1622 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1626 free(hdr_uio, M_IOV);
1628 free(trl_uio, M_IOV);
1632 #ifdef COMPAT_FREEBSD4
1634 freebsd4_freebsd32_sendfile(struct thread *td,
1635 struct freebsd4_freebsd32_sendfile_args *uap)
1637 return (freebsd32_do_sendfile(td,
1638 (struct freebsd32_sendfile_args *)uap, 1));
1643 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1646 return (freebsd32_do_sendfile(td, uap, 0));
1650 copy_stat(struct stat *in, struct stat32 *out)
1653 CP(*in, *out, st_dev);
1654 CP(*in, *out, st_ino);
1655 CP(*in, *out, st_mode);
1656 CP(*in, *out, st_nlink);
1657 CP(*in, *out, st_uid);
1658 CP(*in, *out, st_gid);
1659 CP(*in, *out, st_rdev);
1660 TS_CP(*in, *out, st_atim);
1661 TS_CP(*in, *out, st_mtim);
1662 TS_CP(*in, *out, st_ctim);
1663 CP(*in, *out, st_size);
1664 CP(*in, *out, st_blocks);
1665 CP(*in, *out, st_blksize);
1666 CP(*in, *out, st_flags);
1667 CP(*in, *out, st_gen);
1668 TS_CP(*in, *out, st_birthtim);
1673 copy_ostat(struct stat *in, struct ostat32 *out)
1676 CP(*in, *out, st_dev);
1677 CP(*in, *out, st_ino);
1678 CP(*in, *out, st_mode);
1679 CP(*in, *out, st_nlink);
1680 CP(*in, *out, st_uid);
1681 CP(*in, *out, st_gid);
1682 CP(*in, *out, st_rdev);
1683 CP(*in, *out, st_size);
1684 TS_CP(*in, *out, st_atim);
1685 TS_CP(*in, *out, st_mtim);
1686 TS_CP(*in, *out, st_ctim);
1687 CP(*in, *out, st_blksize);
1688 CP(*in, *out, st_blocks);
1689 CP(*in, *out, st_flags);
1690 CP(*in, *out, st_gen);
1695 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1701 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1705 copy_stat(&sb, &sb32);
1706 error = copyout(&sb32, uap->ub, sizeof (sb32));
1712 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1715 struct ostat32 sb32;
1718 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1722 copy_ostat(&sb, &sb32);
1723 error = copyout(&sb32, uap->ub, sizeof (sb32));
1729 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1735 error = kern_fstat(td, uap->fd, &ub);
1738 copy_stat(&ub, &ub32);
1739 error = copyout(&ub32, uap->ub, sizeof(ub32));
1745 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1748 struct ostat32 ub32;
1751 error = kern_fstat(td, uap->fd, &ub);
1754 copy_ostat(&ub, &ub32);
1755 error = copyout(&ub32, uap->ub, sizeof(ub32));
1761 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1767 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1771 copy_stat(&ub, &ub32);
1772 error = copyout(&ub32, uap->buf, sizeof(ub32));
1777 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1783 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1784 UIO_USERSPACE, &sb, NULL);
1787 copy_stat(&sb, &sb32);
1788 error = copyout(&sb32, uap->ub, sizeof (sb32));
1794 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1797 struct ostat32 sb32;
1800 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1801 UIO_USERSPACE, &sb, NULL);
1804 copy_ostat(&sb, &sb32);
1805 error = copyout(&sb32, uap->ub, sizeof (sb32));
1811 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1813 int error, name[CTL_MAXNAME];
1817 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1819 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1823 error = fueword32(uap->oldlenp, &tmp);
1830 error = userland_sysctl(td, name, uap->namelen,
1831 uap->old, &oldlen, 1,
1832 uap->new, uap->newlen, &j, SCTL_MASK32);
1833 if (error && error != ENOMEM)
1836 suword32(uap->oldlenp, j);
1841 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1847 error = copyin(uap->jail, &version, sizeof(uint32_t));
1854 /* FreeBSD single IPv4 jails. */
1855 struct jail32_v0 j32_v0;
1857 bzero(&j, sizeof(struct jail));
1858 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1861 CP(j32_v0, j, version);
1862 PTRIN_CP(j32_v0, j, path);
1863 PTRIN_CP(j32_v0, j, hostname);
1864 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1870 * Version 1 was used by multi-IPv4 jail implementations
1871 * that never made it into the official kernel.
1875 case 2: /* JAIL_API_VERSION */
1877 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1880 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1883 CP(j32, j, version);
1884 PTRIN_CP(j32, j, path);
1885 PTRIN_CP(j32, j, hostname);
1886 PTRIN_CP(j32, j, jailname);
1889 PTRIN_CP(j32, j, ip4);
1890 PTRIN_CP(j32, j, ip6);
1895 /* Sci-Fi jails are not supported, sorry. */
1898 return (kern_jail(td, &j));
1902 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1907 /* Check that we have an even number of iovecs. */
1908 if (uap->iovcnt & 1)
1911 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1914 error = kern_jail_set(td, auio, uap->flags);
1920 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1922 struct iovec32 iov32;
1926 /* Check that we have an even number of iovecs. */
1927 if (uap->iovcnt & 1)
1930 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1933 error = kern_jail_get(td, auio, uap->flags);
1935 for (i = 0; i < uap->iovcnt; i++) {
1936 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1937 CP(auio->uio_iov[i], iov32, iov_len);
1938 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
1947 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
1949 struct sigaction32 s32;
1950 struct sigaction sa, osa, *sap;
1954 error = copyin(uap->act, &s32, sizeof(s32));
1957 sa.sa_handler = PTRIN(s32.sa_u);
1958 CP(s32, sa, sa_flags);
1959 CP(s32, sa, sa_mask);
1963 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
1964 if (error == 0 && uap->oact != NULL) {
1965 s32.sa_u = PTROUT(osa.sa_handler);
1966 CP(osa, s32, sa_flags);
1967 CP(osa, s32, sa_mask);
1968 error = copyout(&s32, uap->oact, sizeof(s32));
1973 #ifdef COMPAT_FREEBSD4
1975 freebsd4_freebsd32_sigaction(struct thread *td,
1976 struct freebsd4_freebsd32_sigaction_args *uap)
1978 struct sigaction32 s32;
1979 struct sigaction sa, osa, *sap;
1983 error = copyin(uap->act, &s32, sizeof(s32));
1986 sa.sa_handler = PTRIN(s32.sa_u);
1987 CP(s32, sa, sa_flags);
1988 CP(s32, sa, sa_mask);
1992 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
1993 if (error == 0 && uap->oact != NULL) {
1994 s32.sa_u = PTROUT(osa.sa_handler);
1995 CP(osa, s32, sa_flags);
1996 CP(osa, s32, sa_mask);
1997 error = copyout(&s32, uap->oact, sizeof(s32));
2004 struct osigaction32 {
2013 ofreebsd32_sigaction(struct thread *td,
2014 struct ofreebsd32_sigaction_args *uap)
2016 struct osigaction32 s32;
2017 struct sigaction sa, osa, *sap;
2020 if (uap->signum <= 0 || uap->signum >= ONSIG)
2024 error = copyin(uap->nsa, &s32, sizeof(s32));
2027 sa.sa_handler = PTRIN(s32.sa_u);
2028 CP(s32, sa, sa_flags);
2029 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2033 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2034 if (error == 0 && uap->osa != NULL) {
2035 s32.sa_u = PTROUT(osa.sa_handler);
2036 CP(osa, s32, sa_flags);
2037 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2038 error = copyout(&s32, uap->osa, sizeof(s32));
2044 ofreebsd32_sigprocmask(struct thread *td,
2045 struct ofreebsd32_sigprocmask_args *uap)
2050 OSIG2SIG(uap->mask, set);
2051 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2052 SIG2OSIG(oset, td->td_retval[0]);
2057 ofreebsd32_sigpending(struct thread *td,
2058 struct ofreebsd32_sigpending_args *uap)
2060 struct proc *p = td->td_proc;
2064 siglist = p->p_siglist;
2065 SIGSETOR(siglist, td->td_siglist);
2067 SIG2OSIG(siglist, td->td_retval[0]);
2072 u_int32_t sv_handler;
2078 ofreebsd32_sigvec(struct thread *td,
2079 struct ofreebsd32_sigvec_args *uap)
2081 struct sigvec32 vec;
2082 struct sigaction sa, osa, *sap;
2085 if (uap->signum <= 0 || uap->signum >= ONSIG)
2089 error = copyin(uap->nsv, &vec, sizeof(vec));
2092 sa.sa_handler = PTRIN(vec.sv_handler);
2093 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2094 sa.sa_flags = vec.sv_flags;
2095 sa.sa_flags ^= SA_RESTART;
2099 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2100 if (error == 0 && uap->osv != NULL) {
2101 vec.sv_handler = PTROUT(osa.sa_handler);
2102 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2103 vec.sv_flags = osa.sa_flags;
2104 vec.sv_flags &= ~SA_NOCLDWAIT;
2105 vec.sv_flags ^= SA_RESTART;
2106 error = copyout(&vec, uap->osv, sizeof(vec));
2112 ofreebsd32_sigblock(struct thread *td,
2113 struct ofreebsd32_sigblock_args *uap)
2117 OSIG2SIG(uap->mask, set);
2118 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2119 SIG2OSIG(oset, td->td_retval[0]);
2124 ofreebsd32_sigsetmask(struct thread *td,
2125 struct ofreebsd32_sigsetmask_args *uap)
2129 OSIG2SIG(uap->mask, set);
2130 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2131 SIG2OSIG(oset, td->td_retval[0]);
2136 ofreebsd32_sigsuspend(struct thread *td,
2137 struct ofreebsd32_sigsuspend_args *uap)
2141 OSIG2SIG(uap->mask, mask);
2142 return (kern_sigsuspend(td, mask));
2151 ofreebsd32_sigstack(struct thread *td,
2152 struct ofreebsd32_sigstack_args *uap)
2154 struct sigstack32 s32;
2155 struct sigstack nss, oss;
2156 int error = 0, unss;
2158 if (uap->nss != NULL) {
2159 error = copyin(uap->nss, &s32, sizeof(s32));
2162 nss.ss_sp = PTRIN(s32.ss_sp);
2163 CP(s32, nss, ss_onstack);
2168 oss.ss_sp = td->td_sigstk.ss_sp;
2169 oss.ss_onstack = sigonstack(cpu_getstack(td));
2171 td->td_sigstk.ss_sp = nss.ss_sp;
2172 td->td_sigstk.ss_size = 0;
2173 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2174 td->td_pflags |= TDP_ALTSTACK;
2176 if (uap->oss != NULL) {
2177 s32.ss_sp = PTROUT(oss.ss_sp);
2178 CP(oss, s32, ss_onstack);
2179 error = copyout(&s32, uap->oss, sizeof(s32));
2186 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2188 struct timespec32 rmt32, rqt32;
2189 struct timespec rmt, rqt;
2192 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2196 CP(rqt32, rqt, tv_sec);
2197 CP(rqt32, rqt, tv_nsec);
2200 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2202 error = kern_nanosleep(td, &rqt, &rmt);
2203 if (error && uap->rmtp) {
2206 CP(rmt, rmt32, tv_sec);
2207 CP(rmt, rmt32, tv_nsec);
2209 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2217 freebsd32_clock_gettime(struct thread *td,
2218 struct freebsd32_clock_gettime_args *uap)
2220 struct timespec ats;
2221 struct timespec32 ats32;
2224 error = kern_clock_gettime(td, uap->clock_id, &ats);
2226 CP(ats, ats32, tv_sec);
2227 CP(ats, ats32, tv_nsec);
2228 error = copyout(&ats32, uap->tp, sizeof(ats32));
2234 freebsd32_clock_settime(struct thread *td,
2235 struct freebsd32_clock_settime_args *uap)
2237 struct timespec ats;
2238 struct timespec32 ats32;
2241 error = copyin(uap->tp, &ats32, sizeof(ats32));
2244 CP(ats32, ats, tv_sec);
2245 CP(ats32, ats, tv_nsec);
2247 return (kern_clock_settime(td, uap->clock_id, &ats));
2251 freebsd32_clock_getres(struct thread *td,
2252 struct freebsd32_clock_getres_args *uap)
2255 struct timespec32 ts32;
2258 if (uap->tp == NULL)
2260 error = kern_clock_getres(td, uap->clock_id, &ts);
2262 CP(ts, ts32, tv_sec);
2263 CP(ts, ts32, tv_nsec);
2264 error = copyout(&ts32, uap->tp, sizeof(ts32));
2269 int freebsd32_ktimer_create(struct thread *td,
2270 struct freebsd32_ktimer_create_args *uap)
2272 struct sigevent32 ev32;
2273 struct sigevent ev, *evp;
2276 if (uap->evp == NULL) {
2280 error = copyin(uap->evp, &ev32, sizeof(ev32));
2283 error = convert_sigevent32(&ev32, &ev);
2287 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2289 error = copyout(&id, uap->timerid, sizeof(int));
2291 kern_ktimer_delete(td, id);
2297 freebsd32_ktimer_settime(struct thread *td,
2298 struct freebsd32_ktimer_settime_args *uap)
2300 struct itimerspec32 val32, oval32;
2301 struct itimerspec val, oval, *ovalp;
2304 error = copyin(uap->value, &val32, sizeof(val32));
2308 ovalp = uap->ovalue != NULL ? &oval : NULL;
2309 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2310 if (error == 0 && uap->ovalue != NULL) {
2311 ITS_CP(oval, oval32);
2312 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2318 freebsd32_ktimer_gettime(struct thread *td,
2319 struct freebsd32_ktimer_gettime_args *uap)
2321 struct itimerspec32 val32;
2322 struct itimerspec val;
2325 error = kern_ktimer_gettime(td, uap->timerid, &val);
2328 error = copyout(&val32, uap->value, sizeof(val32));
2334 freebsd32_clock_getcpuclockid2(struct thread *td,
2335 struct freebsd32_clock_getcpuclockid2_args *uap)
2340 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2341 uap->which, &clk_id);
2343 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2348 freebsd32_thr_new(struct thread *td,
2349 struct freebsd32_thr_new_args *uap)
2351 struct thr_param32 param32;
2352 struct thr_param param;
2355 if (uap->param_size < 0 ||
2356 uap->param_size > sizeof(struct thr_param32))
2358 bzero(¶m, sizeof(struct thr_param));
2359 bzero(¶m32, sizeof(struct thr_param32));
2360 error = copyin(uap->param, ¶m32, uap->param_size);
2363 param.start_func = PTRIN(param32.start_func);
2364 param.arg = PTRIN(param32.arg);
2365 param.stack_base = PTRIN(param32.stack_base);
2366 param.stack_size = param32.stack_size;
2367 param.tls_base = PTRIN(param32.tls_base);
2368 param.tls_size = param32.tls_size;
2369 param.child_tid = PTRIN(param32.child_tid);
2370 param.parent_tid = PTRIN(param32.parent_tid);
2371 param.flags = param32.flags;
2372 param.rtp = PTRIN(param32.rtp);
2373 param.spare[0] = PTRIN(param32.spare[0]);
2374 param.spare[1] = PTRIN(param32.spare[1]);
2375 param.spare[2] = PTRIN(param32.spare[2]);
2377 return (kern_thr_new(td, ¶m));
2381 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2383 struct timespec32 ts32;
2384 struct timespec ts, *tsp;
2389 if (uap->timeout != NULL) {
2390 error = copyin((const void *)uap->timeout, (void *)&ts32,
2391 sizeof(struct timespec32));
2394 ts.tv_sec = ts32.tv_sec;
2395 ts.tv_nsec = ts32.tv_nsec;
2398 return (kern_thr_suspend(td, tsp));
2402 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2404 bzero(dst, sizeof(*dst));
2405 dst->si_signo = src->si_signo;
2406 dst->si_errno = src->si_errno;
2407 dst->si_code = src->si_code;
2408 dst->si_pid = src->si_pid;
2409 dst->si_uid = src->si_uid;
2410 dst->si_status = src->si_status;
2411 dst->si_addr = (uintptr_t)src->si_addr;
2412 dst->si_value.sival_int = src->si_value.sival_int;
2413 dst->si_timerid = src->si_timerid;
2414 dst->si_overrun = src->si_overrun;
2418 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2420 struct timespec32 ts32;
2422 struct timespec *timeout;
2425 struct siginfo32 si32;
2429 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2432 ts.tv_sec = ts32.tv_sec;
2433 ts.tv_nsec = ts32.tv_nsec;
2438 error = copyin(uap->set, &set, sizeof(set));
2442 error = kern_sigtimedwait(td, set, &ksi, timeout);
2447 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2448 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2452 td->td_retval[0] = ksi.ksi_signo;
2460 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2463 struct siginfo32 si32;
2467 error = copyin(uap->set, &set, sizeof(set));
2471 error = kern_sigtimedwait(td, set, &ksi, NULL);
2476 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2477 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2480 td->td_retval[0] = ksi.ksi_signo;
2485 freebsd32_cpuset_setid(struct thread *td,
2486 struct freebsd32_cpuset_setid_args *uap)
2488 struct cpuset_setid_args ap;
2490 ap.which = uap->which;
2491 ap.id = PAIR32TO64(id_t,uap->id);
2492 ap.setid = uap->setid;
2494 return (sys_cpuset_setid(td, &ap));
2498 freebsd32_cpuset_getid(struct thread *td,
2499 struct freebsd32_cpuset_getid_args *uap)
2501 struct cpuset_getid_args ap;
2503 ap.level = uap->level;
2504 ap.which = uap->which;
2505 ap.id = PAIR32TO64(id_t,uap->id);
2506 ap.setid = uap->setid;
2508 return (sys_cpuset_getid(td, &ap));
2512 freebsd32_cpuset_getaffinity(struct thread *td,
2513 struct freebsd32_cpuset_getaffinity_args *uap)
2515 struct cpuset_getaffinity_args ap;
2517 ap.level = uap->level;
2518 ap.which = uap->which;
2519 ap.id = PAIR32TO64(id_t,uap->id);
2520 ap.cpusetsize = uap->cpusetsize;
2521 ap.mask = uap->mask;
2523 return (sys_cpuset_getaffinity(td, &ap));
2527 freebsd32_cpuset_setaffinity(struct thread *td,
2528 struct freebsd32_cpuset_setaffinity_args *uap)
2530 struct cpuset_setaffinity_args ap;
2532 ap.level = uap->level;
2533 ap.which = uap->which;
2534 ap.id = PAIR32TO64(id_t,uap->id);
2535 ap.cpusetsize = uap->cpusetsize;
2536 ap.mask = uap->mask;
2538 return (sys_cpuset_setaffinity(td, &ap));
2542 freebsd32_nmount(struct thread *td,
2543 struct freebsd32_nmount_args /* {
2545 unsigned int iovcnt;
2554 * Mount flags are now 64-bits. On 32-bit archtectures only
2555 * 32-bits are passed in, but from here on everything handles
2556 * 64-bit flags correctly.
2560 AUDIT_ARG_FFLAGS(flags);
2563 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2564 * userspace to set this flag, but we must filter it out if we want
2565 * MNT_UPDATE on the root file system to work.
2566 * MNT_ROOTFS should only be set by the kernel when mounting its
2569 flags &= ~MNT_ROOTFS;
2572 * check that we have an even number of iovec's
2573 * and that we have at least two options.
2575 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2578 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2581 error = vfs_donmount(td, flags, auio);
2589 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2591 struct yyy32 *p32, s32;
2592 struct yyy *p = NULL, s;
2597 error = copyin(uap->zzz, &s32, sizeof(s32));
2603 error = kern_xxx(td, p);
2608 error = copyout(&s32, p32, sizeof(s32));
2615 syscall32_register(int *offset, struct sysent *new_sysent,
2616 struct sysent *old_sysent, int flags)
2619 if ((flags & ~SY_THR_STATIC) != 0)
2622 if (*offset == NO_SYSCALL) {
2625 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2626 if (freebsd32_sysent[i].sy_call ==
2627 (sy_call_t *)lkmnosys)
2629 if (i == SYS_MAXSYSCALL)
2632 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2634 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2635 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2638 *old_sysent = freebsd32_sysent[*offset];
2639 freebsd32_sysent[*offset] = *new_sysent;
2640 atomic_store_rel_32(&freebsd32_sysent[*offset].sy_thrcnt, flags);
2645 syscall32_deregister(int *offset, struct sysent *old_sysent)
2651 freebsd32_sysent[*offset] = *old_sysent;
2656 syscall32_module_handler(struct module *mod, int what, void *arg)
2658 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2664 error = syscall32_register(data->offset, data->new_sysent,
2665 &data->old_sysent, SY_THR_STATIC_KLD);
2667 /* Leave a mark so we know to safely unload below. */
2668 data->offset = NULL;
2671 ms.intval = *data->offset;
2673 module_setspecific(mod, &ms);
2676 error = data->chainevh(mod, what, data->chainarg);
2680 * MOD_LOAD failed, so just return without calling the
2681 * chained handler since we didn't pass along the MOD_LOAD
2684 if (data->offset == NULL)
2686 if (data->chainevh) {
2687 error = data->chainevh(mod, what, data->chainarg);
2691 error = syscall32_deregister(data->offset, &data->old_sysent);
2696 error = data->chainevh(mod, what, data->chainarg);
2702 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
2704 struct syscall_helper_data *sd1;
2707 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2708 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2709 &sd1->old_sysent, flags);
2711 syscall32_helper_unregister(sd);
2714 sd1->registered = 1;
2720 syscall32_helper_unregister(struct syscall_helper_data *sd)
2722 struct syscall_helper_data *sd1;
2724 for (sd1 = sd; sd1->registered != 0; sd1++) {
2725 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2726 sd1->registered = 0;
2732 freebsd32_copyout_strings(struct image_params *imgp)
2738 u_int32_t *stack_base;
2739 struct freebsd32_ps_strings *arginfo;
2740 char canary[sizeof(long) * 8];
2741 int32_t pagesizes32[MAXPAGESIZES];
2742 size_t execpath_len;
2746 * Calculate string base and vector table pointers.
2747 * Also deal with signal trampoline code for this exec type.
2749 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2750 execpath_len = strlen(imgp->execpath) + 1;
2753 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2755 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2756 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2759 destp = (uintptr_t)arginfo;
2764 if (szsigcode != 0) {
2766 destp = rounddown2(destp, sizeof(uint32_t));
2767 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2772 * Copy the image path for the rtld.
2774 if (execpath_len != 0) {
2775 destp -= execpath_len;
2776 imgp->execpathp = destp;
2777 copyout(imgp->execpath, (void *)destp, execpath_len);
2781 * Prepare the canary for SSP.
2783 arc4rand(canary, sizeof(canary), 0);
2784 destp -= sizeof(canary);
2785 imgp->canary = destp;
2786 copyout(canary, (void *)destp, sizeof(canary));
2787 imgp->canarylen = sizeof(canary);
2790 * Prepare the pagesizes array.
2792 for (i = 0; i < MAXPAGESIZES; i++)
2793 pagesizes32[i] = (uint32_t)pagesizes[i];
2794 destp -= sizeof(pagesizes32);
2795 destp = rounddown2(destp, sizeof(uint32_t));
2796 imgp->pagesizes = destp;
2797 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2798 imgp->pagesizeslen = sizeof(pagesizes32);
2800 destp -= ARG_MAX - imgp->args->stringspace;
2801 destp = rounddown2(destp, sizeof(uint32_t));
2804 * If we have a valid auxargs ptr, prepare some room
2807 if (imgp->auxargs) {
2809 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2810 * lower compatibility.
2812 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2815 * The '+ 2' is for the null pointers at the end of each of
2816 * the arg and env vector sets,and imgp->auxarg_size is room
2817 * for argument of Runtime loader.
2819 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2820 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2824 * The '+ 2' is for the null pointers at the end of each of
2825 * the arg and env vector sets
2827 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2828 imgp->args->envc + 2) * sizeof(u_int32_t));
2832 * vectp also becomes our initial stack base
2836 stringp = imgp->args->begin_argv;
2837 argc = imgp->args->argc;
2838 envc = imgp->args->envc;
2840 * Copy out strings - arguments and environment.
2842 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2845 * Fill in "ps_strings" struct for ps, w, etc.
2847 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2848 suword32(&arginfo->ps_nargvstr, argc);
2851 * Fill in argument portion of vector table.
2853 for (; argc > 0; --argc) {
2854 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2855 while (*stringp++ != 0)
2860 /* a null vector table pointer separates the argp's from the envp's */
2861 suword32(vectp++, 0);
2863 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2864 suword32(&arginfo->ps_nenvstr, envc);
2867 * Fill in environment portion of vector table.
2869 for (; envc > 0; --envc) {
2870 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2871 while (*stringp++ != 0)
2876 /* end of vector table is a null pointer */
2879 return ((register_t *)stack_base);
2883 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2885 struct kld_file_stat stat;
2886 struct kld32_file_stat stat32;
2889 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2892 if (version != sizeof(struct kld32_file_stat_1) &&
2893 version != sizeof(struct kld32_file_stat))
2896 error = kern_kldstat(td, uap->fileid, &stat);
2900 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2901 CP(stat, stat32, refs);
2902 CP(stat, stat32, id);
2903 PTROUT_CP(stat, stat32, address);
2904 CP(stat, stat32, size);
2905 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2906 return (copyout(&stat32, uap->stat, version));
2910 freebsd32_posix_fallocate(struct thread *td,
2911 struct freebsd32_posix_fallocate_args *uap)
2914 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
2915 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
2920 freebsd32_posix_fadvise(struct thread *td,
2921 struct freebsd32_posix_fadvise_args *uap)
2924 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
2925 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
2931 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
2934 CP(*sig32, *sig, sigev_notify);
2935 switch (sig->sigev_notify) {
2938 case SIGEV_THREAD_ID:
2939 CP(*sig32, *sig, sigev_notify_thread_id);
2942 CP(*sig32, *sig, sigev_signo);
2943 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2946 CP(*sig32, *sig, sigev_notify_kqueue);
2947 CP(*sig32, *sig, sigev_notify_kevent_flags);
2948 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2957 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
2961 struct procctl_reaper_status rs;
2962 struct procctl_reaper_pids rp;
2963 struct procctl_reaper_kill rk;
2966 struct procctl_reaper_pids32 rp;
2968 int error, error1, flags;
2972 case PROC_TRACE_CTL:
2973 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
2978 case PROC_REAP_ACQUIRE:
2979 case PROC_REAP_RELEASE:
2980 if (uap->data != NULL)
2984 case PROC_REAP_STATUS:
2987 case PROC_REAP_GETPIDS:
2988 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
2991 CP(x32.rp, x.rp, rp_count);
2992 PTRIN_CP(x32.rp, x.rp, rp_pids);
2995 case PROC_REAP_KILL:
2996 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3001 case PROC_TRACE_STATUS:
3007 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3010 case PROC_REAP_STATUS:
3012 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3014 case PROC_REAP_KILL:
3015 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3019 case PROC_TRACE_STATUS:
3021 error = copyout(&flags, uap->data, sizeof(flags));
3028 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3034 * Do unsigned conversion for arg when operation
3035 * interprets it as flags or pointer.
3037 case F_SETLK_REMOTE:
3046 tmp = (unsigned int)(uap->arg);
3052 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3056 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3058 struct timespec32 ts32;
3059 struct timespec ts, *tsp;
3063 if (uap->ts != NULL) {
3064 error = copyin(uap->ts, &ts32, sizeof(ts32));
3067 CP(ts32, ts, tv_sec);
3068 CP(ts32, ts, tv_nsec);
3072 if (uap->set != NULL) {
3073 error = copyin(uap->set, &set, sizeof(set));
3080 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));