2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include "opt_inet6.h"
34 #define __ELF_WORD_SIZE 32
36 #include <sys/param.h>
38 #include <sys/capsicum.h>
39 #include <sys/clock.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/linker.h>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/imgact.h>
54 #include <sys/module.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
57 #include <sys/namei.h>
59 #include <sys/procctl.h>
60 #include <sys/reboot.h>
61 #include <sys/resource.h>
62 #include <sys/resourcevar.h>
63 #include <sys/selinfo.h>
64 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
65 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
66 #include <sys/signal.h>
67 #include <sys/signalvar.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
71 #include <sys/syscall.h>
72 #include <sys/syscallsubr.h>
73 #include <sys/sysctl.h>
74 #include <sys/sysent.h>
75 #include <sys/sysproto.h>
76 #include <sys/systm.h>
78 #include <sys/unistd.h>
79 #include <sys/ucontext.h>
80 #include <sys/vnode.h>
88 #include <netinet/in.h>
92 #include <vm/vm_param.h>
94 #include <vm/vm_map.h>
95 #include <vm/vm_object.h>
96 #include <vm/vm_extern.h>
98 #include <machine/cpu.h>
99 #include <machine/elf.h>
101 #include <security/audit/audit.h>
103 #include <compat/freebsd32/freebsd32_util.h>
104 #include <compat/freebsd32/freebsd32.h>
105 #include <compat/freebsd32/freebsd32_ipc.h>
106 #include <compat/freebsd32/freebsd32_misc.h>
107 #include <compat/freebsd32/freebsd32_signal.h>
108 #include <compat/freebsd32/freebsd32_proto.h>
110 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
113 CTASSERT(sizeof(struct timeval32) == 8);
114 CTASSERT(sizeof(struct timespec32) == 8);
115 CTASSERT(sizeof(struct itimerval32) == 16);
117 CTASSERT(sizeof(struct statfs32) == 256);
119 CTASSERT(sizeof(struct rusage32) == 72);
121 CTASSERT(sizeof(struct sigaltstack32) == 12);
122 CTASSERT(sizeof(struct kevent32) == 20);
123 CTASSERT(sizeof(struct iovec32) == 8);
124 CTASSERT(sizeof(struct msghdr32) == 28);
126 CTASSERT(sizeof(struct stat32) == 96);
128 CTASSERT(sizeof(struct sigaction32) == 24);
130 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
131 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
134 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
137 TV_CP(*s, *s32, ru_utime);
138 TV_CP(*s, *s32, ru_stime);
139 CP(*s, *s32, ru_maxrss);
140 CP(*s, *s32, ru_ixrss);
141 CP(*s, *s32, ru_idrss);
142 CP(*s, *s32, ru_isrss);
143 CP(*s, *s32, ru_minflt);
144 CP(*s, *s32, ru_majflt);
145 CP(*s, *s32, ru_nswap);
146 CP(*s, *s32, ru_inblock);
147 CP(*s, *s32, ru_oublock);
148 CP(*s, *s32, ru_msgsnd);
149 CP(*s, *s32, ru_msgrcv);
150 CP(*s, *s32, ru_nsignals);
151 CP(*s, *s32, ru_nvcsw);
152 CP(*s, *s32, ru_nivcsw);
156 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
159 struct rusage32 ru32;
160 struct rusage ru, *rup;
162 if (uap->rusage != NULL)
166 error = kern_wait(td, uap->pid, &status, uap->options, rup);
169 if (uap->status != NULL)
170 error = copyout(&status, uap->status, sizeof(status));
171 if (uap->rusage != NULL && error == 0) {
172 freebsd32_rusage_out(&ru, &ru32);
173 error = copyout(&ru32, uap->rusage, sizeof(ru32));
179 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
181 struct wrusage32 wru32;
182 struct __wrusage wru, *wrup;
183 struct siginfo32 si32;
184 struct __siginfo si, *sip;
187 if (uap->wrusage != NULL)
191 if (uap->info != NULL) {
193 bzero(sip, sizeof(*sip));
196 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
197 &status, uap->options, wrup, sip);
200 if (uap->status != NULL)
201 error = copyout(&status, uap->status, sizeof(status));
202 if (uap->wrusage != NULL && error == 0) {
203 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
204 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
205 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
207 if (uap->info != NULL && error == 0) {
208 siginfo_to_siginfo32 (&si, &si32);
209 error = copyout(&si32, uap->info, sizeof(si32));
214 #ifdef COMPAT_FREEBSD4
216 copy_statfs(struct statfs *in, struct statfs32 *out)
219 statfs_scale_blocks(in, INT32_MAX);
220 bzero(out, sizeof(*out));
221 CP(*in, *out, f_bsize);
222 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
223 CP(*in, *out, f_blocks);
224 CP(*in, *out, f_bfree);
225 CP(*in, *out, f_bavail);
226 out->f_files = MIN(in->f_files, INT32_MAX);
227 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
228 CP(*in, *out, f_fsid);
229 CP(*in, *out, f_owner);
230 CP(*in, *out, f_type);
231 CP(*in, *out, f_flags);
232 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
233 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
234 strlcpy(out->f_fstypename,
235 in->f_fstypename, MFSNAMELEN);
236 strlcpy(out->f_mntonname,
237 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
238 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
239 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
240 strlcpy(out->f_mntfromname,
241 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
245 #ifdef COMPAT_FREEBSD4
247 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
249 struct statfs *buf, *sp;
250 struct statfs32 stat32;
254 count = uap->bufsize / sizeof(struct statfs32);
255 size = count * sizeof(struct statfs);
256 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
258 count = td->td_retval[0];
260 while (count > 0 && error == 0) {
261 copy_statfs(sp, &stat32);
262 error = copyout(&stat32, uap->buf, sizeof(stat32));
274 freebsd32_sigaltstack(struct thread *td,
275 struct freebsd32_sigaltstack_args *uap)
277 struct sigaltstack32 s32;
278 struct sigaltstack ss, oss, *ssp;
281 if (uap->ss != NULL) {
282 error = copyin(uap->ss, &s32, sizeof(s32));
285 PTRIN_CP(s32, ss, ss_sp);
286 CP(s32, ss, ss_size);
287 CP(s32, ss, ss_flags);
291 error = kern_sigaltstack(td, ssp, &oss);
292 if (error == 0 && uap->oss != NULL) {
293 PTROUT_CP(oss, s32, ss_sp);
294 CP(oss, s32, ss_size);
295 CP(oss, s32, ss_flags);
296 error = copyout(&s32, uap->oss, sizeof(s32));
302 * Custom version of exec_copyin_args() so that we can translate
306 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
307 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
314 bzero(args, sizeof(*args));
319 * Allocate demand-paged memory for the file name, argument, and
320 * environment strings.
322 error = exec_alloc_args(args);
327 * Copy the file name.
330 args->fname = args->buf;
331 error = (segflg == UIO_SYSSPACE) ?
332 copystr(fname, args->fname, PATH_MAX, &length) :
333 copyinstr(fname, args->fname, PATH_MAX, &length);
339 args->begin_argv = args->buf + length;
340 args->endp = args->begin_argv;
341 args->stringspace = ARG_MAX;
344 * extract arguments first
348 error = copyin(p32++, &arg, sizeof(arg));
354 error = copyinstr(argp, args->endp, args->stringspace, &length);
356 if (error == ENAMETOOLONG)
360 args->stringspace -= length;
361 args->endp += length;
365 args->begin_envv = args->endp;
368 * extract environment strings
373 error = copyin(p32++, &arg, sizeof(arg));
379 error = copyinstr(envp, args->endp, args->stringspace,
382 if (error == ENAMETOOLONG)
386 args->stringspace -= length;
387 args->endp += length;
395 exec_free_args(args);
400 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
402 struct image_args eargs;
403 struct vmspace *oldvmspace;
406 error = pre_execve(td, &oldvmspace);
409 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
410 uap->argv, uap->envv);
412 error = kern_execve(td, &eargs, NULL);
413 post_execve(td, error, oldvmspace);
418 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
420 struct image_args eargs;
421 struct vmspace *oldvmspace;
424 error = pre_execve(td, &oldvmspace);
427 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
428 uap->argv, uap->envv);
431 error = kern_execve(td, &eargs, NULL);
433 post_execve(td, error, oldvmspace);
439 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
440 int prot, int fd, off_t pos)
443 vm_map_entry_t entry;
446 map = &td->td_proc->p_vmspace->vm_map;
448 prot |= VM_PROT_WRITE;
450 if (vm_map_lookup_entry(map, start, &entry)) {
451 if ((entry->protection & prot) != prot) {
452 rv = vm_map_protect(map,
455 entry->protection | prot,
457 if (rv != KERN_SUCCESS)
461 vm_offset_t addr = trunc_page(start);
462 rv = vm_map_find(map, NULL, 0, &addr, PAGE_SIZE, 0,
463 VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
464 if (rv != KERN_SUCCESS)
471 r.buf = (void *) start;
472 r.nbyte = end - start;
474 return (sys_pread(td, &r));
476 while (start < end) {
477 subyte((void *) start, 0);
486 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
488 struct mprotect_args ap;
490 ap.addr = PTRIN(uap->addr);
493 #if defined(__amd64__) || defined(__ia64__)
494 if (i386_read_exec && (ap.prot & PROT_READ) != 0)
495 ap.prot |= PROT_EXEC;
497 return (sys_mprotect(td, &ap));
501 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
504 vm_offset_t addr = (vm_offset_t) uap->addr;
505 vm_size_t len = uap->len;
506 int prot = uap->prot;
507 int flags = uap->flags;
509 off_t pos = PAIR32TO64(off_t,uap->pos);
515 * Attempt to handle page size hassles.
517 pageoff = (pos & PAGE_MASK);
518 if (flags & MAP_FIXED) {
519 vm_offset_t start, end;
523 if (start != trunc_page(start)) {
524 error = freebsd32_mmap_partial(td, start,
525 round_page(start), prot,
528 pos += round_page(start) - start;
529 start = round_page(start);
531 if (end != round_page(end)) {
532 vm_offset_t t = trunc_page(end);
533 error = freebsd32_mmap_partial(td, t, end,
536 end = trunc_page(end);
538 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
540 * We can't map this region at all. The specified
541 * address doesn't have the same alignment as the file
542 * position. Fake the mapping by simply reading the
543 * entire region into memory. First we need to make
544 * sure the region exists.
550 prot |= VM_PROT_WRITE;
551 map = &td->td_proc->p_vmspace->vm_map;
552 rv = vm_map_remove(map, start, end);
553 if (rv != KERN_SUCCESS)
555 rv = vm_map_find(map, NULL, 0, &start, end - start,
556 0, VMFS_NO_SPACE, prot, VM_PROT_ALL, 0);
557 if (rv != KERN_SUCCESS)
560 r.buf = (void *) start;
561 r.nbyte = end - start;
563 error = sys_pread(td, &r);
567 td->td_retval[0] = addr;
572 * After dealing with the ragged ends, there
573 * might be none left.
575 td->td_retval[0] = addr;
583 #if defined(__amd64__) || defined(__ia64__)
584 if (i386_read_exec && (prot & PROT_READ))
588 ap.addr = (void *) addr;
595 return (sys_mmap(td, &ap));
598 #ifdef COMPAT_FREEBSD6
600 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
602 struct freebsd32_mmap_args ap;
607 ap.flags = uap->flags;
612 return (freebsd32_mmap(td, &ap));
617 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
619 struct itimerval itv, oitv, *itvp;
620 struct itimerval32 i32;
623 if (uap->itv != NULL) {
624 error = copyin(uap->itv, &i32, sizeof(i32));
627 TV_CP(i32, itv, it_interval);
628 TV_CP(i32, itv, it_value);
632 error = kern_setitimer(td, uap->which, itvp, &oitv);
633 if (error || uap->oitv == NULL)
635 TV_CP(oitv, i32, it_interval);
636 TV_CP(oitv, i32, it_value);
637 return (copyout(&i32, uap->oitv, sizeof(i32)));
641 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
643 struct itimerval itv;
644 struct itimerval32 i32;
647 error = kern_getitimer(td, uap->which, &itv);
648 if (error || uap->itv == NULL)
650 TV_CP(itv, i32, it_interval);
651 TV_CP(itv, i32, it_value);
652 return (copyout(&i32, uap->itv, sizeof(i32)));
656 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
658 struct timeval32 tv32;
659 struct timeval tv, *tvp;
662 if (uap->tv != NULL) {
663 error = copyin(uap->tv, &tv32, sizeof(tv32));
666 CP(tv32, tv, tv_sec);
667 CP(tv32, tv, tv_usec);
672 * XXX Do pointers need PTRIN()?
674 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
675 sizeof(int32_t) * 8));
679 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
681 struct timespec32 ts32;
683 struct timeval tv, *tvp;
687 if (uap->ts != NULL) {
688 error = copyin(uap->ts, &ts32, sizeof(ts32));
691 CP(ts32, ts, tv_sec);
692 CP(ts32, ts, tv_nsec);
693 TIMESPEC_TO_TIMEVAL(&tv, &ts);
697 if (uap->sm != NULL) {
698 error = copyin(uap->sm, &set, sizeof(set));
705 * XXX Do pointers need PTRIN()?
707 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
708 uset, sizeof(int32_t) * 8);
713 * Copy 'count' items into the destination list pointed to by uap->eventlist.
716 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
718 struct freebsd32_kevent_args *uap;
719 struct kevent32 ks32[KQ_NEVENTS];
722 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
723 uap = (struct freebsd32_kevent_args *)arg;
725 for (i = 0; i < count; i++) {
726 CP(kevp[i], ks32[i], ident);
727 CP(kevp[i], ks32[i], filter);
728 CP(kevp[i], ks32[i], flags);
729 CP(kevp[i], ks32[i], fflags);
730 CP(kevp[i], ks32[i], data);
731 PTROUT_CP(kevp[i], ks32[i], udata);
733 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
735 uap->eventlist += count;
740 * Copy 'count' items from the list pointed to by uap->changelist.
743 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
745 struct freebsd32_kevent_args *uap;
746 struct kevent32 ks32[KQ_NEVENTS];
749 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
750 uap = (struct freebsd32_kevent_args *)arg;
752 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
755 uap->changelist += count;
757 for (i = 0; i < count; i++) {
758 CP(ks32[i], kevp[i], ident);
759 CP(ks32[i], kevp[i], filter);
760 CP(ks32[i], kevp[i], flags);
761 CP(ks32[i], kevp[i], fflags);
762 CP(ks32[i], kevp[i], data);
763 PTRIN_CP(ks32[i], kevp[i], udata);
770 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
772 struct timespec32 ts32;
773 struct timespec ts, *tsp;
774 struct kevent_copyops k_ops = { uap,
775 freebsd32_kevent_copyout,
776 freebsd32_kevent_copyin};
781 error = copyin(uap->timeout, &ts32, sizeof(ts32));
784 CP(ts32, ts, tv_sec);
785 CP(ts32, ts, tv_nsec);
789 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
795 freebsd32_gettimeofday(struct thread *td,
796 struct freebsd32_gettimeofday_args *uap)
799 struct timeval32 atv32;
805 CP(atv, atv32, tv_sec);
806 CP(atv, atv32, tv_usec);
807 error = copyout(&atv32, uap->tp, sizeof (atv32));
809 if (error == 0 && uap->tzp != NULL) {
810 rtz.tz_minuteswest = tz_minuteswest;
811 rtz.tz_dsttime = tz_dsttime;
812 error = copyout(&rtz, uap->tzp, sizeof (rtz));
818 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
824 error = kern_getrusage(td, uap->who, &s);
827 if (uap->rusage != NULL) {
828 freebsd32_rusage_out(&s, &s32);
829 error = copyout(&s32, uap->rusage, sizeof(s32));
835 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
837 struct iovec32 iov32;
844 if (iovcnt > UIO_MAXIOV)
846 iovlen = iovcnt * sizeof(struct iovec);
847 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
848 iov = (struct iovec *)(uio + 1);
849 for (i = 0; i < iovcnt; i++) {
850 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
855 iov[i].iov_base = PTRIN(iov32.iov_base);
856 iov[i].iov_len = iov32.iov_len;
859 uio->uio_iovcnt = iovcnt;
860 uio->uio_segflg = UIO_USERSPACE;
861 uio->uio_offset = -1;
863 for (i = 0; i < iovcnt; i++) {
864 if (iov->iov_len > INT_MAX - uio->uio_resid) {
868 uio->uio_resid += iov->iov_len;
876 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
881 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
884 error = kern_readv(td, uap->fd, auio);
890 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
895 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
898 error = kern_writev(td, uap->fd, auio);
904 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
909 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
912 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
918 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
923 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
926 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
932 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
935 struct iovec32 iov32;
941 if (iovcnt > UIO_MAXIOV)
943 iovlen = iovcnt * sizeof(struct iovec);
944 iov = malloc(iovlen, M_IOV, M_WAITOK);
945 for (i = 0; i < iovcnt; i++) {
946 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
951 iov[i].iov_base = PTRIN(iov32.iov_base);
952 iov[i].iov_len = iov32.iov_len;
959 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
964 error = copyin(msg32, &m32, sizeof(m32));
967 msg->msg_name = PTRIN(m32.msg_name);
968 msg->msg_namelen = m32.msg_namelen;
969 msg->msg_iov = PTRIN(m32.msg_iov);
970 msg->msg_iovlen = m32.msg_iovlen;
971 msg->msg_control = PTRIN(m32.msg_control);
972 msg->msg_controllen = m32.msg_controllen;
973 msg->msg_flags = m32.msg_flags;
978 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
983 m32.msg_name = PTROUT(msg->msg_name);
984 m32.msg_namelen = msg->msg_namelen;
985 m32.msg_iov = PTROUT(msg->msg_iov);
986 m32.msg_iovlen = msg->msg_iovlen;
987 m32.msg_control = PTROUT(msg->msg_control);
988 m32.msg_controllen = msg->msg_controllen;
989 m32.msg_flags = msg->msg_flags;
990 error = copyout(&m32, msg32, sizeof(m32));
995 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
997 #define FREEBSD32_ALIGNBYTES (sizeof(long) - 1)
999 #define FREEBSD32_ALIGN(p) \
1000 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
1001 #define FREEBSD32_CMSG_SPACE(l) \
1002 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
1004 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1005 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1007 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1011 socklen_t clen, datalen;
1014 int len, maxlen, copylen;
1018 len = msg->msg_controllen;
1019 maxlen = msg->msg_controllen;
1020 msg->msg_controllen = 0;
1023 ctlbuf = msg->msg_control;
1025 while (m && len > 0) {
1026 cm = mtod(m, struct cmsghdr *);
1029 while (cm != NULL) {
1031 if (sizeof(struct cmsghdr) > clen ||
1032 cm->cmsg_len > clen) {
1037 data = CMSG_DATA(cm);
1038 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1040 /* Adjust message length */
1041 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1046 copylen = sizeof(struct cmsghdr);
1047 if (len < copylen) {
1048 msg->msg_flags |= MSG_CTRUNC;
1052 error = copyout(cm,ctlbuf,copylen);
1056 ctlbuf += FREEBSD32_ALIGN(copylen);
1057 len -= FREEBSD32_ALIGN(copylen);
1064 if (len < copylen) {
1065 msg->msg_flags |= MSG_CTRUNC;
1069 error = copyout(data,ctlbuf,copylen);
1073 ctlbuf += FREEBSD32_ALIGN(copylen);
1074 len -= FREEBSD32_ALIGN(copylen);
1076 if (CMSG_SPACE(datalen) < clen) {
1077 clen -= CMSG_SPACE(datalen);
1078 cm = (struct cmsghdr *)
1079 ((caddr_t)cm + CMSG_SPACE(datalen));
1088 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
1096 freebsd32_recvmsg(td, uap)
1098 struct freebsd32_recvmsg_args /* {
1100 struct msghdr32 *msg;
1105 struct msghdr32 m32;
1106 struct iovec *uiov, *iov;
1107 struct mbuf *control = NULL;
1108 struct mbuf **controlp;
1111 error = copyin(uap->msg, &m32, sizeof(m32));
1114 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1117 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1121 msg.msg_flags = uap->flags;
1125 controlp = (msg.msg_control != NULL) ? &control : NULL;
1126 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1130 if (control != NULL)
1131 error = freebsd32_copy_msg_out(&msg, control);
1133 msg.msg_controllen = 0;
1136 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1140 if (control != NULL)
1147 * Copy-in the array of control messages constructed using alignment
1148 * and padding suitable for a 32-bit environment and construct an
1149 * mbuf using alignment and padding suitable for a 64-bit kernel.
1150 * The alignment and padding are defined indirectly by CMSG_DATA(),
1151 * CMSG_SPACE() and CMSG_LEN().
1154 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1158 u_int idx, len, msglen;
1161 buflen = FREEBSD32_ALIGN(buflen);
1163 if (buflen > MCLBYTES)
1167 * Iterate over the buffer and get the length of each message
1168 * in there. This has 32-bit alignment and padding. Use it to
1169 * determine the length of these messages when using 64-bit
1170 * alignment and padding.
1174 while (idx < buflen) {
1175 error = copyin(buf + idx, &msglen, sizeof(msglen));
1178 if (msglen < sizeof(struct cmsghdr))
1180 msglen = FREEBSD32_ALIGN(msglen);
1181 if (idx + msglen > buflen)
1184 msglen += CMSG_ALIGN(sizeof(struct cmsghdr)) -
1185 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1186 len += CMSG_ALIGN(msglen);
1192 m = m_get(M_WAITOK, MT_CONTROL);
1194 MCLGET(m, M_WAITOK);
1197 md = mtod(m, void *);
1198 while (buflen > 0) {
1199 error = copyin(buf, md, sizeof(struct cmsghdr));
1202 msglen = *(u_int *)md;
1203 msglen = FREEBSD32_ALIGN(msglen);
1205 /* Modify the message length to account for alignment. */
1206 *(u_int *)md = msglen + CMSG_ALIGN(sizeof(struct cmsghdr)) -
1207 FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1209 md = (char *)md + CMSG_ALIGN(sizeof(struct cmsghdr));
1210 buf += FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1211 buflen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1213 msglen -= FREEBSD32_ALIGN(sizeof(struct cmsghdr));
1215 error = copyin(buf, md, msglen);
1218 md = (char *)md + CMSG_ALIGN(msglen);
1232 freebsd32_sendmsg(struct thread *td,
1233 struct freebsd32_sendmsg_args *uap)
1236 struct msghdr32 m32;
1238 struct mbuf *control = NULL;
1239 struct sockaddr *to = NULL;
1242 error = copyin(uap->msg, &m32, sizeof(m32));
1245 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1248 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1253 if (msg.msg_name != NULL) {
1254 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1262 if (msg.msg_control) {
1263 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1268 error = freebsd32_copyin_control(&control, msg.msg_control,
1269 msg.msg_controllen);
1273 msg.msg_control = NULL;
1274 msg.msg_controllen = 0;
1277 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1288 freebsd32_recvfrom(struct thread *td,
1289 struct freebsd32_recvfrom_args *uap)
1295 if (uap->fromlenaddr) {
1296 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1297 sizeof(msg.msg_namelen));
1301 msg.msg_namelen = 0;
1304 msg.msg_name = PTRIN(uap->from);
1305 msg.msg_iov = &aiov;
1307 aiov.iov_base = PTRIN(uap->buf);
1308 aiov.iov_len = uap->len;
1309 msg.msg_control = NULL;
1310 msg.msg_flags = uap->flags;
1311 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1312 if (error == 0 && uap->fromlenaddr)
1313 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1314 sizeof (msg.msg_namelen));
1319 freebsd32_settimeofday(struct thread *td,
1320 struct freebsd32_settimeofday_args *uap)
1322 struct timeval32 tv32;
1323 struct timeval tv, *tvp;
1324 struct timezone tz, *tzp;
1328 error = copyin(uap->tv, &tv32, sizeof(tv32));
1331 CP(tv32, tv, tv_sec);
1332 CP(tv32, tv, tv_usec);
1337 error = copyin(uap->tzp, &tz, sizeof(tz));
1343 return (kern_settimeofday(td, tvp, tzp));
1347 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1349 struct timeval32 s32[2];
1350 struct timeval s[2], *sp;
1353 if (uap->tptr != NULL) {
1354 error = copyin(uap->tptr, s32, sizeof(s32));
1357 CP(s32[0], s[0], tv_sec);
1358 CP(s32[0], s[0], tv_usec);
1359 CP(s32[1], s[1], tv_sec);
1360 CP(s32[1], s[1], tv_usec);
1364 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1368 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1370 struct timeval32 s32[2];
1371 struct timeval s[2], *sp;
1374 if (uap->tptr != NULL) {
1375 error = copyin(uap->tptr, s32, sizeof(s32));
1378 CP(s32[0], s[0], tv_sec);
1379 CP(s32[0], s[0], tv_usec);
1380 CP(s32[1], s[1], tv_sec);
1381 CP(s32[1], s[1], tv_usec);
1385 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1389 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1391 struct timeval32 s32[2];
1392 struct timeval s[2], *sp;
1395 if (uap->tptr != NULL) {
1396 error = copyin(uap->tptr, s32, sizeof(s32));
1399 CP(s32[0], s[0], tv_sec);
1400 CP(s32[0], s[0], tv_usec);
1401 CP(s32[1], s[1], tv_sec);
1402 CP(s32[1], s[1], tv_usec);
1406 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1410 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1412 struct timeval32 s32[2];
1413 struct timeval s[2], *sp;
1416 if (uap->times != NULL) {
1417 error = copyin(uap->times, s32, sizeof(s32));
1420 CP(s32[0], s[0], tv_sec);
1421 CP(s32[0], s[0], tv_usec);
1422 CP(s32[1], s[1], tv_sec);
1423 CP(s32[1], s[1], tv_usec);
1427 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1432 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1434 struct timeval32 tv32;
1435 struct timeval delta, olddelta, *deltap;
1439 error = copyin(uap->delta, &tv32, sizeof(tv32));
1442 CP(tv32, delta, tv_sec);
1443 CP(tv32, delta, tv_usec);
1447 error = kern_adjtime(td, deltap, &olddelta);
1448 if (uap->olddelta && error == 0) {
1449 CP(olddelta, tv32, tv_sec);
1450 CP(olddelta, tv32, tv_usec);
1451 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1456 #ifdef COMPAT_FREEBSD4
1458 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1460 struct statfs32 s32;
1464 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1467 copy_statfs(&s, &s32);
1468 return (copyout(&s32, uap->buf, sizeof(s32)));
1472 #ifdef COMPAT_FREEBSD4
1474 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1476 struct statfs32 s32;
1480 error = kern_fstatfs(td, uap->fd, &s);
1483 copy_statfs(&s, &s32);
1484 return (copyout(&s32, uap->buf, sizeof(s32)));
1488 #ifdef COMPAT_FREEBSD4
1490 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1492 struct statfs32 s32;
1497 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1499 error = kern_fhstatfs(td, fh, &s);
1502 copy_statfs(&s, &s32);
1503 return (copyout(&s32, uap->buf, sizeof(s32)));
1508 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1510 struct pread_args ap;
1514 ap.nbyte = uap->nbyte;
1515 ap.offset = PAIR32TO64(off_t,uap->offset);
1516 return (sys_pread(td, &ap));
1520 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1522 struct pwrite_args ap;
1526 ap.nbyte = uap->nbyte;
1527 ap.offset = PAIR32TO64(off_t,uap->offset);
1528 return (sys_pwrite(td, &ap));
1533 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1535 struct lseek_args nuap;
1538 nuap.offset = uap->offset;
1539 nuap.whence = uap->whence;
1540 return (sys_lseek(td, &nuap));
1545 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1548 struct lseek_args ap;
1552 ap.offset = PAIR32TO64(off_t,uap->offset);
1553 ap.whence = uap->whence;
1554 error = sys_lseek(td, &ap);
1555 /* Expand the quad return into two parts for eax and edx */
1556 pos = *(off_t *)(td->td_retval);
1557 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1558 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1563 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1565 struct truncate_args ap;
1567 ap.path = uap->path;
1568 ap.length = PAIR32TO64(off_t,uap->length);
1569 return (sys_truncate(td, &ap));
1573 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1575 struct ftruncate_args ap;
1578 ap.length = PAIR32TO64(off_t,uap->length);
1579 return (sys_ftruncate(td, &ap));
1584 ofreebsd32_getdirentries(struct thread *td,
1585 struct ofreebsd32_getdirentries_args *uap)
1587 struct ogetdirentries_args ap;
1594 ap.count = uap->count;
1596 error = kern_ogetdirentries(td, &ap, &loff);
1599 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
1606 freebsd32_getdirentries(struct thread *td,
1607 struct freebsd32_getdirentries_args *uap)
1613 error = kern_getdirentries(td, uap->fd, uap->buf, uap->count, &base,
1614 NULL, UIO_USERSPACE);
1617 if (uap->basep != NULL) {
1619 error = copyout(&base32, uap->basep, sizeof(int32_t));
1624 #ifdef COMPAT_FREEBSD6
1625 /* versions with the 'int pad' argument */
1627 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1629 struct pread_args ap;
1633 ap.nbyte = uap->nbyte;
1634 ap.offset = PAIR32TO64(off_t,uap->offset);
1635 return (sys_pread(td, &ap));
1639 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1641 struct pwrite_args ap;
1645 ap.nbyte = uap->nbyte;
1646 ap.offset = PAIR32TO64(off_t,uap->offset);
1647 return (sys_pwrite(td, &ap));
1651 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1654 struct lseek_args ap;
1658 ap.offset = PAIR32TO64(off_t,uap->offset);
1659 ap.whence = uap->whence;
1660 error = sys_lseek(td, &ap);
1661 /* Expand the quad return into two parts for eax and edx */
1662 pos = *(off_t *)(td->td_retval);
1663 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1664 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1669 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1671 struct truncate_args ap;
1673 ap.path = uap->path;
1674 ap.length = PAIR32TO64(off_t,uap->length);
1675 return (sys_truncate(td, &ap));
1679 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1681 struct ftruncate_args ap;
1684 ap.length = PAIR32TO64(off_t,uap->length);
1685 return (sys_ftruncate(td, &ap));
1687 #endif /* COMPAT_FREEBSD6 */
1697 freebsd32_do_sendfile(struct thread *td,
1698 struct freebsd32_sendfile_args *uap, int compat)
1700 struct sf_hdtr32 hdtr32;
1701 struct sf_hdtr hdtr;
1702 struct uio *hdr_uio, *trl_uio;
1703 struct iovec32 *iov32;
1705 cap_rights_t rights;
1709 offset = PAIR32TO64(off_t, uap->offset);
1713 hdr_uio = trl_uio = NULL;
1715 if (uap->hdtr != NULL) {
1716 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1719 PTRIN_CP(hdtr32, hdtr, headers);
1720 CP(hdtr32, hdtr, hdr_cnt);
1721 PTRIN_CP(hdtr32, hdtr, trailers);
1722 CP(hdtr32, hdtr, trl_cnt);
1724 if (hdtr.headers != NULL) {
1725 iov32 = PTRIN(hdtr32.headers);
1726 error = freebsd32_copyinuio(iov32,
1727 hdtr32.hdr_cnt, &hdr_uio);
1731 if (hdtr.trailers != NULL) {
1732 iov32 = PTRIN(hdtr32.trailers);
1733 error = freebsd32_copyinuio(iov32,
1734 hdtr32.trl_cnt, &trl_uio);
1740 AUDIT_ARG_FD(uap->fd);
1742 if ((error = fget_read(td, uap->fd,
1743 cap_rights_init(&rights, CAP_PREAD), &fp)) != 0) {
1747 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
1748 uap->nbytes, uap->sbytes, uap->flags, compat ? SFK_COMPAT : 0, td);
1753 free(hdr_uio, M_IOV);
1755 free(trl_uio, M_IOV);
1759 #ifdef COMPAT_FREEBSD4
1761 freebsd4_freebsd32_sendfile(struct thread *td,
1762 struct freebsd4_freebsd32_sendfile_args *uap)
1764 return (freebsd32_do_sendfile(td,
1765 (struct freebsd32_sendfile_args *)uap, 1));
1770 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1773 return (freebsd32_do_sendfile(td, uap, 0));
1777 copy_stat(struct stat *in, struct stat32 *out)
1780 CP(*in, *out, st_dev);
1781 CP(*in, *out, st_ino);
1782 CP(*in, *out, st_mode);
1783 CP(*in, *out, st_nlink);
1784 CP(*in, *out, st_uid);
1785 CP(*in, *out, st_gid);
1786 CP(*in, *out, st_rdev);
1787 TS_CP(*in, *out, st_atim);
1788 TS_CP(*in, *out, st_mtim);
1789 TS_CP(*in, *out, st_ctim);
1790 CP(*in, *out, st_size);
1791 CP(*in, *out, st_blocks);
1792 CP(*in, *out, st_blksize);
1793 CP(*in, *out, st_flags);
1794 CP(*in, *out, st_gen);
1795 TS_CP(*in, *out, st_birthtim);
1800 copy_ostat(struct stat *in, struct ostat32 *out)
1803 CP(*in, *out, st_dev);
1804 CP(*in, *out, st_ino);
1805 CP(*in, *out, st_mode);
1806 CP(*in, *out, st_nlink);
1807 CP(*in, *out, st_uid);
1808 CP(*in, *out, st_gid);
1809 CP(*in, *out, st_rdev);
1810 CP(*in, *out, st_size);
1811 TS_CP(*in, *out, st_atim);
1812 TS_CP(*in, *out, st_mtim);
1813 TS_CP(*in, *out, st_ctim);
1814 CP(*in, *out, st_blksize);
1815 CP(*in, *out, st_blocks);
1816 CP(*in, *out, st_flags);
1817 CP(*in, *out, st_gen);
1822 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1828 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1831 copy_stat(&sb, &sb32);
1832 error = copyout(&sb32, uap->ub, sizeof (sb32));
1838 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
1841 struct ostat32 sb32;
1844 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1847 copy_ostat(&sb, &sb32);
1848 error = copyout(&sb32, uap->ub, sizeof (sb32));
1854 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1860 error = kern_fstat(td, uap->fd, &ub);
1863 copy_stat(&ub, &ub32);
1864 error = copyout(&ub32, uap->ub, sizeof(ub32));
1870 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
1873 struct ostat32 ub32;
1876 error = kern_fstat(td, uap->fd, &ub);
1879 copy_ostat(&ub, &ub32);
1880 error = copyout(&ub32, uap->ub, sizeof(ub32));
1886 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
1892 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE, &ub);
1895 copy_stat(&ub, &ub32);
1896 error = copyout(&ub32, uap->buf, sizeof(ub32));
1901 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1907 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1910 copy_stat(&sb, &sb32);
1911 error = copyout(&sb32, uap->ub, sizeof (sb32));
1917 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
1920 struct ostat32 sb32;
1923 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1926 copy_ostat(&sb, &sb32);
1927 error = copyout(&sb32, uap->ub, sizeof (sb32));
1933 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1935 int error, name[CTL_MAXNAME];
1939 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1941 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1945 error = fueword32(uap->oldlenp, &tmp);
1952 error = userland_sysctl(td, name, uap->namelen,
1953 uap->old, &oldlen, 1,
1954 uap->new, uap->newlen, &j, SCTL_MASK32);
1955 if (error && error != ENOMEM)
1958 suword32(uap->oldlenp, j);
1963 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
1969 error = copyin(uap->jail, &version, sizeof(uint32_t));
1976 /* FreeBSD single IPv4 jails. */
1977 struct jail32_v0 j32_v0;
1979 bzero(&j, sizeof(struct jail));
1980 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
1983 CP(j32_v0, j, version);
1984 PTRIN_CP(j32_v0, j, path);
1985 PTRIN_CP(j32_v0, j, hostname);
1986 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
1992 * Version 1 was used by multi-IPv4 jail implementations
1993 * that never made it into the official kernel.
1997 case 2: /* JAIL_API_VERSION */
1999 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
2002 error = copyin(uap->jail, &j32, sizeof(struct jail32));
2005 CP(j32, j, version);
2006 PTRIN_CP(j32, j, path);
2007 PTRIN_CP(j32, j, hostname);
2008 PTRIN_CP(j32, j, jailname);
2011 PTRIN_CP(j32, j, ip4);
2012 PTRIN_CP(j32, j, ip6);
2017 /* Sci-Fi jails are not supported, sorry. */
2020 return (kern_jail(td, &j));
2024 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2029 /* Check that we have an even number of iovecs. */
2030 if (uap->iovcnt & 1)
2033 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2036 error = kern_jail_set(td, auio, uap->flags);
2042 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2044 struct iovec32 iov32;
2048 /* Check that we have an even number of iovecs. */
2049 if (uap->iovcnt & 1)
2052 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2055 error = kern_jail_get(td, auio, uap->flags);
2057 for (i = 0; i < uap->iovcnt; i++) {
2058 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2059 CP(auio->uio_iov[i], iov32, iov_len);
2060 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2069 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2071 struct sigaction32 s32;
2072 struct sigaction sa, osa, *sap;
2076 error = copyin(uap->act, &s32, sizeof(s32));
2079 sa.sa_handler = PTRIN(s32.sa_u);
2080 CP(s32, sa, sa_flags);
2081 CP(s32, sa, sa_mask);
2085 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2086 if (error == 0 && uap->oact != NULL) {
2087 s32.sa_u = PTROUT(osa.sa_handler);
2088 CP(osa, s32, sa_flags);
2089 CP(osa, s32, sa_mask);
2090 error = copyout(&s32, uap->oact, sizeof(s32));
2095 #ifdef COMPAT_FREEBSD4
2097 freebsd4_freebsd32_sigaction(struct thread *td,
2098 struct freebsd4_freebsd32_sigaction_args *uap)
2100 struct sigaction32 s32;
2101 struct sigaction sa, osa, *sap;
2105 error = copyin(uap->act, &s32, sizeof(s32));
2108 sa.sa_handler = PTRIN(s32.sa_u);
2109 CP(s32, sa, sa_flags);
2110 CP(s32, sa, sa_mask);
2114 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2115 if (error == 0 && uap->oact != NULL) {
2116 s32.sa_u = PTROUT(osa.sa_handler);
2117 CP(osa, s32, sa_flags);
2118 CP(osa, s32, sa_mask);
2119 error = copyout(&s32, uap->oact, sizeof(s32));
2126 struct osigaction32 {
2135 ofreebsd32_sigaction(struct thread *td,
2136 struct ofreebsd32_sigaction_args *uap)
2138 struct osigaction32 s32;
2139 struct sigaction sa, osa, *sap;
2142 if (uap->signum <= 0 || uap->signum >= ONSIG)
2146 error = copyin(uap->nsa, &s32, sizeof(s32));
2149 sa.sa_handler = PTRIN(s32.sa_u);
2150 CP(s32, sa, sa_flags);
2151 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2155 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2156 if (error == 0 && uap->osa != NULL) {
2157 s32.sa_u = PTROUT(osa.sa_handler);
2158 CP(osa, s32, sa_flags);
2159 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2160 error = copyout(&s32, uap->osa, sizeof(s32));
2166 ofreebsd32_sigprocmask(struct thread *td,
2167 struct ofreebsd32_sigprocmask_args *uap)
2172 OSIG2SIG(uap->mask, set);
2173 error = kern_sigprocmask(td, uap->how, &set, &oset, SIGPROCMASK_OLD);
2174 SIG2OSIG(oset, td->td_retval[0]);
2179 ofreebsd32_sigpending(struct thread *td,
2180 struct ofreebsd32_sigpending_args *uap)
2182 struct proc *p = td->td_proc;
2186 siglist = p->p_siglist;
2187 SIGSETOR(siglist, td->td_siglist);
2189 SIG2OSIG(siglist, td->td_retval[0]);
2194 u_int32_t sv_handler;
2200 ofreebsd32_sigvec(struct thread *td,
2201 struct ofreebsd32_sigvec_args *uap)
2203 struct sigvec32 vec;
2204 struct sigaction sa, osa, *sap;
2207 if (uap->signum <= 0 || uap->signum >= ONSIG)
2211 error = copyin(uap->nsv, &vec, sizeof(vec));
2214 sa.sa_handler = PTRIN(vec.sv_handler);
2215 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2216 sa.sa_flags = vec.sv_flags;
2217 sa.sa_flags ^= SA_RESTART;
2221 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2222 if (error == 0 && uap->osv != NULL) {
2223 vec.sv_handler = PTROUT(osa.sa_handler);
2224 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2225 vec.sv_flags = osa.sa_flags;
2226 vec.sv_flags &= ~SA_NOCLDWAIT;
2227 vec.sv_flags ^= SA_RESTART;
2228 error = copyout(&vec, uap->osv, sizeof(vec));
2234 ofreebsd32_sigblock(struct thread *td,
2235 struct ofreebsd32_sigblock_args *uap)
2239 OSIG2SIG(uap->mask, set);
2240 kern_sigprocmask(td, SIG_BLOCK, &set, &oset, 0);
2241 SIG2OSIG(oset, td->td_retval[0]);
2246 ofreebsd32_sigsetmask(struct thread *td,
2247 struct ofreebsd32_sigsetmask_args *uap)
2251 OSIG2SIG(uap->mask, set);
2252 kern_sigprocmask(td, SIG_SETMASK, &set, &oset, 0);
2253 SIG2OSIG(oset, td->td_retval[0]);
2258 ofreebsd32_sigsuspend(struct thread *td,
2259 struct ofreebsd32_sigsuspend_args *uap)
2263 OSIG2SIG(uap->mask, mask);
2264 return (kern_sigsuspend(td, mask));
2273 ofreebsd32_sigstack(struct thread *td,
2274 struct ofreebsd32_sigstack_args *uap)
2276 struct sigstack32 s32;
2277 struct sigstack nss, oss;
2278 int error = 0, unss;
2280 if (uap->nss != NULL) {
2281 error = copyin(uap->nss, &s32, sizeof(s32));
2284 nss.ss_sp = PTRIN(s32.ss_sp);
2285 CP(s32, nss, ss_onstack);
2290 oss.ss_sp = td->td_sigstk.ss_sp;
2291 oss.ss_onstack = sigonstack(cpu_getstack(td));
2293 td->td_sigstk.ss_sp = nss.ss_sp;
2294 td->td_sigstk.ss_size = 0;
2295 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2296 td->td_pflags |= TDP_ALTSTACK;
2298 if (uap->oss != NULL) {
2299 s32.ss_sp = PTROUT(oss.ss_sp);
2300 CP(oss, s32, ss_onstack);
2301 error = copyout(&s32, uap->oss, sizeof(s32));
2308 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2310 struct timespec32 rmt32, rqt32;
2311 struct timespec rmt, rqt;
2314 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2318 CP(rqt32, rqt, tv_sec);
2319 CP(rqt32, rqt, tv_nsec);
2322 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2324 error = kern_nanosleep(td, &rqt, &rmt);
2325 if (error && uap->rmtp) {
2328 CP(rmt, rmt32, tv_sec);
2329 CP(rmt, rmt32, tv_nsec);
2331 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2339 freebsd32_clock_gettime(struct thread *td,
2340 struct freebsd32_clock_gettime_args *uap)
2342 struct timespec ats;
2343 struct timespec32 ats32;
2346 error = kern_clock_gettime(td, uap->clock_id, &ats);
2348 CP(ats, ats32, tv_sec);
2349 CP(ats, ats32, tv_nsec);
2350 error = copyout(&ats32, uap->tp, sizeof(ats32));
2356 freebsd32_clock_settime(struct thread *td,
2357 struct freebsd32_clock_settime_args *uap)
2359 struct timespec ats;
2360 struct timespec32 ats32;
2363 error = copyin(uap->tp, &ats32, sizeof(ats32));
2366 CP(ats32, ats, tv_sec);
2367 CP(ats32, ats, tv_nsec);
2369 return (kern_clock_settime(td, uap->clock_id, &ats));
2373 freebsd32_clock_getres(struct thread *td,
2374 struct freebsd32_clock_getres_args *uap)
2377 struct timespec32 ts32;
2380 if (uap->tp == NULL)
2382 error = kern_clock_getres(td, uap->clock_id, &ts);
2384 CP(ts, ts32, tv_sec);
2385 CP(ts, ts32, tv_nsec);
2386 error = copyout(&ts32, uap->tp, sizeof(ts32));
2391 int freebsd32_ktimer_create(struct thread *td,
2392 struct freebsd32_ktimer_create_args *uap)
2394 struct sigevent32 ev32;
2395 struct sigevent ev, *evp;
2398 if (uap->evp == NULL) {
2402 error = copyin(uap->evp, &ev32, sizeof(ev32));
2405 error = convert_sigevent32(&ev32, &ev);
2409 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
2411 error = copyout(&id, uap->timerid, sizeof(int));
2413 kern_ktimer_delete(td, id);
2419 freebsd32_ktimer_settime(struct thread *td,
2420 struct freebsd32_ktimer_settime_args *uap)
2422 struct itimerspec32 val32, oval32;
2423 struct itimerspec val, oval, *ovalp;
2426 error = copyin(uap->value, &val32, sizeof(val32));
2430 ovalp = uap->ovalue != NULL ? &oval : NULL;
2431 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
2432 if (error == 0 && uap->ovalue != NULL) {
2433 ITS_CP(oval, oval32);
2434 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
2440 freebsd32_ktimer_gettime(struct thread *td,
2441 struct freebsd32_ktimer_gettime_args *uap)
2443 struct itimerspec32 val32;
2444 struct itimerspec val;
2447 error = kern_ktimer_gettime(td, uap->timerid, &val);
2450 error = copyout(&val32, uap->value, sizeof(val32));
2456 freebsd32_clock_getcpuclockid2(struct thread *td,
2457 struct freebsd32_clock_getcpuclockid2_args *uap)
2462 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
2463 uap->which, &clk_id);
2465 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
2470 freebsd32_thr_new(struct thread *td,
2471 struct freebsd32_thr_new_args *uap)
2473 struct thr_param32 param32;
2474 struct thr_param param;
2477 if (uap->param_size < 0 ||
2478 uap->param_size > sizeof(struct thr_param32))
2480 bzero(¶m, sizeof(struct thr_param));
2481 bzero(¶m32, sizeof(struct thr_param32));
2482 error = copyin(uap->param, ¶m32, uap->param_size);
2485 param.start_func = PTRIN(param32.start_func);
2486 param.arg = PTRIN(param32.arg);
2487 param.stack_base = PTRIN(param32.stack_base);
2488 param.stack_size = param32.stack_size;
2489 param.tls_base = PTRIN(param32.tls_base);
2490 param.tls_size = param32.tls_size;
2491 param.child_tid = PTRIN(param32.child_tid);
2492 param.parent_tid = PTRIN(param32.parent_tid);
2493 param.flags = param32.flags;
2494 param.rtp = PTRIN(param32.rtp);
2495 param.spare[0] = PTRIN(param32.spare[0]);
2496 param.spare[1] = PTRIN(param32.spare[1]);
2497 param.spare[2] = PTRIN(param32.spare[2]);
2499 return (kern_thr_new(td, ¶m));
2503 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2505 struct timespec32 ts32;
2506 struct timespec ts, *tsp;
2511 if (uap->timeout != NULL) {
2512 error = copyin((const void *)uap->timeout, (void *)&ts32,
2513 sizeof(struct timespec32));
2516 ts.tv_sec = ts32.tv_sec;
2517 ts.tv_nsec = ts32.tv_nsec;
2520 return (kern_thr_suspend(td, tsp));
2524 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
2526 bzero(dst, sizeof(*dst));
2527 dst->si_signo = src->si_signo;
2528 dst->si_errno = src->si_errno;
2529 dst->si_code = src->si_code;
2530 dst->si_pid = src->si_pid;
2531 dst->si_uid = src->si_uid;
2532 dst->si_status = src->si_status;
2533 dst->si_addr = (uintptr_t)src->si_addr;
2534 dst->si_value.sival_int = src->si_value.sival_int;
2535 dst->si_timerid = src->si_timerid;
2536 dst->si_overrun = src->si_overrun;
2540 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2542 struct timespec32 ts32;
2544 struct timespec *timeout;
2547 struct siginfo32 si32;
2551 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2554 ts.tv_sec = ts32.tv_sec;
2555 ts.tv_nsec = ts32.tv_nsec;
2560 error = copyin(uap->set, &set, sizeof(set));
2564 error = kern_sigtimedwait(td, set, &ksi, timeout);
2569 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2570 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2574 td->td_retval[0] = ksi.ksi_signo;
2582 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2585 struct siginfo32 si32;
2589 error = copyin(uap->set, &set, sizeof(set));
2593 error = kern_sigtimedwait(td, set, &ksi, NULL);
2598 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2599 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2602 td->td_retval[0] = ksi.ksi_signo;
2607 freebsd32_cpuset_setid(struct thread *td,
2608 struct freebsd32_cpuset_setid_args *uap)
2610 struct cpuset_setid_args ap;
2612 ap.which = uap->which;
2613 ap.id = PAIR32TO64(id_t,uap->id);
2614 ap.setid = uap->setid;
2616 return (sys_cpuset_setid(td, &ap));
2620 freebsd32_cpuset_getid(struct thread *td,
2621 struct freebsd32_cpuset_getid_args *uap)
2623 struct cpuset_getid_args ap;
2625 ap.level = uap->level;
2626 ap.which = uap->which;
2627 ap.id = PAIR32TO64(id_t,uap->id);
2628 ap.setid = uap->setid;
2630 return (sys_cpuset_getid(td, &ap));
2634 freebsd32_cpuset_getaffinity(struct thread *td,
2635 struct freebsd32_cpuset_getaffinity_args *uap)
2637 struct cpuset_getaffinity_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_getaffinity(td, &ap));
2649 freebsd32_cpuset_setaffinity(struct thread *td,
2650 struct freebsd32_cpuset_setaffinity_args *uap)
2652 struct cpuset_setaffinity_args ap;
2654 ap.level = uap->level;
2655 ap.which = uap->which;
2656 ap.id = PAIR32TO64(id_t,uap->id);
2657 ap.cpusetsize = uap->cpusetsize;
2658 ap.mask = uap->mask;
2660 return (sys_cpuset_setaffinity(td, &ap));
2664 freebsd32_nmount(struct thread *td,
2665 struct freebsd32_nmount_args /* {
2667 unsigned int iovcnt;
2676 * Mount flags are now 64-bits. On 32-bit archtectures only
2677 * 32-bits are passed in, but from here on everything handles
2678 * 64-bit flags correctly.
2682 AUDIT_ARG_FFLAGS(flags);
2685 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
2686 * userspace to set this flag, but we must filter it out if we want
2687 * MNT_UPDATE on the root file system to work.
2688 * MNT_ROOTFS should only be set by the kernel when mounting its
2691 flags &= ~MNT_ROOTFS;
2694 * check that we have an even number of iovec's
2695 * and that we have at least two options.
2697 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
2700 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2703 error = vfs_donmount(td, flags, auio);
2711 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2713 struct yyy32 *p32, s32;
2714 struct yyy *p = NULL, s;
2719 error = copyin(uap->zzz, &s32, sizeof(s32));
2725 error = kern_xxx(td, p);
2730 error = copyout(&s32, p32, sizeof(s32));
2737 syscall32_register(int *offset, struct sysent *new_sysent,
2738 struct sysent *old_sysent)
2740 if (*offset == NO_SYSCALL) {
2743 for (i = 1; i < SYS_MAXSYSCALL; ++i)
2744 if (freebsd32_sysent[i].sy_call ==
2745 (sy_call_t *)lkmnosys)
2747 if (i == SYS_MAXSYSCALL)
2750 } else if (*offset < 0 || *offset >= SYS_MAXSYSCALL)
2752 else if (freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmnosys &&
2753 freebsd32_sysent[*offset].sy_call != (sy_call_t *)lkmressys)
2756 *old_sysent = freebsd32_sysent[*offset];
2757 freebsd32_sysent[*offset] = *new_sysent;
2762 syscall32_deregister(int *offset, struct sysent *old_sysent)
2766 freebsd32_sysent[*offset] = *old_sysent;
2771 syscall32_module_handler(struct module *mod, int what, void *arg)
2773 struct syscall_module_data *data = (struct syscall_module_data*)arg;
2779 error = syscall32_register(data->offset, data->new_sysent,
2782 /* Leave a mark so we know to safely unload below. */
2783 data->offset = NULL;
2786 ms.intval = *data->offset;
2788 module_setspecific(mod, &ms);
2791 error = data->chainevh(mod, what, data->chainarg);
2795 * MOD_LOAD failed, so just return without calling the
2796 * chained handler since we didn't pass along the MOD_LOAD
2799 if (data->offset == NULL)
2801 if (data->chainevh) {
2802 error = data->chainevh(mod, what, data->chainarg);
2806 error = syscall32_deregister(data->offset, &data->old_sysent);
2811 error = data->chainevh(mod, what, data->chainarg);
2817 syscall32_helper_register(struct syscall_helper_data *sd)
2819 struct syscall_helper_data *sd1;
2822 for (sd1 = sd; sd1->syscall_no != NO_SYSCALL; sd1++) {
2823 error = syscall32_register(&sd1->syscall_no, &sd1->new_sysent,
2826 syscall32_helper_unregister(sd);
2829 sd1->registered = 1;
2835 syscall32_helper_unregister(struct syscall_helper_data *sd)
2837 struct syscall_helper_data *sd1;
2839 for (sd1 = sd; sd1->registered != 0; sd1++) {
2840 syscall32_deregister(&sd1->syscall_no, &sd1->old_sysent);
2841 sd1->registered = 0;
2847 freebsd32_copyout_strings(struct image_params *imgp)
2853 u_int32_t *stack_base;
2854 struct freebsd32_ps_strings *arginfo;
2855 char canary[sizeof(long) * 8];
2856 int32_t pagesizes32[MAXPAGESIZES];
2857 size_t execpath_len;
2861 * Calculate string base and vector table pointers.
2862 * Also deal with signal trampoline code for this exec type.
2864 if (imgp->execpath != NULL && imgp->auxargs != NULL)
2865 execpath_len = strlen(imgp->execpath) + 1;
2868 arginfo = (struct freebsd32_ps_strings *)curproc->p_sysent->
2870 if (imgp->proc->p_sysent->sv_sigcode_base == 0)
2871 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
2874 destp = (uintptr_t)arginfo;
2879 if (szsigcode != 0) {
2881 destp = rounddown2(destp, sizeof(uint32_t));
2882 copyout(imgp->proc->p_sysent->sv_sigcode, (void *)destp,
2887 * Copy the image path for the rtld.
2889 if (execpath_len != 0) {
2890 destp -= execpath_len;
2891 imgp->execpathp = destp;
2892 copyout(imgp->execpath, (void *)destp, execpath_len);
2896 * Prepare the canary for SSP.
2898 arc4rand(canary, sizeof(canary), 0);
2899 destp -= sizeof(canary);
2900 imgp->canary = destp;
2901 copyout(canary, (void *)destp, sizeof(canary));
2902 imgp->canarylen = sizeof(canary);
2905 * Prepare the pagesizes array.
2907 for (i = 0; i < MAXPAGESIZES; i++)
2908 pagesizes32[i] = (uint32_t)pagesizes[i];
2909 destp -= sizeof(pagesizes32);
2910 destp = rounddown2(destp, sizeof(uint32_t));
2911 imgp->pagesizes = destp;
2912 copyout(pagesizes32, (void *)destp, sizeof(pagesizes32));
2913 imgp->pagesizeslen = sizeof(pagesizes32);
2915 destp -= ARG_MAX - imgp->args->stringspace;
2916 destp = rounddown2(destp, sizeof(uint32_t));
2919 * If we have a valid auxargs ptr, prepare some room
2922 if (imgp->auxargs) {
2924 * 'AT_COUNT*2' is size for the ELF Auxargs data. This is for
2925 * lower compatibility.
2927 imgp->auxarg_size = (imgp->auxarg_size) ? imgp->auxarg_size
2930 * The '+ 2' is for the null pointers at the end of each of
2931 * the arg and env vector sets,and imgp->auxarg_size is room
2932 * for argument of Runtime loader.
2934 vectp = (u_int32_t *) (destp - (imgp->args->argc +
2935 imgp->args->envc + 2 + imgp->auxarg_size + execpath_len) *
2939 * The '+ 2' is for the null pointers at the end of each of
2940 * the arg and env vector sets
2942 vectp = (u_int32_t *)(destp - (imgp->args->argc +
2943 imgp->args->envc + 2) * sizeof(u_int32_t));
2947 * vectp also becomes our initial stack base
2951 stringp = imgp->args->begin_argv;
2952 argc = imgp->args->argc;
2953 envc = imgp->args->envc;
2955 * Copy out strings - arguments and environment.
2957 copyout(stringp, (void *)destp, ARG_MAX - imgp->args->stringspace);
2960 * Fill in "ps_strings" struct for ps, w, etc.
2962 suword32(&arginfo->ps_argvstr, (u_int32_t)(intptr_t)vectp);
2963 suword32(&arginfo->ps_nargvstr, argc);
2966 * Fill in argument portion of vector table.
2968 for (; argc > 0; --argc) {
2969 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2970 while (*stringp++ != 0)
2975 /* a null vector table pointer separates the argp's from the envp's */
2976 suword32(vectp++, 0);
2978 suword32(&arginfo->ps_envstr, (u_int32_t)(intptr_t)vectp);
2979 suword32(&arginfo->ps_nenvstr, envc);
2982 * Fill in environment portion of vector table.
2984 for (; envc > 0; --envc) {
2985 suword32(vectp++, (u_int32_t)(intptr_t)destp);
2986 while (*stringp++ != 0)
2991 /* end of vector table is a null pointer */
2994 return ((register_t *)stack_base);
2998 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
3000 struct kld_file_stat stat;
3001 struct kld32_file_stat stat32;
3004 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
3007 if (version != sizeof(struct kld32_file_stat_1) &&
3008 version != sizeof(struct kld32_file_stat))
3011 error = kern_kldstat(td, uap->fileid, &stat);
3015 bcopy(&stat.name[0], &stat32.name[0], sizeof(stat.name));
3016 CP(stat, stat32, refs);
3017 CP(stat, stat32, id);
3018 PTROUT_CP(stat, stat32, address);
3019 CP(stat, stat32, size);
3020 bcopy(&stat.pathname[0], &stat32.pathname[0], sizeof(stat.pathname));
3021 return (copyout(&stat32, uap->stat, version));
3025 freebsd32_posix_fallocate(struct thread *td,
3026 struct freebsd32_posix_fallocate_args *uap)
3029 td->td_retval[0] = kern_posix_fallocate(td, uap->fd,
3030 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3035 freebsd32_posix_fadvise(struct thread *td,
3036 struct freebsd32_posix_fadvise_args *uap)
3039 td->td_retval[0] = kern_posix_fadvise(td, uap->fd,
3040 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len),
3046 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3049 CP(*sig32, *sig, sigev_notify);
3050 switch (sig->sigev_notify) {
3053 case SIGEV_THREAD_ID:
3054 CP(*sig32, *sig, sigev_notify_thread_id);
3057 CP(*sig32, *sig, sigev_signo);
3058 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3061 CP(*sig32, *sig, sigev_notify_kqueue);
3062 CP(*sig32, *sig, sigev_notify_kevent_flags);
3063 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3072 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3076 struct procctl_reaper_status rs;
3077 struct procctl_reaper_pids rp;
3078 struct procctl_reaper_kill rk;
3081 struct procctl_reaper_pids32 rp;
3083 int error, error1, flags;
3087 case PROC_TRACE_CTL:
3088 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3093 case PROC_REAP_ACQUIRE:
3094 case PROC_REAP_RELEASE:
3095 if (uap->data != NULL)
3099 case PROC_REAP_STATUS:
3102 case PROC_REAP_GETPIDS:
3103 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3106 CP(x32.rp, x.rp, rp_count);
3107 PTRIN_CP(x32.rp, x.rp, rp_pids);
3110 case PROC_REAP_KILL:
3111 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3116 case PROC_TRACE_STATUS:
3122 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3125 case PROC_REAP_STATUS:
3127 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3129 case PROC_REAP_KILL:
3130 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3134 case PROC_TRACE_STATUS:
3136 error = copyout(&flags, uap->data, sizeof(flags));
3143 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3149 * Do unsigned conversion for arg when operation
3150 * interprets it as flags or pointer.
3152 case F_SETLK_REMOTE:
3161 tmp = (unsigned int)(uap->arg);
3167 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3171 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3173 struct timespec32 ts32;
3174 struct timespec ts, *tsp;
3178 if (uap->ts != NULL) {
3179 error = copyin(uap->ts, &ts32, sizeof(ts32));
3182 CP(ts32, ts, tv_sec);
3183 CP(ts32, ts, tv_nsec);
3187 if (uap->set != NULL) {
3188 error = copyin(uap->set, &set, sizeof(set));
3195 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));