2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include "opt_inet6.h"
34 #define __ELF_WORD_SIZE 32
36 #include <sys/param.h>
38 #include <sys/capsicum.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.h>
59 #include <sys/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
249 struct statfs *buf, *sp;
250 struct statfs32 stat32;
251 size_t count, size, copycount;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->flags);
260 while (copycount > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
270 td->td_retval[0] = count;
276 freebsd32_sigaltstack(struct thread *td,
277 struct freebsd32_sigaltstack_args *uap)
279 struct sigaltstack32 s32;
280 struct sigaltstack ss, oss, *ssp;
283 if (uap->ss != NULL) {
284 error = copyin(uap->ss, &s32, sizeof(s32));
287 PTRIN_CP(s32, ss, ss_sp);
288 CP(s32, ss, ss_size);
289 CP(s32, ss, ss_flags);
293 error = kern_sigaltstack(td, ssp, &oss);
294 if (error == 0 && uap->oss != NULL) {
295 PTROUT_CP(oss, s32, ss_sp);
296 CP(oss, s32, ss_size);
297 CP(oss, s32, ss_flags);
298 error = copyout(&s32, uap->oss, sizeof(s32));
304 * Custom version of exec_copyin_args() so that we can translate
308 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
309 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
316 bzero(args, sizeof(*args));
321 * Allocate demand-paged memory for the file name, argument, and
322 * environment strings.
324 error = exec_alloc_args(args);
329 * Copy the file name.
332 args->fname = args->buf;
333 error = (segflg == UIO_SYSSPACE) ?
334 copystr(fname, args->fname, PATH_MAX, &length) :
335 copyinstr(fname, args->fname, PATH_MAX, &length);
341 args->begin_argv = args->buf + length;
342 args->endp = args->begin_argv;
343 args->stringspace = ARG_MAX;
346 * extract arguments first
350 error = copyin(p32++, &arg, sizeof(arg));
356 error = copyinstr(argp, args->endp, args->stringspace, &length);
358 if (error == ENAMETOOLONG)
362 args->stringspace -= length;
363 args->endp += length;
367 args->begin_envv = args->endp;
370 * extract environment strings
375 error = copyin(p32++, &arg, sizeof(arg));
381 error = copyinstr(envp, args->endp, args->stringspace,
384 if (error == ENAMETOOLONG)
388 args->stringspace -= length;
389 args->endp += length;
397 exec_free_args(args);
402 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
404 struct image_args eargs;
405 struct vmspace *oldvmspace;
408 error = pre_execve(td, &oldvmspace);
411 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
412 uap->argv, uap->envv);
414 error = kern_execve(td, &eargs, NULL);
415 post_execve(td, error, oldvmspace);
420 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
422 struct image_args eargs;
423 struct vmspace *oldvmspace;
426 error = pre_execve(td, &oldvmspace);
429 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
430 uap->argv, uap->envv);
433 error = kern_execve(td, &eargs, NULL);
435 post_execve(td, error, oldvmspace);
440 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
442 struct mprotect_args ap;
444 ap.addr = PTRIN(uap->addr);
447 #if defined(__amd64__)
448 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
449 ap.prot |= PROT_EXEC;
451 return (sys_mprotect(td, &ap));
455 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
458 vm_offset_t addr = (vm_offset_t) uap->addr;
459 vm_size_t len = uap->len;
460 int prot = uap->prot;
461 int flags = uap->flags;
463 off_t pos = PAIR32TO64(off_t,uap->pos);
465 #if defined(__amd64__)
466 if (i386_read_exec && (prot & PROT_READ))
470 ap.addr = (void *) addr;
477 return (sys_mmap(td, &ap));
480 #ifdef COMPAT_FREEBSD6
482 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
484 struct freebsd32_mmap_args ap;
489 ap.flags = uap->flags;
494 return (freebsd32_mmap(td, &ap));
499 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
501 struct itimerval itv, oitv, *itvp;
502 struct itimerval32 i32;
505 if (uap->itv != NULL) {
506 error = copyin(uap->itv, &i32, sizeof(i32));
509 TV_CP(i32, itv, it_interval);
510 TV_CP(i32, itv, it_value);
514 error = kern_setitimer(td, uap->which, itvp, &oitv);
515 if (error || uap->oitv == NULL)
517 TV_CP(oitv, i32, it_interval);
518 TV_CP(oitv, i32, it_value);
519 return (copyout(&i32, uap->oitv, sizeof(i32)));
523 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
525 struct itimerval itv;
526 struct itimerval32 i32;
529 error = kern_getitimer(td, uap->which, &itv);
530 if (error || uap->itv == NULL)
532 TV_CP(itv, i32, it_interval);
533 TV_CP(itv, i32, it_value);
534 return (copyout(&i32, uap->itv, sizeof(i32)));
538 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
540 struct timeval32 tv32;
541 struct timeval tv, *tvp;
544 if (uap->tv != NULL) {
545 error = copyin(uap->tv, &tv32, sizeof(tv32));
548 CP(tv32, tv, tv_sec);
549 CP(tv32, tv, tv_usec);
554 * XXX Do pointers need PTRIN()?
556 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
557 sizeof(int32_t) * 8));
561 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
563 struct timespec32 ts32;
565 struct timeval tv, *tvp;
569 if (uap->ts != NULL) {
570 error = copyin(uap->ts, &ts32, sizeof(ts32));
573 CP(ts32, ts, tv_sec);
574 CP(ts32, ts, tv_nsec);
575 TIMESPEC_TO_TIMEVAL(&tv, &ts);
579 if (uap->sm != NULL) {
580 error = copyin(uap->sm, &set, sizeof(set));
587 * XXX Do pointers need PTRIN()?
589 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
590 uset, sizeof(int32_t) * 8);
595 * Copy 'count' items into the destination list pointed to by uap->eventlist.
598 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
600 struct freebsd32_kevent_args *uap;
601 struct kevent32 ks32[KQ_NEVENTS];
604 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
605 uap = (struct freebsd32_kevent_args *)arg;
607 for (i = 0; i < count; i++) {
608 CP(kevp[i], ks32[i], ident);
609 CP(kevp[i], ks32[i], filter);
610 CP(kevp[i], ks32[i], flags);
611 CP(kevp[i], ks32[i], fflags);
612 CP(kevp[i], ks32[i], data);
613 PTROUT_CP(kevp[i], ks32[i], udata);
615 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
617 uap->eventlist += count;
622 * Copy 'count' items from the list pointed to by uap->changelist.
625 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
627 struct freebsd32_kevent_args *uap;
628 struct kevent32 ks32[KQ_NEVENTS];
631 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
632 uap = (struct freebsd32_kevent_args *)arg;
634 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
637 uap->changelist += count;
639 for (i = 0; i < count; i++) {
640 CP(ks32[i], kevp[i], ident);
641 CP(ks32[i], kevp[i], filter);
642 CP(ks32[i], kevp[i], flags);
643 CP(ks32[i], kevp[i], fflags);
644 CP(ks32[i], kevp[i], data);
645 PTRIN_CP(ks32[i], kevp[i], udata);
652 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
654 struct timespec32 ts32;
655 struct timespec ts, *tsp;
656 struct kevent_copyops k_ops = { uap,
657 freebsd32_kevent_copyout,
658 freebsd32_kevent_copyin};
663 error = copyin(uap->timeout, &ts32, sizeof(ts32));
666 CP(ts32, ts, tv_sec);
667 CP(ts32, ts, tv_nsec);
671 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
677 freebsd32_gettimeofday(struct thread *td,
678 struct freebsd32_gettimeofday_args *uap)
681 struct timeval32 atv32;
687 CP(atv, atv32, tv_sec);
688 CP(atv, atv32, tv_usec);
689 error = copyout(&atv32, uap->tp, sizeof (atv32));
691 if (error == 0 && uap->tzp != NULL) {
692 rtz.tz_minuteswest = tz_minuteswest;
693 rtz.tz_dsttime = tz_dsttime;
694 error = copyout(&rtz, uap->tzp, sizeof (rtz));
700 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
706 error = kern_getrusage(td, uap->who, &s);
709 if (uap->rusage != NULL) {
710 freebsd32_rusage_out(&s, &s32);
711 error = copyout(&s32, uap->rusage, sizeof(s32));
717 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
719 struct iovec32 iov32;
726 if (iovcnt > UIO_MAXIOV)
728 iovlen = iovcnt * sizeof(struct iovec);
729 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
730 iov = (struct iovec *)(uio + 1);
731 for (i = 0; i < iovcnt; i++) {
732 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
737 iov[i].iov_base = PTRIN(iov32.iov_base);
738 iov[i].iov_len = iov32.iov_len;
741 uio->uio_iovcnt = iovcnt;
742 uio->uio_segflg = UIO_USERSPACE;
743 uio->uio_offset = -1;
745 for (i = 0; i < iovcnt; i++) {
746 if (iov->iov_len > INT_MAX - uio->uio_resid) {
750 uio->uio_resid += iov->iov_len;
758 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
763 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
766 error = kern_readv(td, uap->fd, auio);
772 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
777 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
780 error = kern_writev(td, uap->fd, auio);
786 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
791 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
794 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
800 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
805 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
808 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
814 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
817 struct iovec32 iov32;
823 if (iovcnt > UIO_MAXIOV)
825 iovlen = iovcnt * sizeof(struct iovec);
826 iov = malloc(iovlen, M_IOV, M_WAITOK);
827 for (i = 0; i < iovcnt; i++) {
828 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
833 iov[i].iov_base = PTRIN(iov32.iov_base);
834 iov[i].iov_len = iov32.iov_len;
841 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
846 error = copyin(msg32, &m32, sizeof(m32));
849 msg->msg_name = PTRIN(m32.msg_name);
850 msg->msg_namelen = m32.msg_namelen;
851 msg->msg_iov = PTRIN(m32.msg_iov);
852 msg->msg_iovlen = m32.msg_iovlen;
853 msg->msg_control = PTRIN(m32.msg_control);
854 msg->msg_controllen = m32.msg_controllen;
855 msg->msg_flags = m32.msg_flags;
860 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
865 m32.msg_name = PTROUT(msg->msg_name);
866 m32.msg_namelen = msg->msg_namelen;
867 m32.msg_iov = PTROUT(msg->msg_iov);
868 m32.msg_iovlen = msg->msg_iovlen;
869 m32.msg_control = PTROUT(msg->msg_control);
870 m32.msg_controllen = msg->msg_controllen;
871 m32.msg_flags = msg->msg_flags;
872 error = copyout(&m32, msg32, sizeof(m32));
877 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
879 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
881 #define FREEBSD32_ALIGN(p) \
882 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
883 #define FREEBSD32_CMSG_SPACE(l) \
884 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
886 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
887 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
889 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
893 socklen_t clen, datalen;
896 int len, maxlen, copylen;
900 len = msg->msg_controllen;
901 maxlen = msg->msg_controllen;
902 msg->msg_controllen = 0;
905 ctlbuf = msg->msg_control;
907 while (m && len > 0) {
908 cm = mtod(m, struct cmsghdr *);
913 if (sizeof(struct cmsghdr) > clen ||
914 cm->cmsg_len > clen) {
919 data = CMSG_DATA(cm);
920 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
922 /* Adjust message length */
923 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
928 copylen = sizeof(struct cmsghdr);
930 msg->msg_flags |= MSG_CTRUNC;
934 error = copyout(cm,ctlbuf,copylen);
938 ctlbuf += FREEBSD32_ALIGN(copylen);
939 len -= FREEBSD32_ALIGN(copylen);
947 msg->msg_flags |= MSG_CTRUNC;
951 error = copyout(data,ctlbuf,copylen);
955 ctlbuf += FREEBSD32_ALIGN(copylen);
956 len -= FREEBSD32_ALIGN(copylen);
958 if (CMSG_SPACE(datalen) < clen) {
959 clen -= CMSG_SPACE(datalen);
960 cm = (struct cmsghdr *)
961 ((caddr_t)cm + CMSG_SPACE(datalen));
970 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
978 freebsd32_recvmsg(td, uap)
980 struct freebsd32_recvmsg_args /* {
982 struct msghdr32 *msg;
988 struct iovec *uiov, *iov;
989 struct mbuf *control = NULL;
990 struct mbuf **controlp;
993 error = copyin(uap->msg, &m32, sizeof(m32));
996 error = freebsd32_copyinmsghdr(uap->msg, &msg);
999 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1003 msg.msg_flags = uap->flags;
1007 controlp = (msg.msg_control != NULL) ? &control : NULL;
1008 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1012 if (control != NULL)
1013 error = freebsd32_copy_msg_out(&msg, control);
1015 msg.msg_controllen = 0;
1018 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1022 if (control != NULL)
1029 * Copy-in the array of control messages constructed using alignment
1030 * and padding suitable for a 32-bit environment and construct an
1031 * mbuf using alignment and padding suitable for a 64-bit kernel.
1032 * The alignment and padding are defined indirectly by CMSG_DATA(),
1033 * CMSG_SPACE() and CMSG_LEN().
1036 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1040 u_int idx, len, msglen;
1043 buflen = FREEBSD32_ALIGN(buflen);
1045 if (buflen > MCLBYTES)
1049 * Iterate over the buffer and get the length of each message
1050 * in there. This has 32-bit alignment and padding. Use it to
1051 * determine the length of these messages when using 64-bit
1052 * alignment and padding.
1056 while (idx < buflen) {
1057 error = copyin(buf + idx, &msglen, sizeof(msglen));
1060 if (msglen < sizeof(struct cmsghdr))
1062 msglen = FREEBSD32_ALIGN(msglen);
1063 if (idx + msglen > buflen)
1066 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1067 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1068 len += CMSG_ALIGN(msglen);
1074 m = m_get(M_WAITOK, MT_CONTROL);
1076 MCLGET(m, M_WAITOK);
1079 md = mtod(m, void *);
1080 while (buflen > 0) {
1081 error = copyin(buf, md, sizeof(struct cmsghdr));
1084 msglen = *(u_int *)md;
1085 msglen = FREEBSD32_ALIGN(msglen);
1087 /* Modify the message length to account for alignment. */
1088 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1089 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1091 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1092 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1093 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1095 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1097 error = copyin(buf, md, msglen);
1100 md = (char *)md + CMSG_ALIGN(msglen);
1114 freebsd32_sendmsg(struct thread *td,
1115 struct freebsd32_sendmsg_args *uap)
1118 struct msghdr32 m32;
1120 struct mbuf *control = NULL;
1121 struct sockaddr *to = NULL;
1124 error = copyin(uap->msg, &m32, sizeof(m32));
1127 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1130 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1135 if (msg.msg_name != NULL) {
1136 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1144 if (msg.msg_control) {
1145 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1150 error = freebsd32_copyin_control(&control, msg.msg_control,
1151 msg.msg_controllen);
1155 msg.msg_control = NULL;
1156 msg.msg_controllen = 0;
1159 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1170 freebsd32_recvfrom(struct thread *td,
1171 struct freebsd32_recvfrom_args *uap)
1177 if (uap->fromlenaddr) {
1178 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1179 sizeof(msg.msg_namelen));
1183 msg.msg_namelen = 0;
1186 msg.msg_name = PTRIN(uap->from);
1187 msg.msg_iov = &aiov;
1189 aiov.iov_base = PTRIN(uap->buf);
1190 aiov.iov_len = uap->len;
1191 msg.msg_control = NULL;
1192 msg.msg_flags = uap->flags;
1193 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1194 if (error == 0 && uap->fromlenaddr)
1195 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1196 sizeof (msg.msg_namelen));
1201 freebsd32_settimeofday(struct thread *td,
1202 struct freebsd32_settimeofday_args *uap)
1204 struct timeval32 tv32;
1205 struct timeval tv, *tvp;
1206 struct timezone tz, *tzp;
1210 error = copyin(uap->tv, &tv32, sizeof(tv32));
1213 CP(tv32, tv, tv_sec);
1214 CP(tv32, tv, tv_usec);
1219 error = copyin(uap->tzp, &tz, sizeof(tz));
1225 return (kern_settimeofday(td, tvp, tzp));
1229 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1231 struct timeval32 s32[2];
1232 struct timeval s[2], *sp;
1235 if (uap->tptr != NULL) {
1236 error = copyin(uap->tptr, s32, sizeof(s32));
1239 CP(s32[0], s[0], tv_sec);
1240 CP(s32[0], s[0], tv_usec);
1241 CP(s32[1], s[1], tv_sec);
1242 CP(s32[1], s[1], tv_usec);
1246 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1251 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1253 struct timeval32 s32[2];
1254 struct timeval s[2], *sp;
1257 if (uap->tptr != NULL) {
1258 error = copyin(uap->tptr, s32, sizeof(s32));
1261 CP(s32[0], s[0], tv_sec);
1262 CP(s32[0], s[0], tv_usec);
1263 CP(s32[1], s[1], tv_sec);
1264 CP(s32[1], s[1], tv_usec);
1268 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1272 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1274 struct timeval32 s32[2];
1275 struct timeval s[2], *sp;
1278 if (uap->tptr != NULL) {
1279 error = copyin(uap->tptr, s32, sizeof(s32));
1282 CP(s32[0], s[0], tv_sec);
1283 CP(s32[0], s[0], tv_usec);
1284 CP(s32[1], s[1], tv_sec);
1285 CP(s32[1], s[1], tv_usec);
1289 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1293 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1295 struct timeval32 s32[2];
1296 struct timeval s[2], *sp;
1299 if (uap->times != NULL) {
1300 error = copyin(uap->times, s32, sizeof(s32));
1303 CP(s32[0], s[0], tv_sec);
1304 CP(s32[0], s[0], tv_usec);
1305 CP(s32[1], s[1], tv_sec);
1306 CP(s32[1], s[1], tv_usec);
1310 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1315 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1317 struct timespec32 ts32[2];
1318 struct timespec ts[2], *tsp;
1321 if (uap->times != NULL) {
1322 error = copyin(uap->times, ts32, sizeof(ts32));
1325 CP(ts32[0], ts[0], tv_sec);
1326 CP(ts32[0], ts[0], tv_nsec);
1327 CP(ts32[1], ts[1], tv_sec);
1328 CP(ts32[1], ts[1], tv_nsec);
1332 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1336 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1338 struct timespec32 ts32[2];
1339 struct timespec ts[2], *tsp;
1342 if (uap->times != NULL) {
1343 error = copyin(uap->times, ts32, sizeof(ts32));
1346 CP(ts32[0], ts[0], tv_sec);
1347 CP(ts32[0], ts[0], tv_nsec);
1348 CP(ts32[1], ts[1], tv_sec);
1349 CP(ts32[1], ts[1], tv_nsec);
1353 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1354 tsp, UIO_SYSSPACE, uap->flag));
1358 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1360 struct timeval32 tv32;
1361 struct timeval delta, olddelta, *deltap;
1365 error = copyin(uap->delta, &tv32, sizeof(tv32));
1368 CP(tv32, delta, tv_sec);
1369 CP(tv32, delta, tv_usec);
1373 error = kern_adjtime(td, deltap, &olddelta);
1374 if (uap->olddelta && error == 0) {
1375 CP(olddelta, tv32, tv_sec);
1376 CP(olddelta, tv32, tv_usec);
1377 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1382 #ifdef COMPAT_FREEBSD4
1384 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1386 struct statfs32 s32;
1390 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1393 copy_statfs(&s, &s32);
1394 return (copyout(&s32, uap->buf, sizeof(s32)));
1398 #ifdef COMPAT_FREEBSD4
1400 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1402 struct statfs32 s32;
1406 error = kern_fstatfs(td, uap->fd, &s);
1409 copy_statfs(&s, &s32);
1410 return (copyout(&s32, uap->buf, sizeof(s32)));
1414 #ifdef COMPAT_FREEBSD4
1416 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1418 struct statfs32 s32;
1423 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1425 error = kern_fhstatfs(td, fh, &s);
1428 copy_statfs(&s, &s32);
1429 return (copyout(&s32, uap->buf, sizeof(s32)));
1434 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1436 struct pread_args ap;
1440 ap.nbyte = uap->nbyte;
1441 ap.offset = PAIR32TO64(off_t,uap->offset);
1442 return (sys_pread(td, &ap));
1446 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1448 struct pwrite_args ap;
1452 ap.nbyte = uap->nbyte;
1453 ap.offset = PAIR32TO64(off_t,uap->offset);
1454 return (sys_pwrite(td, &ap));
1459 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1461 struct lseek_args nuap;
1464 nuap.offset = uap->offset;
1465 nuap.whence = uap->whence;
1466 return (sys_lseek(td, &nuap));
1471 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1474 struct lseek_args ap;
1478 ap.offset = PAIR32TO64(off_t,uap->offset);
1479 ap.whence = uap->whence;
1480 error = sys_lseek(td, &ap);
1481 /* Expand the quad return into two parts for eax and edx */
1482 pos = td->td_uretoff.tdu_off;
1483 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1484 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1489 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1491 struct truncate_args ap;
1493 ap.path = uap->path;
1494 ap.length = PAIR32TO64(off_t,uap->length);
1495 return (sys_truncate(td, &ap));
1499 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1501 struct ftruncate_args ap;
1504 ap.length = PAIR32TO64(off_t,uap->length);
1505 return (sys_ftruncate(td, &ap));
1510 ofreebsd32_getdirentries(struct thread *td,
1511 struct ofreebsd32_getdirentries_args *uap)
1513 struct ogetdirentries_args ap;
1520 ap.count = uap->count;
1522 error = kern_ogetdirentries(td, &ap, &loff);
1525 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1532 freebsd32_getdirentries(struct thread *td,
1533 struct freebsd32_getdirentries_args *uap)
1539 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1540 NULL, UIO_USERSPACE);
1543 if (uap->basep != NULL) {
1545 error = copyout(&base32, uap->basep, sizeof(int32_t));
1550 #ifdef COMPAT_FREEBSD6
1551 /* versions with the 'int pad' argument */
1553 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1555 struct pread_args ap;
1559 ap.nbyte = uap->nbyte;
1560 ap.offset = PAIR32TO64(off_t,uap->offset);
1561 return (sys_pread(td, &ap));
1565 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1567 struct pwrite_args ap;
1571 ap.nbyte = uap->nbyte;
1572 ap.offset = PAIR32TO64(off_t,uap->offset);
1573 return (sys_pwrite(td, &ap));
1577 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1580 struct lseek_args ap;
1584 ap.offset = PAIR32TO64(off_t,uap->offset);
1585 ap.whence = uap->whence;
1586 error = sys_lseek(td, &ap);
1587 /* Expand the quad return into two parts for eax and edx */
1588 pos = *(off_t *)(td->td_retval);
1589 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1590 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1595 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1597 struct truncate_args ap;
1599 ap.path = uap->path;
1600 ap.length = PAIR32TO64(off_t,uap->length);
1601 return (sys_truncate(td, &ap));
1605 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1607 struct ftruncate_args ap;
1610 ap.length = PAIR32TO64(off_t,uap->length);
1611 return (sys_ftruncate(td, &ap));
1613 #endif /* COMPAT_FREEBSD6 */
1623 freebsd32_do_sendfile(struct thread *td,
1624 struct freebsd32_sendfile_args *uap, int compat)
1626 struct sf_hdtr32 hdtr32;
1627 struct sf_hdtr hdtr;
1628 struct uio *hdr_uio, *trl_uio;
1630 cap_rights_t rights;
1631 struct iovec32 *iov32;
1632 off_t offset, sbytes;
1635 offset = PAIR32TO64(off_t, uap->offset);
1639 hdr_uio = trl_uio = NULL;
1641 if (uap->hdtr != NULL) {
1642 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1645 PTRIN_CP(hdtr32, hdtr, headers);
1646 CP(hdtr32, hdtr, hdr_cnt);
1647 PTRIN_CP(hdtr32, hdtr, trailers);
1648 CP(hdtr32, hdtr, trl_cnt);
1650 if (hdtr.headers != NULL) {
1651 iov32 = PTRIN(hdtr32.headers);
1652 error = freebsd32_copyinuio(iov32,
1653 hdtr32.hdr_cnt, &hdr_uio);
1656 #ifdef COMPAT_FREEBSD4
1658 * In FreeBSD < 5.0 the nbytes to send also included
1659 * the header. If compat is specified subtract the
1660 * header size from nbytes.
1663 if (uap->nbytes > hdr_uio->uio_resid)
1664 uap->nbytes -= hdr_uio->uio_resid;
1670 if (hdtr.trailers != NULL) {
1671 iov32 = PTRIN(hdtr32.trailers);
1672 error = freebsd32_copyinuio(iov32,
1673 hdtr32.trl_cnt, &trl_uio);
1679 AUDIT_ARG_FD(uap->fd);
1681 if ((error = fget_read(td, uap->fd,
1682 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0)
1685 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1686 uap->nbytes, &sbytes, uap->flags, td);
1689 if (uap->sbytes != NULL)
1690 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1694 free(hdr_uio, M_IOV);
1696 free(trl_uio, M_IOV);
1700 #ifdef COMPAT_FREEBSD4
1702 freebsd4_freebsd32_sendfile(struct thread *td,
1703 struct freebsd4_freebsd32_sendfile_args *uap)
1705 return (freebsd32_do_sendfile(td,
1706 (struct freebsd32_sendfile_args *)uap, 1));
1711 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1714 return (freebsd32_do_sendfile(td, uap, 0));
1718 copy_stat(struct stat *in, struct stat32 *out)
1721 CP(*in, *out, st_dev);
1722 CP(*in, *out, st_ino);
1723 CP(*in, *out, st_mode);
1724 CP(*in, *out, st_nlink);
1725 CP(*in, *out, st_uid);
1726 CP(*in, *out, st_gid);
1727 CP(*in, *out, st_rdev);
1728 TS_CP(*in, *out, st_atim);
1729 TS_CP(*in, *out, st_mtim);
1730 TS_CP(*in, *out, st_ctim);
1731 CP(*in, *out, st_size);
1732 CP(*in, *out, st_blocks);
1733 CP(*in, *out, st_blksize);
1734 CP(*in, *out, st_flags);
1735 CP(*in, *out, st_gen);
1736 TS_CP(*in, *out, st_birthtim);
1741 copy_ostat(struct stat *in, struct ostat32 *out)
1744 CP(*in, *out, st_dev);
1745 CP(*in, *out, st_ino);
1746 CP(*in, *out, st_mode);
1747 CP(*in, *out, st_nlink);
1748 CP(*in, *out, st_uid);
1749 CP(*in, *out, st_gid);
1750 CP(*in, *out, st_rdev);
1751 CP(*in, *out, st_size);
1752 TS_CP(*in, *out, st_atim);
1753 TS_CP(*in, *out, st_mtim);
1754 TS_CP(*in, *out, st_ctim);
1755 CP(*in, *out, st_blksize);
1756 CP(*in, *out, st_blocks);
1757 CP(*in, *out, st_flags);
1758 CP(*in, *out, st_gen);
1763 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1769 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1773 copy_stat(&sb, &sb32);
1774 error = copyout(&sb32, uap->ub, sizeof (sb32));
1780 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1783 struct ostat32 sb32;
1786 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE,
1790 copy_ostat(&sb, &sb32);
1791 error = copyout(&sb32, uap->ub, sizeof (sb32));
1797 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1803 error = kern_fstat(td, uap->fd, &ub);
1806 copy_stat(&ub, &ub32);
1807 error = copyout(&ub32, uap->ub, sizeof(ub32));
1813 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1816 struct ostat32 ub32;
1819 error = kern_fstat(td, uap->fd, &ub);
1822 copy_ostat(&ub, &ub32);
1823 error = copyout(&ub32, uap->ub, sizeof(ub32));
1829 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1835 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
1839 copy_stat(&ub, &ub32);
1840 error = copyout(&ub32, uap->buf, sizeof(ub32));
1845 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1851 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1852 UIO_USERSPACE, &sb, NULL);
1855 copy_stat(&sb, &sb32);
1856 error = copyout(&sb32, uap->ub, sizeof (sb32));
1862 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1865 struct ostat32 sb32;
1868 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
1869 UIO_USERSPACE, &sb, NULL);
1872 copy_ostat(&sb, &sb32);
1873 error = copyout(&sb32, uap->ub, sizeof (sb32));
1879 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1881 int error, name[CTL_MAXNAME];
1885 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1887 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1891 error = fueword32(uap->oldlenp, &tmp);
1898 error = userland_sysctl(td, name, uap->namelen,
1899 uap->old, &oldlen, 1,
1900 uap->new, uap->newlen, &j, SCTL_MASK32);
1901 if (error && error != ENOMEM)
1904 suword32(uap->oldlenp, j);
1909 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1915 error = copyin(uap->jail, &version, sizeof(uint32_t));
1922 /* FreeBSD single IPv4 jails. */
1923 struct jail32_v0 j32_v0;
1925 bzero(&j, sizeof(struct jail));
1926 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1929 CP(j32_v0, j, version);
1930 PTRIN_CP(j32_v0, j, path);
1931 PTRIN_CP(j32_v0, j, hostname);
1932 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1938 * Version 1 was used by multi-IPv4 jail implementations
1939 * that never made it into the official kernel.
1943 case 2: /* JAIL_API_VERSION */
1945 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1948 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1951 CP(j32, j, version);
1952 PTRIN_CP(j32, j, path);
1953 PTRIN_CP(j32, j, hostname);
1954 PTRIN_CP(j32, j, jailname);
1957 PTRIN_CP(j32, j, ip4);
1958 PTRIN_CP(j32, j, ip6);
1963 /* Sci-Fi jails are not supported, sorry. */
1966 return (kern_jail(td, &j));
1970 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
1975 /* Check that we have an even number of iovecs. */
1976 if (uap->iovcnt & 1)
1979 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1982 error = kern_jail_set(td, auio, uap->flags);
1988 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
1990 struct iovec32 iov32;
1994 /* Check that we have an even number of iovecs. */
1995 if (uap->iovcnt & 1)
1998 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2001 error = kern_jail_get(td, auio, uap->flags);
2003 for (i = 0; i < uap->iovcnt; i++) {
2004 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2005 CP(auio->uio_iov[i], iov32, iov_len);
2006 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2015 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2017 struct sigaction32 s32;
2018 struct sigaction sa, osa, *sap;
2022 error = copyin(uap->act, &s32, sizeof(s32));
2025 sa.sa_handler = PTRIN(s32.sa_u);
2026 CP(s32, sa, sa_flags);
2027 CP(s32, sa, sa_mask);
2031 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2032 if (error == 0 && uap->oact != NULL) {
2033 s32.sa_u = PTROUT(osa.sa_handler);
2034 CP(osa, s32, sa_flags);
2035 CP(osa, s32, sa_mask);
2036 error = copyout(&s32, uap->oact, sizeof(s32));
2041 #ifdef COMPAT_FREEBSD4
2043 freebsd4_freebsd32_sigaction(struct thread *td,
2044 struct freebsd4_freebsd32_sigaction_args *uap)
2046 struct sigaction32 s32;
2047 struct sigaction sa, osa, *sap;
2051 error = copyin(uap->act, &s32, sizeof(s32));
2054 sa.sa_handler = PTRIN(s32.sa_u);
2055 CP(s32, sa, sa_flags);
2056 CP(s32, sa, sa_mask);
2060 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2061 if (error == 0 && uap->oact != NULL) {
2062 s32.sa_u = PTROUT(osa.sa_handler);
2063 CP(osa, s32, sa_flags);
2064 CP(osa, s32, sa_mask);
2065 error = copyout(&s32, uap->oact, sizeof(s32));
2072 struct osigaction32 {
2081 ofreebsd32_sigaction(struct thread *td,
2082 struct ofreebsd32_sigaction_args *uap)
2084 struct osigaction32 s32;
2085 struct sigaction sa, osa, *sap;
2088 if (uap->signum <= 0 || uap->signum >= ONSIG)
2092 error = copyin(uap->nsa, &s32, sizeof(s32));
2095 sa.sa_handler = PTRIN(s32.sa_u);
2096 CP(s32, sa, sa_flags);
2097 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2101 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2102 if (error == 0 && uap->osa != NULL) {
2103 s32.sa_u = PTROUT(osa.sa_handler);
2104 CP(osa, s32, sa_flags);
2105 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2106 error = copyout(&s32, uap->osa, sizeof(s32));
2112 ofreebsd32_sigprocmask(struct thread *td,
2113 struct ofreebsd32_sigprocmask_args *uap)
2118 OSIG2SIG(uap->mask, set);
2119 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2120 SIG2OSIG(oset, td->td_retval[0]);
2125 ofreebsd32_sigpending(struct thread *td,
2126 struct ofreebsd32_sigpending_args *uap)
2128 struct proc *p = td->td_proc;
2132 siglist = p->p_siglist;
2133 SIGSETOR(siglist, td->td_siglist);
2135 SIG2OSIG(siglist, td->td_retval[0]);
2140 u_int32_t sv_handler;
2146 ofreebsd32_sigvec(struct thread *td,
2147 struct ofreebsd32_sigvec_args *uap)
2149 struct sigvec32 vec;
2150 struct sigaction sa, osa, *sap;
2153 if (uap->signum <= 0 || uap->signum >= ONSIG)
2157 error = copyin(uap->nsv, &vec, sizeof(vec));
2160 sa.sa_handler = PTRIN(vec.sv_handler);
2161 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2162 sa.sa_flags = vec.sv_flags;
2163 sa.sa_flags ^= SA_RESTART;
2167 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2168 if (error == 0 && uap->osv != NULL) {
2169 vec.sv_handler = PTROUT(osa.sa_handler);
2170 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2171 vec.sv_flags = osa.sa_flags;
2172 vec.sv_flags &= ~SA_NOCLDWAIT;
2173 vec.sv_flags ^= SA_RESTART;
2174 error = copyout(&vec, uap->osv, sizeof(vec));
2180 ofreebsd32_sigblock(struct thread *td,
2181 struct ofreebsd32_sigblock_args *uap)
2185 OSIG2SIG(uap->mask, set);
2186 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2187 SIG2OSIG(oset, td->td_retval[0]);
2192 ofreebsd32_sigsetmask(struct thread *td,
2193 struct ofreebsd32_sigsetmask_args *uap)
2197 OSIG2SIG(uap->mask, set);
2198 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2199 SIG2OSIG(oset, td->td_retval[0]);
2204 ofreebsd32_sigsuspend(struct thread *td,
2205 struct ofreebsd32_sigsuspend_args *uap)
2209 OSIG2SIG(uap->mask, mask);
2210 return (kern_sigsuspend(td, mask));
2219 ofreebsd32_sigstack(struct thread *td,
2220 struct ofreebsd32_sigstack_args *uap)
2222 struct sigstack32 s32;
2223 struct sigstack nss, oss;
2224 int error = 0, unss;
2226 if (uap->nss != NULL) {
2227 error = copyin(uap->nss, &s32, sizeof(s32));
2230 nss.ss_sp = PTRIN(s32.ss_sp);
2231 CP(s32, nss, ss_onstack);
2236 oss.ss_sp = td->td_sigstk.ss_sp;
2237 oss.ss_onstack = sigonstack(cpu_getstack(td));
2239 td->td_sigstk.ss_sp = nss.ss_sp;
2240 td->td_sigstk.ss_size = 0;
2241 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2242 td->td_pflags |= TDP_ALTSTACK;
2244 if (uap->oss != NULL) {
2245 s32.ss_sp = PTROUT(oss.ss_sp);
2246 CP(oss, s32, ss_onstack);
2247 error = copyout(&s32, uap->oss, sizeof(s32));
2254 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2256 struct timespec32 rmt32, rqt32;
2257 struct timespec rmt, rqt;
2260 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2264 CP(rqt32, rqt, tv_sec);
2265 CP(rqt32, rqt, tv_nsec);
2268 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2270 error = kern_nanosleep(td, &rqt, &rmt);
2271 if (error && uap->rmtp) {
2274 CP(rmt, rmt32, tv_sec);
2275 CP(rmt, rmt32, tv_nsec);
2277 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2285 freebsd32_clock_gettime(struct thread *td,
2286 struct freebsd32_clock_gettime_args *uap)
2288 struct timespec ats;
2289 struct timespec32 ats32;
2292 error = kern_clock_gettime(td, uap->clock_id, &ats);
2294 CP(ats, ats32, tv_sec);
2295 CP(ats, ats32, tv_nsec);
2296 error = copyout(&ats32, uap->tp, sizeof(ats32));
2302 freebsd32_clock_settime(struct thread *td,
2303 struct freebsd32_clock_settime_args *uap)
2305 struct timespec ats;
2306 struct timespec32 ats32;
2309 error = copyin(uap->tp, &ats32, sizeof(ats32));
2312 CP(ats32, ats, tv_sec);
2313 CP(ats32, ats, tv_nsec);
2315 return (kern_clock_settime(td, uap->clock_id, &ats));
2319 freebsd32_clock_getres(struct thread *td,
2320 struct freebsd32_clock_getres_args *uap)
2323 struct timespec32 ts32;
2326 if (uap->tp == NULL)
2328 error = kern_clock_getres(td, uap->clock_id, &ts);
2330 CP(ts, ts32, tv_sec);
2331 CP(ts, ts32, tv_nsec);
2332 error = copyout(&ts32, uap->tp, sizeof(ts32));
2337 int freebsd32_ktimer_create(struct thread *td,
2338 struct freebsd32_ktimer_create_args *uap)
2340 struct sigevent32 ev32;
2341 struct sigevent ev, *evp;
2344 if (uap->evp == NULL) {
2348 error = copyin(uap->evp, &ev32, sizeof(ev32));
2351 error = convert_sigevent32(&ev32, &ev);
2355 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2357 error = copyout(&id, uap->timerid, sizeof(int));
2359 kern_ktimer_delete(td, id);
2365 freebsd32_ktimer_settime(struct thread *td,
2366 struct freebsd32_ktimer_settime_args *uap)
2368 struct itimerspec32 val32, oval32;
2369 struct itimerspec val, oval, *ovalp;
2372 error = copyin(uap->value, &val32, sizeof(val32));
2376 ovalp = uap->ovalue != NULL ? &oval : NULL;
2377 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2378 if (error == 0 && uap->ovalue != NULL) {
2379 ITS_CP(oval, oval32);
2380 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2386 freebsd32_ktimer_gettime(struct thread *td,
2387 struct freebsd32_ktimer_gettime_args *uap)
2389 struct itimerspec32 val32;
2390 struct itimerspec val;
2393 error = kern_ktimer_gettime(td, uap->timerid, &val);
2396 error = copyout(&val32, uap->value, sizeof(val32));
2402 freebsd32_clock_getcpuclockid2(struct thread *td,
2403 struct freebsd32_clock_getcpuclockid2_args *uap)
2408 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2409 uap->which, &clk_id);
2411 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2416 freebsd32_thr_new(struct thread *td,
2417 struct freebsd32_thr_new_args *uap)
2419 struct thr_param32 param32;
2420 struct thr_param param;
2423 if (uap->param_size < 0 ||
2424 uap->param_size > sizeof(struct thr_param32))
2426 bzero(¶m, sizeof(struct thr_param));
2427 bzero(¶m32, sizeof(struct thr_param32));
2428 error = copyin(uap->param, ¶m32, uap->param_size);
2431 param.start_func = PTRIN(param32.start_func);
2432 param.arg = PTRIN(param32.arg);
2433 param.stack_base = PTRIN(param32.stack_base);
2434 param.stack_size = param32.stack_size;
2435 param.tls_base = PTRIN(param32.tls_base);
2436 param.tls_size = param32.tls_size;
2437 param.child_tid = PTRIN(param32.child_tid);
2438 param.parent_tid = PTRIN(param32.parent_tid);
2439 param.flags = param32.flags;
2440 param.rtp = PTRIN(param32.rtp);
2441 param.spare[0] = PTRIN(param32.spare[0]);
2442 param.spare[1] = PTRIN(param32.spare[1]);
2443 param.spare[2] = PTRIN(param32.spare[2]);
2445 return (kern_thr_new(td, ¶m));
2449 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2451 struct timespec32 ts32;
2452 struct timespec ts, *tsp;
2457 if (uap->timeout != NULL) {
2458 error = copyin((const void *)uap->timeout, (void *)&ts32,
2459 sizeof(struct timespec32));
2462 ts.tv_sec = ts32.tv_sec;
2463 ts.tv_nsec = ts32.tv_nsec;
2466 return (kern_thr_suspend(td, tsp));
2470 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2472 bzero(dst, sizeof(*dst));
2473 dst->si_signo = src->si_signo;
2474 dst->si_errno = src->si_errno;
2475 dst->si_code = src->si_code;
2476 dst->si_pid = src->si_pid;
2477 dst->si_uid = src->si_uid;
2478 dst->si_status = src->si_status;
2479 dst->si_addr = (uintptr_t)src->si_addr;
2480 dst->si_value.sival_int = src->si_value.sival_int;
2481 dst->si_timerid = src->si_timerid;
2482 dst->si_overrun = src->si_overrun;
2486 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2488 struct timespec32 ts32;
2490 struct timespec *timeout;
2493 struct siginfo32 si32;
2497 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2500 ts.tv_sec = ts32.tv_sec;
2501 ts.tv_nsec = ts32.tv_nsec;
2506 error = copyin(uap->set, &set, sizeof(set));
2510 error = kern_sigtimedwait(td, set, &ksi, timeout);
2515 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2516 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2520 td->td_retval[0] = ksi.ksi_signo;
2528 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2531 struct siginfo32 si32;
2535 error = copyin(uap->set, &set, sizeof(set));
2539 error = kern_sigtimedwait(td, set, &ksi, NULL);
2544 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2545 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2548 td->td_retval[0] = ksi.ksi_signo;
2553 freebsd32_cpuset_setid(struct thread *td,
2554 struct freebsd32_cpuset_setid_args *uap)
2556 struct cpuset_setid_args ap;
2558 ap.which = uap->which;
2559 ap.id = PAIR32TO64(id_t,uap->id);
2560 ap.setid = uap->setid;
2562 return (sys_cpuset_setid(td, &ap));
2566 freebsd32_cpuset_getid(struct thread *td,
2567 struct freebsd32_cpuset_getid_args *uap)
2569 struct cpuset_getid_args ap;
2571 ap.level = uap->level;
2572 ap.which = uap->which;
2573 ap.id = PAIR32TO64(id_t,uap->id);
2574 ap.setid = uap->setid;
2576 return (sys_cpuset_getid(td, &ap));
2580 freebsd32_cpuset_getaffinity(struct thread *td,
2581 struct freebsd32_cpuset_getaffinity_args *uap)
2583 struct cpuset_getaffinity_args ap;
2585 ap.level = uap->level;
2586 ap.which = uap->which;
2587 ap.id = PAIR32TO64(id_t,uap->id);
2588 ap.cpusetsize = uap->cpusetsize;
2589 ap.mask = uap->mask;
2591 return (sys_cpuset_getaffinity(td, &ap));
2595 freebsd32_cpuset_setaffinity(struct thread *td,
2596 struct freebsd32_cpuset_setaffinity_args *uap)
2598 struct cpuset_setaffinity_args ap;
2600 ap.level = uap->level;
2601 ap.which = uap->which;
2602 ap.id = PAIR32TO64(id_t,uap->id);
2603 ap.cpusetsize = uap->cpusetsize;
2604 ap.mask = uap->mask;
2606 return (sys_cpuset_setaffinity(td, &ap));
2610 freebsd32_nmount(struct thread *td,
2611 struct freebsd32_nmount_args /* {
2613 unsigned int iovcnt;
2622 * Mount flags are now 64-bits. On 32-bit archtectures only
2623 * 32-bits are passed in, but from here on everything handles
2624 * 64-bit flags correctly.
2628 AUDIT_ARG_FFLAGS(flags);
2631 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2632 * userspace to set this flag, but we must filter it out if we want
2633 * MNT_UPDATE on the root file system to work.
2634 * MNT_ROOTFS should only be set by the kernel when mounting its
2637 flags &= ~MNT_ROOTFS;
2640 * check that we have an even number of iovec's
2641 * and that we have at least two options.
2643 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2646 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2649 error = vfs_donmount(td, flags, auio);
2657 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2659 struct yyy32 *p32, s32;
2660 struct yyy *p = NULL, s;
2665 error = copyin(uap->zzz, &s32, sizeof(s32));
2671 error = kern_xxx(td, p);
2676 error = copyout(&s32, p32, sizeof(s32));
2683 syscall32_register(int *offset, struct sysent *new_sysent,
2684 struct sysent *old_sysent, int flags)
2687 if ((flags & ~SY_THR_STATIC) != 0)
2690 if (*offset == NO_SYSCALL) {
2693 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2694 if (freebsd32_sysent[i].sy_call ==
2695 (sy_call_t *)lkmnosys)
2697 if (i == SYS_MAXSYSCALL)
2700 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2702 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2703 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2706 *old_sysent = freebsd32_sysent[*offset];
2707 freebsd32_sysent[*offset] = *new_sysent;
2708 atomic_store_rel_32(&freebsd32_sysent[*offset].sy_thrcnt, flags);
2713 syscall32_deregister(int *offset, struct sysent *old_sysent)
2719 freebsd32_sysent[*offset] = *old_sysent;
2724 syscall32_module_handler(struct module *mod, int what, void *arg)
2726 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2732 error = syscall32_register(data->offset, data->new_sysent,
2733 &data->old_sysent, SY_THR_STATIC_KLD);
2735 /* Leave a mark so we know to safely unload below. */
2736 data->offset = NULL;
2739 ms.intval = *data->offset;
2741 module_setspecific(mod, &ms);
2744 error = data->chainevh(mod, what, data->chainarg);
2748 * MOD_LOAD failed, so just return without calling the
2749 * chained handler since we didn't pass along the MOD_LOAD
2752 if (data->offset == NULL)
2754 if (data->chainevh) {
2755 error = data->chainevh(mod, what, data->chainarg);
2759 error = syscall32_deregister(data->offset, &data->old_sysent);
2764 error = data->chainevh(mod, what, data->chainarg);
2770 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
2772 struct syscall_helper_data *sd1;
2775 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2776 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2777 &sd1->old_sysent, flags);
2779 syscall32_helper_unregister(sd);
2782 sd1->registered = 1;
2788 syscall32_helper_unregister(struct syscall_helper_data *sd)
2790 struct syscall_helper_data *sd1;
2792 for (sd1 = sd; sd1->registered != 0; sd1++) {
2793 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2794 sd1->registered = 0;
2800 freebsd32_copyout_strings(struct image_params *imgp)
2806 u_int32_t *stack_base;
2807 struct freebsd32_ps_strings *arginfo;
2808 char canary[sizeof(long) * 8];
2809 int32_t pagesizes32[MAXPAGESIZES];
2810 size_t execpath_len;
2814 * Calculate string base and vector table pointers.
2815 * Also deal with signal trampoline code for this exec type.
2817 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2818 execpath_len = strlen(imgp->execpath) + 1;
2821 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2823 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2824 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2827 destp = (uintptr_t)arginfo;
2832 if (szsigcode != 0) {
2834 destp = rounddown2(destp, sizeof(uint32_t));
2835 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2840 * Copy the image path for the rtld.
2842 if (execpath_len != 0) {
2843 destp -= execpath_len;
2844 imgp->execpathp = destp;
2845 copyout(imgp->execpath, (void *)destp, execpath_len);
2849 * Prepare the canary for SSP.
2851 arc4rand(canary, sizeof(canary), 0);
2852 destp -= sizeof(canary);
2853 imgp->canary = destp;
2854 copyout(canary, (void *)destp, sizeof(canary));
2855 imgp->canarylen = sizeof(canary);
2858 * Prepare the pagesizes array.
2860 for (i = 0; i < MAXPAGESIZES; i++)
2861 pagesizes32[i] = (uint32_t)pagesizes[i];
2862 destp -= sizeof(pagesizes32);
2863 destp = rounddown2(destp, sizeof(uint32_t));
2864 imgp->pagesizes = destp;
2865 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2866 imgp->pagesizeslen = sizeof(pagesizes32);
2868 destp -= ARG_MAX - imgp->args->stringspace;
2869 destp = rounddown2(destp, sizeof(uint32_t));
2872 * If we have a valid auxargs ptr, prepare some room
2875 if (imgp->auxargs) {
2877 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2878 * lower compatibility.
2880 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2883 * The '+ 2' is for the null pointers at the end of each of
2884 * the arg and env vector sets,and imgp->auxarg_size is room
2885 * for argument of Runtime loader.
2887 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2888 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2892 * The '+ 2' is for the null pointers at the end of each of
2893 * the arg and env vector sets
2895 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2896 imgp->args->envc + 2) * sizeof(u_int32_t));
2900 * vectp also becomes our initial stack base
2904 stringp = imgp->args->begin_argv;
2905 argc = imgp->args->argc;
2906 envc = imgp->args->envc;
2908 * Copy out strings - arguments and environment.
2910 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2913 * Fill in "ps_strings" struct for ps, w, etc.
2915 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2916 suword32(&arginfo->ps_nargvstr, argc);
2919 * Fill in argument portion of vector table.
2921 for (; argc > 0; --argc) {
2922 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2923 while (*stringp++ != 0)
2928 /* a null vector table pointer separates the argp's from the envp's */
2929 suword32(vectp++, 0);
2931 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2932 suword32(&arginfo->ps_nenvstr, envc);
2935 * Fill in environment portion of vector table.
2937 for (; envc > 0; --envc) {
2938 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2939 while (*stringp++ != 0)
2944 /* end of vector table is a null pointer */
2947 return ((register_t *)stack_base);
2951 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2953 struct kld_file_stat stat;
2954 struct kld32_file_stat stat32;
2957 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2960 if (version != sizeof(struct kld32_file_stat_1) &&
2961 version != sizeof(struct kld32_file_stat))
2964 error = kern_kldstat(td, uap->fileid, &stat);
2968 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2969 CP(stat, stat32, refs);
2970 CP(stat, stat32, id);
2971 PTROUT_CP(stat, stat32, address);
2972 CP(stat, stat32, size);
2973 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2974 return (copyout(&stat32, uap->stat, version));
2978 freebsd32_posix_fallocate(struct thread *td,
2979 struct freebsd32_posix_fallocate_args *uap)
2983 error = kern_posix_fallocate(td, uap->fd,
2984 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
2985 return (kern_posix_error(td, error));
2989 freebsd32_posix_fadvise(struct thread *td,
2990 struct freebsd32_posix_fadvise_args *uap)
2994 error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2995 PAIR32TO64(off_t, uap->len), uap->advice);
2996 return (kern_posix_error(td, error));
3000 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3003 CP(*sig32, *sig, sigev_notify);
3004 switch (sig->sigev_notify) {
3007 case SIGEV_THREAD_ID:
3008 CP(*sig32, *sig, sigev_notify_thread_id);
3011 CP(*sig32, *sig, sigev_signo);
3012 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3015 CP(*sig32, *sig, sigev_notify_kqueue);
3016 CP(*sig32, *sig, sigev_notify_kevent_flags);
3017 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3026 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3030 struct procctl_reaper_status rs;
3031 struct procctl_reaper_pids rp;
3032 struct procctl_reaper_kill rk;
3035 struct procctl_reaper_pids32 rp;
3037 int error, error1, flags;
3041 case PROC_TRACE_CTL:
3042 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3047 case PROC_REAP_ACQUIRE:
3048 case PROC_REAP_RELEASE:
3049 if (uap->data != NULL)
3053 case PROC_REAP_STATUS:
3056 case PROC_REAP_GETPIDS:
3057 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3060 CP(x32.rp, x.rp, rp_count);
3061 PTRIN_CP(x32.rp, x.rp, rp_pids);
3064 case PROC_REAP_KILL:
3065 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3070 case PROC_TRACE_STATUS:
3076 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3079 case PROC_REAP_STATUS:
3081 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3083 case PROC_REAP_KILL:
3084 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3088 case PROC_TRACE_STATUS:
3090 error = copyout(&flags, uap->data, sizeof(flags));
3097 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3103 * Do unsigned conversion for arg when operation
3104 * interprets it as flags or pointer.
3106 case F_SETLK_REMOTE:
3115 tmp = (unsigned int)(uap->arg);
3121 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3125 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3127 struct timespec32 ts32;
3128 struct timespec ts, *tsp;
3132 if (uap->ts != NULL) {
3133 error = copyin(uap->ts, &ts32, sizeof(ts32));
3136 CP(ts32, ts, tv_sec);
3137 CP(ts32, ts, tv_nsec);
3141 if (uap->set != NULL) {
3142 error = copyin(uap->set, &set, sizeof(set));
3149 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));