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>
86 #include <sys/condvar.h>
87 #include <sys/sf_buf.h>
88 #include <sys/sf_sync.h>
89 #include <sys/sf_base.h>
92 #include <netinet/in.h>
96 #include <vm/vm_param.h>
98 #include <vm/vm_map.h>
99 #include <vm/vm_object.h>
100 #include <vm/vm_extern.h>
102 #include <machine/cpu.h>
103 #include <machine/elf.h>
105 #include <security/audit/audit.h>
107 #include <compat/freebsd32/freebsd32_util.h>
108 #include <compat/freebsd32/freebsd32.h>
109 #include <compat/freebsd32/freebsd32_ipc.h>
110 #include <compat/freebsd32/freebsd32_misc.h>
111 #include <compat/freebsd32/freebsd32_signal.h>
112 #include <compat/freebsd32/freebsd32_proto.h>
114 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
117 CTASSERT(sizeof(struct timeval32) == 8);
118 CTASSERT(sizeof(struct timespec32) == 8);
119 CTASSERT(sizeof(struct itimerval32) == 16);
121 CTASSERT(sizeof(struct statfs32) == 256);
123 CTASSERT(sizeof(struct rusage32) == 72);
125 CTASSERT(sizeof(struct sigaltstack32) == 12);
126 CTASSERT(sizeof(struct kevent32) == 20);
127 CTASSERT(sizeof(struct iovec32) == 8);
128 CTASSERT(sizeof(struct msghdr32) == 28);
130 CTASSERT(sizeof(struct stat32) == 96);
132 CTASSERT(sizeof(struct sigaction32) == 24);
134 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
135 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
138 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
141 TV_CP(*s, *s32, ru_utime);
142 TV_CP(*s, *s32, ru_stime);
143 CP(*s, *s32, ru_maxrss);
144 CP(*s, *s32, ru_ixrss);
145 CP(*s, *s32, ru_idrss);
146 CP(*s, *s32, ru_isrss);
147 CP(*s, *s32, ru_minflt);
148 CP(*s, *s32, ru_majflt);
149 CP(*s, *s32, ru_nswap);
150 CP(*s, *s32, ru_inblock);
151 CP(*s, *s32, ru_oublock);
152 CP(*s, *s32, ru_msgsnd);
153 CP(*s, *s32, ru_msgrcv);
154 CP(*s, *s32, ru_nsignals);
155 CP(*s, *s32, ru_nvcsw);
156 CP(*s, *s32, ru_nivcsw);
160 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
163 struct rusage32 ru32;
164 struct rusage ru, *rup;
166 if (uap->rusage != NULL)
170 error = kern_wait(td, uap->pid, &status, uap->options, rup);
173 if (uap->status != NULL)
174 error = copyout(&status, uap->status, sizeof(status));
175 if (uap->rusage != NULL && error == 0) {
176 freebsd32_rusage_out(&ru, &ru32);
177 error = copyout(&ru32, uap->rusage, sizeof(ru32));
183 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
185 struct wrusage32 wru32;
186 struct __wrusage wru, *wrup;
187 struct siginfo32 si32;
188 struct __siginfo si, *sip;
191 if (uap->wrusage != NULL)
195 if (uap->info != NULL) {
197 bzero(sip, sizeof(*sip));
200 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
201 &status, uap->options, wrup, sip);
204 if (uap->status != NULL)
205 error = copyout(&status, uap->status, sizeof(status));
206 if (uap->wrusage != NULL && error == 0) {
207 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
208 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
209 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
211 if (uap->info != NULL && error == 0) {
212 siginfo_to_siginfo32 (&si, &si32);
213 error = copyout(&si32, uap->info, sizeof(si32));
218 #ifdef COMPAT_FREEBSD4
220 copy_statfs(struct statfs *in, struct statfs32 *out)
223 statfs_scale_blocks(in, INT32_MAX);
224 bzero(out, sizeof(*out));
225 CP(*in, *out, f_bsize);
226 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
227 CP(*in, *out, f_blocks);
228 CP(*in, *out, f_bfree);
229 CP(*in, *out, f_bavail);
230 out->f_files = MIN(in->f_files, INT32_MAX);
231 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
232 CP(*in, *out, f_fsid);
233 CP(*in, *out, f_owner);
234 CP(*in, *out, f_type);
235 CP(*in, *out, f_flags);
236 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
237 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
238 strlcpy(out->f_fstypename,
239 in->f_fstypename, MFSNAMELEN);
240 strlcpy(out->f_mntonname,
241 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
242 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
243 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
244 strlcpy(out->f_mntfromname,
245 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
249 #ifdef COMPAT_FREEBSD4
251 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
253 struct statfs *buf, *sp;
254 struct statfs32 stat32;
258 count = uap->bufsize / sizeof(struct statfs32);
259 size = count * sizeof(struct statfs);
260 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
262 count = td->td_retval[0];
264 while (count > 0 && error == 0) {
265 copy_statfs(sp, &stat32);
266 error = copyout(&stat32, uap->buf, sizeof(stat32));
278 freebsd32_sigaltstack(struct thread *td,
279 struct freebsd32_sigaltstack_args *uap)
281 struct sigaltstack32 s32;
282 struct sigaltstack ss, oss, *ssp;
285 if (uap->ss != NULL) {
286 error = copyin(uap->ss, &s32, sizeof(s32));
289 PTRIN_CP(s32, ss, ss_sp);
290 CP(s32, ss, ss_size);
291 CP(s32, ss, ss_flags);
295 error = kern_sigaltstack(td, ssp, &oss);
296 if (error == 0 && uap->oss != NULL) {
297 PTROUT_CP(oss, s32, ss_sp);
298 CP(oss, s32, ss_size);
299 CP(oss, s32, ss_flags);
300 error = copyout(&s32, uap->oss, sizeof(s32));
306 * Custom version of exec_copyin_args() so that we can translate
310 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
311 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
318 bzero(args, sizeof(*args));
323 * Allocate demand-paged memory for the file name, argument, and
324 * environment strings.
326 error = exec_alloc_args(args);
331 * Copy the file name.
334 args->fname = args->buf;
335 error = (segflg == UIO_SYSSPACE) ?
336 copystr(fname, args->fname, PATH_MAX, &length) :
337 copyinstr(fname, args->fname, PATH_MAX, &length);
343 args->begin_argv = args->buf + length;
344 args->endp = args->begin_argv;
345 args->stringspace = ARG_MAX;
348 * extract arguments first
352 error = copyin(p32++, &arg, sizeof(arg));
358 error = copyinstr(argp, args->endp, args->stringspace, &length);
360 if (error == ENAMETOOLONG)
364 args->stringspace -= length;
365 args->endp += length;
369 args->begin_envv = args->endp;
372 * extract environment strings
377 error = copyin(p32++, &arg, sizeof(arg));
383 error = copyinstr(envp, args->endp, args->stringspace,
386 if (error == ENAMETOOLONG)
390 args->stringspace -= length;
391 args->endp += length;
399 exec_free_args(args);
404 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
406 struct image_args eargs;
409 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
410 uap->argv, uap->envv);
412 error = kern_execve(td, &eargs, NULL);
417 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
419 struct image_args eargs;
422 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
423 uap->argv, uap->envv);
426 error = kern_execve(td, &eargs, NULL);
433 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
434 int prot, int fd, off_t pos)
437 vm_map_entry_t entry;
440 map = &td->td_proc->p_vmspace->vm_map;
442 prot |= VM_PROT_WRITE;
444 if (vm_map_lookup_entry(map, start, &entry)) {
445 if ((entry->protection & prot) != prot) {
446 rv = vm_map_protect(map,
449 entry->protection | prot,
451 if (rv != KERN_SUCCESS)
455 vm_offset_t addr = trunc_page(start);
456 rv = vm_map_find(map, NULL, 0, &addr, PAGE_SIZE, 0,
457 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
458 if (rv != KERN_SUCCESS)
465 r.buf = (void *) start;
466 r.nbyte = end - start;
468 return (sys_pread(td, &r));
470 while (start < end) {
471 subyte((void *) start, 0);
480 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
482 struct mprotect_args ap;
484 ap.addr = PTRIN(uap->addr);
487 #if defined(__amd64__) || defined(__ia64__)
488 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
489 ap.prot |= PROT_EXEC;
491 return (sys_mprotect(td, &ap));
495 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
498 vm_offset_t addr = (vm_offset_t) uap->addr;
499 vm_size_t len = uap->len;
500 int prot = uap->prot;
501 int flags = uap->flags;
503 off_t pos = PAIR32TO64(off_t,uap->pos);
509 * Attempt to handle page size hassles.
511 pageoff = (pos & PAGE_MASK);
512 if (flags & MAP_FIXED) {
513 vm_offset_t start, end;
517 if (start != trunc_page(start)) {
518 error = freebsd32_mmap_partial(td, start,
519 round_page(start), prot,
522 pos += round_page(start) - start;
523 start = round_page(start);
525 if (end != round_page(end)) {
526 vm_offset_t t = trunc_page(end);
527 error = freebsd32_mmap_partial(td, t, end,
530 end = trunc_page(end);
532 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
534 * We can't map this region at all. The specified
535 * address doesn't have the same alignment as the file
536 * position. Fake the mapping by simply reading the
537 * entire region into memory. First we need to make
538 * sure the region exists.
544 prot |= VM_PROT_WRITE;
545 map = &td->td_proc->p_vmspace->vm_map;
546 rv = vm_map_remove(map, start, end);
547 if (rv != KERN_SUCCESS)
549 rv = vm_map_find(map, NULL, 0, &start, end - start,
550 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
551 if (rv != KERN_SUCCESS)
554 r.buf = (void *) start;
555 r.nbyte = end - start;
557 error = sys_pread(td, &r);
561 td->td_retval[0] = addr;
566 * After dealing with the ragged ends, there
567 * might be none left.
569 td->td_retval[0] = addr;
577 #if defined(__amd64__) || defined(__ia64__)
578 if (i386_read_exec && (prot & PROT_READ))
582 ap.addr = (void *) addr;
589 return (sys_mmap(td, &ap));
592 #ifdef COMPAT_FREEBSD6
594 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
596 struct freebsd32_mmap_args ap;
601 ap.flags = uap->flags;
606 return (freebsd32_mmap(td, &ap));
611 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
613 struct itimerval itv, oitv, *itvp;
614 struct itimerval32 i32;
617 if (uap->itv != NULL) {
618 error = copyin(uap->itv, &i32, sizeof(i32));
621 TV_CP(i32, itv, it_interval);
622 TV_CP(i32, itv, it_value);
626 error = kern_setitimer(td, uap->which, itvp, &oitv);
627 if (error || uap->oitv == NULL)
629 TV_CP(oitv, i32, it_interval);
630 TV_CP(oitv, i32, it_value);
631 return (copyout(&i32, uap->oitv, sizeof(i32)));
635 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
637 struct itimerval itv;
638 struct itimerval32 i32;
641 error = kern_getitimer(td, uap->which, &itv);
642 if (error || uap->itv == NULL)
644 TV_CP(itv, i32, it_interval);
645 TV_CP(itv, i32, it_value);
646 return (copyout(&i32, uap->itv, sizeof(i32)));
650 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
652 struct timeval32 tv32;
653 struct timeval tv, *tvp;
656 if (uap->tv != NULL) {
657 error = copyin(uap->tv, &tv32, sizeof(tv32));
660 CP(tv32, tv, tv_sec);
661 CP(tv32, tv, tv_usec);
666 * XXX Do pointers need PTRIN()?
668 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
669 sizeof(int32_t) * 8));
673 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
675 struct timespec32 ts32;
677 struct timeval tv, *tvp;
681 if (uap->ts != NULL) {
682 error = copyin(uap->ts, &ts32, sizeof(ts32));
685 CP(ts32, ts, tv_sec);
686 CP(ts32, ts, tv_nsec);
687 TIMESPEC_TO_TIMEVAL(&tv, &ts);
691 if (uap->sm != NULL) {
692 error = copyin(uap->sm, &set, sizeof(set));
699 * XXX Do pointers need PTRIN()?
701 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
702 uset, sizeof(int32_t) * 8);
707 * Copy 'count' items into the destination list pointed to by uap->eventlist.
710 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
712 struct freebsd32_kevent_args *uap;
713 struct kevent32 ks32[KQ_NEVENTS];
716 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
717 uap = (struct freebsd32_kevent_args *)arg;
719 for (i = 0; i < count; i++) {
720 CP(kevp[i], ks32[i], ident);
721 CP(kevp[i], ks32[i], filter);
722 CP(kevp[i], ks32[i], flags);
723 CP(kevp[i], ks32[i], fflags);
724 CP(kevp[i], ks32[i], data);
725 PTROUT_CP(kevp[i], ks32[i], udata);
727 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
729 uap->eventlist += count;
734 * Copy 'count' items from the list pointed to by uap->changelist.
737 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
739 struct freebsd32_kevent_args *uap;
740 struct kevent32 ks32[KQ_NEVENTS];
743 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
744 uap = (struct freebsd32_kevent_args *)arg;
746 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
749 uap->changelist += count;
751 for (i = 0; i < count; i++) {
752 CP(ks32[i], kevp[i], ident);
753 CP(ks32[i], kevp[i], filter);
754 CP(ks32[i], kevp[i], flags);
755 CP(ks32[i], kevp[i], fflags);
756 CP(ks32[i], kevp[i], data);
757 PTRIN_CP(ks32[i], kevp[i], udata);
764 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
766 struct timespec32 ts32;
767 struct timespec ts, *tsp;
768 struct kevent_copyops k_ops = { uap,
769 freebsd32_kevent_copyout,
770 freebsd32_kevent_copyin};
775 error = copyin(uap->timeout, &ts32, sizeof(ts32));
778 CP(ts32, ts, tv_sec);
779 CP(ts32, ts, tv_nsec);
783 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
789 freebsd32_gettimeofday(struct thread *td,
790 struct freebsd32_gettimeofday_args *uap)
793 struct timeval32 atv32;
799 CP(atv, atv32, tv_sec);
800 CP(atv, atv32, tv_usec);
801 error = copyout(&atv32, uap->tp, sizeof (atv32));
803 if (error == 0 && uap->tzp != NULL) {
804 rtz.tz_minuteswest = tz_minuteswest;
805 rtz.tz_dsttime = tz_dsttime;
806 error = copyout(&rtz, uap->tzp, sizeof (rtz));
812 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
818 error = kern_getrusage(td, uap->who, &s);
821 if (uap->rusage != NULL) {
822 freebsd32_rusage_out(&s, &s32);
823 error = copyout(&s32, uap->rusage, sizeof(s32));
829 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
831 struct iovec32 iov32;
838 if (iovcnt > UIO_MAXIOV)
840 iovlen = iovcnt * sizeof(struct iovec);
841 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
842 iov = (struct iovec *)(uio + 1);
843 for (i = 0; i < iovcnt; i++) {
844 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
849 iov[i].iov_base = PTRIN(iov32.iov_base);
850 iov[i].iov_len = iov32.iov_len;
853 uio->uio_iovcnt = iovcnt;
854 uio->uio_segflg = UIO_USERSPACE;
855 uio->uio_offset = -1;
857 for (i = 0; i < iovcnt; i++) {
858 if (iov->iov_len > INT_MAX - uio->uio_resid) {
862 uio->uio_resid += iov->iov_len;
870 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
875 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
878 error = kern_readv(td, uap->fd, auio);
884 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
889 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
892 error = kern_writev(td, uap->fd, auio);
898 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
903 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
906 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
912 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
917 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
920 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
926 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
929 struct iovec32 iov32;
935 if (iovcnt > UIO_MAXIOV)
937 iovlen = iovcnt * sizeof(struct iovec);
938 iov = malloc(iovlen, M_IOV, M_WAITOK);
939 for (i = 0; i < iovcnt; i++) {
940 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
945 iov[i].iov_base = PTRIN(iov32.iov_base);
946 iov[i].iov_len = iov32.iov_len;
953 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
958 error = copyin(msg32, &m32, sizeof(m32));
961 msg->msg_name = PTRIN(m32.msg_name);
962 msg->msg_namelen = m32.msg_namelen;
963 msg->msg_iov = PTRIN(m32.msg_iov);
964 msg->msg_iovlen = m32.msg_iovlen;
965 msg->msg_control = PTRIN(m32.msg_control);
966 msg->msg_controllen = m32.msg_controllen;
967 msg->msg_flags = m32.msg_flags;
972 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
977 m32.msg_name = PTROUT(msg->msg_name);
978 m32.msg_namelen = msg->msg_namelen;
979 m32.msg_iov = PTROUT(msg->msg_iov);
980 m32.msg_iovlen = msg->msg_iovlen;
981 m32.msg_control = PTROUT(msg->msg_control);
982 m32.msg_controllen = msg->msg_controllen;
983 m32.msg_flags = msg->msg_flags;
984 error = copyout(&m32, msg32, sizeof(m32));
989 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
991 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
993 #define FREEBSD32_ALIGN(p) \
994 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
995 #define FREEBSD32_CMSG_SPACE(l) \
996 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
998 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
999 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1001 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1005 socklen_t clen, datalen;
1008 int len, maxlen, copylen;
1012 len = msg->msg_controllen;
1013 maxlen = msg->msg_controllen;
1014 msg->msg_controllen = 0;
1017 ctlbuf = msg->msg_control;
1019 while (m && len > 0) {
1020 cm = mtod(m, struct cmsghdr *);
1023 while (cm != NULL) {
1025 if (sizeof(struct cmsghdr) > clen ||
1026 cm->cmsg_len > clen) {
1031 data = CMSG_DATA(cm);
1032 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1034 /* Adjust message length */
1035 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1040 copylen = sizeof(struct cmsghdr);
1041 if (len < copylen) {
1042 msg->msg_flags |= MSG_CTRUNC;
1046 error = copyout(cm,ctlbuf,copylen);
1050 ctlbuf += FREEBSD32_ALIGN(copylen);
1051 len -= FREEBSD32_ALIGN(copylen);
1058 if (len < copylen) {
1059 msg->msg_flags |= MSG_CTRUNC;
1063 error = copyout(data,ctlbuf,copylen);
1067 ctlbuf += FREEBSD32_ALIGN(copylen);
1068 len -= FREEBSD32_ALIGN(copylen);
1070 if (CMSG_SPACE(datalen) < clen) {
1071 clen -= CMSG_SPACE(datalen);
1072 cm = (struct cmsghdr *)
1073 ((caddr_t)cm + CMSG_SPACE(datalen));
1082 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1090 freebsd32_recvmsg(td, uap)
1092 struct freebsd32_recvmsg_args /* {
1094 struct msghdr32 *msg;
1099 struct msghdr32 m32;
1100 struct iovec *uiov, *iov;
1101 struct mbuf *control = NULL;
1102 struct mbuf **controlp;
1105 error = copyin(uap->msg, &m32, sizeof(m32));
1108 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1111 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1115 msg.msg_flags = uap->flags;
1119 controlp = (msg.msg_control != NULL) ? &control : NULL;
1120 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1124 if (control != NULL)
1125 error = freebsd32_copy_msg_out(&msg, control);
1127 msg.msg_controllen = 0;
1130 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1134 if (control != NULL)
1142 freebsd32_convert_msg_in(struct mbuf **controlp)
1144 struct mbuf *control = *controlp;
1145 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1147 socklen_t clen = control->m_len, datalen;
1153 while (cm != NULL) {
1154 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) {
1159 data = FREEBSD32_CMSG_DATA(cm);
1160 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1162 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type,
1164 controlp = &(*controlp)->m_next;
1166 if (FREEBSD32_CMSG_SPACE(datalen) < clen) {
1167 clen -= FREEBSD32_CMSG_SPACE(datalen);
1168 cm = (struct cmsghdr *)
1169 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen));
1182 freebsd32_sendmsg(struct thread *td,
1183 struct freebsd32_sendmsg_args *uap)
1186 struct msghdr32 m32;
1188 struct mbuf *control = NULL;
1189 struct sockaddr *to = NULL;
1192 error = copyin(uap->msg, &m32, sizeof(m32));
1195 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1198 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1203 if (msg.msg_name != NULL) {
1204 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1212 if (msg.msg_control) {
1213 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1218 error = sockargs(&control, msg.msg_control,
1219 msg.msg_controllen, MT_CONTROL);
1223 error = freebsd32_convert_msg_in(&control);
1228 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1239 freebsd32_recvfrom(struct thread *td,
1240 struct freebsd32_recvfrom_args *uap)
1246 if (uap->fromlenaddr) {
1247 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1248 sizeof(msg.msg_namelen));
1252 msg.msg_namelen = 0;
1255 msg.msg_name = PTRIN(uap->from);
1256 msg.msg_iov = &aiov;
1258 aiov.iov_base = PTRIN(uap->buf);
1259 aiov.iov_len = uap->len;
1260 msg.msg_control = NULL;
1261 msg.msg_flags = uap->flags;
1262 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1263 if (error == 0 && uap->fromlenaddr)
1264 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1265 sizeof (msg.msg_namelen));
1270 freebsd32_settimeofday(struct thread *td,
1271 struct freebsd32_settimeofday_args *uap)
1273 struct timeval32 tv32;
1274 struct timeval tv, *tvp;
1275 struct timezone tz, *tzp;
1279 error = copyin(uap->tv, &tv32, sizeof(tv32));
1282 CP(tv32, tv, tv_sec);
1283 CP(tv32, tv, tv_usec);
1288 error = copyin(uap->tzp, &tz, sizeof(tz));
1294 return (kern_settimeofday(td, tvp, tzp));
1298 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1300 struct timeval32 s32[2];
1301 struct timeval s[2], *sp;
1304 if (uap->tptr != NULL) {
1305 error = copyin(uap->tptr, s32, sizeof(s32));
1308 CP(s32[0], s[0], tv_sec);
1309 CP(s32[0], s[0], tv_usec);
1310 CP(s32[1], s[1], tv_sec);
1311 CP(s32[1], s[1], tv_usec);
1315 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1319 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1321 struct timeval32 s32[2];
1322 struct timeval s[2], *sp;
1325 if (uap->tptr != NULL) {
1326 error = copyin(uap->tptr, s32, sizeof(s32));
1329 CP(s32[0], s[0], tv_sec);
1330 CP(s32[0], s[0], tv_usec);
1331 CP(s32[1], s[1], tv_sec);
1332 CP(s32[1], s[1], tv_usec);
1336 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1340 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1342 struct timeval32 s32[2];
1343 struct timeval s[2], *sp;
1346 if (uap->tptr != NULL) {
1347 error = copyin(uap->tptr, s32, sizeof(s32));
1350 CP(s32[0], s[0], tv_sec);
1351 CP(s32[0], s[0], tv_usec);
1352 CP(s32[1], s[1], tv_sec);
1353 CP(s32[1], s[1], tv_usec);
1357 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1361 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1363 struct timeval32 s32[2];
1364 struct timeval s[2], *sp;
1367 if (uap->times != NULL) {
1368 error = copyin(uap->times, s32, sizeof(s32));
1371 CP(s32[0], s[0], tv_sec);
1372 CP(s32[0], s[0], tv_usec);
1373 CP(s32[1], s[1], tv_sec);
1374 CP(s32[1], s[1], tv_usec);
1378 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1383 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1385 struct timeval32 tv32;
1386 struct timeval delta, olddelta, *deltap;
1390 error = copyin(uap->delta, &tv32, sizeof(tv32));
1393 CP(tv32, delta, tv_sec);
1394 CP(tv32, delta, tv_usec);
1398 error = kern_adjtime(td, deltap, &olddelta);
1399 if (uap->olddelta && error == 0) {
1400 CP(olddelta, tv32, tv_sec);
1401 CP(olddelta, tv32, tv_usec);
1402 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1407 #ifdef COMPAT_FREEBSD4
1409 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1411 struct statfs32 s32;
1415 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1418 copy_statfs(&s, &s32);
1419 return (copyout(&s32, uap->buf, sizeof(s32)));
1423 #ifdef COMPAT_FREEBSD4
1425 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1427 struct statfs32 s32;
1431 error = kern_fstatfs(td, uap->fd, &s);
1434 copy_statfs(&s, &s32);
1435 return (copyout(&s32, uap->buf, sizeof(s32)));
1439 #ifdef COMPAT_FREEBSD4
1441 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1443 struct statfs32 s32;
1448 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1450 error = kern_fhstatfs(td, fh, &s);
1453 copy_statfs(&s, &s32);
1454 return (copyout(&s32, uap->buf, sizeof(s32)));
1459 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1461 struct pread_args ap;
1465 ap.nbyte = uap->nbyte;
1466 ap.offset = PAIR32TO64(off_t,uap->offset);
1467 return (sys_pread(td, &ap));
1471 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1473 struct pwrite_args ap;
1477 ap.nbyte = uap->nbyte;
1478 ap.offset = PAIR32TO64(off_t,uap->offset);
1479 return (sys_pwrite(td, &ap));
1484 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1486 struct lseek_args nuap;
1489 nuap.offset = uap->offset;
1490 nuap.whence = uap->whence;
1491 return (sys_lseek(td, &nuap));
1496 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1499 struct lseek_args ap;
1503 ap.offset = PAIR32TO64(off_t,uap->offset);
1504 ap.whence = uap->whence;
1505 error = sys_lseek(td, &ap);
1506 /* Expand the quad return into two parts for eax and edx */
1507 pos = td->td_uretoff.tdu_off;
1508 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1509 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1514 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1516 struct truncate_args ap;
1518 ap.path = uap->path;
1519 ap.length = PAIR32TO64(off_t,uap->length);
1520 return (sys_truncate(td, &ap));
1524 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1526 struct ftruncate_args ap;
1529 ap.length = PAIR32TO64(off_t,uap->length);
1530 return (sys_ftruncate(td, &ap));
1535 ofreebsd32_getdirentries(struct thread *td,
1536 struct ofreebsd32_getdirentries_args *uap)
1538 struct ogetdirentries_args ap;
1545 ap.count = uap->count;
1547 error = kern_ogetdirentries(td, &ap, &loff);
1550 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1557 freebsd32_getdirentries(struct thread *td,
1558 struct freebsd32_getdirentries_args *uap)
1564 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1565 NULL, UIO_USERSPACE);
1568 if (uap->basep != NULL) {
1570 error = copyout(&base32, uap->basep, sizeof(int32_t));
1575 #ifdef COMPAT_FREEBSD6
1576 /* versions with the 'int pad' argument */
1578 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1580 struct pread_args ap;
1584 ap.nbyte = uap->nbyte;
1585 ap.offset = PAIR32TO64(off_t,uap->offset);
1586 return (sys_pread(td, &ap));
1590 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1592 struct pwrite_args ap;
1596 ap.nbyte = uap->nbyte;
1597 ap.offset = PAIR32TO64(off_t,uap->offset);
1598 return (sys_pwrite(td, &ap));
1602 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1605 struct lseek_args ap;
1609 ap.offset = PAIR32TO64(off_t,uap->offset);
1610 ap.whence = uap->whence;
1611 error = sys_lseek(td, &ap);
1612 /* Expand the quad return into two parts for eax and edx */
1613 pos = *(off_t *)(td->td_retval);
1614 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1615 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1620 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1622 struct truncate_args ap;
1624 ap.path = uap->path;
1625 ap.length = PAIR32TO64(off_t,uap->length);
1626 return (sys_truncate(td, &ap));
1630 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1632 struct ftruncate_args ap;
1635 ap.length = PAIR32TO64(off_t,uap->length);
1636 return (sys_ftruncate(td, &ap));
1638 #endif /* COMPAT_FREEBSD6 */
1647 struct sf_hdtr_kq32 {
1650 uint32_t kq_udata; /* 32-bit void ptr */
1651 uint32_t kq_ident; /* 32-bit uintptr_t */
1655 freebsd32_do_sendfile(struct thread *td,
1656 struct freebsd32_sendfile_args *uap, int compat)
1658 struct sf_hdtr32 hdtr32;
1659 struct sf_hdtr hdtr;
1660 struct sf_hdtr_kq32 hdtr_kq32;
1661 struct sf_hdtr_kq hdtr_kq;
1662 struct uio *hdr_uio, *trl_uio;
1663 struct iovec32 *iov32;
1667 struct sendfile_sync *sfs;
1670 offset = PAIR32TO64(off_t, uap->offset);
1674 hdr_uio = trl_uio = NULL;
1677 if (uap->hdtr != NULL) {
1678 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1681 PTRIN_CP(hdtr32, hdtr, headers);
1682 CP(hdtr32, hdtr, hdr_cnt);
1683 PTRIN_CP(hdtr32, hdtr, trailers);
1684 CP(hdtr32, hdtr, trl_cnt);
1686 if (hdtr.headers != NULL) {
1687 iov32 = PTRIN(hdtr32.headers);
1688 error = freebsd32_copyinuio(iov32,
1689 hdtr32.hdr_cnt, &hdr_uio);
1693 if (hdtr.trailers != NULL) {
1694 iov32 = PTRIN(hdtr32.trailers);
1695 error = freebsd32_copyinuio(iov32,
1696 hdtr32.trl_cnt, &trl_uio);
1702 * If SF_KQUEUE is set, then we need to also copy in
1703 * the kqueue data after the normal hdtr set and set do_kqueue=1.
1705 if (uap->flags & SF_KQUEUE) {
1706 error = copyin(((char *) uap->hdtr) + sizeof(hdtr32),
1712 /* 32->64 bit fields */
1713 CP(hdtr_kq32, hdtr_kq, kq_fd);
1714 CP(hdtr_kq32, hdtr_kq, kq_flags);
1715 PTRIN_CP(hdtr_kq32, hdtr_kq, kq_udata);
1716 CP(hdtr_kq32, hdtr_kq, kq_ident);
1723 /* XXX stack depth! */
1724 error = _do_sendfile(td, uap->fd, uap->s, uap->flags, compat,
1725 offset, uap->nbytes, &sbytes, hdr_uio, trl_uio, &hdtr_kq);
1727 if (uap->sbytes != NULL)
1728 copyout(&sbytes, uap->sbytes, sizeof(off_t));
1732 free(hdr_uio, M_IOV);
1734 free(trl_uio, M_IOV);
1738 #ifdef COMPAT_FREEBSD4
1740 freebsd4_freebsd32_sendfile(struct thread *td,
1741 struct freebsd4_freebsd32_sendfile_args *uap)
1743 return (freebsd32_do_sendfile(td,
1744 (struct freebsd32_sendfile_args *)uap, 1));
1749 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1752 return (freebsd32_do_sendfile(td, uap, 0));
1756 copy_stat(struct stat *in, struct stat32 *out)
1759 CP(*in, *out, st_dev);
1760 CP(*in, *out, st_ino);
1761 CP(*in, *out, st_mode);
1762 CP(*in, *out, st_nlink);
1763 CP(*in, *out, st_uid);
1764 CP(*in, *out, st_gid);
1765 CP(*in, *out, st_rdev);
1766 TS_CP(*in, *out, st_atim);
1767 TS_CP(*in, *out, st_mtim);
1768 TS_CP(*in, *out, st_ctim);
1769 CP(*in, *out, st_size);
1770 CP(*in, *out, st_blocks);
1771 CP(*in, *out, st_blksize);
1772 CP(*in, *out, st_flags);
1773 CP(*in, *out, st_gen);
1774 TS_CP(*in, *out, st_birthtim);
1779 copy_ostat(struct stat *in, struct ostat32 *out)
1782 CP(*in, *out, st_dev);
1783 CP(*in, *out, st_ino);
1784 CP(*in, *out, st_mode);
1785 CP(*in, *out, st_nlink);
1786 CP(*in, *out, st_uid);
1787 CP(*in, *out, st_gid);
1788 CP(*in, *out, st_rdev);
1789 CP(*in, *out, st_size);
1790 TS_CP(*in, *out, st_atim);
1791 TS_CP(*in, *out, st_mtim);
1792 TS_CP(*in, *out, st_ctim);
1793 CP(*in, *out, st_blksize);
1794 CP(*in, *out, st_blocks);
1795 CP(*in, *out, st_flags);
1796 CP(*in, *out, st_gen);
1801 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1807 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1810 copy_stat(&sb, &sb32);
1811 error = copyout(&sb32, uap->ub, sizeof (sb32));
1817 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1820 struct ostat32 sb32;
1823 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1826 copy_ostat(&sb, &sb32);
1827 error = copyout(&sb32, uap->ub, sizeof (sb32));
1833 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1839 error = kern_fstat(td, uap->fd, &ub);
1842 copy_stat(&ub, &ub32);
1843 error = copyout(&ub32, uap->ub, sizeof(ub32));
1849 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1852 struct ostat32 ub32;
1855 error = kern_fstat(td, uap->fd, &ub);
1858 copy_ostat(&ub, &ub32);
1859 error = copyout(&ub32, uap->ub, sizeof(ub32));
1865 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1871 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1874 copy_stat(&ub, &ub32);
1875 error = copyout(&ub32, uap->buf, sizeof(ub32));
1880 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1886 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1889 copy_stat(&sb, &sb32);
1890 error = copyout(&sb32, uap->ub, sizeof (sb32));
1896 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1899 struct ostat32 sb32;
1902 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1905 copy_ostat(&sb, &sb32);
1906 error = copyout(&sb32, uap->ub, sizeof (sb32));
1912 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1914 int error, name[CTL_MAXNAME];
1917 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1919 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1923 oldlen = fuword32(uap->oldlenp);
1926 error = userland_sysctl(td, name, uap->namelen,
1927 uap->old, &oldlen, 1,
1928 uap->new, uap->newlen, &j, SCTL_MASK32);
1929 if (error && error != ENOMEM)
1932 suword32(uap->oldlenp, j);
1937 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1943 error = copyin(uap->jail, &version, sizeof(uint32_t));
1950 /* FreeBSD single IPv4 jails. */
1951 struct jail32_v0 j32_v0;
1953 bzero(&j, sizeof(struct jail));
1954 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1957 CP(j32_v0, j, version);
1958 PTRIN_CP(j32_v0, j, path);
1959 PTRIN_CP(j32_v0, j, hostname);
1960 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1966 * Version 1 was used by multi-IPv4 jail implementations
1967 * that never made it into the official kernel.
1971 case 2: /* JAIL_API_VERSION */
1973 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1976 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1979 CP(j32, j, version);
1980 PTRIN_CP(j32, j, path);
1981 PTRIN_CP(j32, j, hostname);
1982 PTRIN_CP(j32, j, jailname);
1985 PTRIN_CP(j32, j, ip4);
1986 PTRIN_CP(j32, j, ip6);
1991 /* Sci-Fi jails are not supported, sorry. */
1994 return (kern_jail(td, &j));
1998 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2003 /* Check that we have an even number of iovecs. */
2004 if (uap->iovcnt & 1)
2007 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2010 error = kern_jail_set(td, auio, uap->flags);
2016 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2018 struct iovec32 iov32;
2022 /* Check that we have an even number of iovecs. */
2023 if (uap->iovcnt & 1)
2026 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2029 error = kern_jail_get(td, auio, uap->flags);
2031 for (i = 0; i < uap->iovcnt; i++) {
2032 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2033 CP(auio->uio_iov[i], iov32, iov_len);
2034 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2043 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2045 struct sigaction32 s32;
2046 struct sigaction sa, osa, *sap;
2050 error = copyin(uap->act, &s32, sizeof(s32));
2053 sa.sa_handler = PTRIN(s32.sa_u);
2054 CP(s32, sa, sa_flags);
2055 CP(s32, sa, sa_mask);
2059 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2060 if (error == 0 && uap->oact != NULL) {
2061 s32.sa_u = PTROUT(osa.sa_handler);
2062 CP(osa, s32, sa_flags);
2063 CP(osa, s32, sa_mask);
2064 error = copyout(&s32, uap->oact, sizeof(s32));
2069 #ifdef COMPAT_FREEBSD4
2071 freebsd4_freebsd32_sigaction(struct thread *td,
2072 struct freebsd4_freebsd32_sigaction_args *uap)
2074 struct sigaction32 s32;
2075 struct sigaction sa, osa, *sap;
2079 error = copyin(uap->act, &s32, sizeof(s32));
2082 sa.sa_handler = PTRIN(s32.sa_u);
2083 CP(s32, sa, sa_flags);
2084 CP(s32, sa, sa_mask);
2088 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2089 if (error == 0 && uap->oact != NULL) {
2090 s32.sa_u = PTROUT(osa.sa_handler);
2091 CP(osa, s32, sa_flags);
2092 CP(osa, s32, sa_mask);
2093 error = copyout(&s32, uap->oact, sizeof(s32));
2100 struct osigaction32 {
2109 ofreebsd32_sigaction(struct thread *td,
2110 struct ofreebsd32_sigaction_args *uap)
2112 struct osigaction32 s32;
2113 struct sigaction sa, osa, *sap;
2116 if (uap->signum <= 0 || uap->signum >= ONSIG)
2120 error = copyin(uap->nsa, &s32, sizeof(s32));
2123 sa.sa_handler = PTRIN(s32.sa_u);
2124 CP(s32, sa, sa_flags);
2125 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2129 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2130 if (error == 0 && uap->osa != NULL) {
2131 s32.sa_u = PTROUT(osa.sa_handler);
2132 CP(osa, s32, sa_flags);
2133 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2134 error = copyout(&s32, uap->osa, sizeof(s32));
2140 ofreebsd32_sigprocmask(struct thread *td,
2141 struct ofreebsd32_sigprocmask_args *uap)
2146 OSIG2SIG(uap->mask, set);
2147 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2148 SIG2OSIG(oset, td->td_retval[0]);
2153 ofreebsd32_sigpending(struct thread *td,
2154 struct ofreebsd32_sigpending_args *uap)
2156 struct proc *p = td->td_proc;
2160 siglist = p->p_siglist;
2161 SIGSETOR(siglist, td->td_siglist);
2163 SIG2OSIG(siglist, td->td_retval[0]);
2168 u_int32_t sv_handler;
2174 ofreebsd32_sigvec(struct thread *td,
2175 struct ofreebsd32_sigvec_args *uap)
2177 struct sigvec32 vec;
2178 struct sigaction sa, osa, *sap;
2181 if (uap->signum <= 0 || uap->signum >= ONSIG)
2185 error = copyin(uap->nsv, &vec, sizeof(vec));
2188 sa.sa_handler = PTRIN(vec.sv_handler);
2189 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2190 sa.sa_flags = vec.sv_flags;
2191 sa.sa_flags ^= SA_RESTART;
2195 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2196 if (error == 0 && uap->osv != NULL) {
2197 vec.sv_handler = PTROUT(osa.sa_handler);
2198 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2199 vec.sv_flags = osa.sa_flags;
2200 vec.sv_flags &= ~SA_NOCLDWAIT;
2201 vec.sv_flags ^= SA_RESTART;
2202 error = copyout(&vec, uap->osv, sizeof(vec));
2208 ofreebsd32_sigblock(struct thread *td,
2209 struct ofreebsd32_sigblock_args *uap)
2213 OSIG2SIG(uap->mask, set);
2214 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2215 SIG2OSIG(oset, td->td_retval[0]);
2220 ofreebsd32_sigsetmask(struct thread *td,
2221 struct ofreebsd32_sigsetmask_args *uap)
2225 OSIG2SIG(uap->mask, set);
2226 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2227 SIG2OSIG(oset, td->td_retval[0]);
2232 ofreebsd32_sigsuspend(struct thread *td,
2233 struct ofreebsd32_sigsuspend_args *uap)
2237 OSIG2SIG(uap->mask, mask);
2238 return (kern_sigsuspend(td, mask));
2247 ofreebsd32_sigstack(struct thread *td,
2248 struct ofreebsd32_sigstack_args *uap)
2250 struct sigstack32 s32;
2251 struct sigstack nss, oss;
2252 int error = 0, unss;
2254 if (uap->nss != NULL) {
2255 error = copyin(uap->nss, &s32, sizeof(s32));
2258 nss.ss_sp = PTRIN(s32.ss_sp);
2259 CP(s32, nss, ss_onstack);
2264 oss.ss_sp = td->td_sigstk.ss_sp;
2265 oss.ss_onstack = sigonstack(cpu_getstack(td));
2267 td->td_sigstk.ss_sp = nss.ss_sp;
2268 td->td_sigstk.ss_size = 0;
2269 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2270 td->td_pflags |= TDP_ALTSTACK;
2272 if (uap->oss != NULL) {
2273 s32.ss_sp = PTROUT(oss.ss_sp);
2274 CP(oss, s32, ss_onstack);
2275 error = copyout(&s32, uap->oss, sizeof(s32));
2282 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2284 struct timespec32 rmt32, rqt32;
2285 struct timespec rmt, rqt;
2288 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2292 CP(rqt32, rqt, tv_sec);
2293 CP(rqt32, rqt, tv_nsec);
2296 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2298 error = kern_nanosleep(td, &rqt, &rmt);
2299 if (error && uap->rmtp) {
2302 CP(rmt, rmt32, tv_sec);
2303 CP(rmt, rmt32, tv_nsec);
2305 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2313 freebsd32_clock_gettime(struct thread *td,
2314 struct freebsd32_clock_gettime_args *uap)
2316 struct timespec ats;
2317 struct timespec32 ats32;
2320 error = kern_clock_gettime(td, uap->clock_id, &ats);
2322 CP(ats, ats32, tv_sec);
2323 CP(ats, ats32, tv_nsec);
2324 error = copyout(&ats32, uap->tp, sizeof(ats32));
2330 freebsd32_clock_settime(struct thread *td,
2331 struct freebsd32_clock_settime_args *uap)
2333 struct timespec ats;
2334 struct timespec32 ats32;
2337 error = copyin(uap->tp, &ats32, sizeof(ats32));
2340 CP(ats32, ats, tv_sec);
2341 CP(ats32, ats, tv_nsec);
2343 return (kern_clock_settime(td, uap->clock_id, &ats));
2347 freebsd32_clock_getres(struct thread *td,
2348 struct freebsd32_clock_getres_args *uap)
2351 struct timespec32 ts32;
2354 if (uap->tp == NULL)
2356 error = kern_clock_getres(td, uap->clock_id, &ts);
2358 CP(ts, ts32, tv_sec);
2359 CP(ts, ts32, tv_nsec);
2360 error = copyout(&ts32, uap->tp, sizeof(ts32));
2365 int freebsd32_ktimer_create(struct thread *td,
2366 struct freebsd32_ktimer_create_args *uap)
2368 struct sigevent32 ev32;
2369 struct sigevent ev, *evp;
2372 if (uap->evp == NULL) {
2376 error = copyin(uap->evp, &ev32, sizeof(ev32));
2379 error = convert_sigevent32(&ev32, &ev);
2383 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2385 error = copyout(&id, uap->timerid, sizeof(int));
2387 kern_ktimer_delete(td, id);
2393 freebsd32_ktimer_settime(struct thread *td,
2394 struct freebsd32_ktimer_settime_args *uap)
2396 struct itimerspec32 val32, oval32;
2397 struct itimerspec val, oval, *ovalp;
2400 error = copyin(uap->value, &val32, sizeof(val32));
2404 ovalp = uap->ovalue != NULL ? &oval : NULL;
2405 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2406 if (error == 0 && uap->ovalue != NULL) {
2407 ITS_CP(oval, oval32);
2408 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2414 freebsd32_ktimer_gettime(struct thread *td,
2415 struct freebsd32_ktimer_gettime_args *uap)
2417 struct itimerspec32 val32;
2418 struct itimerspec val;
2421 error = kern_ktimer_gettime(td, uap->timerid, &val);
2424 error = copyout(&val32, uap->value, sizeof(val32));
2430 freebsd32_clock_getcpuclockid2(struct thread *td,
2431 struct freebsd32_clock_getcpuclockid2_args *uap)
2436 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2437 uap->which, &clk_id);
2439 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2444 freebsd32_thr_new(struct thread *td,
2445 struct freebsd32_thr_new_args *uap)
2447 struct thr_param32 param32;
2448 struct thr_param param;
2451 if (uap->param_size < 0 ||
2452 uap->param_size > sizeof(struct thr_param32))
2454 bzero(¶m, sizeof(struct thr_param));
2455 bzero(¶m32, sizeof(struct thr_param32));
2456 error = copyin(uap->param, ¶m32, uap->param_size);
2459 param.start_func = PTRIN(param32.start_func);
2460 param.arg = PTRIN(param32.arg);
2461 param.stack_base = PTRIN(param32.stack_base);
2462 param.stack_size = param32.stack_size;
2463 param.tls_base = PTRIN(param32.tls_base);
2464 param.tls_size = param32.tls_size;
2465 param.child_tid = PTRIN(param32.child_tid);
2466 param.parent_tid = PTRIN(param32.parent_tid);
2467 param.flags = param32.flags;
2468 param.rtp = PTRIN(param32.rtp);
2469 param.spare[0] = PTRIN(param32.spare[0]);
2470 param.spare[1] = PTRIN(param32.spare[1]);
2471 param.spare[2] = PTRIN(param32.spare[2]);
2473 return (kern_thr_new(td, ¶m));
2477 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2479 struct timespec32 ts32;
2480 struct timespec ts, *tsp;
2485 if (uap->timeout != NULL) {
2486 error = copyin((const void *)uap->timeout, (void *)&ts32,
2487 sizeof(struct timespec32));
2490 ts.tv_sec = ts32.tv_sec;
2491 ts.tv_nsec = ts32.tv_nsec;
2494 return (kern_thr_suspend(td, tsp));
2498 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2500 bzero(dst, sizeof(*dst));
2501 dst->si_signo = src->si_signo;
2502 dst->si_errno = src->si_errno;
2503 dst->si_code = src->si_code;
2504 dst->si_pid = src->si_pid;
2505 dst->si_uid = src->si_uid;
2506 dst->si_status = src->si_status;
2507 dst->si_addr = (uintptr_t)src->si_addr;
2508 dst->si_value.sival_int = src->si_value.sival_int;
2509 dst->si_timerid = src->si_timerid;
2510 dst->si_overrun = src->si_overrun;
2514 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2516 struct timespec32 ts32;
2518 struct timespec *timeout;
2521 struct siginfo32 si32;
2525 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2528 ts.tv_sec = ts32.tv_sec;
2529 ts.tv_nsec = ts32.tv_nsec;
2534 error = copyin(uap->set, &set, sizeof(set));
2538 error = kern_sigtimedwait(td, set, &ksi, timeout);
2543 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2544 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2548 td->td_retval[0] = ksi.ksi_signo;
2556 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2559 struct siginfo32 si32;
2563 error = copyin(uap->set, &set, sizeof(set));
2567 error = kern_sigtimedwait(td, set, &ksi, NULL);
2572 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2573 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2576 td->td_retval[0] = ksi.ksi_signo;
2581 freebsd32_cpuset_setid(struct thread *td,
2582 struct freebsd32_cpuset_setid_args *uap)
2584 struct cpuset_setid_args ap;
2586 ap.which = uap->which;
2587 ap.id = PAIR32TO64(id_t,uap->id);
2588 ap.setid = uap->setid;
2590 return (sys_cpuset_setid(td, &ap));
2594 freebsd32_cpuset_getid(struct thread *td,
2595 struct freebsd32_cpuset_getid_args *uap)
2597 struct cpuset_getid_args ap;
2599 ap.level = uap->level;
2600 ap.which = uap->which;
2601 ap.id = PAIR32TO64(id_t,uap->id);
2602 ap.setid = uap->setid;
2604 return (sys_cpuset_getid(td, &ap));
2608 freebsd32_cpuset_getaffinity(struct thread *td,
2609 struct freebsd32_cpuset_getaffinity_args *uap)
2611 struct cpuset_getaffinity_args ap;
2613 ap.level = uap->level;
2614 ap.which = uap->which;
2615 ap.id = PAIR32TO64(id_t,uap->id);
2616 ap.cpusetsize = uap->cpusetsize;
2617 ap.mask = uap->mask;
2619 return (sys_cpuset_getaffinity(td, &ap));
2623 freebsd32_cpuset_setaffinity(struct thread *td,
2624 struct freebsd32_cpuset_setaffinity_args *uap)
2626 struct cpuset_setaffinity_args ap;
2628 ap.level = uap->level;
2629 ap.which = uap->which;
2630 ap.id = PAIR32TO64(id_t,uap->id);
2631 ap.cpusetsize = uap->cpusetsize;
2632 ap.mask = uap->mask;
2634 return (sys_cpuset_setaffinity(td, &ap));
2638 freebsd32_nmount(struct thread *td,
2639 struct freebsd32_nmount_args /* {
2641 unsigned int iovcnt;
2650 * Mount flags are now 64-bits. On 32-bit archtectures only
2651 * 32-bits are passed in, but from here on everything handles
2652 * 64-bit flags correctly.
2656 AUDIT_ARG_FFLAGS(flags);
2659 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2660 * userspace to set this flag, but we must filter it out if we want
2661 * MNT_UPDATE on the root file system to work.
2662 * MNT_ROOTFS should only be set by the kernel when mounting its
2665 flags &= ~MNT_ROOTFS;
2668 * check that we have an even number of iovec's
2669 * and that we have at least two options.
2671 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2674 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2677 error = vfs_donmount(td, flags, auio);
2685 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2687 struct yyy32 *p32, s32;
2688 struct yyy *p = NULL, s;
2693 error = copyin(uap->zzz, &s32, sizeof(s32));
2699 error = kern_xxx(td, p);
2704 error = copyout(&s32, p32, sizeof(s32));
2711 syscall32_register(int *offset, struct sysent *new_sysent,
2712 struct sysent *old_sysent)
2714 if (*offset == NO_SYSCALL) {
2717 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2718 if (freebsd32_sysent[i].sy_call ==
2719 (sy_call_t *)lkmnosys)
2721 if (i == SYS_MAXSYSCALL)
2724 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2726 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2727 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2730 *old_sysent = freebsd32_sysent[*offset];
2731 freebsd32_sysent[*offset] = *new_sysent;
2736 syscall32_deregister(int *offset, struct sysent *old_sysent)
2740 freebsd32_sysent[*offset] = *old_sysent;
2745 syscall32_module_handler(struct module *mod, int what, void *arg)
2747 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2753 error = syscall32_register(data->offset, data->new_sysent,
2756 /* Leave a mark so we know to safely unload below. */
2757 data->offset = NULL;
2760 ms.intval = *data->offset;
2762 module_setspecific(mod, &ms);
2765 error = data->chainevh(mod, what, data->chainarg);
2769 * MOD_LOAD failed, so just return without calling the
2770 * chained handler since we didn't pass along the MOD_LOAD
2773 if (data->offset == NULL)
2775 if (data->chainevh) {
2776 error = data->chainevh(mod, what, data->chainarg);
2780 error = syscall32_deregister(data->offset, &data->old_sysent);
2785 error = data->chainevh(mod, what, data->chainarg);
2791 syscall32_helper_register(struct syscall_helper_data *sd)
2793 struct syscall_helper_data *sd1;
2796 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2797 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2800 syscall32_helper_unregister(sd);
2803 sd1->registered = 1;
2809 syscall32_helper_unregister(struct syscall_helper_data *sd)
2811 struct syscall_helper_data *sd1;
2813 for (sd1 = sd; sd1->registered != 0; sd1++) {
2814 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2815 sd1->registered = 0;
2821 freebsd32_copyout_strings(struct image_params *imgp)
2825 char *stringp, *destp;
2826 u_int32_t *stack_base;
2827 struct freebsd32_ps_strings *arginfo;
2828 char canary[sizeof(long) * 8];
2829 int32_t pagesizes32[MAXPAGESIZES];
2830 size_t execpath_len;
2834 * Calculate string base and vector table pointers.
2835 * Also deal with signal trampoline code for this exec type.
2837 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2838 execpath_len = strlen(imgp->execpath) + 1;
2841 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2843 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2844 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2847 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
2848 roundup(execpath_len, sizeof(char *)) -
2849 roundup(sizeof(canary), sizeof(char *)) -
2850 roundup(sizeof(pagesizes32), sizeof(char *)) -
2851 roundup((ARG_MAX - imgp->args->stringspace), sizeof(char *));
2857 copyout(imgp->proc->p_sysent->sv_sigcode,
2858 ((caddr_t)arginfo - szsigcode), szsigcode);
2861 * Copy the image path for the rtld.
2863 if (execpath_len != 0) {
2864 imgp->execpathp = (uintptr_t)arginfo - szsigcode - execpath_len;
2865 copyout(imgp->execpath, (void *)imgp->execpathp,
2870 * Prepare the canary for SSP.
2872 arc4rand(canary, sizeof(canary), 0);
2873 imgp->canary = (uintptr_t)arginfo - szsigcode - execpath_len -
2875 copyout(canary, (void *)imgp->canary, sizeof(canary));
2876 imgp->canarylen = sizeof(canary);
2879 * Prepare the pagesizes array.
2881 for (i = 0; i < MAXPAGESIZES; i++)
2882 pagesizes32[i] = (uint32_t)pagesizes[i];
2883 imgp->pagesizes = (uintptr_t)arginfo - szsigcode - execpath_len -
2884 roundup(sizeof(canary), sizeof(char *)) - sizeof(pagesizes32);
2885 copyout(pagesizes32, (void *)imgp->pagesizes, sizeof(pagesizes32));
2886 imgp->pagesizeslen = sizeof(pagesizes32);
2889 * If we have a valid auxargs ptr, prepare some room
2892 if (imgp->auxargs) {
2894 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2895 * lower compatibility.
2897 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2900 * The '+ 2' is for the null pointers at the end of each of
2901 * the arg and env vector sets,and imgp->auxarg_size is room
2902 * for argument of Runtime loader.
2904 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2905 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2909 * The '+ 2' is for the null pointers at the end of each of
2910 * the arg and env vector sets
2912 vectp = (u_int32_t *)
2913 (destp - (imgp->args->argc + imgp->args->envc + 2) * sizeof(u_int32_t));
2916 * vectp also becomes our initial stack base
2920 stringp = imgp->args->begin_argv;
2921 argc = imgp->args->argc;
2922 envc = imgp->args->envc;
2924 * Copy out strings - arguments and environment.
2926 copyout(stringp, destp, ARG_MAX - imgp->args->stringspace);
2929 * Fill in "ps_strings" struct for ps, w, etc.
2931 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2932 suword32(&arginfo->ps_nargvstr, argc);
2935 * Fill in argument portion of vector table.
2937 for (; argc > 0; --argc) {
2938 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2939 while (*stringp++ != 0)
2944 /* a null vector table pointer separates the argp's from the envp's */
2945 suword32(vectp++, 0);
2947 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2948 suword32(&arginfo->ps_nenvstr, envc);
2951 * Fill in environment portion of vector table.
2953 for (; envc > 0; --envc) {
2954 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2955 while (*stringp++ != 0)
2960 /* end of vector table is a null pointer */
2963 return ((register_t *)stack_base);
2967 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2969 struct kld_file_stat stat;
2970 struct kld32_file_stat stat32;
2973 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2976 if (version != sizeof(struct kld32_file_stat_1) &&
2977 version != sizeof(struct kld32_file_stat))
2980 error = kern_kldstat(td, uap->fileid, &stat);
2984 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
2985 CP(stat, stat32, refs);
2986 CP(stat, stat32, id);
2987 PTROUT_CP(stat, stat32, address);
2988 CP(stat, stat32, size);
2989 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
2990 return (copyout(&stat32, uap->stat, version));
2994 freebsd32_posix_fallocate(struct thread *td,
2995 struct freebsd32_posix_fallocate_args *uap)
2998 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
2999 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3004 freebsd32_posix_fadvise(struct thread *td,
3005 struct freebsd32_posix_fadvise_args *uap)
3008 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
3009 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
3015 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3018 CP(*sig32, *sig, sigev_notify);
3019 switch (sig->sigev_notify) {
3022 case SIGEV_THREAD_ID:
3023 CP(*sig32, *sig, sigev_notify_thread_id);
3026 CP(*sig32, *sig, sigev_signo);
3027 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3030 CP(*sig32, *sig, sigev_notify_kqueue);
3031 CP(*sig32, *sig, sigev_notify_kevent_flags);
3032 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3041 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3048 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3056 return (kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),