2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2002 Doug Rabson
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include "opt_ffclock.h"
34 #include "opt_inet6.h"
35 #include "opt_ktrace.h"
37 #define __ELF_WORD_SIZE 32
39 #ifdef COMPAT_FREEBSD11
40 #define _WANT_FREEBSD11_KEVENT
43 #include <sys/param.h>
45 #include <sys/capsicum.h>
46 #include <sys/clock.h>
48 #include <sys/fcntl.h>
49 #include <sys/filedesc.h>
50 #include <sys/imgact.h>
52 #include <sys/kernel.h>
53 #include <sys/limits.h>
54 #include <sys/linker.h>
56 #include <sys/malloc.h>
57 #include <sys/file.h> /* Must come after sys/malloc.h */
58 #include <sys/imgact.h>
61 #include <sys/module.h>
62 #include <sys/mount.h>
63 #include <sys/mutex.h>
64 #include <sys/namei.h>
67 #include <sys/procctl.h>
68 #include <sys/ptrace.h>
69 #include <sys/reboot.h>
70 #include <sys/resource.h>
71 #include <sys/resourcevar.h>
72 #include <sys/selinfo.h>
73 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
74 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
75 #include <sys/signal.h>
76 #include <sys/signalvar.h>
77 #include <sys/socket.h>
78 #include <sys/socketvar.h>
80 #include <sys/syscall.h>
81 #include <sys/syscallsubr.h>
82 #include <sys/sysctl.h>
83 #include <sys/sysent.h>
84 #include <sys/sysproto.h>
85 #include <sys/systm.h>
87 #include <sys/timex.h>
88 #include <sys/unistd.h>
89 #include <sys/ucontext.h>
90 #include <sys/vnode.h>
96 #include <sys/timeffc.h>
98 #include <sys/ktrace.h>
102 #include <netinet/in.h>
106 #include <vm/vm_param.h>
108 #include <vm/vm_map.h>
109 #include <vm/vm_object.h>
110 #include <vm/vm_extern.h>
112 #include <machine/cpu.h>
113 #include <machine/elf.h>
115 #include <machine/md_var.h>
118 #include <security/audit/audit.h>
120 #include <compat/freebsd32/freebsd32_util.h>
121 #include <compat/freebsd32/freebsd32.h>
122 #include <compat/freebsd32/freebsd32_ipc.h>
123 #include <compat/freebsd32/freebsd32_misc.h>
124 #include <compat/freebsd32/freebsd32_signal.h>
125 #include <compat/freebsd32/freebsd32_proto.h>
127 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
129 struct ptrace_io_desc32 {
136 struct ptrace_vm_entry32 {
150 CTASSERT(sizeof(struct timeval32) == 8);
151 CTASSERT(sizeof(struct timespec32) == 8);
152 CTASSERT(sizeof(struct itimerval32) == 16);
153 CTASSERT(sizeof(struct bintime32) == 12);
155 CTASSERT(sizeof(struct timeval32) == 16);
156 CTASSERT(sizeof(struct timespec32) == 16);
157 CTASSERT(sizeof(struct itimerval32) == 32);
158 CTASSERT(sizeof(struct bintime32) == 16);
160 CTASSERT(sizeof(struct ostatfs32) == 256);
162 CTASSERT(sizeof(struct rusage32) == 72);
164 CTASSERT(sizeof(struct rusage32) == 88);
166 CTASSERT(sizeof(struct sigaltstack32) == 12);
168 CTASSERT(sizeof(struct kevent32) == 56);
170 CTASSERT(sizeof(struct kevent32) == 64);
172 CTASSERT(sizeof(struct iovec32) == 8);
173 CTASSERT(sizeof(struct msghdr32) == 28);
175 CTASSERT(sizeof(struct stat32) == 208);
176 CTASSERT(sizeof(struct freebsd11_stat32) == 96);
178 CTASSERT(sizeof(struct stat32) == 224);
179 CTASSERT(sizeof(struct freebsd11_stat32) == 120);
181 CTASSERT(sizeof(struct sigaction32) == 24);
183 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
184 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
185 static int freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
186 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp);
189 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
192 TV_CP(*s, *s32, ru_utime);
193 TV_CP(*s, *s32, ru_stime);
194 CP(*s, *s32, ru_maxrss);
195 CP(*s, *s32, ru_ixrss);
196 CP(*s, *s32, ru_idrss);
197 CP(*s, *s32, ru_isrss);
198 CP(*s, *s32, ru_minflt);
199 CP(*s, *s32, ru_majflt);
200 CP(*s, *s32, ru_nswap);
201 CP(*s, *s32, ru_inblock);
202 CP(*s, *s32, ru_oublock);
203 CP(*s, *s32, ru_msgsnd);
204 CP(*s, *s32, ru_msgrcv);
205 CP(*s, *s32, ru_nsignals);
206 CP(*s, *s32, ru_nvcsw);
207 CP(*s, *s32, ru_nivcsw);
211 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
214 struct rusage32 ru32;
215 struct rusage ru, *rup;
217 if (uap->rusage != NULL)
221 error = kern_wait(td, uap->pid, &status, uap->options, rup);
224 if (uap->status != NULL)
225 error = copyout(&status, uap->status, sizeof(status));
226 if (uap->rusage != NULL && error == 0) {
227 freebsd32_rusage_out(&ru, &ru32);
228 error = copyout(&ru32, uap->rusage, sizeof(ru32));
234 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
236 struct __wrusage32 wru32;
237 struct __wrusage wru, *wrup;
238 struct siginfo32 si32;
239 struct __siginfo si, *sip;
242 if (uap->wrusage != NULL)
246 if (uap->info != NULL) {
248 bzero(sip, sizeof(*sip));
251 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
252 &status, uap->options, wrup, sip);
255 if (uap->status != NULL)
256 error = copyout(&status, uap->status, sizeof(status));
257 if (uap->wrusage != NULL && error == 0) {
258 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
259 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
260 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
262 if (uap->info != NULL && error == 0) {
263 siginfo_to_siginfo32 (&si, &si32);
264 error = copyout(&si32, uap->info, sizeof(si32));
269 #ifdef COMPAT_FREEBSD4
271 copy_statfs(struct statfs *in, struct ostatfs32 *out)
274 statfs_scale_blocks(in, INT32_MAX);
275 bzero(out, sizeof(*out));
276 CP(*in, *out, f_bsize);
277 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
278 CP(*in, *out, f_blocks);
279 CP(*in, *out, f_bfree);
280 CP(*in, *out, f_bavail);
281 out->f_files = MIN(in->f_files, INT32_MAX);
282 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
283 CP(*in, *out, f_fsid);
284 CP(*in, *out, f_owner);
285 CP(*in, *out, f_type);
286 CP(*in, *out, f_flags);
287 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
288 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
289 strlcpy(out->f_fstypename,
290 in->f_fstypename, MFSNAMELEN);
291 strlcpy(out->f_mntonname,
292 in->f_mntonname, min(MNAMELEN, FREEBSD4_OMNAMELEN));
293 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
294 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
295 strlcpy(out->f_mntfromname,
296 in->f_mntfromname, min(MNAMELEN, FREEBSD4_OMNAMELEN));
301 freebsd32_getfsstat(struct thread *td, struct freebsd32_getfsstat_args *uap)
306 if (uap->bufsize < 0 || uap->bufsize > SIZE_MAX)
308 error = kern_getfsstat(td, &uap->buf, uap->bufsize, &count,
309 UIO_USERSPACE, uap->mode);
311 td->td_retval[0] = count;
315 #ifdef COMPAT_FREEBSD4
317 freebsd4_freebsd32_getfsstat(struct thread *td,
318 struct freebsd4_freebsd32_getfsstat_args *uap)
320 struct statfs *buf, *sp;
321 struct ostatfs32 stat32;
322 size_t count, size, copycount;
325 count = uap->bufsize / sizeof(struct ostatfs32);
326 size = count * sizeof(struct statfs);
327 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
331 while (copycount > 0 && error == 0) {
332 copy_statfs(sp, &stat32);
333 error = copyout(&stat32, uap->buf, sizeof(stat32));
341 td->td_retval[0] = count;
346 #ifdef COMPAT_FREEBSD11
348 freebsd11_freebsd32_getfsstat(struct thread *td,
349 struct freebsd11_freebsd32_getfsstat_args *uap)
351 return(kern_freebsd11_getfsstat(td, uap->buf, uap->bufsize,
357 freebsd32_sigaltstack(struct thread *td,
358 struct freebsd32_sigaltstack_args *uap)
360 struct sigaltstack32 s32;
361 struct sigaltstack ss, oss, *ssp;
364 if (uap->ss != NULL) {
365 error = copyin(uap->ss, &s32, sizeof(s32));
368 PTRIN_CP(s32, ss, ss_sp);
369 CP(s32, ss, ss_size);
370 CP(s32, ss, ss_flags);
374 error = kern_sigaltstack(td, ssp, &oss);
375 if (error == 0 && uap->oss != NULL) {
376 PTROUT_CP(oss, s32, ss_sp);
377 CP(oss, s32, ss_size);
378 CP(oss, s32, ss_flags);
379 error = copyout(&s32, uap->oss, sizeof(s32));
385 * Custom version of exec_copyin_args() so that we can translate
389 freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
390 enum uio_seg segflg, uint32_t *argv, uint32_t *envv)
396 bzero(args, sizeof(*args));
401 * Allocate demand-paged memory for the file name, argument, and
402 * environment strings.
404 error = exec_alloc_args(args);
409 * Copy the file name.
411 error = exec_args_add_fname(args, fname, segflg);
416 * extract arguments first
420 error = copyin(p32++, &arg, sizeof(arg));
426 error = exec_args_add_arg(args, argp, UIO_USERSPACE);
432 * extract environment strings
437 error = copyin(p32++, &arg, sizeof(arg));
443 error = exec_args_add_env(args, envp, UIO_USERSPACE);
452 exec_free_args(args);
457 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
459 struct image_args eargs;
460 struct vmspace *oldvmspace;
463 error = pre_execve(td, &oldvmspace);
466 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
467 uap->argv, uap->envv);
469 error = kern_execve(td, &eargs, NULL, oldvmspace);
470 post_execve(td, error, oldvmspace);
471 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
476 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
478 struct image_args eargs;
479 struct vmspace *oldvmspace;
482 error = pre_execve(td, &oldvmspace);
485 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
486 uap->argv, uap->envv);
489 error = kern_execve(td, &eargs, NULL, oldvmspace);
491 post_execve(td, error, oldvmspace);
492 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
497 freebsd32_mknodat(struct thread *td, struct freebsd32_mknodat_args *uap)
500 return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE,
501 uap->mode, PAIR32TO64(dev_t, uap->dev)));
505 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
510 #if defined(__amd64__)
511 if (i386_read_exec && (prot & PROT_READ) != 0)
514 return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len,
519 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
524 #if defined(__amd64__)
525 if (i386_read_exec && (prot & PROT_READ))
529 return (kern_mmap(td, &(struct mmap_req){
530 .mr_hint = (uintptr_t)uap->addr,
533 .mr_flags = uap->flags,
535 .mr_pos = PAIR32TO64(off_t, uap->pos),
539 #ifdef COMPAT_FREEBSD6
541 freebsd6_freebsd32_mmap(struct thread *td,
542 struct freebsd6_freebsd32_mmap_args *uap)
547 #if defined(__amd64__)
548 if (i386_read_exec && (prot & PROT_READ))
552 return (kern_mmap(td, &(struct mmap_req){
553 .mr_hint = (uintptr_t)uap->addr,
556 .mr_flags = uap->flags,
558 .mr_pos = PAIR32TO64(off_t, uap->pos),
565 ofreebsd32_mmap(struct thread *td, struct ofreebsd32_mmap_args *uap)
567 return (kern_ommap(td, (uintptr_t)uap->addr, uap->len, uap->prot,
568 uap->flags, uap->fd, uap->pos));
573 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
575 struct itimerval itv, oitv, *itvp;
576 struct itimerval32 i32;
579 if (uap->itv != NULL) {
580 error = copyin(uap->itv, &i32, sizeof(i32));
583 TV_CP(i32, itv, it_interval);
584 TV_CP(i32, itv, it_value);
588 error = kern_setitimer(td, uap->which, itvp, &oitv);
589 if (error || uap->oitv == NULL)
591 TV_CP(oitv, i32, it_interval);
592 TV_CP(oitv, i32, it_value);
593 return (copyout(&i32, uap->oitv, sizeof(i32)));
597 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
599 struct itimerval itv;
600 struct itimerval32 i32;
603 error = kern_getitimer(td, uap->which, &itv);
604 if (error || uap->itv == NULL)
606 TV_CP(itv, i32, it_interval);
607 TV_CP(itv, i32, it_value);
608 return (copyout(&i32, uap->itv, sizeof(i32)));
612 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
614 struct timeval32 tv32;
615 struct timeval tv, *tvp;
618 if (uap->tv != NULL) {
619 error = copyin(uap->tv, &tv32, sizeof(tv32));
622 CP(tv32, tv, tv_sec);
623 CP(tv32, tv, tv_usec);
628 * XXX Do pointers need PTRIN()?
630 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
631 sizeof(int32_t) * 8));
635 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
637 struct timespec32 ts32;
639 struct timeval tv, *tvp;
643 if (uap->ts != NULL) {
644 error = copyin(uap->ts, &ts32, sizeof(ts32));
647 CP(ts32, ts, tv_sec);
648 CP(ts32, ts, tv_nsec);
649 TIMESPEC_TO_TIMEVAL(&tv, &ts);
653 if (uap->sm != NULL) {
654 error = copyin(uap->sm, &set, sizeof(set));
661 * XXX Do pointers need PTRIN()?
663 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
664 uset, sizeof(int32_t) * 8);
669 * Copy 'count' items into the destination list pointed to by uap->eventlist.
672 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
674 struct freebsd32_kevent_args *uap;
675 struct kevent32 ks32[KQ_NEVENTS];
679 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
680 uap = (struct freebsd32_kevent_args *)arg;
682 for (i = 0; i < count; i++) {
683 CP(kevp[i], ks32[i], ident);
684 CP(kevp[i], ks32[i], filter);
685 CP(kevp[i], ks32[i], flags);
686 CP(kevp[i], ks32[i], fflags);
687 #if BYTE_ORDER == LITTLE_ENDIAN
688 ks32[i].data1 = kevp[i].data;
689 ks32[i].data2 = kevp[i].data >> 32;
691 ks32[i].data1 = kevp[i].data >> 32;
692 ks32[i].data2 = kevp[i].data;
694 PTROUT_CP(kevp[i], ks32[i], udata);
695 for (j = 0; j < nitems(kevp->ext); j++) {
697 #if BYTE_ORDER == LITTLE_ENDIAN
698 ks32[i].ext64[2 * j] = e;
699 ks32[i].ext64[2 * j + 1] = e >> 32;
701 ks32[i].ext64[2 * j] = e >> 32;
702 ks32[i].ext64[2 * j + 1] = e;
706 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
708 uap->eventlist += count;
713 * Copy 'count' items from the list pointed to by uap->changelist.
716 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
718 struct freebsd32_kevent_args *uap;
719 struct kevent32 ks32[KQ_NEVENTS];
723 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
724 uap = (struct freebsd32_kevent_args *)arg;
726 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
729 uap->changelist += count;
731 for (i = 0; i < count; i++) {
732 CP(ks32[i], kevp[i], ident);
733 CP(ks32[i], kevp[i], filter);
734 CP(ks32[i], kevp[i], flags);
735 CP(ks32[i], kevp[i], fflags);
736 kevp[i].data = PAIR32TO64(uint64_t, ks32[i].data);
737 PTRIN_CP(ks32[i], kevp[i], udata);
738 for (j = 0; j < nitems(kevp->ext); j++) {
739 #if BYTE_ORDER == LITTLE_ENDIAN
740 e = ks32[i].ext64[2 * j + 1];
742 e += ks32[i].ext64[2 * j];
744 e = ks32[i].ext64[2 * j];
746 e += ks32[i].ext64[2 * j + 1];
756 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
758 struct timespec32 ts32;
759 struct timespec ts, *tsp;
760 struct kevent_copyops k_ops = {
762 .k_copyout = freebsd32_kevent_copyout,
763 .k_copyin = freebsd32_kevent_copyin,
766 struct kevent32 *eventlist = uap->eventlist;
771 error = copyin(uap->timeout, &ts32, sizeof(ts32));
774 CP(ts32, ts, tv_sec);
775 CP(ts32, ts, tv_nsec);
780 if (KTRPOINT(td, KTR_STRUCT_ARRAY))
781 ktrstructarray("kevent32", UIO_USERSPACE, uap->changelist,
782 uap->nchanges, sizeof(struct kevent32));
784 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
787 if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
788 ktrstructarray("kevent32", UIO_USERSPACE, eventlist,
789 td->td_retval[0], sizeof(struct kevent32));
794 #ifdef COMPAT_FREEBSD11
796 freebsd32_kevent11_copyout(void *arg, struct kevent *kevp, int count)
798 struct freebsd11_freebsd32_kevent_args *uap;
799 struct freebsd11_kevent32 ks32[KQ_NEVENTS];
802 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
803 uap = (struct freebsd11_freebsd32_kevent_args *)arg;
805 for (i = 0; i < count; i++) {
806 CP(kevp[i], ks32[i], ident);
807 CP(kevp[i], ks32[i], filter);
808 CP(kevp[i], ks32[i], flags);
809 CP(kevp[i], ks32[i], fflags);
810 CP(kevp[i], ks32[i], data);
811 PTROUT_CP(kevp[i], ks32[i], udata);
813 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
815 uap->eventlist += count;
820 * Copy 'count' items from the list pointed to by uap->changelist.
823 freebsd32_kevent11_copyin(void *arg, struct kevent *kevp, int count)
825 struct freebsd11_freebsd32_kevent_args *uap;
826 struct freebsd11_kevent32 ks32[KQ_NEVENTS];
829 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
830 uap = (struct freebsd11_freebsd32_kevent_args *)arg;
832 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
835 uap->changelist += count;
837 for (i = 0; i < count; i++) {
838 CP(ks32[i], kevp[i], ident);
839 CP(ks32[i], kevp[i], filter);
840 CP(ks32[i], kevp[i], flags);
841 CP(ks32[i], kevp[i], fflags);
842 CP(ks32[i], kevp[i], data);
843 PTRIN_CP(ks32[i], kevp[i], udata);
844 for (j = 0; j < nitems(kevp->ext); j++)
852 freebsd11_freebsd32_kevent(struct thread *td,
853 struct freebsd11_freebsd32_kevent_args *uap)
855 struct timespec32 ts32;
856 struct timespec ts, *tsp;
857 struct kevent_copyops k_ops = {
859 .k_copyout = freebsd32_kevent11_copyout,
860 .k_copyin = freebsd32_kevent11_copyin,
863 struct freebsd11_kevent32 *eventlist = uap->eventlist;
868 error = copyin(uap->timeout, &ts32, sizeof(ts32));
871 CP(ts32, ts, tv_sec);
872 CP(ts32, ts, tv_nsec);
877 if (KTRPOINT(td, KTR_STRUCT_ARRAY))
878 ktrstructarray("freebsd11_kevent32", UIO_USERSPACE,
879 uap->changelist, uap->nchanges,
880 sizeof(struct freebsd11_kevent32));
882 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
885 if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
886 ktrstructarray("freebsd11_kevent32", UIO_USERSPACE,
887 eventlist, td->td_retval[0],
888 sizeof(struct freebsd11_kevent32));
895 freebsd32_gettimeofday(struct thread *td,
896 struct freebsd32_gettimeofday_args *uap)
899 struct timeval32 atv32;
905 CP(atv, atv32, tv_sec);
906 CP(atv, atv32, tv_usec);
907 error = copyout(&atv32, uap->tp, sizeof (atv32));
909 if (error == 0 && uap->tzp != NULL) {
910 rtz.tz_minuteswest = 0;
912 error = copyout(&rtz, uap->tzp, sizeof (rtz));
918 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
924 error = kern_getrusage(td, uap->who, &s);
926 freebsd32_rusage_out(&s, &s32);
927 error = copyout(&s32, uap->rusage, sizeof(s32));
933 ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl,
934 struct ptrace_lwpinfo32 *pl32)
937 bzero(pl32, sizeof(*pl32));
938 pl32->pl_lwpid = pl->pl_lwpid;
939 pl32->pl_event = pl->pl_event;
940 pl32->pl_flags = pl->pl_flags;
941 pl32->pl_sigmask = pl->pl_sigmask;
942 pl32->pl_siglist = pl->pl_siglist;
943 siginfo_to_siginfo32(&pl->pl_siginfo, &pl32->pl_siginfo);
944 strcpy(pl32->pl_tdname, pl->pl_tdname);
945 pl32->pl_child_pid = pl->pl_child_pid;
946 pl32->pl_syscall_code = pl->pl_syscall_code;
947 pl32->pl_syscall_narg = pl->pl_syscall_narg;
951 ptrace_sc_ret_to32(const struct ptrace_sc_ret *psr,
952 struct ptrace_sc_ret32 *psr32)
955 bzero(psr32, sizeof(*psr32));
956 psr32->sr_retval[0] = psr->sr_retval[0];
957 psr32->sr_retval[1] = psr->sr_retval[1];
958 psr32->sr_error = psr->sr_error;
962 freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
965 struct ptrace_io_desc piod;
966 struct ptrace_lwpinfo pl;
967 struct ptrace_vm_entry pve;
968 struct ptrace_coredump pc;
969 struct ptrace_sc_remote sr;
970 struct dbreg32 dbreg;
971 struct fpreg32 fpreg;
974 register_t args[nitems(td->td_sa.args)];
975 struct ptrace_sc_ret psr;
979 struct ptrace_io_desc32 piod;
980 struct ptrace_lwpinfo32 pl;
981 struct ptrace_vm_entry32 pve;
982 struct ptrace_coredump32 pc;
983 struct ptrace_sc_remote32 sr;
984 uint32_t args[nitems(td->td_sa.args)];
985 struct ptrace_sc_ret32 psr;
988 syscallarg_t pscr_args[nitems(td->td_sa.args)];
989 u_int pscr_args32[nitems(td->td_sa.args)];
997 AUDIT_ARG_PID(uap->pid);
998 AUDIT_ARG_CMD(uap->req);
999 AUDIT_ARG_VALUE(uap->data);
1003 case PT_GET_EVENT_MASK:
1004 case PT_GET_SC_ARGS:
1008 if (uap->data > sizeof(r32.pl))
1012 * Pass size of native structure in 'data'. Truncate
1013 * if necessary to avoid siginfo.
1015 data = sizeof(r.pl);
1016 if (uap->data < offsetof(struct ptrace_lwpinfo32, pl_siginfo) +
1017 sizeof(struct siginfo32))
1018 data = offsetof(struct ptrace_lwpinfo, pl_siginfo);
1021 bzero(&r.reg, sizeof(r.reg));
1024 bzero(&r.fpreg, sizeof(r.fpreg));
1027 bzero(&r.dbreg, sizeof(r.dbreg));
1030 error = copyin(uap->addr, &r.reg, sizeof(r.reg));
1033 error = copyin(uap->addr, &r.fpreg, sizeof(r.fpreg));
1036 error = copyin(uap->addr, &r.dbreg, sizeof(r.dbreg));
1040 error = copyin(uap->addr, &r32.vec, sizeof(r32.vec));
1044 r.vec.iov_len = r32.vec.iov_len;
1045 r.vec.iov_base = PTRIN(r32.vec.iov_base);
1047 case PT_SET_EVENT_MASK:
1048 if (uap->data != sizeof(r.ptevents))
1051 error = copyin(uap->addr, &r.ptevents, uap->data);
1054 error = copyin(uap->addr, &r32.piod, sizeof(r32.piod));
1057 CP(r32.piod, r.piod, piod_op);
1058 PTRIN_CP(r32.piod, r.piod, piod_offs);
1059 PTRIN_CP(r32.piod, r.piod, piod_addr);
1060 CP(r32.piod, r.piod, piod_len);
1063 error = copyin(uap->addr, &r32.pve, sizeof(r32.pve));
1067 CP(r32.pve, r.pve, pve_entry);
1068 CP(r32.pve, r.pve, pve_timestamp);
1069 CP(r32.pve, r.pve, pve_start);
1070 CP(r32.pve, r.pve, pve_end);
1071 CP(r32.pve, r.pve, pve_offset);
1072 CP(r32.pve, r.pve, pve_prot);
1073 CP(r32.pve, r.pve, pve_pathlen);
1074 CP(r32.pve, r.pve, pve_fileid);
1075 CP(r32.pve, r.pve, pve_fsid);
1076 PTRIN_CP(r32.pve, r.pve, pve_path);
1079 if (uap->data != sizeof(r32.pc))
1082 error = copyin(uap->addr, &r32.pc, uap->data);
1083 CP(r32.pc, r.pc, pc_fd);
1084 CP(r32.pc, r.pc, pc_flags);
1085 r.pc.pc_limit = PAIR32TO64(off_t, r32.pc.pc_limit);
1086 data = sizeof(r.pc);
1089 if (uap->data != sizeof(r32.sr)) {
1093 error = copyin(uap->addr, &r32.sr, uap->data);
1096 CP(r32.sr, r.sr, pscr_syscall);
1097 CP(r32.sr, r.sr, pscr_nargs);
1098 if (r.sr.pscr_nargs > nitems(td->td_sa.args)) {
1102 error = copyin(PTRIN(r32.sr.pscr_args), pscr_args32,
1103 sizeof(u_int) * r32.sr.pscr_nargs);
1106 for (i = 0; i < r32.sr.pscr_nargs; i++)
1107 pscr_args[i] = pscr_args32[i];
1108 r.sr.pscr_args = pscr_args;
1117 error = kern_ptrace(td, uap->req, uap->pid, addr, data);
1123 CP(r.pve, r32.pve, pve_entry);
1124 CP(r.pve, r32.pve, pve_timestamp);
1125 CP(r.pve, r32.pve, pve_start);
1126 CP(r.pve, r32.pve, pve_end);
1127 CP(r.pve, r32.pve, pve_offset);
1128 CP(r.pve, r32.pve, pve_prot);
1129 CP(r.pve, r32.pve, pve_pathlen);
1130 CP(r.pve, r32.pve, pve_fileid);
1131 CP(r.pve, r32.pve, pve_fsid);
1132 error = copyout(&r32.pve, uap->addr, sizeof(r32.pve));
1135 CP(r.piod, r32.piod, piod_len);
1136 error = copyout(&r32.piod, uap->addr, sizeof(r32.piod));
1139 error = copyout(&r.reg, uap->addr, sizeof(r.reg));
1142 error = copyout(&r.fpreg, uap->addr, sizeof(r.fpreg));
1145 error = copyout(&r.dbreg, uap->addr, sizeof(r.dbreg));
1148 r32.vec.iov_len = r.vec.iov_len;
1149 error = copyout(&r32.vec, uap->addr, sizeof(r32.vec));
1151 case PT_GET_EVENT_MASK:
1152 /* NB: The size in uap->data is validated in kern_ptrace(). */
1153 error = copyout(&r.ptevents, uap->addr, uap->data);
1156 ptrace_lwpinfo_to32(&r.pl, &r32.pl);
1157 error = copyout(&r32.pl, uap->addr, uap->data);
1159 case PT_GET_SC_ARGS:
1160 for (i = 0; i < nitems(r.args); i++)
1161 r32.args[i] = (uint32_t)r.args[i];
1162 error = copyout(r32.args, uap->addr, MIN(uap->data,
1166 ptrace_sc_ret_to32(&r.psr, &r32.psr);
1167 error = copyout(&r32.psr, uap->addr, MIN(uap->data,
1171 ptrace_sc_ret_to32(&r.sr.pscr_ret, &r32.sr.pscr_ret);
1172 error = copyout(&r32.sr.pscr_ret, uap->addr +
1173 offsetof(struct ptrace_sc_remote32, pscr_ret),
1182 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
1184 struct iovec32 iov32;
1191 if (iovcnt > UIO_MAXIOV)
1193 iovlen = iovcnt * sizeof(struct iovec);
1194 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
1195 iov = (struct iovec *)(uio + 1);
1196 for (i = 0; i < iovcnt; i++) {
1197 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
1202 iov[i].iov_base = PTRIN(iov32.iov_base);
1203 iov[i].iov_len = iov32.iov_len;
1206 uio->uio_iovcnt = iovcnt;
1207 uio->uio_segflg = UIO_USERSPACE;
1208 uio->uio_offset = -1;
1210 for (i = 0; i < iovcnt; i++) {
1211 if (iov->iov_len > INT_MAX - uio->uio_resid) {
1215 uio->uio_resid += iov->iov_len;
1223 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
1228 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1231 error = kern_readv(td, uap->fd, auio);
1237 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
1242 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1245 error = kern_writev(td, uap->fd, auio);
1251 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
1256 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1259 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
1265 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
1270 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1273 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
1279 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
1282 struct iovec32 iov32;
1288 if (iovcnt > UIO_MAXIOV)
1290 iovlen = iovcnt * sizeof(struct iovec);
1291 iov = malloc(iovlen, M_IOV, M_WAITOK);
1292 for (i = 0; i < iovcnt; i++) {
1293 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
1298 iov[i].iov_base = PTRIN(iov32.iov_base);
1299 iov[i].iov_len = iov32.iov_len;
1306 freebsd32_copyinmsghdr(const struct msghdr32 *msg32, struct msghdr *msg)
1308 struct msghdr32 m32;
1311 error = copyin(msg32, &m32, sizeof(m32));
1314 msg->msg_name = PTRIN(m32.msg_name);
1315 msg->msg_namelen = m32.msg_namelen;
1316 msg->msg_iov = PTRIN(m32.msg_iov);
1317 msg->msg_iovlen = m32.msg_iovlen;
1318 msg->msg_control = PTRIN(m32.msg_control);
1319 msg->msg_controllen = m32.msg_controllen;
1320 msg->msg_flags = m32.msg_flags;
1325 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
1327 struct msghdr32 m32;
1330 m32.msg_name = PTROUT(msg->msg_name);
1331 m32.msg_namelen = msg->msg_namelen;
1332 m32.msg_iov = PTROUT(msg->msg_iov);
1333 m32.msg_iovlen = msg->msg_iovlen;
1334 m32.msg_control = PTROUT(msg->msg_control);
1335 m32.msg_controllen = msg->msg_controllen;
1336 m32.msg_flags = msg->msg_flags;
1337 error = copyout(&m32, msg32, sizeof(m32));
1341 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
1342 #define FREEBSD32_ALIGN(p) \
1343 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
1344 #define FREEBSD32_CMSG_SPACE(l) \
1345 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
1347 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1348 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1351 freebsd32_cmsg_convert(const struct cmsghdr *cm, void *data, socklen_t datalen)
1355 struct timespec32 ts;
1356 struct timeval32 tv;
1357 struct bintime32 bt;
1368 switch (cm->cmsg_level) {
1370 switch (cm->cmsg_type) {
1372 TV_CP(*in, tmp32, tv);
1373 copylen = sizeof(tmp32.tv);
1377 BT_CP(*in, tmp32, bt);
1378 copylen = sizeof(tmp32.bt);
1383 TS_CP(*in, tmp32, ts);
1384 copylen = sizeof(tmp32.ts);
1398 KASSERT((datalen >= copylen), ("corrupted cmsghdr"));
1400 bcopy(&tmp32, data, copylen);
1405 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1409 socklen_t clen, datalen, datalen_out, oldclen;
1416 len = msg->msg_controllen;
1417 msg->msg_controllen = 0;
1419 ctlbuf = msg->msg_control;
1420 for (m = control; m != NULL && len > 0; m = m->m_next) {
1421 cm = mtod(m, struct cmsghdr *);
1423 while (cm != NULL) {
1424 if (sizeof(struct cmsghdr) > clen ||
1425 cm->cmsg_len > clen) {
1430 data = CMSG_DATA(cm);
1431 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1432 datalen_out = freebsd32_cmsg_convert(cm, data, datalen);
1435 * Copy out the message header. Preserve the native
1436 * message size in case we need to inspect the message
1439 copylen = sizeof(struct cmsghdr);
1440 if (len < copylen) {
1441 msg->msg_flags |= MSG_CTRUNC;
1442 m_dispose_extcontrolm(m);
1445 oldclen = cm->cmsg_len;
1446 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1448 error = copyout(cm, ctlbuf, copylen);
1449 cm->cmsg_len = oldclen;
1453 ctlbuf += FREEBSD32_ALIGN(copylen);
1454 len -= FREEBSD32_ALIGN(copylen);
1456 copylen = datalen_out;
1457 if (len < copylen) {
1458 msg->msg_flags |= MSG_CTRUNC;
1459 m_dispose_extcontrolm(m);
1463 /* Copy out the message data. */
1464 error = copyout(data, ctlbuf, copylen);
1468 ctlbuf += FREEBSD32_ALIGN(copylen);
1469 len -= FREEBSD32_ALIGN(copylen);
1471 if (CMSG_SPACE(datalen) < clen) {
1472 clen -= CMSG_SPACE(datalen);
1473 cm = (struct cmsghdr *)
1474 ((caddr_t)cm + CMSG_SPACE(datalen));
1480 msg->msg_controllen +=
1481 FREEBSD32_CMSG_SPACE(datalen_out);
1484 if (len == 0 && m != NULL) {
1485 msg->msg_flags |= MSG_CTRUNC;
1486 m_dispose_extcontrolm(m);
1494 freebsd32_recvmsg(struct thread *td, struct freebsd32_recvmsg_args *uap)
1497 struct iovec *uiov, *iov;
1498 struct mbuf *control = NULL;
1499 struct mbuf **controlp;
1502 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1505 error = freebsd32_copyiniov((void *)msg.msg_iov, msg.msg_iovlen, &iov,
1509 msg.msg_flags = uap->flags;
1513 controlp = (msg.msg_control != NULL) ? &control : NULL;
1514 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1518 if (control != NULL)
1519 error = freebsd32_copy_msg_out(&msg, control);
1521 msg.msg_controllen = 0;
1524 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1528 if (control != NULL) {
1530 m_dispose_extcontrolm(control);
1539 ofreebsd32_recvmsg(struct thread *td, struct ofreebsd32_recvmsg_args *uap)
1546 * Copy-in the array of control messages constructed using alignment
1547 * and padding suitable for a 32-bit environment and construct an
1548 * mbuf using alignment and padding suitable for a 64-bit kernel.
1549 * The alignment and padding are defined indirectly by CMSG_DATA(),
1550 * CMSG_SPACE() and CMSG_LEN().
1553 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1557 void *in, *in1, *md;
1558 u_int msglen, outlen;
1561 /* Enforce the size limit of the native implementation. */
1562 if (buflen > MCLBYTES)
1565 in = malloc(buflen, M_TEMP, M_WAITOK);
1566 error = copyin(buf, in, buflen);
1571 * Make a pass over the input buffer to determine the amount of space
1572 * required for 64 bit-aligned copies of the control messages.
1576 while (buflen > 0) {
1577 if (buflen < sizeof(*cm)) {
1581 cm = (struct cmsghdr *)in1;
1582 if (cm->cmsg_len < FREEBSD32_ALIGN(sizeof(*cm)) ||
1583 cm->cmsg_len > buflen) {
1587 msglen = FREEBSD32_ALIGN(cm->cmsg_len);
1588 if (msglen < cm->cmsg_len) {
1592 /* The native ABI permits the final padding to be omitted. */
1593 if (msglen > buflen)
1597 in1 = (char *)in1 + msglen;
1598 outlen += CMSG_ALIGN(sizeof(*cm)) +
1599 CMSG_ALIGN(msglen - FREEBSD32_ALIGN(sizeof(*cm)));
1605 * Allocate up to MJUMPAGESIZE space for the re-aligned and
1606 * re-padded control messages. This allows a full MCLBYTES of
1607 * 32-bit sized and aligned messages to fit and avoids an ABI
1608 * mismatch with the native implementation.
1610 m = m_get2(outlen, M_WAITOK, MT_CONTROL, 0);
1616 md = mtod(m, void *);
1619 * Make a second pass over input messages, copying them into the output
1623 while (outlen > 0) {
1624 /* Copy the message header and align the length field. */
1626 memcpy(cm, in1, sizeof(*cm));
1627 msglen = cm->cmsg_len - FREEBSD32_ALIGN(sizeof(*cm));
1628 cm->cmsg_len = CMSG_ALIGN(sizeof(*cm)) + msglen;
1630 /* Copy the message body. */
1631 in1 = (char *)in1 + FREEBSD32_ALIGN(sizeof(*cm));
1632 md = (char *)md + CMSG_ALIGN(sizeof(*cm));
1633 memcpy(md, in1, msglen);
1634 in1 = (char *)in1 + FREEBSD32_ALIGN(msglen);
1635 md = (char *)md + CMSG_ALIGN(msglen);
1636 KASSERT(outlen >= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen),
1637 ("outlen %u underflow, msglen %u", outlen, msglen));
1638 outlen -= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen);
1648 freebsd32_sendmsg(struct thread *td, struct freebsd32_sendmsg_args *uap)
1652 struct mbuf *control = NULL;
1653 struct sockaddr *to = NULL;
1656 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1659 error = freebsd32_copyiniov((void *)msg.msg_iov, msg.msg_iovlen, &iov,
1664 if (msg.msg_name != NULL) {
1665 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1673 if (msg.msg_control) {
1674 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1679 error = freebsd32_copyin_control(&control, msg.msg_control,
1680 msg.msg_controllen);
1684 msg.msg_control = NULL;
1685 msg.msg_controllen = 0;
1688 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1700 ofreebsd32_sendmsg(struct thread *td, struct ofreebsd32_sendmsg_args *uap)
1708 freebsd32_settimeofday(struct thread *td,
1709 struct freebsd32_settimeofday_args *uap)
1711 struct timeval32 tv32;
1712 struct timeval tv, *tvp;
1713 struct timezone tz, *tzp;
1717 error = copyin(uap->tv, &tv32, sizeof(tv32));
1720 CP(tv32, tv, tv_sec);
1721 CP(tv32, tv, tv_usec);
1726 error = copyin(uap->tzp, &tz, sizeof(tz));
1732 return (kern_settimeofday(td, tvp, tzp));
1736 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1738 struct timeval32 s32[2];
1739 struct timeval s[2], *sp;
1742 if (uap->tptr != NULL) {
1743 error = copyin(uap->tptr, s32, sizeof(s32));
1746 CP(s32[0], s[0], tv_sec);
1747 CP(s32[0], s[0], tv_usec);
1748 CP(s32[1], s[1], tv_sec);
1749 CP(s32[1], s[1], tv_usec);
1753 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1758 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1760 struct timeval32 s32[2];
1761 struct timeval s[2], *sp;
1764 if (uap->tptr != NULL) {
1765 error = copyin(uap->tptr, s32, sizeof(s32));
1768 CP(s32[0], s[0], tv_sec);
1769 CP(s32[0], s[0], tv_usec);
1770 CP(s32[1], s[1], tv_sec);
1771 CP(s32[1], s[1], tv_usec);
1775 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1779 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1781 struct timeval32 s32[2];
1782 struct timeval s[2], *sp;
1785 if (uap->tptr != NULL) {
1786 error = copyin(uap->tptr, s32, sizeof(s32));
1789 CP(s32[0], s[0], tv_sec);
1790 CP(s32[0], s[0], tv_usec);
1791 CP(s32[1], s[1], tv_sec);
1792 CP(s32[1], s[1], tv_usec);
1796 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1800 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1802 struct timeval32 s32[2];
1803 struct timeval s[2], *sp;
1806 if (uap->times != NULL) {
1807 error = copyin(uap->times, s32, sizeof(s32));
1810 CP(s32[0], s[0], tv_sec);
1811 CP(s32[0], s[0], tv_usec);
1812 CP(s32[1], s[1], tv_sec);
1813 CP(s32[1], s[1], tv_usec);
1817 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1822 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1824 struct timespec32 ts32[2];
1825 struct timespec ts[2], *tsp;
1828 if (uap->times != NULL) {
1829 error = copyin(uap->times, ts32, sizeof(ts32));
1832 CP(ts32[0], ts[0], tv_sec);
1833 CP(ts32[0], ts[0], tv_nsec);
1834 CP(ts32[1], ts[1], tv_sec);
1835 CP(ts32[1], ts[1], tv_nsec);
1839 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1843 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1845 struct timespec32 ts32[2];
1846 struct timespec ts[2], *tsp;
1849 if (uap->times != NULL) {
1850 error = copyin(uap->times, ts32, sizeof(ts32));
1853 CP(ts32[0], ts[0], tv_sec);
1854 CP(ts32[0], ts[0], tv_nsec);
1855 CP(ts32[1], ts[1], tv_sec);
1856 CP(ts32[1], ts[1], tv_nsec);
1860 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1861 tsp, UIO_SYSSPACE, uap->flag));
1865 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1867 struct timeval32 tv32;
1868 struct timeval delta, olddelta, *deltap;
1872 error = copyin(uap->delta, &tv32, sizeof(tv32));
1875 CP(tv32, delta, tv_sec);
1876 CP(tv32, delta, tv_usec);
1880 error = kern_adjtime(td, deltap, &olddelta);
1881 if (uap->olddelta && error == 0) {
1882 CP(olddelta, tv32, tv_sec);
1883 CP(olddelta, tv32, tv_usec);
1884 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1889 #ifdef COMPAT_FREEBSD4
1891 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1893 struct ostatfs32 s32;
1897 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1898 error = kern_statfs(td, uap->path, UIO_USERSPACE, sp);
1900 copy_statfs(sp, &s32);
1901 error = copyout(&s32, uap->buf, sizeof(s32));
1908 #ifdef COMPAT_FREEBSD4
1910 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1912 struct ostatfs32 s32;
1916 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1917 error = kern_fstatfs(td, uap->fd, sp);
1919 copy_statfs(sp, &s32);
1920 error = copyout(&s32, uap->buf, sizeof(s32));
1927 #ifdef COMPAT_FREEBSD4
1929 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1931 struct ostatfs32 s32;
1936 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1938 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1939 error = kern_fhstatfs(td, fh, sp);
1941 copy_statfs(sp, &s32);
1942 error = copyout(&s32, uap->buf, sizeof(s32));
1950 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1953 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1954 PAIR32TO64(off_t, uap->offset)));
1958 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1961 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1962 PAIR32TO64(off_t, uap->offset)));
1967 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1970 return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
1975 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1980 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1982 /* Expand the quad return into two parts for eax and edx */
1983 pos = td->td_uretoff.tdu_off;
1984 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1985 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1990 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1993 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1994 PAIR32TO64(off_t, uap->length)));
1999 ofreebsd32_truncate(struct thread *td, struct ofreebsd32_truncate_args *uap)
2001 return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length));
2006 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
2009 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
2014 ofreebsd32_ftruncate(struct thread *td, struct ofreebsd32_ftruncate_args *uap)
2016 return (kern_ftruncate(td, uap->fd, uap->length));
2020 ofreebsd32_getdirentries(struct thread *td,
2021 struct ofreebsd32_getdirentries_args *uap)
2023 struct ogetdirentries_args ap;
2030 ap.count = uap->count;
2032 error = kern_ogetdirentries(td, &ap, &loff);
2035 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
2041 #if defined(COMPAT_FREEBSD11)
2043 freebsd11_freebsd32_getdirentries(struct thread *td,
2044 struct freebsd11_freebsd32_getdirentries_args *uap)
2050 error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
2054 if (uap->basep != NULL) {
2056 error = copyout(&base32, uap->basep, sizeof(int32_t));
2060 #endif /* COMPAT_FREEBSD11 */
2062 #ifdef COMPAT_FREEBSD6
2063 /* versions with the 'int pad' argument */
2065 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
2068 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
2069 PAIR32TO64(off_t, uap->offset)));
2073 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
2076 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
2077 PAIR32TO64(off_t, uap->offset)));
2081 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
2086 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2088 /* Expand the quad return into two parts for eax and edx */
2089 pos = *(off_t *)(td->td_retval);
2090 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
2091 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
2096 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
2099 return (kern_truncate(td, uap->path, UIO_USERSPACE,
2100 PAIR32TO64(off_t, uap->length)));
2104 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
2107 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
2109 #endif /* COMPAT_FREEBSD6 */
2119 freebsd32_do_sendfile(struct thread *td,
2120 struct freebsd32_sendfile_args *uap, int compat)
2122 struct sf_hdtr32 hdtr32;
2123 struct sf_hdtr hdtr;
2124 struct uio *hdr_uio, *trl_uio;
2126 cap_rights_t rights;
2127 struct iovec32 *iov32;
2128 off_t offset, sbytes;
2131 offset = PAIR32TO64(off_t, uap->offset);
2135 hdr_uio = trl_uio = NULL;
2137 if (uap->hdtr != NULL) {
2138 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
2141 PTRIN_CP(hdtr32, hdtr, headers);
2142 CP(hdtr32, hdtr, hdr_cnt);
2143 PTRIN_CP(hdtr32, hdtr, trailers);
2144 CP(hdtr32, hdtr, trl_cnt);
2146 if (hdtr.headers != NULL) {
2147 iov32 = PTRIN(hdtr32.headers);
2148 error = freebsd32_copyinuio(iov32,
2149 hdtr32.hdr_cnt, &hdr_uio);
2152 #ifdef COMPAT_FREEBSD4
2154 * In FreeBSD < 5.0 the nbytes to send also included
2155 * the header. If compat is specified subtract the
2156 * header size from nbytes.
2159 if (uap->nbytes > hdr_uio->uio_resid)
2160 uap->nbytes -= hdr_uio->uio_resid;
2166 if (hdtr.trailers != NULL) {
2167 iov32 = PTRIN(hdtr32.trailers);
2168 error = freebsd32_copyinuio(iov32,
2169 hdtr32.trl_cnt, &trl_uio);
2175 AUDIT_ARG_FD(uap->fd);
2177 if ((error = fget_read(td, uap->fd,
2178 cap_rights_init_one(&rights, CAP_PREAD), &fp)) != 0)
2181 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
2182 uap->nbytes, &sbytes, uap->flags, td);
2185 if (uap->sbytes != NULL)
2186 copyout(&sbytes, uap->sbytes, sizeof(off_t));
2190 free(hdr_uio, M_IOV);
2192 free(trl_uio, M_IOV);
2196 #ifdef COMPAT_FREEBSD4
2198 freebsd4_freebsd32_sendfile(struct thread *td,
2199 struct freebsd4_freebsd32_sendfile_args *uap)
2201 return (freebsd32_do_sendfile(td,
2202 (struct freebsd32_sendfile_args *)uap, 1));
2207 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
2210 return (freebsd32_do_sendfile(td, uap, 0));
2214 copy_stat(struct stat *in, struct stat32 *out)
2219 * 32-bit architectures other than i386 have 64-bit time_t. This
2220 * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
2221 * and 4 bytes of padding. Zero the padding holes in struct stat32.
2223 bzero(&out->st_atim, sizeof(out->st_atim));
2224 bzero(&out->st_mtim, sizeof(out->st_mtim));
2225 bzero(&out->st_ctim, sizeof(out->st_ctim));
2226 bzero(&out->st_birthtim, sizeof(out->st_birthtim));
2228 CP(*in, *out, st_dev);
2229 CP(*in, *out, st_ino);
2230 CP(*in, *out, st_mode);
2231 CP(*in, *out, st_nlink);
2232 CP(*in, *out, st_uid);
2233 CP(*in, *out, st_gid);
2234 CP(*in, *out, st_rdev);
2235 TS_CP(*in, *out, st_atim);
2236 TS_CP(*in, *out, st_mtim);
2237 TS_CP(*in, *out, st_ctim);
2238 CP(*in, *out, st_size);
2239 CP(*in, *out, st_blocks);
2240 CP(*in, *out, st_blksize);
2241 CP(*in, *out, st_flags);
2242 CP(*in, *out, st_gen);
2243 TS_CP(*in, *out, st_birthtim);
2244 out->st_padding0 = 0;
2245 out->st_padding1 = 0;
2246 #ifdef __STAT32_TIME_T_EXT
2247 out->st_atim_ext = 0;
2248 out->st_mtim_ext = 0;
2249 out->st_ctim_ext = 0;
2250 out->st_btim_ext = 0;
2252 bzero(out->st_spare, sizeof(out->st_spare));
2257 copy_ostat(struct stat *in, struct ostat32 *out)
2260 bzero(out, sizeof(*out));
2261 CP(*in, *out, st_dev);
2262 CP(*in, *out, st_ino);
2263 CP(*in, *out, st_mode);
2264 CP(*in, *out, st_nlink);
2265 CP(*in, *out, st_uid);
2266 CP(*in, *out, st_gid);
2267 CP(*in, *out, st_rdev);
2268 out->st_size = MIN(in->st_size, INT32_MAX);
2269 TS_CP(*in, *out, st_atim);
2270 TS_CP(*in, *out, st_mtim);
2271 TS_CP(*in, *out, st_ctim);
2272 CP(*in, *out, st_blksize);
2273 CP(*in, *out, st_blocks);
2274 CP(*in, *out, st_flags);
2275 CP(*in, *out, st_gen);
2281 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
2284 struct ostat32 sb32;
2287 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2290 copy_ostat(&sb, &sb32);
2291 error = copyout(&sb32, uap->ub, sizeof (sb32));
2297 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
2303 error = kern_fstat(td, uap->fd, &ub);
2306 copy_stat(&ub, &ub32);
2307 error = copyout(&ub32, uap->sb, sizeof(ub32));
2313 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
2316 struct ostat32 ub32;
2319 error = kern_fstat(td, uap->fd, &ub);
2322 copy_ostat(&ub, &ub32);
2323 error = copyout(&ub32, uap->sb, sizeof(ub32));
2329 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
2335 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
2339 copy_stat(&ub, &ub32);
2340 error = copyout(&ub32, uap->buf, sizeof(ub32));
2346 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
2349 struct ostat32 sb32;
2352 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2353 UIO_USERSPACE, &sb);
2356 copy_ostat(&sb, &sb32);
2357 error = copyout(&sb32, uap->ub, sizeof (sb32));
2363 freebsd32_fhstat(struct thread *td, struct freebsd32_fhstat_args *uap)
2370 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2373 error = kern_fhstat(td, fh, &sb);
2376 copy_stat(&sb, &sb32);
2377 error = copyout(&sb32, uap->sb, sizeof (sb32));
2381 #if defined(COMPAT_FREEBSD11)
2382 extern int ino64_trunc_error;
2385 freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
2390 * 32-bit architectures other than i386 have 64-bit time_t. This
2391 * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
2392 * and 4 bytes of padding. Zero the padding holes in freebsd11_stat32.
2394 bzero(&out->st_atim, sizeof(out->st_atim));
2395 bzero(&out->st_mtim, sizeof(out->st_mtim));
2396 bzero(&out->st_ctim, sizeof(out->st_ctim));
2397 bzero(&out->st_birthtim, sizeof(out->st_birthtim));
2400 CP(*in, *out, st_ino);
2401 if (in->st_ino != out->st_ino) {
2402 switch (ino64_trunc_error) {
2409 out->st_ino = UINT32_MAX;
2413 CP(*in, *out, st_nlink);
2414 if (in->st_nlink != out->st_nlink) {
2415 switch (ino64_trunc_error) {
2422 out->st_nlink = UINT16_MAX;
2426 out->st_dev = in->st_dev;
2427 if (out->st_dev != in->st_dev) {
2428 switch (ino64_trunc_error) {
2435 CP(*in, *out, st_mode);
2436 CP(*in, *out, st_uid);
2437 CP(*in, *out, st_gid);
2438 out->st_rdev = in->st_rdev;
2439 if (out->st_rdev != in->st_rdev) {
2440 switch (ino64_trunc_error) {
2447 TS_CP(*in, *out, st_atim);
2448 TS_CP(*in, *out, st_mtim);
2449 TS_CP(*in, *out, st_ctim);
2450 CP(*in, *out, st_size);
2451 CP(*in, *out, st_blocks);
2452 CP(*in, *out, st_blksize);
2453 CP(*in, *out, st_flags);
2454 CP(*in, *out, st_gen);
2455 TS_CP(*in, *out, st_birthtim);
2457 bzero((char *)&out->st_birthtim + sizeof(out->st_birthtim),
2458 sizeof(*out) - offsetof(struct freebsd11_stat32,
2459 st_birthtim) - sizeof(out->st_birthtim));
2464 freebsd11_freebsd32_stat(struct thread *td,
2465 struct freebsd11_freebsd32_stat_args *uap)
2468 struct freebsd11_stat32 sb32;
2471 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2474 error = freebsd11_cvtstat32(&sb, &sb32);
2476 error = copyout(&sb32, uap->ub, sizeof (sb32));
2481 freebsd11_freebsd32_fstat(struct thread *td,
2482 struct freebsd11_freebsd32_fstat_args *uap)
2485 struct freebsd11_stat32 sb32;
2488 error = kern_fstat(td, uap->fd, &sb);
2491 error = freebsd11_cvtstat32(&sb, &sb32);
2493 error = copyout(&sb32, uap->sb, sizeof (sb32));
2498 freebsd11_freebsd32_fstatat(struct thread *td,
2499 struct freebsd11_freebsd32_fstatat_args *uap)
2502 struct freebsd11_stat32 sb32;
2505 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
2509 error = freebsd11_cvtstat32(&sb, &sb32);
2511 error = copyout(&sb32, uap->buf, sizeof (sb32));
2516 freebsd11_freebsd32_lstat(struct thread *td,
2517 struct freebsd11_freebsd32_lstat_args *uap)
2520 struct freebsd11_stat32 sb32;
2523 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2524 UIO_USERSPACE, &sb);
2527 error = freebsd11_cvtstat32(&sb, &sb32);
2529 error = copyout(&sb32, uap->ub, sizeof (sb32));
2534 freebsd11_freebsd32_fhstat(struct thread *td,
2535 struct freebsd11_freebsd32_fhstat_args *uap)
2538 struct freebsd11_stat32 sb32;
2542 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2545 error = kern_fhstat(td, fh, &sb);
2548 error = freebsd11_cvtstat32(&sb, &sb32);
2550 error = copyout(&sb32, uap->sb, sizeof (sb32));
2555 freebsd11_cvtnstat32(struct stat *sb, struct nstat32 *nsb32)
2560 error = freebsd11_cvtnstat(sb, &nsb);
2564 bzero(nsb32, sizeof(*nsb32));
2565 CP(nsb, *nsb32, st_dev);
2566 CP(nsb, *nsb32, st_ino);
2567 CP(nsb, *nsb32, st_mode);
2568 CP(nsb, *nsb32, st_nlink);
2569 CP(nsb, *nsb32, st_uid);
2570 CP(nsb, *nsb32, st_gid);
2571 CP(nsb, *nsb32, st_rdev);
2572 CP(nsb, *nsb32, st_atim.tv_sec);
2573 CP(nsb, *nsb32, st_atim.tv_nsec);
2574 CP(nsb, *nsb32, st_mtim.tv_sec);
2575 CP(nsb, *nsb32, st_mtim.tv_nsec);
2576 CP(nsb, *nsb32, st_ctim.tv_sec);
2577 CP(nsb, *nsb32, st_ctim.tv_nsec);
2578 CP(nsb, *nsb32, st_size);
2579 CP(nsb, *nsb32, st_blocks);
2580 CP(nsb, *nsb32, st_blksize);
2581 CP(nsb, *nsb32, st_flags);
2582 CP(nsb, *nsb32, st_gen);
2583 CP(nsb, *nsb32, st_birthtim.tv_sec);
2584 CP(nsb, *nsb32, st_birthtim.tv_nsec);
2589 freebsd11_freebsd32_nstat(struct thread *td,
2590 struct freebsd11_freebsd32_nstat_args *uap)
2596 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2599 error = freebsd11_cvtnstat32(&sb, &nsb);
2601 error = copyout(&nsb, uap->ub, sizeof (nsb));
2606 freebsd11_freebsd32_nlstat(struct thread *td,
2607 struct freebsd11_freebsd32_nlstat_args *uap)
2613 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2614 UIO_USERSPACE, &sb);
2617 error = freebsd11_cvtnstat32(&sb, &nsb);
2619 error = copyout(&nsb, uap->ub, sizeof (nsb));
2624 freebsd11_freebsd32_nfstat(struct thread *td,
2625 struct freebsd11_freebsd32_nfstat_args *uap)
2631 error = kern_fstat(td, uap->fd, &ub);
2634 error = freebsd11_cvtnstat32(&ub, &nub);
2636 error = copyout(&nub, uap->sb, sizeof(nub));
2642 freebsd32___sysctl(struct thread *td, struct freebsd32___sysctl_args *uap)
2644 int error, name[CTL_MAXNAME];
2648 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
2650 error = copyin(uap->name, name, uap->namelen * sizeof(int));
2654 error = fueword32(uap->oldlenp, &tmp);
2661 error = userland_sysctl(td, name, uap->namelen,
2662 uap->old, &oldlen, 1,
2663 uap->new, uap->newlen, &j, SCTL_MASK32);
2667 suword32(uap->oldlenp, j);
2672 freebsd32___sysctlbyname(struct thread *td,
2673 struct freebsd32___sysctlbyname_args *uap)
2679 if (uap->oldlenp != NULL) {
2680 error = fueword32(uap->oldlenp, &tmp);
2687 error = kern___sysctlbyname(td, uap->name, uap->namelen, uap->old,
2688 &oldlen, uap->new, uap->newlen, &rv, SCTL_MASK32, 1);
2691 if (uap->oldlenp != NULL)
2692 error = suword32(uap->oldlenp, rv);
2698 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
2704 error = copyin(uap->jail, &version, sizeof(uint32_t));
2711 /* FreeBSD single IPv4 jails. */
2712 struct jail32_v0 j32_v0;
2714 bzero(&j, sizeof(struct jail));
2715 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
2718 CP(j32_v0, j, version);
2719 PTRIN_CP(j32_v0, j, path);
2720 PTRIN_CP(j32_v0, j, hostname);
2721 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
2727 * Version 1 was used by multi-IPv4 jail implementations
2728 * that never made it into the official kernel.
2732 case 2: /* JAIL_API_VERSION */
2734 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
2737 error = copyin(uap->jail, &j32, sizeof(struct jail32));
2740 CP(j32, j, version);
2741 PTRIN_CP(j32, j, path);
2742 PTRIN_CP(j32, j, hostname);
2743 PTRIN_CP(j32, j, jailname);
2746 PTRIN_CP(j32, j, ip4);
2747 PTRIN_CP(j32, j, ip6);
2752 /* Sci-Fi jails are not supported, sorry. */
2755 return (kern_jail(td, &j));
2759 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2764 /* Check that we have an even number of iovecs. */
2765 if (uap->iovcnt & 1)
2768 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2771 error = kern_jail_set(td, auio, uap->flags);
2777 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2779 struct iovec32 iov32;
2783 /* Check that we have an even number of iovecs. */
2784 if (uap->iovcnt & 1)
2787 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2790 error = kern_jail_get(td, auio, uap->flags);
2792 for (i = 0; i < uap->iovcnt; i++) {
2793 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2794 CP(auio->uio_iov[i], iov32, iov_len);
2795 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2804 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2806 struct sigaction32 s32;
2807 struct sigaction sa, osa, *sap;
2811 error = copyin(uap->act, &s32, sizeof(s32));
2814 sa.sa_handler = PTRIN(s32.sa_u);
2815 CP(s32, sa, sa_flags);
2816 CP(s32, sa, sa_mask);
2820 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2821 if (error == 0 && uap->oact != NULL) {
2822 s32.sa_u = PTROUT(osa.sa_handler);
2823 CP(osa, s32, sa_flags);
2824 CP(osa, s32, sa_mask);
2825 error = copyout(&s32, uap->oact, sizeof(s32));
2830 #ifdef COMPAT_FREEBSD4
2832 freebsd4_freebsd32_sigaction(struct thread *td,
2833 struct freebsd4_freebsd32_sigaction_args *uap)
2835 struct sigaction32 s32;
2836 struct sigaction sa, osa, *sap;
2840 error = copyin(uap->act, &s32, sizeof(s32));
2843 sa.sa_handler = PTRIN(s32.sa_u);
2844 CP(s32, sa, sa_flags);
2845 CP(s32, sa, sa_mask);
2849 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2850 if (error == 0 && uap->oact != NULL) {
2851 s32.sa_u = PTROUT(osa.sa_handler);
2852 CP(osa, s32, sa_flags);
2853 CP(osa, s32, sa_mask);
2854 error = copyout(&s32, uap->oact, sizeof(s32));
2861 struct osigaction32 {
2870 ofreebsd32_sigaction(struct thread *td,
2871 struct ofreebsd32_sigaction_args *uap)
2873 struct osigaction32 s32;
2874 struct sigaction sa, osa, *sap;
2877 if (uap->signum <= 0 || uap->signum >= ONSIG)
2881 error = copyin(uap->nsa, &s32, sizeof(s32));
2884 sa.sa_handler = PTRIN(s32.sa_u);
2885 CP(s32, sa, sa_flags);
2886 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2890 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2891 if (error == 0 && uap->osa != NULL) {
2892 s32.sa_u = PTROUT(osa.sa_handler);
2893 CP(osa, s32, sa_flags);
2894 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2895 error = copyout(&s32, uap->osa, sizeof(s32));
2901 uint32_t sv_handler;
2907 ofreebsd32_sigvec(struct thread *td,
2908 struct ofreebsd32_sigvec_args *uap)
2910 struct sigvec32 vec;
2911 struct sigaction sa, osa, *sap;
2914 if (uap->signum <= 0 || uap->signum >= ONSIG)
2918 error = copyin(uap->nsv, &vec, sizeof(vec));
2921 sa.sa_handler = PTRIN(vec.sv_handler);
2922 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2923 sa.sa_flags = vec.sv_flags;
2924 sa.sa_flags ^= SA_RESTART;
2928 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2929 if (error == 0 && uap->osv != NULL) {
2930 vec.sv_handler = PTROUT(osa.sa_handler);
2931 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2932 vec.sv_flags = osa.sa_flags;
2933 vec.sv_flags &= ~SA_NOCLDWAIT;
2934 vec.sv_flags ^= SA_RESTART;
2935 error = copyout(&vec, uap->osv, sizeof(vec));
2946 ofreebsd32_sigstack(struct thread *td,
2947 struct ofreebsd32_sigstack_args *uap)
2949 struct sigstack32 s32;
2950 struct sigstack nss, oss;
2951 int error = 0, unss;
2953 if (uap->nss != NULL) {
2954 error = copyin(uap->nss, &s32, sizeof(s32));
2957 nss.ss_sp = PTRIN(s32.ss_sp);
2958 CP(s32, nss, ss_onstack);
2963 oss.ss_sp = td->td_sigstk.ss_sp;
2964 oss.ss_onstack = sigonstack(cpu_getstack(td));
2966 td->td_sigstk.ss_sp = nss.ss_sp;
2967 td->td_sigstk.ss_size = 0;
2968 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2969 td->td_pflags |= TDP_ALTSTACK;
2971 if (uap->oss != NULL) {
2972 s32.ss_sp = PTROUT(oss.ss_sp);
2973 CP(oss, s32, ss_onstack);
2974 error = copyout(&s32, uap->oss, sizeof(s32));
2981 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2984 return (freebsd32_user_clock_nanosleep(td, CLOCK_REALTIME,
2985 TIMER_RELTIME, uap->rqtp, uap->rmtp));
2989 freebsd32_clock_nanosleep(struct thread *td,
2990 struct freebsd32_clock_nanosleep_args *uap)
2994 error = freebsd32_user_clock_nanosleep(td, uap->clock_id, uap->flags,
2995 uap->rqtp, uap->rmtp);
2996 return (kern_posix_error(td, error));
3000 freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
3001 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp)
3003 struct timespec32 rmt32, rqt32;
3004 struct timespec rmt, rqt;
3007 error = copyin(ua_rqtp, &rqt32, sizeof(rqt32));
3011 CP(rqt32, rqt, tv_sec);
3012 CP(rqt32, rqt, tv_nsec);
3014 error = kern_clock_nanosleep(td, clock_id, flags, &rqt, &rmt);
3015 if (error == EINTR && ua_rmtp != NULL && (flags & TIMER_ABSTIME) == 0) {
3016 CP(rmt, rmt32, tv_sec);
3017 CP(rmt, rmt32, tv_nsec);
3019 error2 = copyout(&rmt32, ua_rmtp, sizeof(rmt32));
3027 freebsd32_clock_gettime(struct thread *td,
3028 struct freebsd32_clock_gettime_args *uap)
3030 struct timespec ats;
3031 struct timespec32 ats32;
3034 error = kern_clock_gettime(td, uap->clock_id, &ats);
3036 CP(ats, ats32, tv_sec);
3037 CP(ats, ats32, tv_nsec);
3038 error = copyout(&ats32, uap->tp, sizeof(ats32));
3044 freebsd32_clock_settime(struct thread *td,
3045 struct freebsd32_clock_settime_args *uap)
3047 struct timespec ats;
3048 struct timespec32 ats32;
3051 error = copyin(uap->tp, &ats32, sizeof(ats32));
3054 CP(ats32, ats, tv_sec);
3055 CP(ats32, ats, tv_nsec);
3057 return (kern_clock_settime(td, uap->clock_id, &ats));
3061 freebsd32_clock_getres(struct thread *td,
3062 struct freebsd32_clock_getres_args *uap)
3065 struct timespec32 ts32;
3068 if (uap->tp == NULL)
3070 error = kern_clock_getres(td, uap->clock_id, &ts);
3072 CP(ts, ts32, tv_sec);
3073 CP(ts, ts32, tv_nsec);
3074 error = copyout(&ts32, uap->tp, sizeof(ts32));
3079 int freebsd32_ktimer_create(struct thread *td,
3080 struct freebsd32_ktimer_create_args *uap)
3082 struct sigevent32 ev32;
3083 struct sigevent ev, *evp;
3086 if (uap->evp == NULL) {
3090 error = copyin(uap->evp, &ev32, sizeof(ev32));
3093 error = convert_sigevent32(&ev32, &ev);
3097 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
3099 error = copyout(&id, uap->timerid, sizeof(int));
3101 kern_ktimer_delete(td, id);
3107 freebsd32_ktimer_settime(struct thread *td,
3108 struct freebsd32_ktimer_settime_args *uap)
3110 struct itimerspec32 val32, oval32;
3111 struct itimerspec val, oval, *ovalp;
3114 error = copyin(uap->value, &val32, sizeof(val32));
3118 ovalp = uap->ovalue != NULL ? &oval : NULL;
3119 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
3120 if (error == 0 && uap->ovalue != NULL) {
3121 ITS_CP(oval, oval32);
3122 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
3128 freebsd32_ktimer_gettime(struct thread *td,
3129 struct freebsd32_ktimer_gettime_args *uap)
3131 struct itimerspec32 val32;
3132 struct itimerspec val;
3135 error = kern_ktimer_gettime(td, uap->timerid, &val);
3138 error = copyout(&val32, uap->value, sizeof(val32));
3144 freebsd32_clock_getcpuclockid2(struct thread *td,
3145 struct freebsd32_clock_getcpuclockid2_args *uap)
3150 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
3151 uap->which, &clk_id);
3153 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
3158 freebsd32_thr_new(struct thread *td,
3159 struct freebsd32_thr_new_args *uap)
3161 struct thr_param32 param32;
3162 struct thr_param param;
3165 if (uap->param_size < 0 ||
3166 uap->param_size > sizeof(struct thr_param32))
3168 bzero(¶m, sizeof(struct thr_param));
3169 bzero(¶m32, sizeof(struct thr_param32));
3170 error = copyin(uap->param, ¶m32, uap->param_size);
3173 param.start_func = PTRIN(param32.start_func);
3174 param.arg = PTRIN(param32.arg);
3175 param.stack_base = PTRIN(param32.stack_base);
3176 param.stack_size = param32.stack_size;
3177 param.tls_base = PTRIN(param32.tls_base);
3178 param.tls_size = param32.tls_size;
3179 param.child_tid = PTRIN(param32.child_tid);
3180 param.parent_tid = PTRIN(param32.parent_tid);
3181 param.flags = param32.flags;
3182 param.rtp = PTRIN(param32.rtp);
3183 param.spare[0] = PTRIN(param32.spare[0]);
3184 param.spare[1] = PTRIN(param32.spare[1]);
3185 param.spare[2] = PTRIN(param32.spare[2]);
3187 return (kern_thr_new(td, ¶m));
3191 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
3193 struct timespec32 ts32;
3194 struct timespec ts, *tsp;
3199 if (uap->timeout != NULL) {
3200 error = copyin((const void *)uap->timeout, (void *)&ts32,
3201 sizeof(struct timespec32));
3204 ts.tv_sec = ts32.tv_sec;
3205 ts.tv_nsec = ts32.tv_nsec;
3208 return (kern_thr_suspend(td, tsp));
3212 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
3214 bzero(dst, sizeof(*dst));
3215 dst->si_signo = src->si_signo;
3216 dst->si_errno = src->si_errno;
3217 dst->si_code = src->si_code;
3218 dst->si_pid = src->si_pid;
3219 dst->si_uid = src->si_uid;
3220 dst->si_status = src->si_status;
3221 dst->si_addr = (uintptr_t)src->si_addr;
3222 dst->si_value.sival_int = src->si_value.sival_int;
3223 dst->si_timerid = src->si_timerid;
3224 dst->si_overrun = src->si_overrun;
3227 #ifndef _FREEBSD32_SYSPROTO_H_
3228 struct freebsd32_sigqueue_args {
3231 /* union sigval32 */ int value;
3235 freebsd32_sigqueue(struct thread *td, struct freebsd32_sigqueue_args *uap)
3240 * On 32-bit ABIs, sival_int and sival_ptr are the same.
3241 * On 64-bit little-endian ABIs, the low bits are the same.
3242 * In 64-bit big-endian ABIs, sival_int overlaps with
3243 * sival_ptr's HIGH bits. We choose to support sival_int
3244 * rather than sival_ptr in this case as it seems to be
3247 bzero(&sv, sizeof(sv));
3248 sv.sival_int = (uint32_t)(uint64_t)uap->value;
3250 return (kern_sigqueue(td, uap->pid, uap->signum, &sv));
3254 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
3256 struct timespec32 ts32;
3258 struct timespec *timeout;
3261 struct siginfo32 si32;
3265 error = copyin(uap->timeout, &ts32, sizeof(ts32));
3268 ts.tv_sec = ts32.tv_sec;
3269 ts.tv_nsec = ts32.tv_nsec;
3274 error = copyin(uap->set, &set, sizeof(set));
3278 error = kern_sigtimedwait(td, set, &ksi, timeout);
3283 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
3284 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
3288 td->td_retval[0] = ksi.ksi_signo;
3296 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
3299 struct siginfo32 si32;
3303 error = copyin(uap->set, &set, sizeof(set));
3307 error = kern_sigtimedwait(td, set, &ksi, NULL);
3312 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
3313 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
3316 td->td_retval[0] = ksi.ksi_signo;
3321 freebsd32_cpuset_setid(struct thread *td,
3322 struct freebsd32_cpuset_setid_args *uap)
3325 return (kern_cpuset_setid(td, uap->which,
3326 PAIR32TO64(id_t, uap->id), uap->setid));
3330 freebsd32_cpuset_getid(struct thread *td,
3331 struct freebsd32_cpuset_getid_args *uap)
3334 return (kern_cpuset_getid(td, uap->level, uap->which,
3335 PAIR32TO64(id_t, uap->id), uap->setid));
3339 copyin32_set(const void *u, void *k, size_t size)
3341 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
3343 struct bitset *kb = k;
3346 rv = copyin(u, k, size);
3350 p = (int *)kb->__bits;
3351 /* Loop through swapping words.
3352 * `size' is in bytes, we need bits. */
3353 for (int i = 0; i < __bitset_words(size * 8); i++) {
3361 return (copyin(u, k, size));
3366 copyout32_set(const void *k, void *u, size_t size)
3368 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
3369 const struct bitset *kb = k;
3370 struct bitset *ub = u;
3371 const int *kp = (const int *)kb->__bits;
3372 int *up = (int *)ub->__bits;
3375 for (int i = 0; i < __bitset_words(CPU_SETSIZE); i++) {
3376 /* `size' is in bytes, we need bits. */
3377 for (int i = 0; i < __bitset_words(size * 8); i++) {
3378 rv = suword32(up, kp[1]);
3380 rv = suword32(up + 1, kp[0]);
3387 return (copyout(k, u, size));
3391 static const struct cpuset_copy_cb cpuset_copy32_cb = {
3392 .cpuset_copyin = copyin32_set,
3393 .cpuset_copyout = copyout32_set
3397 freebsd32_cpuset_getaffinity(struct thread *td,
3398 struct freebsd32_cpuset_getaffinity_args *uap)
3401 return (user_cpuset_getaffinity(td, uap->level, uap->which,
3402 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
3403 &cpuset_copy32_cb));
3407 freebsd32_cpuset_setaffinity(struct thread *td,
3408 struct freebsd32_cpuset_setaffinity_args *uap)
3411 return (user_cpuset_setaffinity(td, uap->level, uap->which,
3412 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
3413 &cpuset_copy32_cb));
3417 freebsd32_cpuset_getdomain(struct thread *td,
3418 struct freebsd32_cpuset_getdomain_args *uap)
3421 return (kern_cpuset_getdomain(td, uap->level, uap->which,
3422 PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
3423 &cpuset_copy32_cb));
3427 freebsd32_cpuset_setdomain(struct thread *td,
3428 struct freebsd32_cpuset_setdomain_args *uap)
3431 return (kern_cpuset_setdomain(td, uap->level, uap->which,
3432 PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
3433 &cpuset_copy32_cb));
3437 freebsd32_nmount(struct thread *td,
3438 struct freebsd32_nmount_args /* {
3440 unsigned int iovcnt;
3449 * Mount flags are now 64-bits. On 32-bit archtectures only
3450 * 32-bits are passed in, but from here on everything handles
3451 * 64-bit flags correctly.
3455 AUDIT_ARG_FFLAGS(flags);
3458 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
3459 * userspace to set this flag, but we must filter it out if we want
3460 * MNT_UPDATE on the root file system to work.
3461 * MNT_ROOTFS should only be set by the kernel when mounting its
3464 flags &= ~MNT_ROOTFS;
3467 * check that we have an even number of iovec's
3468 * and that we have at least two options.
3470 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
3473 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
3476 error = vfs_donmount(td, flags, auio);
3484 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
3486 struct yyy32 *p32, s32;
3487 struct yyy *p = NULL, s;
3492 error = copyin(uap->zzz, &s32, sizeof(s32));
3498 error = kern_xxx(td, p);
3503 error = copyout(&s32, p32, sizeof(s32));
3510 syscall32_module_handler(struct module *mod, int what, void *arg)
3513 return (kern_syscall_module_handler(freebsd32_sysent, mod, what, arg));
3517 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
3520 return (kern_syscall_helper_register(freebsd32_sysent, sd, flags));
3524 syscall32_helper_unregister(struct syscall_helper_data *sd)
3527 return (kern_syscall_helper_unregister(freebsd32_sysent, sd));
3531 freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
3533 struct sysentvec *sysent;
3537 uintptr_t destp, ustringp;
3538 struct freebsd32_ps_strings *arginfo;
3539 char canary[sizeof(long) * 8];
3540 int32_t pagesizes32[MAXPAGESIZES];
3541 size_t execpath_len;
3542 int error, szsigcode;
3544 sysent = imgp->sysent;
3546 arginfo = (struct freebsd32_ps_strings *)PROC_PS_STRINGS(imgp->proc);
3547 imgp->ps_strings = arginfo;
3548 destp = (uintptr_t)arginfo;
3553 if (!PROC_HAS_SHP(imgp->proc)) {
3554 szsigcode = *sysent->sv_szsigcode;
3556 destp = rounddown2(destp, sizeof(uint32_t));
3557 error = copyout(sysent->sv_sigcode, (void *)destp,
3564 * Copy the image path for the rtld.
3566 if (imgp->execpath != NULL && imgp->auxargs != NULL) {
3567 execpath_len = strlen(imgp->execpath) + 1;
3568 destp -= execpath_len;
3569 imgp->execpathp = (void *)destp;
3570 error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
3576 * Prepare the canary for SSP.
3578 arc4rand(canary, sizeof(canary), 0);
3579 destp -= sizeof(canary);
3580 imgp->canary = (void *)destp;
3581 error = copyout(canary, imgp->canary, sizeof(canary));
3584 imgp->canarylen = sizeof(canary);
3587 * Prepare the pagesizes array.
3589 for (i = 0; i < MAXPAGESIZES; i++)
3590 pagesizes32[i] = (uint32_t)pagesizes[i];
3591 destp -= sizeof(pagesizes32);
3592 destp = rounddown2(destp, sizeof(uint32_t));
3593 imgp->pagesizes = (void *)destp;
3594 error = copyout(pagesizes32, imgp->pagesizes, sizeof(pagesizes32));
3597 imgp->pagesizeslen = sizeof(pagesizes32);
3600 * Allocate room for the argument and environment strings.
3602 destp -= ARG_MAX - imgp->args->stringspace;
3603 destp = rounddown2(destp, sizeof(uint32_t));
3606 if (imgp->auxargs) {
3608 * Allocate room on the stack for the ELF auxargs
3609 * array. It has up to AT_COUNT entries.
3611 destp -= AT_COUNT * sizeof(Elf32_Auxinfo);
3612 destp = rounddown2(destp, sizeof(uint32_t));
3615 vectp = (uint32_t *)destp;
3618 * Allocate room for the argv[] and env vectors including the
3619 * terminating NULL pointers.
3621 vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
3624 * vectp also becomes our initial stack base
3626 *stack_base = (uintptr_t)vectp;
3628 stringp = imgp->args->begin_argv;
3629 argc = imgp->args->argc;
3630 envc = imgp->args->envc;
3632 * Copy out strings - arguments and environment.
3634 error = copyout(stringp, (void *)ustringp,
3635 ARG_MAX - imgp->args->stringspace);
3640 * Fill in "ps_strings" struct for ps, w, etc.
3643 if (suword32(&arginfo->ps_argvstr, (uint32_t)(intptr_t)vectp) != 0 ||
3644 suword32(&arginfo->ps_nargvstr, argc) != 0)
3648 * Fill in argument portion of vector table.
3650 for (; argc > 0; --argc) {
3651 if (suword32(vectp++, ustringp) != 0)
3653 while (*stringp++ != 0)
3658 /* a null vector table pointer separates the argp's from the envp's */
3659 if (suword32(vectp++, 0) != 0)
3663 if (suword32(&arginfo->ps_envstr, (uint32_t)(intptr_t)vectp) != 0 ||
3664 suword32(&arginfo->ps_nenvstr, envc) != 0)
3668 * Fill in environment portion of vector table.
3670 for (; envc > 0; --envc) {
3671 if (suword32(vectp++, ustringp) != 0)
3673 while (*stringp++ != 0)
3678 /* end of vector table is a null pointer */
3679 if (suword32(vectp, 0) != 0)
3682 if (imgp->auxargs) {
3684 error = imgp->sysent->sv_copyout_auxargs(imgp,
3694 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
3696 struct kld_file_stat *stat;
3697 struct kld_file_stat32 *stat32;
3700 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
3703 if (version != sizeof(struct kld_file_stat_1_32) &&
3704 version != sizeof(struct kld_file_stat32))
3707 stat = malloc(sizeof(*stat), M_TEMP, M_WAITOK | M_ZERO);
3708 stat32 = malloc(sizeof(*stat32), M_TEMP, M_WAITOK | M_ZERO);
3709 error = kern_kldstat(td, uap->fileid, stat);
3711 bcopy(&stat->name[0], &stat32->name[0], sizeof(stat->name));
3712 CP(*stat, *stat32, refs);
3713 CP(*stat, *stat32, id);
3714 PTROUT_CP(*stat, *stat32, address);
3715 CP(*stat, *stat32, size);
3716 bcopy(&stat->pathname[0], &stat32->pathname[0],
3717 sizeof(stat->pathname));
3718 stat32->version = version;
3719 error = copyout(stat32, uap->stat, version);
3722 free(stat32, M_TEMP);
3727 freebsd32_posix_fallocate(struct thread *td,
3728 struct freebsd32_posix_fallocate_args *uap)
3732 error = kern_posix_fallocate(td, uap->fd,
3733 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3734 return (kern_posix_error(td, error));
3738 freebsd32_posix_fadvise(struct thread *td,
3739 struct freebsd32_posix_fadvise_args *uap)
3743 error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
3744 PAIR32TO64(off_t, uap->len), uap->advice);
3745 return (kern_posix_error(td, error));
3749 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3752 CP(*sig32, *sig, sigev_notify);
3753 switch (sig->sigev_notify) {
3756 case SIGEV_THREAD_ID:
3757 CP(*sig32, *sig, sigev_notify_thread_id);
3760 CP(*sig32, *sig, sigev_signo);
3761 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3764 CP(*sig32, *sig, sigev_notify_kqueue);
3765 CP(*sig32, *sig, sigev_notify_kevent_flags);
3766 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3775 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3779 struct procctl_reaper_status rs;
3780 struct procctl_reaper_pids rp;
3781 struct procctl_reaper_kill rk;
3784 struct procctl_reaper_pids32 rp;
3786 int error, error1, flags, signum;
3788 if (uap->com >= PROC_PROCCTL_MD_MIN)
3789 return (cpu_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3790 uap->com, PTRIN(uap->data)));
3794 case PROC_PROTMAX_CTL:
3796 case PROC_STACKGAP_CTL:
3797 case PROC_TRACE_CTL:
3798 case PROC_TRAPCAP_CTL:
3799 case PROC_NO_NEW_PRIVS_CTL:
3800 case PROC_WXMAP_CTL:
3801 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3806 case PROC_REAP_ACQUIRE:
3807 case PROC_REAP_RELEASE:
3808 if (uap->data != NULL)
3812 case PROC_REAP_STATUS:
3815 case PROC_REAP_GETPIDS:
3816 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3819 CP(x32.rp, x.rp, rp_count);
3820 PTRIN_CP(x32.rp, x.rp, rp_pids);
3823 case PROC_REAP_KILL:
3824 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3829 case PROC_ASLR_STATUS:
3830 case PROC_PROTMAX_STATUS:
3831 case PROC_STACKGAP_STATUS:
3832 case PROC_TRACE_STATUS:
3833 case PROC_TRAPCAP_STATUS:
3834 case PROC_NO_NEW_PRIVS_STATUS:
3835 case PROC_WXMAP_STATUS:
3838 case PROC_PDEATHSIG_CTL:
3839 error = copyin(uap->data, &signum, sizeof(signum));
3844 case PROC_PDEATHSIG_STATUS:
3850 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3853 case PROC_REAP_STATUS:
3855 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3857 case PROC_REAP_KILL:
3858 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3862 case PROC_ASLR_STATUS:
3863 case PROC_PROTMAX_STATUS:
3864 case PROC_STACKGAP_STATUS:
3865 case PROC_TRACE_STATUS:
3866 case PROC_TRAPCAP_STATUS:
3867 case PROC_NO_NEW_PRIVS_STATUS:
3868 case PROC_WXMAP_STATUS:
3870 error = copyout(&flags, uap->data, sizeof(flags));
3872 case PROC_PDEATHSIG_STATUS:
3874 error = copyout(&signum, uap->data, sizeof(signum));
3881 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3887 * Do unsigned conversion for arg when operation
3888 * interprets it as flags or pointer.
3890 case F_SETLK_REMOTE:
3900 tmp = (unsigned int)(uap->arg);
3906 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3910 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3912 struct timespec32 ts32;
3913 struct timespec ts, *tsp;
3917 if (uap->ts != NULL) {
3918 error = copyin(uap->ts, &ts32, sizeof(ts32));
3921 CP(ts32, ts, tv_sec);
3922 CP(ts32, ts, tv_nsec);
3926 if (uap->set != NULL) {
3927 error = copyin(uap->set, &set, sizeof(set));
3934 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));
3938 freebsd32_sched_rr_get_interval(struct thread *td,
3939 struct freebsd32_sched_rr_get_interval_args *uap)
3942 struct timespec32 ts32;
3945 error = kern_sched_rr_get_interval(td, uap->pid, &ts);
3947 CP(ts, ts32, tv_sec);
3948 CP(ts, ts32, tv_nsec);
3949 error = copyout(&ts32, uap->interval, sizeof(ts32));
3955 timex_to_32(struct timex32 *dst, struct timex *src)
3957 CP(*src, *dst, modes);
3958 CP(*src, *dst, offset);
3959 CP(*src, *dst, freq);
3960 CP(*src, *dst, maxerror);
3961 CP(*src, *dst, esterror);
3962 CP(*src, *dst, status);
3963 CP(*src, *dst, constant);
3964 CP(*src, *dst, precision);
3965 CP(*src, *dst, tolerance);
3966 CP(*src, *dst, ppsfreq);
3967 CP(*src, *dst, jitter);
3968 CP(*src, *dst, shift);
3969 CP(*src, *dst, stabil);
3970 CP(*src, *dst, jitcnt);
3971 CP(*src, *dst, calcnt);
3972 CP(*src, *dst, errcnt);
3973 CP(*src, *dst, stbcnt);
3977 timex_from_32(struct timex *dst, struct timex32 *src)
3979 CP(*src, *dst, modes);
3980 CP(*src, *dst, offset);
3981 CP(*src, *dst, freq);
3982 CP(*src, *dst, maxerror);
3983 CP(*src, *dst, esterror);
3984 CP(*src, *dst, status);
3985 CP(*src, *dst, constant);
3986 CP(*src, *dst, precision);
3987 CP(*src, *dst, tolerance);
3988 CP(*src, *dst, ppsfreq);
3989 CP(*src, *dst, jitter);
3990 CP(*src, *dst, shift);
3991 CP(*src, *dst, stabil);
3992 CP(*src, *dst, jitcnt);
3993 CP(*src, *dst, calcnt);
3994 CP(*src, *dst, errcnt);
3995 CP(*src, *dst, stbcnt);
3999 freebsd32_ntp_adjtime(struct thread *td, struct freebsd32_ntp_adjtime_args *uap)
4002 struct timex32 tx32;
4005 error = copyin(uap->tp, &tx32, sizeof(tx32));
4007 timex_from_32(&tx, &tx32);
4008 error = kern_ntp_adjtime(td, &tx, &retval);
4010 timex_to_32(&tx32, &tx);
4011 error = copyout(&tx32, uap->tp, sizeof(tx32));
4013 td->td_retval[0] = retval;
4020 extern struct mtx ffclock_mtx;
4021 extern struct ffclock_estimate ffclock_estimate;
4022 extern int8_t ffclock_updated;
4025 freebsd32_ffclock_setestimate(struct thread *td,
4026 struct freebsd32_ffclock_setestimate_args *uap)
4028 struct ffclock_estimate cest;
4029 struct ffclock_estimate32 cest32;
4032 /* Reuse of PRIV_CLOCK_SETTIME. */
4033 if ((error = priv_check(td, PRIV_CLOCK_SETTIME)) != 0)
4036 if ((error = copyin(uap->cest, &cest32,
4037 sizeof(struct ffclock_estimate32))) != 0)
4040 CP(cest.update_time, cest32.update_time, sec);
4041 memcpy(&cest.update_time.frac, &cest32.update_time.frac, sizeof(uint64_t));
4042 CP(cest, cest32, update_ffcount);
4043 CP(cest, cest32, leapsec_next);
4044 CP(cest, cest32, period);
4045 CP(cest, cest32, errb_abs);
4046 CP(cest, cest32, errb_rate);
4047 CP(cest, cest32, status);
4048 CP(cest, cest32, leapsec_total);
4049 CP(cest, cest32, leapsec);
4051 mtx_lock(&ffclock_mtx);
4052 memcpy(&ffclock_estimate, &cest, sizeof(struct ffclock_estimate));
4054 mtx_unlock(&ffclock_mtx);
4059 freebsd32_ffclock_getestimate(struct thread *td,
4060 struct freebsd32_ffclock_getestimate_args *uap)
4062 struct ffclock_estimate cest;
4063 struct ffclock_estimate32 cest32;
4066 mtx_lock(&ffclock_mtx);
4067 memcpy(&cest, &ffclock_estimate, sizeof(struct ffclock_estimate));
4068 mtx_unlock(&ffclock_mtx);
4070 CP(cest32.update_time, cest.update_time, sec);
4071 memcpy(&cest32.update_time.frac, &cest.update_time.frac, sizeof(uint64_t));
4072 CP(cest32, cest, update_ffcount);
4073 CP(cest32, cest, leapsec_next);
4074 CP(cest32, cest, period);
4075 CP(cest32, cest, errb_abs);
4076 CP(cest32, cest, errb_rate);
4077 CP(cest32, cest, status);
4078 CP(cest32, cest, leapsec_total);
4079 CP(cest32, cest, leapsec);
4081 error = copyout(&cest32, uap->cest, sizeof(struct ffclock_estimate32));
4084 #else /* !FFCLOCK */
4086 freebsd32_ffclock_setestimate(struct thread *td,
4087 struct freebsd32_ffclock_setestimate_args *uap)
4093 freebsd32_ffclock_getestimate(struct thread *td,
4094 struct freebsd32_ffclock_getestimate_args *uap)
4098 #endif /* FFCLOCK */
4102 ofreebsd32_sethostid(struct thread *td, struct ofreebsd32_sethostid_args *uap)
4104 int name[] = { CTL_KERN, KERN_HOSTID };
4107 hostid = uap->hostid;
4108 return (kernel_sysctl(td, name, nitems(name), NULL, NULL, &hostid,
4109 sizeof(hostid), NULL, 0));