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/capability.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.h>
59 #include <sys/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
249 struct statfs *buf, *sp;
250 struct statfs32 stat32;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
258 count = td->td_retval[0];
260 while (count > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
274 freebsd32_sigaltstack(struct thread *td,
275 struct freebsd32_sigaltstack_args *uap)
277 struct sigaltstack32 s32;
278 struct sigaltstack ss, oss, *ssp;
281 if (uap->ss != NULL) {
282 error = copyin(uap->ss, &s32, sizeof(s32));
285 PTRIN_CP(s32, ss, ss_sp);
286 CP(s32, ss, ss_size);
287 CP(s32, ss, ss_flags);
291 error = kern_sigaltstack(td, ssp, &oss);
292 if (error == 0 && uap->oss != NULL) {
293 PTROUT_CP(oss, s32, ss_sp);
294 CP(oss, s32, ss_size);
295 CP(oss, s32, ss_flags);
296 error = copyout(&s32, uap->oss, sizeof(s32));
302 * Custom version of exec_copyin_args() so that we can translate
306 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
307 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
314 bzero(args, sizeof(*args));
319 * Allocate demand-paged memory for the file name, argument, and
320 * environment strings.
322 error = exec_alloc_args(args);
327 * Copy the file name.
330 args->fname = args->buf;
331 error = (segflg == UIO_SYSSPACE) ?
332 copystr(fname, args->fname, PATH_MAX, &length) :
333 copyinstr(fname, args->fname, PATH_MAX, &length);
339 args->begin_argv = args->buf + length;
340 args->endp = args->begin_argv;
341 args->stringspace = ARG_MAX;
344 * extract arguments first
348 error = copyin(p32++, &arg, sizeof(arg));
354 error = copyinstr(argp, args->endp, args->stringspace, &length);
356 if (error == ENAMETOOLONG)
360 args->stringspace -= length;
361 args->endp += length;
365 args->begin_envv = args->endp;
368 * extract environment strings
373 error = copyin(p32++, &arg, sizeof(arg));
379 error = copyinstr(envp, args->endp, args->stringspace,
382 if (error == ENAMETOOLONG)
386 args->stringspace -= length;
387 args->endp += length;
395 exec_free_args(args);
400 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
402 struct image_args eargs;
405 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
406 uap->argv, uap->envv);
408 error = kern_execve(td, &eargs, NULL);
413 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
415 struct image_args eargs;
418 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
419 uap->argv, uap->envv);
422 error = kern_execve(td, &eargs, NULL);
429 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
430 int prot, int fd, off_t pos)
433 vm_map_entry_t entry;
436 map = &td->td_proc->p_vmspace->vm_map;
438 prot |= VM_PROT_WRITE;
440 if (vm_map_lookup_entry(map, start, &entry)) {
441 if ((entry->protection & prot) != prot) {
442 rv = vm_map_protect(map,
445 entry->protection | prot,
447 if (rv != KERN_SUCCESS)
451 vm_offset_t addr = trunc_page(start);
452 rv = vm_map_find(map, NULL, 0, &addr, PAGE_SIZE, 0,
453 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
454 if (rv != KERN_SUCCESS)
461 r.buf = (void *) start;
462 r.nbyte = end - start;
464 return (sys_pread(td, &r));
466 while (start < end) {
467 subyte((void *) start, 0);
476 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
478 struct mprotect_args ap;
480 ap.addr = PTRIN(uap->addr);
483 #if defined(__amd64__) || defined(__ia64__)
484 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
485 ap.prot |= PROT_EXEC;
487 return (sys_mprotect(td, &ap));
491 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
494 vm_offset_t addr = (vm_offset_t) uap->addr;
495 vm_size_t len = uap->len;
496 int prot = uap->prot;
497 int flags = uap->flags;
499 off_t pos = PAIR32TO64(off_t,uap->pos);
505 * Attempt to handle page size hassles.
507 pageoff = (pos & PAGE_MASK);
508 if (flags & MAP_FIXED) {
509 vm_offset_t start, end;
513 if (start != trunc_page(start)) {
514 error = freebsd32_mmap_partial(td, start,
515 round_page(start), prot,
518 pos += round_page(start) - start;
519 start = round_page(start);
521 if (end != round_page(end)) {
522 vm_offset_t t = trunc_page(end);
523 error = freebsd32_mmap_partial(td, t, end,
526 end = trunc_page(end);
528 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
530 * We can't map this region at all. The specified
531 * address doesn't have the same alignment as the file
532 * position. Fake the mapping by simply reading the
533 * entire region into memory. First we need to make
534 * sure the region exists.
540 prot |= VM_PROT_WRITE;
541 map = &td->td_proc->p_vmspace->vm_map;
542 rv = vm_map_remove(map, start, end);
543 if (rv != KERN_SUCCESS)
545 rv = vm_map_find(map, NULL, 0, &start, end - start,
546 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
547 if (rv != KERN_SUCCESS)
550 r.buf = (void *) start;
551 r.nbyte = end - start;
553 error = sys_pread(td, &r);
557 td->td_retval[0] = addr;
562 * After dealing with the ragged ends, there
563 * might be none left.
565 td->td_retval[0] = addr;
573 #if defined(__amd64__) || defined(__ia64__)
574 if (i386_read_exec && (prot & PROT_READ))
578 ap.addr = (void *) addr;
585 return (sys_mmap(td, &ap));
588 #ifdef COMPAT_FREEBSD6
590 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
592 struct freebsd32_mmap_args ap;
597 ap.flags = uap->flags;
602 return (freebsd32_mmap(td, &ap));
607 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
609 struct itimerval itv, oitv, *itvp;
610 struct itimerval32 i32;
613 if (uap->itv != NULL) {
614 error = copyin(uap->itv, &i32, sizeof(i32));
617 TV_CP(i32, itv, it_interval);
618 TV_CP(i32, itv, it_value);
622 error = kern_setitimer(td, uap->which, itvp, &oitv);
623 if (error || uap->oitv == NULL)
625 TV_CP(oitv, i32, it_interval);
626 TV_CP(oitv, i32, it_value);
627 return (copyout(&i32, uap->oitv, sizeof(i32)));
631 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
633 struct itimerval itv;
634 struct itimerval32 i32;
637 error = kern_getitimer(td, uap->which, &itv);
638 if (error || uap->itv == NULL)
640 TV_CP(itv, i32, it_interval);
641 TV_CP(itv, i32, it_value);
642 return (copyout(&i32, uap->itv, sizeof(i32)));
646 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
648 struct timeval32 tv32;
649 struct timeval tv, *tvp;
652 if (uap->tv != NULL) {
653 error = copyin(uap->tv, &tv32, sizeof(tv32));
656 CP(tv32, tv, tv_sec);
657 CP(tv32, tv, tv_usec);
662 * XXX Do pointers need PTRIN()?
664 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
665 sizeof(int32_t) * 8));
669 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
671 struct timespec32 ts32;
673 struct timeval tv, *tvp;
677 if (uap->ts != NULL) {
678 error = copyin(uap->ts, &ts32, sizeof(ts32));
681 CP(ts32, ts, tv_sec);
682 CP(ts32, ts, tv_nsec);
683 TIMESPEC_TO_TIMEVAL(&tv, &ts);
687 if (uap->sm != NULL) {
688 error = copyin(uap->sm, &set, sizeof(set));
695 * XXX Do pointers need PTRIN()?
697 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
698 uset, sizeof(int32_t) * 8);
703 * Copy 'count' items into the destination list pointed to by uap->eventlist.
706 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
708 struct freebsd32_kevent_args *uap;
709 struct kevent32 ks32[KQ_NEVENTS];
712 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
713 uap = (struct freebsd32_kevent_args *)arg;
715 for (i = 0; i < count; i++) {
716 CP(kevp[i], ks32[i], ident);
717 CP(kevp[i], ks32[i], filter);
718 CP(kevp[i], ks32[i], flags);
719 CP(kevp[i], ks32[i], fflags);
720 CP(kevp[i], ks32[i], data);
721 PTROUT_CP(kevp[i], ks32[i], udata);
723 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
725 uap->eventlist += count;
730 * Copy 'count' items from the list pointed to by uap->changelist.
733 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
735 struct freebsd32_kevent_args *uap;
736 struct kevent32 ks32[KQ_NEVENTS];
739 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
740 uap = (struct freebsd32_kevent_args *)arg;
742 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
745 uap->changelist += count;
747 for (i = 0; i < count; i++) {
748 CP(ks32[i], kevp[i], ident);
749 CP(ks32[i], kevp[i], filter);
750 CP(ks32[i], kevp[i], flags);
751 CP(ks32[i], kevp[i], fflags);
752 CP(ks32[i], kevp[i], data);
753 PTRIN_CP(ks32[i], kevp[i], udata);
760 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
762 struct timespec32 ts32;
763 struct timespec ts, *tsp;
764 struct kevent_copyops k_ops = { uap,
765 freebsd32_kevent_copyout,
766 freebsd32_kevent_copyin};
771 error = copyin(uap->timeout, &ts32, sizeof(ts32));
774 CP(ts32, ts, tv_sec);
775 CP(ts32, ts, tv_nsec);
779 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
785 freebsd32_gettimeofday(struct thread *td,
786 struct freebsd32_gettimeofday_args *uap)
789 struct timeval32 atv32;
795 CP(atv, atv32, tv_sec);
796 CP(atv, atv32, tv_usec);
797 error = copyout(&atv32, uap->tp, sizeof (atv32));
799 if (error == 0 && uap->tzp != NULL) {
800 rtz.tz_minuteswest = tz_minuteswest;
801 rtz.tz_dsttime = tz_dsttime;
802 error = copyout(&rtz, uap->tzp, sizeof (rtz));
808 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
814 error = kern_getrusage(td, uap->who, &s);
817 if (uap->rusage != NULL) {
818 freebsd32_rusage_out(&s, &s32);
819 error = copyout(&s32, uap->rusage, sizeof(s32));
825 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
827 struct iovec32 iov32;
834 if (iovcnt > UIO_MAXIOV)
836 iovlen = iovcnt * sizeof(struct iovec);
837 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
838 iov = (struct iovec *)(uio + 1);
839 for (i = 0; i < iovcnt; i++) {
840 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
845 iov[i].iov_base = PTRIN(iov32.iov_base);
846 iov[i].iov_len = iov32.iov_len;
849 uio->uio_iovcnt = iovcnt;
850 uio->uio_segflg = UIO_USERSPACE;
851 uio->uio_offset = -1;
853 for (i = 0; i < iovcnt; i++) {
854 if (iov->iov_len > INT_MAX - uio->uio_resid) {
858 uio->uio_resid += iov->iov_len;
866 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
871 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
874 error = kern_readv(td, uap->fd, auio);
880 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
885 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
888 error = kern_writev(td, uap->fd, auio);
894 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
899 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
902 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
908 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
913 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
916 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
922 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
925 struct iovec32 iov32;
931 if (iovcnt > UIO_MAXIOV)
933 iovlen = iovcnt * sizeof(struct iovec);
934 iov = malloc(iovlen, M_IOV, M_WAITOK);
935 for (i = 0; i < iovcnt; i++) {
936 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
941 iov[i].iov_base = PTRIN(iov32.iov_base);
942 iov[i].iov_len = iov32.iov_len;
949 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
954 error = copyin(msg32, &m32, sizeof(m32));
957 msg->msg_name = PTRIN(m32.msg_name);
958 msg->msg_namelen = m32.msg_namelen;
959 msg->msg_iov = PTRIN(m32.msg_iov);
960 msg->msg_iovlen = m32.msg_iovlen;
961 msg->msg_control = PTRIN(m32.msg_control);
962 msg->msg_controllen = m32.msg_controllen;
963 msg->msg_flags = m32.msg_flags;
968 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
973 m32.msg_name = PTROUT(msg->msg_name);
974 m32.msg_namelen = msg->msg_namelen;
975 m32.msg_iov = PTROUT(msg->msg_iov);
976 m32.msg_iovlen = msg->msg_iovlen;
977 m32.msg_control = PTROUT(msg->msg_control);
978 m32.msg_controllen = msg->msg_controllen;
979 m32.msg_flags = msg->msg_flags;
980 error = copyout(&m32, msg32, sizeof(m32));
985 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
987 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
989 #define FREEBSD32_ALIGN(p) \
990 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
991 #define FREEBSD32_CMSG_SPACE(l) \
992 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
994 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
995 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
997 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1001 socklen_t clen, datalen;
1004 int len, maxlen, copylen;
1008 len = msg->msg_controllen;
1009 maxlen = msg->msg_controllen;
1010 msg->msg_controllen = 0;
1013 ctlbuf = msg->msg_control;
1015 while (m && len > 0) {
1016 cm = mtod(m, struct cmsghdr *);
1019 while (cm != NULL) {
1021 if (sizeof(struct cmsghdr) > clen ||
1022 cm->cmsg_len > clen) {
1027 data = CMSG_DATA(cm);
1028 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1030 /* Adjust message length */
1031 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1036 copylen = sizeof(struct cmsghdr);
1037 if (len < copylen) {
1038 msg->msg_flags |= MSG_CTRUNC;
1042 error = copyout(cm,ctlbuf,copylen);
1046 ctlbuf += FREEBSD32_ALIGN(copylen);
1047 len -= FREEBSD32_ALIGN(copylen);
1054 if (len < copylen) {
1055 msg->msg_flags |= MSG_CTRUNC;
1059 error = copyout(data,ctlbuf,copylen);
1063 ctlbuf += FREEBSD32_ALIGN(copylen);
1064 len -= FREEBSD32_ALIGN(copylen);
1066 if (CMSG_SPACE(datalen) < clen) {
1067 clen -= CMSG_SPACE(datalen);
1068 cm = (struct cmsghdr *)
1069 ((caddr_t)cm + CMSG_SPACE(datalen));
1078 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1086 freebsd32_recvmsg(td, uap)
1088 struct freebsd32_recvmsg_args /* {
1090 struct msghdr32 *msg;
1095 struct msghdr32 m32;
1096 struct iovec *uiov, *iov;
1097 struct mbuf *control = NULL;
1098 struct mbuf **controlp;
1101 error = copyin(uap->msg, &m32, sizeof(m32));
1104 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1107 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1111 msg.msg_flags = uap->flags;
1115 controlp = (msg.msg_control != NULL) ? &control : NULL;
1116 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1120 if (control != NULL)
1121 error = freebsd32_copy_msg_out(&msg, control);
1123 msg.msg_controllen = 0;
1126 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1130 if (control != NULL)
1137 * Copy-in the array of control messages constructed using alignment
1138 * and padding suitable for a 32-bit environment and construct an
1139 * mbuf using alignment and padding suitable for a 64-bit kernel.
1140 * The alignment and padding are defined indirectly by CMSG_DATA(),
1141 * CMSG_SPACE() and CMSG_LEN().
1144 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1148 u_int idx, len, msglen;
1151 buflen = FREEBSD32_ALIGN(buflen);
1153 if (buflen > MCLBYTES)
1157 * Iterate over the buffer and get the length of each message
1158 * in there. This has 32-bit alignment and padding. Use it to
1159 * determine the length of these messages when using 64-bit
1160 * alignment and padding.
1164 while (idx < buflen) {
1165 error = copyin(buf + idx, &msglen, sizeof(msglen));
1168 if (msglen < sizeof(struct cmsghdr))
1170 msglen = FREEBSD32_ALIGN(msglen);
1171 if (idx + msglen > buflen)
1174 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1175 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1176 len += CMSG_ALIGN(msglen);
1182 m = m_get(M_WAITOK, MT_CONTROL);
1184 MCLGET(m, M_WAITOK);
1187 md = mtod(m, void *);
1188 while (buflen > 0) {
1189 error = copyin(buf, md, sizeof(struct cmsghdr));
1192 msglen = *(u_int *)md;
1193 msglen = FREEBSD32_ALIGN(msglen);
1195 /* Modify the message length to account for alignment. */
1196 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1197 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1199 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1200 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1201 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1203 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1205 error = copyin(buf, md, msglen);
1208 md = (char *)md + CMSG_ALIGN(msglen);
1222 freebsd32_sendmsg(struct thread *td,
1223 struct freebsd32_sendmsg_args *uap)
1226 struct msghdr32 m32;
1228 struct mbuf *control = NULL;
1229 struct sockaddr *to = NULL;
1232 error = copyin(uap->msg, &m32, sizeof(m32));
1235 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1238 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1243 if (msg.msg_name != NULL) {
1244 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1252 if (msg.msg_control) {
1253 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1258 error = freebsd32_copyin_control(&control, msg.msg_control,
1259 msg.msg_controllen);
1263 msg.msg_control = NULL;
1264 msg.msg_controllen = 0;
1267 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1278 freebsd32_recvfrom(struct thread *td,
1279 struct freebsd32_recvfrom_args *uap)
1285 if (uap->fromlenaddr) {
1286 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1287 sizeof(msg.msg_namelen));
1291 msg.msg_namelen = 0;
1294 msg.msg_name = PTRIN(uap->from);
1295 msg.msg_iov = &aiov;
1297 aiov.iov_base = PTRIN(uap->buf);
1298 aiov.iov_len = uap->len;
1299 msg.msg_control = NULL;
1300 msg.msg_flags = uap->flags;
1301 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1302 if (error == 0 && uap->fromlenaddr)
1303 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1304 sizeof (msg.msg_namelen));
1309 freebsd32_settimeofday(struct thread *td,
1310 struct freebsd32_settimeofday_args *uap)
1312 struct timeval32 tv32;
1313 struct timeval tv, *tvp;
1314 struct timezone tz, *tzp;
1318 error = copyin(uap->tv, &tv32, sizeof(tv32));
1321 CP(tv32, tv, tv_sec);
1322 CP(tv32, tv, tv_usec);
1327 error = copyin(uap->tzp, &tz, sizeof(tz));
1333 return (kern_settimeofday(td, tvp, tzp));
1337 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1339 struct timeval32 s32[2];
1340 struct timeval s[2], *sp;
1343 if (uap->tptr != NULL) {
1344 error = copyin(uap->tptr, s32, sizeof(s32));
1347 CP(s32[0], s[0], tv_sec);
1348 CP(s32[0], s[0], tv_usec);
1349 CP(s32[1], s[1], tv_sec);
1350 CP(s32[1], s[1], tv_usec);
1354 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1358 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1360 struct timeval32 s32[2];
1361 struct timeval s[2], *sp;
1364 if (uap->tptr != NULL) {
1365 error = copyin(uap->tptr, s32, sizeof(s32));
1368 CP(s32[0], s[0], tv_sec);
1369 CP(s32[0], s[0], tv_usec);
1370 CP(s32[1], s[1], tv_sec);
1371 CP(s32[1], s[1], tv_usec);
1375 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1379 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1381 struct timeval32 s32[2];
1382 struct timeval s[2], *sp;
1385 if (uap->tptr != NULL) {
1386 error = copyin(uap->tptr, s32, sizeof(s32));
1389 CP(s32[0], s[0], tv_sec);
1390 CP(s32[0], s[0], tv_usec);
1391 CP(s32[1], s[1], tv_sec);
1392 CP(s32[1], s[1], tv_usec);
1396 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1400 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1402 struct timeval32 s32[2];
1403 struct timeval s[2], *sp;
1406 if (uap->times != NULL) {
1407 error = copyin(uap->times, s32, sizeof(s32));
1410 CP(s32[0], s[0], tv_sec);
1411 CP(s32[0], s[0], tv_usec);
1412 CP(s32[1], s[1], tv_sec);
1413 CP(s32[1], s[1], tv_usec);
1417 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1422 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1424 struct timeval32 tv32;
1425 struct timeval delta, olddelta, *deltap;
1429 error = copyin(uap->delta, &tv32, sizeof(tv32));
1432 CP(tv32, delta, tv_sec);
1433 CP(tv32, delta, tv_usec);
1437 error = kern_adjtime(td, deltap, &olddelta);
1438 if (uap->olddelta && error == 0) {
1439 CP(olddelta, tv32, tv_sec);
1440 CP(olddelta, tv32, tv_usec);
1441 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1446 #ifdef COMPAT_FREEBSD4
1448 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1450 struct statfs32 s32;
1454 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1457 copy_statfs(&s, &s32);
1458 return (copyout(&s32, uap->buf, sizeof(s32)));
1462 #ifdef COMPAT_FREEBSD4
1464 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1466 struct statfs32 s32;
1470 error = kern_fstatfs(td, uap->fd, &s);
1473 copy_statfs(&s, &s32);
1474 return (copyout(&s32, uap->buf, sizeof(s32)));
1478 #ifdef COMPAT_FREEBSD4
1480 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1482 struct statfs32 s32;
1487 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1489 error = kern_fhstatfs(td, fh, &s);
1492 copy_statfs(&s, &s32);
1493 return (copyout(&s32, uap->buf, sizeof(s32)));
1498 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1500 struct pread_args ap;
1504 ap.nbyte = uap->nbyte;
1505 ap.offset = PAIR32TO64(off_t,uap->offset);
1506 return (sys_pread(td, &ap));
1510 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1512 struct pwrite_args ap;
1516 ap.nbyte = uap->nbyte;
1517 ap.offset = PAIR32TO64(off_t,uap->offset);
1518 return (sys_pwrite(td, &ap));
1523 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1525 struct lseek_args nuap;
1528 nuap.offset = uap->offset;
1529 nuap.whence = uap->whence;
1530 return (sys_lseek(td, &nuap));
1535 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1538 struct lseek_args ap;
1542 ap.offset = PAIR32TO64(off_t,uap->offset);
1543 ap.whence = uap->whence;
1544 error = sys_lseek(td, &ap);
1545 /* Expand the quad return into two parts for eax and edx */
1546 pos = *(off_t *)(td->td_retval);
1547 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1548 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1553 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1555 struct truncate_args ap;
1557 ap.path = uap->path;
1558 ap.length = PAIR32TO64(off_t,uap->length);
1559 return (sys_truncate(td, &ap));
1563 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1565 struct ftruncate_args ap;
1568 ap.length = PAIR32TO64(off_t,uap->length);
1569 return (sys_ftruncate(td, &ap));
1574 ofreebsd32_getdirentries(struct thread *td,
1575 struct ofreebsd32_getdirentries_args *uap)
1577 struct ogetdirentries_args ap;
1584 ap.count = uap->count;
1586 error = kern_ogetdirentries(td, &ap, &loff);
1589 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1596 freebsd32_getdirentries(struct thread *td,
1597 struct freebsd32_getdirentries_args *uap)
1603 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1604 NULL, UIO_USERSPACE);
1607 if (uap->basep != NULL) {
1609 error = copyout(&base32, uap->basep, sizeof(int32_t));
1614 #ifdef COMPAT_FREEBSD6
1615 /* versions with the 'int pad' argument */
1617 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1619 struct pread_args ap;
1623 ap.nbyte = uap->nbyte;
1624 ap.offset = PAIR32TO64(off_t,uap->offset);
1625 return (sys_pread(td, &ap));
1629 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1631 struct pwrite_args ap;
1635 ap.nbyte = uap->nbyte;
1636 ap.offset = PAIR32TO64(off_t,uap->offset);
1637 return (sys_pwrite(td, &ap));
1641 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1644 struct lseek_args ap;
1648 ap.offset = PAIR32TO64(off_t,uap->offset);
1649 ap.whence = uap->whence;
1650 error = sys_lseek(td, &ap);
1651 /* Expand the quad return into two parts for eax and edx */
1652 pos = *(off_t *)(td->td_retval);
1653 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1654 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1659 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1661 struct truncate_args ap;
1663 ap.path = uap->path;
1664 ap.length = PAIR32TO64(off_t,uap->length);
1665 return (sys_truncate(td, &ap));
1669 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1671 struct ftruncate_args ap;
1674 ap.length = PAIR32TO64(off_t,uap->length);
1675 return (sys_ftruncate(td, &ap));
1677 #endif /* COMPAT_FREEBSD6 */
1687 freebsd32_do_sendfile(struct thread *td,
1688 struct freebsd32_sendfile_args *uap, int compat)
1690 struct sf_hdtr32 hdtr32;
1691 struct sf_hdtr hdtr;
1692 struct uio *hdr_uio, *trl_uio;
1693 struct iovec32 *iov32;
1695 cap_rights_t rights;
1699 offset = PAIR32TO64(off_t, uap->offset);
1703 hdr_uio = trl_uio = NULL;
1705 if (uap->hdtr != NULL) {
1706 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1709 PTRIN_CP(hdtr32, hdtr, headers);
1710 CP(hdtr32, hdtr, hdr_cnt);
1711 PTRIN_CP(hdtr32, hdtr, trailers);
1712 CP(hdtr32, hdtr, trl_cnt);
1714 if (hdtr.headers != NULL) {
1715 iov32 = PTRIN(hdtr32.headers);
1716 error = freebsd32_copyinuio(iov32,
1717 hdtr32.hdr_cnt, &hdr_uio);
1721 if (hdtr.trailers != NULL) {
1722 iov32 = PTRIN(hdtr32.trailers);
1723 error = freebsd32_copyinuio(iov32,
1724 hdtr32.trl_cnt, &trl_uio);
1730 AUDIT_ARG_FD(uap->fd);
1732 if ((error = fget_read(td, uap->fd,
1733 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0) {
1737 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1738 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1743 free(hdr_uio, M_IOV);
1745 free(trl_uio, M_IOV);
1749 #ifdef COMPAT_FREEBSD4
1751 freebsd4_freebsd32_sendfile(struct thread *td,
1752 struct freebsd4_freebsd32_sendfile_args *uap)
1754 return (freebsd32_do_sendfile(td,
1755 (struct freebsd32_sendfile_args *)uap, 1));
1760 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1763 return (freebsd32_do_sendfile(td, uap, 0));
1767 copy_stat(struct stat *in, struct stat32 *out)
1770 CP(*in, *out, st_dev);
1771 CP(*in, *out, st_ino);
1772 CP(*in, *out, st_mode);
1773 CP(*in, *out, st_nlink);
1774 CP(*in, *out, st_uid);
1775 CP(*in, *out, st_gid);
1776 CP(*in, *out, st_rdev);
1777 TS_CP(*in, *out, st_atim);
1778 TS_CP(*in, *out, st_mtim);
1779 TS_CP(*in, *out, st_ctim);
1780 CP(*in, *out, st_size);
1781 CP(*in, *out, st_blocks);
1782 CP(*in, *out, st_blksize);
1783 CP(*in, *out, st_flags);
1784 CP(*in, *out, st_gen);
1785 TS_CP(*in, *out, st_birthtim);
1790 copy_ostat(struct stat *in, struct ostat32 *out)
1793 CP(*in, *out, st_dev);
1794 CP(*in, *out, st_ino);
1795 CP(*in, *out, st_mode);
1796 CP(*in, *out, st_nlink);
1797 CP(*in, *out, st_uid);
1798 CP(*in, *out, st_gid);
1799 CP(*in, *out, st_rdev);
1800 CP(*in, *out, st_size);
1801 TS_CP(*in, *out, st_atim);
1802 TS_CP(*in, *out, st_mtim);
1803 TS_CP(*in, *out, st_ctim);
1804 CP(*in, *out, st_blksize);
1805 CP(*in, *out, st_blocks);
1806 CP(*in, *out, st_flags);
1807 CP(*in, *out, st_gen);
1812 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1818 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1821 copy_stat(&sb, &sb32);
1822 error = copyout(&sb32, uap->ub, sizeof (sb32));
1828 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1831 struct ostat32 sb32;
1834 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1837 copy_ostat(&sb, &sb32);
1838 error = copyout(&sb32, uap->ub, sizeof (sb32));
1844 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1850 error = kern_fstat(td, uap->fd, &ub);
1853 copy_stat(&ub, &ub32);
1854 error = copyout(&ub32, uap->ub, sizeof(ub32));
1860 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1863 struct ostat32 ub32;
1866 error = kern_fstat(td, uap->fd, &ub);
1869 copy_ostat(&ub, &ub32);
1870 error = copyout(&ub32, uap->ub, sizeof(ub32));
1876 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1882 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1885 copy_stat(&ub, &ub32);
1886 error = copyout(&ub32, uap->buf, sizeof(ub32));
1891 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1897 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1900 copy_stat(&sb, &sb32);
1901 error = copyout(&sb32, uap->ub, sizeof (sb32));
1907 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1910 struct ostat32 sb32;
1913 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1916 copy_ostat(&sb, &sb32);
1917 error = copyout(&sb32, uap->ub, sizeof (sb32));
1923 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1925 int error, name[CTL_MAXNAME];
1928 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1930 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1934 oldlen = fuword32(uap->oldlenp);
1937 error = userland_sysctl(td, name, uap->namelen,
1938 uap->old, &oldlen, 1,
1939 uap->new, uap->newlen, &j, SCTL_MASK32);
1940 if (error && error != ENOMEM)
1943 suword32(uap->oldlenp, j);
1948 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1954 error = copyin(uap->jail, &version, sizeof(uint32_t));
1961 /* FreeBSD single IPv4 jails. */
1962 struct jail32_v0 j32_v0;
1964 bzero(&j, sizeof(struct jail));
1965 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1968 CP(j32_v0, j, version);
1969 PTRIN_CP(j32_v0, j, path);
1970 PTRIN_CP(j32_v0, j, hostname);
1971 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1977 * Version 1 was used by multi-IPv4 jail implementations
1978 * that never made it into the official kernel.
1982 case 2: /* JAIL_API_VERSION */
1984 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
1987 error = copyin(uap->jail, &j32, sizeof(struct jail32));
1990 CP(j32, j, version);
1991 PTRIN_CP(j32, j, path);
1992 PTRIN_CP(j32, j, hostname);
1993 PTRIN_CP(j32, j, jailname);
1996 PTRIN_CP(j32, j, ip4);
1997 PTRIN_CP(j32, j, ip6);
2002 /* Sci-Fi jails are not supported, sorry. */
2005 return (kern_jail(td, &j));
2009 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2014 /* Check that we have an even number of iovecs. */
2015 if (uap->iovcnt & 1)
2018 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2021 error = kern_jail_set(td, auio, uap->flags);
2027 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2029 struct iovec32 iov32;
2033 /* Check that we have an even number of iovecs. */
2034 if (uap->iovcnt & 1)
2037 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2040 error = kern_jail_get(td, auio, uap->flags);
2042 for (i = 0; i < uap->iovcnt; i++) {
2043 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2044 CP(auio->uio_iov[i], iov32, iov_len);
2045 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2054 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2056 struct sigaction32 s32;
2057 struct sigaction sa, osa, *sap;
2061 error = copyin(uap->act, &s32, sizeof(s32));
2064 sa.sa_handler = PTRIN(s32.sa_u);
2065 CP(s32, sa, sa_flags);
2066 CP(s32, sa, sa_mask);
2070 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2071 if (error == 0 && uap->oact != NULL) {
2072 s32.sa_u = PTROUT(osa.sa_handler);
2073 CP(osa, s32, sa_flags);
2074 CP(osa, s32, sa_mask);
2075 error = copyout(&s32, uap->oact, sizeof(s32));
2080 #ifdef COMPAT_FREEBSD4
2082 freebsd4_freebsd32_sigaction(struct thread *td,
2083 struct freebsd4_freebsd32_sigaction_args *uap)
2085 struct sigaction32 s32;
2086 struct sigaction sa, osa, *sap;
2090 error = copyin(uap->act, &s32, sizeof(s32));
2093 sa.sa_handler = PTRIN(s32.sa_u);
2094 CP(s32, sa, sa_flags);
2095 CP(s32, sa, sa_mask);
2099 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2100 if (error == 0 && uap->oact != NULL) {
2101 s32.sa_u = PTROUT(osa.sa_handler);
2102 CP(osa, s32, sa_flags);
2103 CP(osa, s32, sa_mask);
2104 error = copyout(&s32, uap->oact, sizeof(s32));
2111 struct osigaction32 {
2120 ofreebsd32_sigaction(struct thread *td,
2121 struct ofreebsd32_sigaction_args *uap)
2123 struct osigaction32 s32;
2124 struct sigaction sa, osa, *sap;
2127 if (uap->signum <= 0 || uap->signum >= ONSIG)
2131 error = copyin(uap->nsa, &s32, sizeof(s32));
2134 sa.sa_handler = PTRIN(s32.sa_u);
2135 CP(s32, sa, sa_flags);
2136 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2140 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2141 if (error == 0 && uap->osa != NULL) {
2142 s32.sa_u = PTROUT(osa.sa_handler);
2143 CP(osa, s32, sa_flags);
2144 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2145 error = copyout(&s32, uap->osa, sizeof(s32));
2151 ofreebsd32_sigprocmask(struct thread *td,
2152 struct ofreebsd32_sigprocmask_args *uap)
2157 OSIG2SIG(uap->mask, set);
2158 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2159 SIG2OSIG(oset, td->td_retval[0]);
2164 ofreebsd32_sigpending(struct thread *td,
2165 struct ofreebsd32_sigpending_args *uap)
2167 struct proc *p = td->td_proc;
2171 siglist = p->p_siglist;
2172 SIGSETOR(siglist, td->td_siglist);
2174 SIG2OSIG(siglist, td->td_retval[0]);
2179 u_int32_t sv_handler;
2185 ofreebsd32_sigvec(struct thread *td,
2186 struct ofreebsd32_sigvec_args *uap)
2188 struct sigvec32 vec;
2189 struct sigaction sa, osa, *sap;
2192 if (uap->signum <= 0 || uap->signum >= ONSIG)
2196 error = copyin(uap->nsv, &vec, sizeof(vec));
2199 sa.sa_handler = PTRIN(vec.sv_handler);
2200 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2201 sa.sa_flags = vec.sv_flags;
2202 sa.sa_flags ^= SA_RESTART;
2206 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2207 if (error == 0 && uap->osv != NULL) {
2208 vec.sv_handler = PTROUT(osa.sa_handler);
2209 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2210 vec.sv_flags = osa.sa_flags;
2211 vec.sv_flags &= ~SA_NOCLDWAIT;
2212 vec.sv_flags ^= SA_RESTART;
2213 error = copyout(&vec, uap->osv, sizeof(vec));
2219 ofreebsd32_sigblock(struct thread *td,
2220 struct ofreebsd32_sigblock_args *uap)
2224 OSIG2SIG(uap->mask, set);
2225 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2226 SIG2OSIG(oset, td->td_retval[0]);
2231 ofreebsd32_sigsetmask(struct thread *td,
2232 struct ofreebsd32_sigsetmask_args *uap)
2236 OSIG2SIG(uap->mask, set);
2237 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2238 SIG2OSIG(oset, td->td_retval[0]);
2243 ofreebsd32_sigsuspend(struct thread *td,
2244 struct ofreebsd32_sigsuspend_args *uap)
2248 OSIG2SIG(uap->mask, mask);
2249 return (kern_sigsuspend(td, mask));
2258 ofreebsd32_sigstack(struct thread *td,
2259 struct ofreebsd32_sigstack_args *uap)
2261 struct sigstack32 s32;
2262 struct sigstack nss, oss;
2263 int error = 0, unss;
2265 if (uap->nss != NULL) {
2266 error = copyin(uap->nss, &s32, sizeof(s32));
2269 nss.ss_sp = PTRIN(s32.ss_sp);
2270 CP(s32, nss, ss_onstack);
2275 oss.ss_sp = td->td_sigstk.ss_sp;
2276 oss.ss_onstack = sigonstack(cpu_getstack(td));
2278 td->td_sigstk.ss_sp = nss.ss_sp;
2279 td->td_sigstk.ss_size = 0;
2280 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2281 td->td_pflags |= TDP_ALTSTACK;
2283 if (uap->oss != NULL) {
2284 s32.ss_sp = PTROUT(oss.ss_sp);
2285 CP(oss, s32, ss_onstack);
2286 error = copyout(&s32, uap->oss, sizeof(s32));
2293 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2295 struct timespec32 rmt32, rqt32;
2296 struct timespec rmt, rqt;
2299 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2303 CP(rqt32, rqt, tv_sec);
2304 CP(rqt32, rqt, tv_nsec);
2307 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2309 error = kern_nanosleep(td, &rqt, &rmt);
2310 if (error && uap->rmtp) {
2313 CP(rmt, rmt32, tv_sec);
2314 CP(rmt, rmt32, tv_nsec);
2316 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2324 freebsd32_clock_gettime(struct thread *td,
2325 struct freebsd32_clock_gettime_args *uap)
2327 struct timespec ats;
2328 struct timespec32 ats32;
2331 error = kern_clock_gettime(td, uap->clock_id, &ats);
2333 CP(ats, ats32, tv_sec);
2334 CP(ats, ats32, tv_nsec);
2335 error = copyout(&ats32, uap->tp, sizeof(ats32));
2341 freebsd32_clock_settime(struct thread *td,
2342 struct freebsd32_clock_settime_args *uap)
2344 struct timespec ats;
2345 struct timespec32 ats32;
2348 error = copyin(uap->tp, &ats32, sizeof(ats32));
2351 CP(ats32, ats, tv_sec);
2352 CP(ats32, ats, tv_nsec);
2354 return (kern_clock_settime(td, uap->clock_id, &ats));
2358 freebsd32_clock_getres(struct thread *td,
2359 struct freebsd32_clock_getres_args *uap)
2362 struct timespec32 ts32;
2365 if (uap->tp == NULL)
2367 error = kern_clock_getres(td, uap->clock_id, &ts);
2369 CP(ts, ts32, tv_sec);
2370 CP(ts, ts32, tv_nsec);
2371 error = copyout(&ts32, uap->tp, sizeof(ts32));
2376 int freebsd32_ktimer_create(struct thread *td,
2377 struct freebsd32_ktimer_create_args *uap)
2379 struct sigevent32 ev32;
2380 struct sigevent ev, *evp;
2383 if (uap->evp == NULL) {
2387 error = copyin(uap->evp, &ev32, sizeof(ev32));
2390 error = convert_sigevent32(&ev32, &ev);
2394 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2396 error = copyout(&id, uap->timerid, sizeof(int));
2398 kern_ktimer_delete(td, id);
2404 freebsd32_ktimer_settime(struct thread *td,
2405 struct freebsd32_ktimer_settime_args *uap)
2407 struct itimerspec32 val32, oval32;
2408 struct itimerspec val, oval, *ovalp;
2411 error = copyin(uap->value, &val32, sizeof(val32));
2415 ovalp = uap->ovalue != NULL ? &oval : NULL;
2416 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2417 if (error == 0 && uap->ovalue != NULL) {
2418 ITS_CP(oval, oval32);
2419 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2425 freebsd32_ktimer_gettime(struct thread *td,
2426 struct freebsd32_ktimer_gettime_args *uap)
2428 struct itimerspec32 val32;
2429 struct itimerspec val;
2432 error = kern_ktimer_gettime(td, uap->timerid, &val);
2435 error = copyout(&val32, uap->value, sizeof(val32));
2441 freebsd32_clock_getcpuclockid2(struct thread *td,
2442 struct freebsd32_clock_getcpuclockid2_args *uap)
2447 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2448 uap->which, &clk_id);
2450 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2455 freebsd32_thr_new(struct thread *td,
2456 struct freebsd32_thr_new_args *uap)
2458 struct thr_param32 param32;
2459 struct thr_param param;
2462 if (uap->param_size < 0 ||
2463 uap->param_size > sizeof(struct thr_param32))
2465 bzero(¶m, sizeof(struct thr_param));
2466 bzero(¶m32, sizeof(struct thr_param32));
2467 error = copyin(uap->param, ¶m32, uap->param_size);
2470 param.start_func = PTRIN(param32.start_func);
2471 param.arg = PTRIN(param32.arg);
2472 param.stack_base = PTRIN(param32.stack_base);
2473 param.stack_size = param32.stack_size;
2474 param.tls_base = PTRIN(param32.tls_base);
2475 param.tls_size = param32.tls_size;
2476 param.child_tid = PTRIN(param32.child_tid);
2477 param.parent_tid = PTRIN(param32.parent_tid);
2478 param.flags = param32.flags;
2479 param.rtp = PTRIN(param32.rtp);
2480 param.spare[0] = PTRIN(param32.spare[0]);
2481 param.spare[1] = PTRIN(param32.spare[1]);
2482 param.spare[2] = PTRIN(param32.spare[2]);
2484 return (kern_thr_new(td, ¶m));
2488 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2490 struct timespec32 ts32;
2491 struct timespec ts, *tsp;
2496 if (uap->timeout != NULL) {
2497 error = copyin((const void *)uap->timeout, (void *)&ts32,
2498 sizeof(struct timespec32));
2501 ts.tv_sec = ts32.tv_sec;
2502 ts.tv_nsec = ts32.tv_nsec;
2505 return (kern_thr_suspend(td, tsp));
2509 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2511 bzero(dst, sizeof(*dst));
2512 dst->si_signo = src->si_signo;
2513 dst->si_errno = src->si_errno;
2514 dst->si_code = src->si_code;
2515 dst->si_pid = src->si_pid;
2516 dst->si_uid = src->si_uid;
2517 dst->si_status = src->si_status;
2518 dst->si_addr = (uintptr_t)src->si_addr;
2519 dst->si_value.sival_int = src->si_value.sival_int;
2520 dst->si_timerid = src->si_timerid;
2521 dst->si_overrun = src->si_overrun;
2525 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2527 struct timespec32 ts32;
2529 struct timespec *timeout;
2532 struct siginfo32 si32;
2536 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2539 ts.tv_sec = ts32.tv_sec;
2540 ts.tv_nsec = ts32.tv_nsec;
2545 error = copyin(uap->set, &set, sizeof(set));
2549 error = kern_sigtimedwait(td, set, &ksi, timeout);
2554 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2555 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2559 td->td_retval[0] = ksi.ksi_signo;
2567 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2570 struct siginfo32 si32;
2574 error = copyin(uap->set, &set, sizeof(set));
2578 error = kern_sigtimedwait(td, set, &ksi, NULL);
2583 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2584 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2587 td->td_retval[0] = ksi.ksi_signo;
2592 freebsd32_cpuset_setid(struct thread *td,
2593 struct freebsd32_cpuset_setid_args *uap)
2595 struct cpuset_setid_args ap;
2597 ap.which = uap->which;
2598 ap.id = PAIR32TO64(id_t,uap->id);
2599 ap.setid = uap->setid;
2601 return (sys_cpuset_setid(td, &ap));
2605 freebsd32_cpuset_getid(struct thread *td,
2606 struct freebsd32_cpuset_getid_args *uap)
2608 struct cpuset_getid_args ap;
2610 ap.level = uap->level;
2611 ap.which = uap->which;
2612 ap.id = PAIR32TO64(id_t,uap->id);
2613 ap.setid = uap->setid;
2615 return (sys_cpuset_getid(td, &ap));
2619 freebsd32_cpuset_getaffinity(struct thread *td,
2620 struct freebsd32_cpuset_getaffinity_args *uap)
2622 struct cpuset_getaffinity_args ap;
2624 ap.level = uap->level;
2625 ap.which = uap->which;
2626 ap.id = PAIR32TO64(id_t,uap->id);
2627 ap.cpusetsize = uap->cpusetsize;
2628 ap.mask = uap->mask;
2630 return (sys_cpuset_getaffinity(td, &ap));
2634 freebsd32_cpuset_setaffinity(struct thread *td,
2635 struct freebsd32_cpuset_setaffinity_args *uap)
2637 struct cpuset_setaffinity_args ap;
2639 ap.level = uap->level;
2640 ap.which = uap->which;
2641 ap.id = PAIR32TO64(id_t,uap->id);
2642 ap.cpusetsize = uap->cpusetsize;
2643 ap.mask = uap->mask;
2645 return (sys_cpuset_setaffinity(td, &ap));
2649 freebsd32_nmount(struct thread *td,
2650 struct freebsd32_nmount_args /* {
2652 unsigned int iovcnt;
2661 * Mount flags are now 64-bits. On 32-bit archtectures only
2662 * 32-bits are passed in, but from here on everything handles
2663 * 64-bit flags correctly.
2667 AUDIT_ARG_FFLAGS(flags);
2670 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2671 * userspace to set this flag, but we must filter it out if we want
2672 * MNT_UPDATE on the root file system to work.
2673 * MNT_ROOTFS should only be set by the kernel when mounting its
2676 flags &= ~MNT_ROOTFS;
2679 * check that we have an even number of iovec's
2680 * and that we have at least two options.
2682 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2685 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2688 error = vfs_donmount(td, flags, auio);
2696 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2698 struct yyy32 *p32, s32;
2699 struct yyy *p = NULL, s;
2704 error = copyin(uap->zzz, &s32, sizeof(s32));
2710 error = kern_xxx(td, p);
2715 error = copyout(&s32, p32, sizeof(s32));
2722 syscall32_register(int *offset, struct sysent *new_sysent,
2723 struct sysent *old_sysent)
2725 if (*offset == NO_SYSCALL) {
2728 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2729 if (freebsd32_sysent[i].sy_call ==
2730 (sy_call_t *)lkmnosys)
2732 if (i == SYS_MAXSYSCALL)
2735 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2737 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2738 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2741 *old_sysent = freebsd32_sysent[*offset];
2742 freebsd32_sysent[*offset] = *new_sysent;
2747 syscall32_deregister(int *offset, struct sysent *old_sysent)
2751 freebsd32_sysent[*offset] = *old_sysent;
2756 syscall32_module_handler(struct module *mod, int what, void *arg)
2758 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2764 error = syscall32_register(data->offset, data->new_sysent,
2767 /* Leave a mark so we know to safely unload below. */
2768 data->offset = NULL;
2771 ms.intval = *data->offset;
2773 module_setspecific(mod, &ms);
2776 error = data->chainevh(mod, what, data->chainarg);
2780 * MOD_LOAD failed, so just return without calling the
2781 * chained handler since we didn't pass along the MOD_LOAD
2784 if (data->offset == NULL)
2786 if (data->chainevh) {
2787 error = data->chainevh(mod, what, data->chainarg);
2791 error = syscall32_deregister(data->offset, &data->old_sysent);
2796 error = data->chainevh(mod, what, data->chainarg);
2802 syscall32_helper_register(struct syscall_helper_data *sd)
2804 struct syscall_helper_data *sd1;
2807 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2808 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2811 syscall32_helper_unregister(sd);
2814 sd1->registered = 1;
2820 syscall32_helper_unregister(struct syscall_helper_data *sd)
2822 struct syscall_helper_data *sd1;
2824 for (sd1 = sd; sd1->registered != 0; sd1++) {
2825 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2826 sd1->registered = 0;
2832 freebsd32_copyout_strings(struct image_params *imgp)
2838 u_int32_t *stack_base;
2839 struct freebsd32_ps_strings *arginfo;
2840 char canary[sizeof(long) * 8];
2841 int32_t pagesizes32[MAXPAGESIZES];
2842 size_t execpath_len;
2846 * Calculate string base and vector table pointers.
2847 * Also deal with signal trampoline code for this exec type.
2849 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2850 execpath_len = strlen(imgp->execpath) + 1;
2853 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2855 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2856 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2859 destp = (uintptr_t)arginfo;
2864 if (szsigcode != 0) {
2866 destp = rounddown2(destp, sizeof(uint32_t));
2867 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2872 * Copy the image path for the rtld.
2874 if (execpath_len != 0) {
2875 destp -= execpath_len;
2876 imgp->execpathp = destp;
2877 copyout(imgp->execpath, (void *)destp, execpath_len);
2881 * Prepare the canary for SSP.
2883 arc4rand(canary, sizeof(canary), 0);
2884 destp -= sizeof(canary);
2885 imgp->canary = destp;
2886 copyout(canary, (void *)destp, sizeof(canary));
2887 imgp->canarylen = sizeof(canary);
2890 * Prepare the pagesizes array.
2892 for (i = 0; i < MAXPAGESIZES; i++)
2893 pagesizes32[i] = (uint32_t)pagesizes[i];
2894 destp -= sizeof(pagesizes32);
2895 destp = rounddown2(destp, sizeof(uint32_t));
2896 imgp->pagesizes = destp;
2897 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2898 imgp->pagesizeslen = sizeof(pagesizes32);
2900 destp -= ARG_MAX - imgp->args->stringspace;
2901 destp = rounddown2(destp, sizeof(uint32_t));
2904 * If we have a valid auxargs ptr, prepare some room
2907 if (imgp->auxargs) {
2909 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2910 * lower compatibility.
2912 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2915 * The '+ 2' is for the null pointers at the end of each of
2916 * the arg and env vector sets,and imgp->auxarg_size is room
2917 * for argument of Runtime loader.
2919 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2920 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2924 * The '+ 2' is for the null pointers at the end of each of
2925 * the arg and env vector sets
2927 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2928 imgp->args->envc + 2) * sizeof(u_int32_t));
2932 * vectp also becomes our initial stack base
2936 stringp = imgp->args->begin_argv;
2937 argc = imgp->args->argc;
2938 envc = imgp->args->envc;
2940 * Copy out strings - arguments and environment.
2942 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2945 * Fill in "ps_strings" struct for ps, w, etc.
2947 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2948 suword32(&arginfo->ps_nargvstr, argc);
2951 * Fill in argument portion of vector table.
2953 for (; argc > 0; --argc) {
2954 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2955 while (*stringp++ != 0)
2960 /* a null vector table pointer separates the argp's from the envp's */
2961 suword32(vectp++, 0);
2963 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2964 suword32(&arginfo->ps_nenvstr, envc);
2967 * Fill in environment portion of vector table.
2969 for (; envc > 0; --envc) {
2970 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2971 while (*stringp++ != 0)
2976 /* end of vector table is a null pointer */
2979 return ((register_t *)stack_base);
2983 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
2985 struct kld_file_stat stat;
2986 struct kld32_file_stat stat32;
2989 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
2992 if (version != sizeof(struct kld32_file_stat_1) &&
2993 version != sizeof(struct kld32_file_stat))
2996 error = kern_kldstat(td, uap->fileid, &stat);
3000 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
3001 CP(stat, stat32, refs);
3002 CP(stat, stat32, id);
3003 PTROUT_CP(stat, stat32, address);
3004 CP(stat, stat32, size);
3005 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
3006 return (copyout(&stat32, uap->stat, version));
3010 freebsd32_posix_fallocate(struct thread *td,
3011 struct freebsd32_posix_fallocate_args *uap)
3014 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
3015 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3020 freebsd32_posix_fadvise(struct thread *td,
3021 struct freebsd32_posix_fadvise_args *uap)
3024 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
3025 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
3031 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3034 CP(*sig32, *sig, sigev_notify);
3035 switch (sig->sigev_notify) {
3038 case SIGEV_THREAD_ID:
3039 CP(*sig32, *sig, sigev_notify_thread_id);
3042 CP(*sig32, *sig, sigev_signo);
3043 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3046 CP(*sig32, *sig, sigev_notify_kqueue);
3047 CP(*sig32, *sig, sigev_notify_kevent_flags);
3048 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3057 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3064 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3072 return (kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3077 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3083 * Do unsigned conversion for arg when operation
3084 * interprets it as flags or pointer.
3086 case F_SETLK_REMOTE:
3092 tmp = (unsigned int)(uap->arg);
3098 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));