2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include "opt_inet6.h"
34 #define __ELF_WORD_SIZE 32
36 #include <sys/param.h>
38 #include <sys/capsicum.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.h>
59 #include <sys/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td,
248 struct freebsd4_freebsd32_getfsstat_args *uap)
250 struct statfs *buf, *sp;
251 struct statfs32 stat32;
252 size_t count, size, copycount;
255 count = uap->bufsize / sizeof(struct statfs32);
256 size = count * sizeof(struct statfs);
257 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
261 while (copycount > 0 && error == 0) {
262 copy_statfs(sp, &stat32);
263 error = copyout(&stat32, uap->buf, sizeof(stat32));
271 td->td_retval[0] = count;
276 #ifdef COMPAT_FREEBSD10
278 freebsd10_freebsd32_pipe(struct thread *td,
279 struct freebsd10_freebsd32_pipe_args *uap) {
281 return (freebsd10_pipe(td, (struct freebsd10_pipe_args*)uap));
286 freebsd32_sigaltstack(struct thread *td,
287 struct freebsd32_sigaltstack_args *uap)
289 struct sigaltstack32 s32;
290 struct sigaltstack ss, oss, *ssp;
293 if (uap->ss != NULL) {
294 error = copyin(uap->ss, &s32, sizeof(s32));
297 PTRIN_CP(s32, ss, ss_sp);
298 CP(s32, ss, ss_size);
299 CP(s32, ss, ss_flags);
303 error = kern_sigaltstack(td, ssp, &oss);
304 if (error == 0 && uap->oss != NULL) {
305 PTROUT_CP(oss, s32, ss_sp);
306 CP(oss, s32, ss_size);
307 CP(oss, s32, ss_flags);
308 error = copyout(&s32, uap->oss, sizeof(s32));
314 * Custom version of exec_copyin_args() so that we can translate
318 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
319 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
326 bzero(args, sizeof(*args));
331 * Allocate demand-paged memory for the file name, argument, and
332 * environment strings.
334 error = exec_alloc_args(args);
339 * Copy the file name.
342 args->fname = args->buf;
343 error = (segflg == UIO_SYSSPACE) ?
344 copystr(fname, args->fname, PATH_MAX, &length) :
345 copyinstr(fname, args->fname, PATH_MAX, &length);
351 args->begin_argv = args->buf + length;
352 args->endp = args->begin_argv;
353 args->stringspace = ARG_MAX;
356 * extract arguments first
360 error = copyin(p32++, &arg, sizeof(arg));
366 error = copyinstr(argp, args->endp, args->stringspace, &length);
368 if (error == ENAMETOOLONG)
372 args->stringspace -= length;
373 args->endp += length;
377 args->begin_envv = args->endp;
380 * extract environment strings
385 error = copyin(p32++, &arg, sizeof(arg));
391 error = copyinstr(envp, args->endp, args->stringspace,
394 if (error == ENAMETOOLONG)
398 args->stringspace -= length;
399 args->endp += length;
407 exec_free_args(args);
412 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
414 struct image_args eargs;
415 struct vmspace *oldvmspace;
418 error = pre_execve(td, &oldvmspace);
421 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
422 uap->argv, uap->envv);
424 error = kern_execve(td, &eargs, NULL);
425 post_execve(td, error, oldvmspace);
430 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
432 struct image_args eargs;
433 struct vmspace *oldvmspace;
436 error = pre_execve(td, &oldvmspace);
439 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
440 uap->argv, uap->envv);
443 error = kern_execve(td, &eargs, NULL);
445 post_execve(td, error, oldvmspace);
450 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
452 struct mprotect_args ap;
454 ap.addr = PTRIN(uap->addr);
457 #if defined(__amd64__)
458 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
459 ap.prot |= PROT_EXEC;
461 return (sys_mprotect(td, &ap));
465 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
468 vm_offset_t addr = (vm_offset_t) uap->addr;
469 vm_size_t len = uap->len;
470 int prot = uap->prot;
471 int flags = uap->flags;
473 off_t pos = PAIR32TO64(off_t,uap->pos);
475 #if defined(__amd64__)
476 if (i386_read_exec && (prot & PROT_READ))
480 ap.addr = (void *) addr;
487 return (sys_mmap(td, &ap));
490 #ifdef COMPAT_FREEBSD6
492 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
494 struct freebsd32_mmap_args ap;
499 ap.flags = uap->flags;
504 return (freebsd32_mmap(td, &ap));
509 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
511 struct itimerval itv, oitv, *itvp;
512 struct itimerval32 i32;
515 if (uap->itv != NULL) {
516 error = copyin(uap->itv, &i32, sizeof(i32));
519 TV_CP(i32, itv, it_interval);
520 TV_CP(i32, itv, it_value);
524 error = kern_setitimer(td, uap->which, itvp, &oitv);
525 if (error || uap->oitv == NULL)
527 TV_CP(oitv, i32, it_interval);
528 TV_CP(oitv, i32, it_value);
529 return (copyout(&i32, uap->oitv, sizeof(i32)));
533 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
535 struct itimerval itv;
536 struct itimerval32 i32;
539 error = kern_getitimer(td, uap->which, &itv);
540 if (error || uap->itv == NULL)
542 TV_CP(itv, i32, it_interval);
543 TV_CP(itv, i32, it_value);
544 return (copyout(&i32, uap->itv, sizeof(i32)));
548 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
550 struct timeval32 tv32;
551 struct timeval tv, *tvp;
554 if (uap->tv != NULL) {
555 error = copyin(uap->tv, &tv32, sizeof(tv32));
558 CP(tv32, tv, tv_sec);
559 CP(tv32, tv, tv_usec);
564 * XXX Do pointers need PTRIN()?
566 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
567 sizeof(int32_t) * 8));
571 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
573 struct timespec32 ts32;
575 struct timeval tv, *tvp;
579 if (uap->ts != NULL) {
580 error = copyin(uap->ts, &ts32, sizeof(ts32));
583 CP(ts32, ts, tv_sec);
584 CP(ts32, ts, tv_nsec);
585 TIMESPEC_TO_TIMEVAL(&tv, &ts);
589 if (uap->sm != NULL) {
590 error = copyin(uap->sm, &set, sizeof(set));
597 * XXX Do pointers need PTRIN()?
599 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
600 uset, sizeof(int32_t) * 8);
605 * Copy 'count' items into the destination list pointed to by uap->eventlist.
608 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
610 struct freebsd32_kevent_args *uap;
611 struct kevent32 ks32[KQ_NEVENTS];
614 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
615 uap = (struct freebsd32_kevent_args *)arg;
617 for (i = 0; i < count; i++) {
618 CP(kevp[i], ks32[i], ident);
619 CP(kevp[i], ks32[i], filter);
620 CP(kevp[i], ks32[i], flags);
621 CP(kevp[i], ks32[i], fflags);
622 CP(kevp[i], ks32[i], data);
623 PTROUT_CP(kevp[i], ks32[i], udata);
625 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
627 uap->eventlist += count;
632 * Copy 'count' items from the list pointed to by uap->changelist.
635 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
637 struct freebsd32_kevent_args *uap;
638 struct kevent32 ks32[KQ_NEVENTS];
641 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
642 uap = (struct freebsd32_kevent_args *)arg;
644 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
647 uap->changelist += count;
649 for (i = 0; i < count; i++) {
650 CP(ks32[i], kevp[i], ident);
651 CP(ks32[i], kevp[i], filter);
652 CP(ks32[i], kevp[i], flags);
653 CP(ks32[i], kevp[i], fflags);
654 CP(ks32[i], kevp[i], data);
655 PTRIN_CP(ks32[i], kevp[i], udata);
662 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
664 struct timespec32 ts32;
665 struct timespec ts, *tsp;
666 struct kevent_copyops k_ops = { uap,
667 freebsd32_kevent_copyout,
668 freebsd32_kevent_copyin};
673 error = copyin(uap->timeout, &ts32, sizeof(ts32));
676 CP(ts32, ts, tv_sec);
677 CP(ts32, ts, tv_nsec);
681 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
687 freebsd32_gettimeofday(struct thread *td,
688 struct freebsd32_gettimeofday_args *uap)
691 struct timeval32 atv32;
697 CP(atv, atv32, tv_sec);
698 CP(atv, atv32, tv_usec);
699 error = copyout(&atv32, uap->tp, sizeof (atv32));
701 if (error == 0 && uap->tzp != NULL) {
702 rtz.tz_minuteswest = tz_minuteswest;
703 rtz.tz_dsttime = tz_dsttime;
704 error = copyout(&rtz, uap->tzp, sizeof (rtz));
710 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
716 error = kern_getrusage(td, uap->who, &s);
719 if (uap->rusage != NULL) {
720 freebsd32_rusage_out(&s, &s32);
721 error = copyout(&s32, uap->rusage, sizeof(s32));
727 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
729 struct iovec32 iov32;
736 if (iovcnt > UIO_MAXIOV)
738 iovlen = iovcnt * sizeof(struct iovec);
739 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
740 iov = (struct iovec *)(uio + 1);
741 for (i = 0; i < iovcnt; i++) {
742 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
747 iov[i].iov_base = PTRIN(iov32.iov_base);
748 iov[i].iov_len = iov32.iov_len;
751 uio->uio_iovcnt = iovcnt;
752 uio->uio_segflg = UIO_USERSPACE;
753 uio->uio_offset = -1;
755 for (i = 0; i < iovcnt; i++) {
756 if (iov->iov_len > INT_MAX - uio->uio_resid) {
760 uio->uio_resid += iov->iov_len;
768 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
773 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
776 error = kern_readv(td, uap->fd, auio);
782 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
787 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
790 error = kern_writev(td, uap->fd, auio);
796 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
801 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
804 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
810 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
815 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
818 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
824 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
827 struct iovec32 iov32;
833 if (iovcnt > UIO_MAXIOV)
835 iovlen = iovcnt * sizeof(struct iovec);
836 iov = malloc(iovlen, M_IOV, M_WAITOK);
837 for (i = 0; i < iovcnt; i++) {
838 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
843 iov[i].iov_base = PTRIN(iov32.iov_base);
844 iov[i].iov_len = iov32.iov_len;
851 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
856 error = copyin(msg32, &m32, sizeof(m32));
859 msg->msg_name = PTRIN(m32.msg_name);
860 msg->msg_namelen = m32.msg_namelen;
861 msg->msg_iov = PTRIN(m32.msg_iov);
862 msg->msg_iovlen = m32.msg_iovlen;
863 msg->msg_control = PTRIN(m32.msg_control);
864 msg->msg_controllen = m32.msg_controllen;
865 msg->msg_flags = m32.msg_flags;
870 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
875 m32.msg_name = PTROUT(msg->msg_name);
876 m32.msg_namelen = msg->msg_namelen;
877 m32.msg_iov = PTROUT(msg->msg_iov);
878 m32.msg_iovlen = msg->msg_iovlen;
879 m32.msg_control = PTROUT(msg->msg_control);
880 m32.msg_controllen = msg->msg_controllen;
881 m32.msg_flags = msg->msg_flags;
882 error = copyout(&m32, msg32, sizeof(m32));
887 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
889 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
891 #define FREEBSD32_ALIGN(p) \
892 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
893 #define FREEBSD32_CMSG_SPACE(l) \
894 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
896 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
897 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
899 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
903 socklen_t clen, datalen;
906 int len, maxlen, copylen;
910 len = msg->msg_controllen;
911 maxlen = msg->msg_controllen;
912 msg->msg_controllen = 0;
915 ctlbuf = msg->msg_control;
917 while (m && len > 0) {
918 cm = mtod(m, struct cmsghdr *);
923 if (sizeof(struct cmsghdr) > clen ||
924 cm->cmsg_len > clen) {
929 data = CMSG_DATA(cm);
930 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
932 /* Adjust message length */
933 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
938 copylen = sizeof(struct cmsghdr);
940 msg->msg_flags |= MSG_CTRUNC;
944 error = copyout(cm,ctlbuf,copylen);
948 ctlbuf += FREEBSD32_ALIGN(copylen);
949 len -= FREEBSD32_ALIGN(copylen);
957 msg->msg_flags |= MSG_CTRUNC;
961 error = copyout(data,ctlbuf,copylen);
965 ctlbuf += FREEBSD32_ALIGN(copylen);
966 len -= FREEBSD32_ALIGN(copylen);
968 if (CMSG_SPACE(datalen) < clen) {
969 clen -= CMSG_SPACE(datalen);
970 cm = (struct cmsghdr *)
971 ((caddr_t)cm + CMSG_SPACE(datalen));
980 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
988 freebsd32_recvmsg(td, uap)
990 struct freebsd32_recvmsg_args /* {
992 struct msghdr32 *msg;
998 struct iovec *uiov, *iov;
999 struct mbuf *control = NULL;
1000 struct mbuf **controlp;
1003 error = copyin(uap->msg, &m32, sizeof(m32));
1006 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1009 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1013 msg.msg_flags = uap->flags;
1017 controlp = (msg.msg_control != NULL) ? &control : NULL;
1018 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1022 if (control != NULL)
1023 error = freebsd32_copy_msg_out(&msg, control);
1025 msg.msg_controllen = 0;
1028 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1032 if (control != NULL)
1039 * Copy-in the array of control messages constructed using alignment
1040 * and padding suitable for a 32-bit environment and construct an
1041 * mbuf using alignment and padding suitable for a 64-bit kernel.
1042 * The alignment and padding are defined indirectly by CMSG_DATA(),
1043 * CMSG_SPACE() and CMSG_LEN().
1046 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1050 u_int idx, len, msglen;
1053 buflen = FREEBSD32_ALIGN(buflen);
1055 if (buflen > MCLBYTES)
1059 * Iterate over the buffer and get the length of each message
1060 * in there. This has 32-bit alignment and padding. Use it to
1061 * determine the length of these messages when using 64-bit
1062 * alignment and padding.
1066 while (idx < buflen) {
1067 error = copyin(buf + idx, &msglen, sizeof(msglen));
1070 if (msglen < sizeof(struct cmsghdr))
1072 msglen = FREEBSD32_ALIGN(msglen);
1073 if (idx + msglen > buflen)
1076 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1077 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1078 len += CMSG_ALIGN(msglen);
1084 m = m_get(M_WAITOK, MT_CONTROL);
1086 MCLGET(m, M_WAITOK);
1089 md = mtod(m, void *);
1090 while (buflen > 0) {
1091 error = copyin(buf, md, sizeof(struct cmsghdr));
1094 msglen = *(u_int *)md;
1095 msglen = FREEBSD32_ALIGN(msglen);
1097 /* Modify the message length to account for alignment. */
1098 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1099 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1101 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1102 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1103 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1105 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1107 error = copyin(buf, md, msglen);
1110 md = (char *)md + CMSG_ALIGN(msglen);
1124 freebsd32_sendmsg(struct thread *td,
1125 struct freebsd32_sendmsg_args *uap)
1128 struct msghdr32 m32;
1130 struct mbuf *control = NULL;
1131 struct sockaddr *to = NULL;
1134 error = copyin(uap->msg, &m32, sizeof(m32));
1137 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1140 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1145 if (msg.msg_name != NULL) {
1146 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1154 if (msg.msg_control) {
1155 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1160 error = freebsd32_copyin_control(&control, msg.msg_control,
1161 msg.msg_controllen);
1165 msg.msg_control = NULL;
1166 msg.msg_controllen = 0;
1169 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1180 freebsd32_recvfrom(struct thread *td,
1181 struct freebsd32_recvfrom_args *uap)
1187 if (uap->fromlenaddr) {
1188 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1189 sizeof(msg.msg_namelen));
1193 msg.msg_namelen = 0;
1196 msg.msg_name = PTRIN(uap->from);
1197 msg.msg_iov = &aiov;
1199 aiov.iov_base = PTRIN(uap->buf);
1200 aiov.iov_len = uap->len;
1201 msg.msg_control = NULL;
1202 msg.msg_flags = uap->flags;
1203 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1204 if (error == 0 && uap->fromlenaddr)
1205 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1206 sizeof (msg.msg_namelen));
1211 freebsd32_settimeofday(struct thread *td,
1212 struct freebsd32_settimeofday_args *uap)
1214 struct timeval32 tv32;
1215 struct timeval tv, *tvp;
1216 struct timezone tz, *tzp;
1220 error = copyin(uap->tv, &tv32, sizeof(tv32));
1223 CP(tv32, tv, tv_sec);
1224 CP(tv32, tv, tv_usec);
1229 error = copyin(uap->tzp, &tz, sizeof(tz));
1235 return (kern_settimeofday(td, tvp, tzp));
1239 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_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_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1261 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1263 struct timeval32 s32[2];
1264 struct timeval s[2], *sp;
1267 if (uap->tptr != NULL) {
1268 error = copyin(uap->tptr, s32, sizeof(s32));
1271 CP(s32[0], s[0], tv_sec);
1272 CP(s32[0], s[0], tv_usec);
1273 CP(s32[1], s[1], tv_sec);
1274 CP(s32[1], s[1], tv_usec);
1278 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1282 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1284 struct timeval32 s32[2];
1285 struct timeval s[2], *sp;
1288 if (uap->tptr != NULL) {
1289 error = copyin(uap->tptr, s32, sizeof(s32));
1292 CP(s32[0], s[0], tv_sec);
1293 CP(s32[0], s[0], tv_usec);
1294 CP(s32[1], s[1], tv_sec);
1295 CP(s32[1], s[1], tv_usec);
1299 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1303 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1305 struct timeval32 s32[2];
1306 struct timeval s[2], *sp;
1309 if (uap->times != NULL) {
1310 error = copyin(uap->times, s32, sizeof(s32));
1313 CP(s32[0], s[0], tv_sec);
1314 CP(s32[0], s[0], tv_usec);
1315 CP(s32[1], s[1], tv_sec);
1316 CP(s32[1], s[1], tv_usec);
1320 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1325 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1327 struct timespec32 ts32[2];
1328 struct timespec ts[2], *tsp;
1331 if (uap->times != NULL) {
1332 error = copyin(uap->times, ts32, sizeof(ts32));
1335 CP(ts32[0], ts[0], tv_sec);
1336 CP(ts32[0], ts[0], tv_nsec);
1337 CP(ts32[1], ts[1], tv_sec);
1338 CP(ts32[1], ts[1], tv_nsec);
1342 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1346 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1348 struct timespec32 ts32[2];
1349 struct timespec ts[2], *tsp;
1352 if (uap->times != NULL) {
1353 error = copyin(uap->times, ts32, sizeof(ts32));
1356 CP(ts32[0], ts[0], tv_sec);
1357 CP(ts32[0], ts[0], tv_nsec);
1358 CP(ts32[1], ts[1], tv_sec);
1359 CP(ts32[1], ts[1], tv_nsec);
1363 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1364 tsp, UIO_SYSSPACE, uap->flag));
1368 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1370 struct timeval32 tv32;
1371 struct timeval delta, olddelta, *deltap;
1375 error = copyin(uap->delta, &tv32, sizeof(tv32));
1378 CP(tv32, delta, tv_sec);
1379 CP(tv32, delta, tv_usec);
1383 error = kern_adjtime(td, deltap, &olddelta);
1384 if (uap->olddelta && error == 0) {
1385 CP(olddelta, tv32, tv_sec);
1386 CP(olddelta, tv32, tv_usec);
1387 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1392 #ifdef COMPAT_FREEBSD4
1394 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1396 struct statfs32 s32;
1400 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1401 error = kern_statfs(td, uap->path, UIO_USERSPACE, sp);
1403 copy_statfs(sp, &s32);
1404 error = copyout(&s32, uap->buf, sizeof(s32));
1411 #ifdef COMPAT_FREEBSD4
1413 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1415 struct statfs32 s32;
1419 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1420 error = kern_fstatfs(td, uap->fd, sp);
1422 copy_statfs(sp, &s32);
1423 error = copyout(&s32, uap->buf, sizeof(s32));
1430 #ifdef COMPAT_FREEBSD4
1432 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1434 struct statfs32 s32;
1439 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1441 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1442 error = kern_fhstatfs(td, fh, sp);
1444 copy_statfs(sp, &s32);
1445 error = copyout(&s32, uap->buf, sizeof(s32));
1453 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1456 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1457 PAIR32TO64(off_t, uap->offset)));
1461 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1464 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1465 PAIR32TO64(off_t, uap->offset)));
1470 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1473 return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
1478 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1483 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1485 /* Expand the quad return into two parts for eax and edx */
1486 pos = td->td_uretoff.tdu_off;
1487 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1488 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1493 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1496 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1497 PAIR32TO64(off_t, uap->length)));
1501 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1504 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
1509 ofreebsd32_getdirentries(struct thread *td,
1510 struct ofreebsd32_getdirentries_args *uap)
1512 struct ogetdirentries_args ap;
1519 ap.count = uap->count;
1521 error = kern_ogetdirentries(td, &ap, &loff);
1524 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1531 freebsd32_getdirentries(struct thread *td,
1532 struct freebsd32_getdirentries_args *uap)
1538 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1539 NULL, UIO_USERSPACE);
1542 if (uap->basep != NULL) {
1544 error = copyout(&base32, uap->basep, sizeof(int32_t));
1549 #ifdef COMPAT_FREEBSD6
1550 /* versions with the 'int pad' argument */
1552 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1555 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1556 PAIR32TO64(off_t, uap->offset)));
1560 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1563 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1564 PAIR32TO64(off_t, uap->offset)));
1568 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1573 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1575 /* Expand the quad return into two parts for eax and edx */
1576 pos = *(off_t *)(td->td_retval);
1577 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1578 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1583 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1586 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1587 PAIR32TO64(off_t, uap->length)));
1591 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1594 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
1596 #endif /* COMPAT_FREEBSD6 */
1606 freebsd32_do_sendfile(struct thread *td,
1607 struct freebsd32_sendfile_args *uap, int compat)
1609 struct sf_hdtr32 hdtr32;
1610 struct sf_hdtr hdtr;
1611 struct uio *hdr_uio, *trl_uio;
1613 cap_rights_t rights;
1614 struct iovec32 *iov32;
1615 off_t offset, sbytes;
1618 offset = PAIR32TO64(off_t, uap->offset);
1622 hdr_uio = trl_uio = NULL;
1624 if (uap->hdtr != NULL) {
1625 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1628 PTRIN_CP(hdtr32, hdtr, headers);
1629 CP(hdtr32, hdtr, hdr_cnt);
1630 PTRIN_CP(hdtr32, hdtr, trailers);
1631 CP(hdtr32, hdtr, trl_cnt);
1633 if (hdtr.headers != NULL) {
1634 iov32 = PTRIN(hdtr32.headers);
1635 error = freebsd32_copyinuio(iov32,
1636 hdtr32.hdr_cnt, &hdr_uio);
1639 #ifdef COMPAT_FREEBSD4
1641 * In FreeBSD < 5.0 the nbytes to send also included
1642 * the header. If compat is specified subtract the
1643 * header size from nbytes.
1646 if (uap->nbytes > hdr_uio->uio_resid)
1647 uap->nbytes -= hdr_uio->uio_resid;
1653 if (hdtr.trailers != NULL) {
1654 iov32 = PTRIN(hdtr32.trailers);
1655 error = freebsd32_copyinuio(iov32,
1656 hdtr32.trl_cnt, &trl_uio);
1662 AUDIT_ARG_FD(uap->fd);
1664 if ((error = fget_read(td, uap->fd,
1665 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
1668 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1669 uap->nbytes, &sbytes, uap->flags, td);
1672 if (uap->sbytes != NULL)
1673 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1677 free(hdr_uio, M_IOV);
1679 free(trl_uio, M_IOV);
1683 #ifdef COMPAT_FREEBSD4
1685 freebsd4_freebsd32_sendfile(struct thread *td,
1686 struct freebsd4_freebsd32_sendfile_args *uap)
1688 return (freebsd32_do_sendfile(td,
1689 (struct freebsd32_sendfile_args *)uap, 1));
1694 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1697 return (freebsd32_do_sendfile(td, uap, 0));
1701 copy_stat(struct stat *in, struct stat32 *out)
1704 CP(*in, *out, st_dev);
1705 CP(*in, *out, st_ino);
1706 CP(*in, *out, st_mode);
1707 CP(*in, *out, st_nlink);
1708 CP(*in, *out, st_uid);
1709 CP(*in, *out, st_gid);
1710 CP(*in, *out, st_rdev);
1711 TS_CP(*in, *out, st_atim);
1712 TS_CP(*in, *out, st_mtim);
1713 TS_CP(*in, *out, st_ctim);
1714 CP(*in, *out, st_size);
1715 CP(*in, *out, st_blocks);
1716 CP(*in, *out, st_blksize);
1717 CP(*in, *out, st_flags);
1718 CP(*in, *out, st_gen);
1719 TS_CP(*in, *out, st_birthtim);
1724 copy_ostat(struct stat *in, struct ostat32 *out)
1727 CP(*in, *out, st_dev);
1728 CP(*in, *out, st_ino);
1729 CP(*in, *out, st_mode);
1730 CP(*in, *out, st_nlink);
1731 CP(*in, *out, st_uid);
1732 CP(*in, *out, st_gid);
1733 CP(*in, *out, st_rdev);
1734 CP(*in, *out, st_size);
1735 TS_CP(*in, *out, st_atim);
1736 TS_CP(*in, *out, st_mtim);
1737 TS_CP(*in, *out, st_ctim);
1738 CP(*in, *out, st_blksize);
1739 CP(*in, *out, st_blocks);
1740 CP(*in, *out, st_flags);
1741 CP(*in, *out, st_gen);
1746 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1752 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1756 copy_stat(&sb, &sb32);
1757 error = copyout(&sb32, uap->ub, sizeof (sb32));
1763 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1766 struct ostat32 sb32;
1769 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1773 copy_ostat(&sb, &sb32);
1774 error = copyout(&sb32, uap->ub, sizeof (sb32));
1780 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1786 error = kern_fstat(td, uap->fd, &ub);
1789 copy_stat(&ub, &ub32);
1790 error = copyout(&ub32, uap->ub, sizeof(ub32));
1796 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1799 struct ostat32 ub32;
1802 error = kern_fstat(td, uap->fd, &ub);
1805 copy_ostat(&ub, &ub32);
1806 error = copyout(&ub32, uap->ub, sizeof(ub32));
1812 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1818 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1822 copy_stat(&ub, &ub32);
1823 error = copyout(&ub32, uap->buf, sizeof(ub32));
1828 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1834 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1835 UIO_USERSPACE, &sb, NULL);
1838 copy_stat(&sb, &sb32);
1839 error = copyout(&sb32, uap->ub, sizeof (sb32));
1845 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1848 struct ostat32 sb32;
1851 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1852 UIO_USERSPACE, &sb, NULL);
1855 copy_ostat(&sb, &sb32);
1856 error = copyout(&sb32, uap->ub, sizeof (sb32));
1862 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1864 int error, name[CTL_MAXNAME];
1868 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1870 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1874 error = fueword32(uap->oldlenp, &tmp);
1881 error = userland_sysctl(td, name, uap->namelen,
1882 uap->old, &oldlen, 1,
1883 uap->new, uap->newlen, &j, SCTL_MASK32);
1884 if (error && error != ENOMEM)
1887 suword32(uap->oldlenp, j);
1892 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1898 error = copyin(uap->jail, &version, sizeof(uint32_t));
1905 /* FreeBSD single IPv4 jails. */
1906 struct jail32_v0 j32_v0;
1908 bzero(&j, sizeof(struct jail));
1909 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1912 CP(j32_v0, j, version);
1913 PTRIN_CP(j32_v0, j, path);
1914 PTRIN_CP(j32_v0, j, hostname);
1915 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1921 * Version 1 was used by multi-IPv4 jail implementations
1922 * that never made it into the official kernel.
1926 case 2: /* JAIL_API_VERSION */
1928 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1931 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1934 CP(j32, j, version);
1935 PTRIN_CP(j32, j, path);
1936 PTRIN_CP(j32, j, hostname);
1937 PTRIN_CP(j32, j, jailname);
1940 PTRIN_CP(j32, j, ip4);
1941 PTRIN_CP(j32, j, ip6);
1946 /* Sci-Fi jails are not supported, sorry. */
1949 return (kern_jail(td, &j));
1953 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1958 /* Check that we have an even number of iovecs. */
1959 if (uap->iovcnt & 1)
1962 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1965 error = kern_jail_set(td, auio, uap->flags);
1971 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1973 struct iovec32 iov32;
1977 /* Check that we have an even number of iovecs. */
1978 if (uap->iovcnt & 1)
1981 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1984 error = kern_jail_get(td, auio, uap->flags);
1986 for (i = 0; i < uap->iovcnt; i++) {
1987 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
1988 CP(auio->uio_iov[i], iov32, iov_len);
1989 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
1998 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2000 struct sigaction32 s32;
2001 struct sigaction sa, osa, *sap;
2005 error = copyin(uap->act, &s32, sizeof(s32));
2008 sa.sa_handler = PTRIN(s32.sa_u);
2009 CP(s32, sa, sa_flags);
2010 CP(s32, sa, sa_mask);
2014 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2015 if (error == 0 && uap->oact != NULL) {
2016 s32.sa_u = PTROUT(osa.sa_handler);
2017 CP(osa, s32, sa_flags);
2018 CP(osa, s32, sa_mask);
2019 error = copyout(&s32, uap->oact, sizeof(s32));
2024 #ifdef COMPAT_FREEBSD4
2026 freebsd4_freebsd32_sigaction(struct thread *td,
2027 struct freebsd4_freebsd32_sigaction_args *uap)
2029 struct sigaction32 s32;
2030 struct sigaction sa, osa, *sap;
2034 error = copyin(uap->act, &s32, sizeof(s32));
2037 sa.sa_handler = PTRIN(s32.sa_u);
2038 CP(s32, sa, sa_flags);
2039 CP(s32, sa, sa_mask);
2043 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2044 if (error == 0 && uap->oact != NULL) {
2045 s32.sa_u = PTROUT(osa.sa_handler);
2046 CP(osa, s32, sa_flags);
2047 CP(osa, s32, sa_mask);
2048 error = copyout(&s32, uap->oact, sizeof(s32));
2055 struct osigaction32 {
2064 ofreebsd32_sigaction(struct thread *td,
2065 struct ofreebsd32_sigaction_args *uap)
2067 struct osigaction32 s32;
2068 struct sigaction sa, osa, *sap;
2071 if (uap->signum <= 0 || uap->signum >= ONSIG)
2075 error = copyin(uap->nsa, &s32, sizeof(s32));
2078 sa.sa_handler = PTRIN(s32.sa_u);
2079 CP(s32, sa, sa_flags);
2080 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2084 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2085 if (error == 0 && uap->osa != NULL) {
2086 s32.sa_u = PTROUT(osa.sa_handler);
2087 CP(osa, s32, sa_flags);
2088 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2089 error = copyout(&s32, uap->osa, sizeof(s32));
2095 ofreebsd32_sigprocmask(struct thread *td,
2096 struct ofreebsd32_sigprocmask_args *uap)
2101 OSIG2SIG(uap->mask, set);
2102 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2103 SIG2OSIG(oset, td->td_retval[0]);
2108 ofreebsd32_sigpending(struct thread *td,
2109 struct ofreebsd32_sigpending_args *uap)
2111 struct proc *p = td->td_proc;
2115 siglist = p->p_siglist;
2116 SIGSETOR(siglist, td->td_siglist);
2118 SIG2OSIG(siglist, td->td_retval[0]);
2123 u_int32_t sv_handler;
2129 ofreebsd32_sigvec(struct thread *td,
2130 struct ofreebsd32_sigvec_args *uap)
2132 struct sigvec32 vec;
2133 struct sigaction sa, osa, *sap;
2136 if (uap->signum <= 0 || uap->signum >= ONSIG)
2140 error = copyin(uap->nsv, &vec, sizeof(vec));
2143 sa.sa_handler = PTRIN(vec.sv_handler);
2144 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2145 sa.sa_flags = vec.sv_flags;
2146 sa.sa_flags ^= SA_RESTART;
2150 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2151 if (error == 0 && uap->osv != NULL) {
2152 vec.sv_handler = PTROUT(osa.sa_handler);
2153 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2154 vec.sv_flags = osa.sa_flags;
2155 vec.sv_flags &= ~SA_NOCLDWAIT;
2156 vec.sv_flags ^= SA_RESTART;
2157 error = copyout(&vec, uap->osv, sizeof(vec));
2163 ofreebsd32_sigblock(struct thread *td,
2164 struct ofreebsd32_sigblock_args *uap)
2168 OSIG2SIG(uap->mask, set);
2169 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2170 SIG2OSIG(oset, td->td_retval[0]);
2175 ofreebsd32_sigsetmask(struct thread *td,
2176 struct ofreebsd32_sigsetmask_args *uap)
2180 OSIG2SIG(uap->mask, set);
2181 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2182 SIG2OSIG(oset, td->td_retval[0]);
2187 ofreebsd32_sigsuspend(struct thread *td,
2188 struct ofreebsd32_sigsuspend_args *uap)
2192 OSIG2SIG(uap->mask, mask);
2193 return (kern_sigsuspend(td, mask));
2202 ofreebsd32_sigstack(struct thread *td,
2203 struct ofreebsd32_sigstack_args *uap)
2205 struct sigstack32 s32;
2206 struct sigstack nss, oss;
2207 int error = 0, unss;
2209 if (uap->nss != NULL) {
2210 error = copyin(uap->nss, &s32, sizeof(s32));
2213 nss.ss_sp = PTRIN(s32.ss_sp);
2214 CP(s32, nss, ss_onstack);
2219 oss.ss_sp = td->td_sigstk.ss_sp;
2220 oss.ss_onstack = sigonstack(cpu_getstack(td));
2222 td->td_sigstk.ss_sp = nss.ss_sp;
2223 td->td_sigstk.ss_size = 0;
2224 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2225 td->td_pflags |= TDP_ALTSTACK;
2227 if (uap->oss != NULL) {
2228 s32.ss_sp = PTROUT(oss.ss_sp);
2229 CP(oss, s32, ss_onstack);
2230 error = copyout(&s32, uap->oss, sizeof(s32));
2237 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2239 struct timespec32 rmt32, rqt32;
2240 struct timespec rmt, rqt;
2243 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2247 CP(rqt32, rqt, tv_sec);
2248 CP(rqt32, rqt, tv_nsec);
2251 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2253 error = kern_nanosleep(td, &rqt, &rmt);
2254 if (error && uap->rmtp) {
2257 CP(rmt, rmt32, tv_sec);
2258 CP(rmt, rmt32, tv_nsec);
2260 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2268 freebsd32_clock_gettime(struct thread *td,
2269 struct freebsd32_clock_gettime_args *uap)
2271 struct timespec ats;
2272 struct timespec32 ats32;
2275 error = kern_clock_gettime(td, uap->clock_id, &ats);
2277 CP(ats, ats32, tv_sec);
2278 CP(ats, ats32, tv_nsec);
2279 error = copyout(&ats32, uap->tp, sizeof(ats32));
2285 freebsd32_clock_settime(struct thread *td,
2286 struct freebsd32_clock_settime_args *uap)
2288 struct timespec ats;
2289 struct timespec32 ats32;
2292 error = copyin(uap->tp, &ats32, sizeof(ats32));
2295 CP(ats32, ats, tv_sec);
2296 CP(ats32, ats, tv_nsec);
2298 return (kern_clock_settime(td, uap->clock_id, &ats));
2302 freebsd32_clock_getres(struct thread *td,
2303 struct freebsd32_clock_getres_args *uap)
2306 struct timespec32 ts32;
2309 if (uap->tp == NULL)
2311 error = kern_clock_getres(td, uap->clock_id, &ts);
2313 CP(ts, ts32, tv_sec);
2314 CP(ts, ts32, tv_nsec);
2315 error = copyout(&ts32, uap->tp, sizeof(ts32));
2320 int freebsd32_ktimer_create(struct thread *td,
2321 struct freebsd32_ktimer_create_args *uap)
2323 struct sigevent32 ev32;
2324 struct sigevent ev, *evp;
2327 if (uap->evp == NULL) {
2331 error = copyin(uap->evp, &ev32, sizeof(ev32));
2334 error = convert_sigevent32(&ev32, &ev);
2338 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2340 error = copyout(&id, uap->timerid, sizeof(int));
2342 kern_ktimer_delete(td, id);
2348 freebsd32_ktimer_settime(struct thread *td,
2349 struct freebsd32_ktimer_settime_args *uap)
2351 struct itimerspec32 val32, oval32;
2352 struct itimerspec val, oval, *ovalp;
2355 error = copyin(uap->value, &val32, sizeof(val32));
2359 ovalp = uap->ovalue != NULL ? &oval : NULL;
2360 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2361 if (error == 0 && uap->ovalue != NULL) {
2362 ITS_CP(oval, oval32);
2363 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2369 freebsd32_ktimer_gettime(struct thread *td,
2370 struct freebsd32_ktimer_gettime_args *uap)
2372 struct itimerspec32 val32;
2373 struct itimerspec val;
2376 error = kern_ktimer_gettime(td, uap->timerid, &val);
2379 error = copyout(&val32, uap->value, sizeof(val32));
2385 freebsd32_clock_getcpuclockid2(struct thread *td,
2386 struct freebsd32_clock_getcpuclockid2_args *uap)
2391 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2392 uap->which, &clk_id);
2394 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2399 freebsd32_thr_new(struct thread *td,
2400 struct freebsd32_thr_new_args *uap)
2402 struct thr_param32 param32;
2403 struct thr_param param;
2406 if (uap->param_size < 0 ||
2407 uap->param_size > sizeof(struct thr_param32))
2409 bzero(¶m, sizeof(struct thr_param));
2410 bzero(¶m32, sizeof(struct thr_param32));
2411 error = copyin(uap->param, ¶m32, uap->param_size);
2414 param.start_func = PTRIN(param32.start_func);
2415 param.arg = PTRIN(param32.arg);
2416 param.stack_base = PTRIN(param32.stack_base);
2417 param.stack_size = param32.stack_size;
2418 param.tls_base = PTRIN(param32.tls_base);
2419 param.tls_size = param32.tls_size;
2420 param.child_tid = PTRIN(param32.child_tid);
2421 param.parent_tid = PTRIN(param32.parent_tid);
2422 param.flags = param32.flags;
2423 param.rtp = PTRIN(param32.rtp);
2424 param.spare[0] = PTRIN(param32.spare[0]);
2425 param.spare[1] = PTRIN(param32.spare[1]);
2426 param.spare[2] = PTRIN(param32.spare[2]);
2428 return (kern_thr_new(td, ¶m));
2432 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2434 struct timespec32 ts32;
2435 struct timespec ts, *tsp;
2440 if (uap->timeout != NULL) {
2441 error = copyin((const void *)uap->timeout, (void *)&ts32,
2442 sizeof(struct timespec32));
2445 ts.tv_sec = ts32.tv_sec;
2446 ts.tv_nsec = ts32.tv_nsec;
2449 return (kern_thr_suspend(td, tsp));
2453 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2455 bzero(dst, sizeof(*dst));
2456 dst->si_signo = src->si_signo;
2457 dst->si_errno = src->si_errno;
2458 dst->si_code = src->si_code;
2459 dst->si_pid = src->si_pid;
2460 dst->si_uid = src->si_uid;
2461 dst->si_status = src->si_status;
2462 dst->si_addr = (uintptr_t)src->si_addr;
2463 dst->si_value.sival_int = src->si_value.sival_int;
2464 dst->si_timerid = src->si_timerid;
2465 dst->si_overrun = src->si_overrun;
2469 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2471 struct timespec32 ts32;
2473 struct timespec *timeout;
2476 struct siginfo32 si32;
2480 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2483 ts.tv_sec = ts32.tv_sec;
2484 ts.tv_nsec = ts32.tv_nsec;
2489 error = copyin(uap->set, &set, sizeof(set));
2493 error = kern_sigtimedwait(td, set, &ksi, timeout);
2498 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2499 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2503 td->td_retval[0] = ksi.ksi_signo;
2511 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2514 struct siginfo32 si32;
2518 error = copyin(uap->set, &set, sizeof(set));
2522 error = kern_sigtimedwait(td, set, &ksi, NULL);
2527 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2528 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2531 td->td_retval[0] = ksi.ksi_signo;
2536 freebsd32_cpuset_setid(struct thread *td,
2537 struct freebsd32_cpuset_setid_args *uap)
2540 return (kern_cpuset_setid(td, uap->which,
2541 PAIR32TO64(id_t, uap->id), uap->setid));
2545 freebsd32_cpuset_getid(struct thread *td,
2546 struct freebsd32_cpuset_getid_args *uap)
2549 return (kern_cpuset_getid(td, uap->level, uap->which,
2550 PAIR32TO64(id_t, uap->id), uap->setid));
2554 freebsd32_cpuset_getaffinity(struct thread *td,
2555 struct freebsd32_cpuset_getaffinity_args *uap)
2557 struct cpuset_getaffinity_args ap;
2559 ap.level = uap->level;
2560 ap.which = uap->which;
2561 ap.id = PAIR32TO64(id_t,uap->id);
2562 ap.cpusetsize = uap->cpusetsize;
2563 ap.mask = uap->mask;
2565 return (sys_cpuset_getaffinity(td, &ap));
2569 freebsd32_cpuset_setaffinity(struct thread *td,
2570 struct freebsd32_cpuset_setaffinity_args *uap)
2572 struct cpuset_setaffinity_args ap;
2574 ap.level = uap->level;
2575 ap.which = uap->which;
2576 ap.id = PAIR32TO64(id_t,uap->id);
2577 ap.cpusetsize = uap->cpusetsize;
2578 ap.mask = uap->mask;
2580 return (sys_cpuset_setaffinity(td, &ap));
2584 freebsd32_nmount(struct thread *td,
2585 struct freebsd32_nmount_args /* {
2587 unsigned int iovcnt;
2596 * Mount flags are now 64-bits. On 32-bit archtectures only
2597 * 32-bits are passed in, but from here on everything handles
2598 * 64-bit flags correctly.
2602 AUDIT_ARG_FFLAGS(flags);
2605 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2606 * userspace to set this flag, but we must filter it out if we want
2607 * MNT_UPDATE on the root file system to work.
2608 * MNT_ROOTFS should only be set by the kernel when mounting its
2611 flags &= ~MNT_ROOTFS;
2614 * check that we have an even number of iovec's
2615 * and that we have at least two options.
2617 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2620 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2623 error = vfs_donmount(td, flags, auio);
2631 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2633 struct yyy32 *p32, s32;
2634 struct yyy *p = NULL, s;
2639 error = copyin(uap->zzz, &s32, sizeof(s32));
2645 error = kern_xxx(td, p);
2650 error = copyout(&s32, p32, sizeof(s32));
2657 syscall32_register(int *offset, struct sysent *new_sysent,
2658 struct sysent *old_sysent, int flags)
2661 if ((flags & ~SY_THR_STATIC) != 0)
2664 if (*offset == NO_SYSCALL) {
2667 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2668 if (freebsd32_sysent[i].sy_call ==
2669 (sy_call_t *)lkmnosys)
2671 if (i == SYS_MAXSYSCALL)
2674 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2676 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2677 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2680 *old_sysent = freebsd32_sysent[*offset];
2681 freebsd32_sysent[*offset] = *new_sysent;
2682 atomic_store_rel_32(&freebsd32_sysent[*offset].sy_thrcnt, flags);
2687 syscall32_deregister(int *offset, struct sysent *old_sysent)
2693 freebsd32_sysent[*offset] = *old_sysent;
2698 syscall32_module_handler(struct module *mod, int what, void *arg)
2700 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2706 error = syscall32_register(data->offset, data->new_sysent,
2707 &data->old_sysent, SY_THR_STATIC_KLD);
2709 /* Leave a mark so we know to safely unload below. */
2710 data->offset = NULL;
2713 ms.intval = *data->offset;
2715 module_setspecific(mod, &ms);
2718 error = data->chainevh(mod, what, data->chainarg);
2722 * MOD_LOAD failed, so just return without calling the
2723 * chained handler since we didn't pass along the MOD_LOAD
2726 if (data->offset == NULL)
2728 if (data->chainevh) {
2729 error = data->chainevh(mod, what, data->chainarg);
2733 error = syscall32_deregister(data->offset, &data->old_sysent);
2738 error = data->chainevh(mod, what, data->chainarg);
2744 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
2746 struct syscall_helper_data *sd1;
2749 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2750 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2751 &sd1->old_sysent, flags);
2753 syscall32_helper_unregister(sd);
2756 sd1->registered = 1;
2762 syscall32_helper_unregister(struct syscall_helper_data *sd)
2764 struct syscall_helper_data *sd1;
2766 for (sd1 = sd; sd1->registered != 0; sd1++) {
2767 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2768 sd1->registered = 0;
2774 freebsd32_copyout_strings(struct image_params *imgp)
2780 u_int32_t *stack_base;
2781 struct freebsd32_ps_strings *arginfo;
2782 char canary[sizeof(long) * 8];
2783 int32_t pagesizes32[MAXPAGESIZES];
2784 size_t execpath_len;
2788 * Calculate string base and vector table pointers.
2789 * Also deal with signal trampoline code for this exec type.
2791 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2792 execpath_len = strlen(imgp->execpath) + 1;
2795 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2797 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2798 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2801 destp = (uintptr_t)arginfo;
2806 if (szsigcode != 0) {
2808 destp = rounddown2(destp, sizeof(uint32_t));
2809 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2814 * Copy the image path for the rtld.
2816 if (execpath_len != 0) {
2817 destp -= execpath_len;
2818 imgp->execpathp = destp;
2819 copyout(imgp->execpath, (void *)destp, execpath_len);
2823 * Prepare the canary for SSP.
2825 arc4rand(canary, sizeof(canary), 0);
2826 destp -= sizeof(canary);
2827 imgp->canary = destp;
2828 copyout(canary, (void *)destp, sizeof(canary));
2829 imgp->canarylen = sizeof(canary);
2832 * Prepare the pagesizes array.
2834 for (i = 0; i < MAXPAGESIZES; i++)
2835 pagesizes32[i] = (uint32_t)pagesizes[i];
2836 destp -= sizeof(pagesizes32);
2837 destp = rounddown2(destp, sizeof(uint32_t));
2838 imgp->pagesizes = destp;
2839 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2840 imgp->pagesizeslen = sizeof(pagesizes32);
2842 destp -= ARG_MAX - imgp->args->stringspace;
2843 destp = rounddown2(destp, sizeof(uint32_t));
2846 * If we have a valid auxargs ptr, prepare some room
2849 if (imgp->auxargs) {
2851 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2852 * lower compatibility.
2854 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2857 * The '+ 2' is for the null pointers at the end of each of
2858 * the arg and env vector sets,and imgp->auxarg_size is room
2859 * for argument of Runtime loader.
2861 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2862 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2866 * The '+ 2' is for the null pointers at the end of each of
2867 * the arg and env vector sets
2869 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2870 imgp->args->envc + 2) * sizeof(u_int32_t));
2874 * vectp also becomes our initial stack base
2878 stringp = imgp->args->begin_argv;
2879 argc = imgp->args->argc;
2880 envc = imgp->args->envc;
2882 * Copy out strings - arguments and environment.
2884 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2887 * Fill in "ps_strings" struct for ps, w, etc.
2889 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2890 suword32(&arginfo->ps_nargvstr, argc);
2893 * Fill in argument portion of vector table.
2895 for (; argc > 0; --argc) {
2896 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2897 while (*stringp++ != 0)
2902 /* a null vector table pointer separates the argp's from the envp's */
2903 suword32(vectp++, 0);
2905 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2906 suword32(&arginfo->ps_nenvstr, envc);
2909 * Fill in environment portion of vector table.
2911 for (; envc > 0; --envc) {
2912 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2913 while (*stringp++ != 0)
2918 /* end of vector table is a null pointer */
2921 return ((register_t *)stack_base);
2925 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2927 struct kld_file_stat stat;
2928 struct kld32_file_stat stat32;
2931 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2934 if (version != sizeof(struct kld32_file_stat_1) &&
2935 version != sizeof(struct kld32_file_stat))
2938 error = kern_kldstat(td, uap->fileid, &stat);
2942 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2943 CP(stat, stat32, refs);
2944 CP(stat, stat32, id);
2945 PTROUT_CP(stat, stat32, address);
2946 CP(stat, stat32, size);
2947 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2948 return (copyout(&stat32, uap->stat, version));
2952 freebsd32_posix_fallocate(struct thread *td,
2953 struct freebsd32_posix_fallocate_args *uap)
2957 error = kern_posix_fallocate(td, uap->fd,
2958 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
2959 return (kern_posix_error(td, error));
2963 freebsd32_posix_fadvise(struct thread *td,
2964 struct freebsd32_posix_fadvise_args *uap)
2968 error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2969 PAIR32TO64(off_t, uap->len), uap->advice);
2970 return (kern_posix_error(td, error));
2974 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
2977 CP(*sig32, *sig, sigev_notify);
2978 switch (sig->sigev_notify) {
2981 case SIGEV_THREAD_ID:
2982 CP(*sig32, *sig, sigev_notify_thread_id);
2985 CP(*sig32, *sig, sigev_signo);
2986 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
2989 CP(*sig32, *sig, sigev_notify_kqueue);
2990 CP(*sig32, *sig, sigev_notify_kevent_flags);
2991 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3000 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3004 struct procctl_reaper_status rs;
3005 struct procctl_reaper_pids rp;
3006 struct procctl_reaper_kill rk;
3009 struct procctl_reaper_pids32 rp;
3011 int error, error1, flags;
3015 case PROC_TRACE_CTL:
3016 case PROC_TRAPCAP_CTL:
3017 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3022 case PROC_REAP_ACQUIRE:
3023 case PROC_REAP_RELEASE:
3024 if (uap->data != NULL)
3028 case PROC_REAP_STATUS:
3031 case PROC_REAP_GETPIDS:
3032 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3035 CP(x32.rp, x.rp, rp_count);
3036 PTRIN_CP(x32.rp, x.rp, rp_pids);
3039 case PROC_REAP_KILL:
3040 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3045 case PROC_TRACE_STATUS:
3046 case PROC_TRAPCAP_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:
3065 case PROC_TRAPCAP_STATUS:
3067 error = copyout(&flags, uap->data, sizeof(flags));
3074 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3080 * Do unsigned conversion for arg when operation
3081 * interprets it as flags or pointer.
3083 case F_SETLK_REMOTE:
3092 tmp = (unsigned int)(uap->arg);
3098 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3102 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3104 struct timespec32 ts32;
3105 struct timespec ts, *tsp;
3109 if (uap->ts != NULL) {
3110 error = copyin(uap->ts, &ts32, sizeof(ts32));
3113 CP(ts32, ts, tv_sec);
3114 CP(ts32, ts, tv_nsec);
3118 if (uap->set != NULL) {
3119 error = copyin(uap->set, &set, sizeof(set));
3126 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));