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 #include "opt_ffclock.h"
32 #include "opt_inet6.h"
33 #include "opt_ktrace.h"
35 #define __ELF_WORD_SIZE 32
37 #ifdef COMPAT_FREEBSD11
38 #define _WANT_FREEBSD11_KEVENT
41 #include <sys/param.h>
43 #include <sys/capsicum.h>
44 #include <sys/clock.h>
46 #include <sys/fcntl.h>
47 #include <sys/filedesc.h>
48 #include <sys/imgact.h>
50 #include <sys/kernel.h>
51 #include <sys/limits.h>
52 #include <sys/linker.h>
54 #include <sys/malloc.h>
55 #include <sys/file.h> /* Must come after sys/malloc.h */
56 #include <sys/imgact.h>
59 #include <sys/module.h>
60 #include <sys/mount.h>
61 #include <sys/mutex.h>
62 #include <sys/namei.h>
65 #include <sys/procctl.h>
66 #include <sys/ptrace.h>
67 #include <sys/reboot.h>
68 #include <sys/resource.h>
69 #include <sys/resourcevar.h>
70 #include <sys/selinfo.h>
71 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
72 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
73 #include <sys/signal.h>
74 #include <sys/signalvar.h>
75 #include <sys/socket.h>
76 #include <sys/socketvar.h>
78 #include <sys/syscall.h>
79 #include <sys/syscallsubr.h>
80 #include <sys/sysctl.h>
81 #include <sys/sysent.h>
82 #include <sys/sysproto.h>
83 #include <sys/systm.h>
85 #include <sys/timerfd.h>
86 #include <sys/timex.h>
87 #include <sys/unistd.h>
88 #include <sys/ucontext.h>
89 #include <sys/vnode.h>
95 #include <sys/timeffc.h>
97 #include <sys/ktrace.h>
101 #include <netinet/in.h>
105 #include <vm/vm_param.h>
107 #include <vm/vm_map.h>
108 #include <vm/vm_object.h>
109 #include <vm/vm_extern.h>
111 #include <machine/cpu.h>
112 #include <machine/elf.h>
114 #include <machine/md_var.h>
117 #include <security/audit/audit.h>
119 #include <compat/freebsd32/freebsd32_util.h>
120 #include <compat/freebsd32/freebsd32.h>
121 #include <compat/freebsd32/freebsd32_ipc.h>
122 #include <compat/freebsd32/freebsd32_misc.h>
123 #include <compat/freebsd32/freebsd32_signal.h>
124 #include <compat/freebsd32/freebsd32_proto.h>
126 FEATURE(compat_freebsd_32bit, "Compatible with 32-bit FreeBSD");
128 struct ptrace_io_desc32 {
135 struct ptrace_vm_entry32 {
149 CTASSERT(sizeof(struct timeval32) == 8);
150 CTASSERT(sizeof(struct timespec32) == 8);
151 CTASSERT(sizeof(struct itimerval32) == 16);
152 CTASSERT(sizeof(struct bintime32) == 12);
154 CTASSERT(sizeof(struct timeval32) == 16);
155 CTASSERT(sizeof(struct timespec32) == 16);
156 CTASSERT(sizeof(struct itimerval32) == 32);
157 CTASSERT(sizeof(struct bintime32) == 16);
159 CTASSERT(sizeof(struct ostatfs32) == 256);
161 CTASSERT(sizeof(struct rusage32) == 72);
163 CTASSERT(sizeof(struct rusage32) == 88);
165 CTASSERT(sizeof(struct sigaltstack32) == 12);
167 CTASSERT(sizeof(struct kevent32) == 56);
169 CTASSERT(sizeof(struct kevent32) == 64);
171 CTASSERT(sizeof(struct iovec32) == 8);
172 CTASSERT(sizeof(struct msghdr32) == 28);
174 CTASSERT(sizeof(struct stat32) == 208);
175 CTASSERT(sizeof(struct freebsd11_stat32) == 96);
177 CTASSERT(sizeof(struct stat32) == 224);
178 CTASSERT(sizeof(struct freebsd11_stat32) == 120);
180 CTASSERT(sizeof(struct sigaction32) == 24);
182 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
183 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
184 static int freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
185 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp);
188 freebsd32_rusage_out(const struct rusage *s, struct rusage32 *s32)
191 TV_CP(*s, *s32, ru_utime);
192 TV_CP(*s, *s32, ru_stime);
193 CP(*s, *s32, ru_maxrss);
194 CP(*s, *s32, ru_ixrss);
195 CP(*s, *s32, ru_idrss);
196 CP(*s, *s32, ru_isrss);
197 CP(*s, *s32, ru_minflt);
198 CP(*s, *s32, ru_majflt);
199 CP(*s, *s32, ru_nswap);
200 CP(*s, *s32, ru_inblock);
201 CP(*s, *s32, ru_oublock);
202 CP(*s, *s32, ru_msgsnd);
203 CP(*s, *s32, ru_msgrcv);
204 CP(*s, *s32, ru_nsignals);
205 CP(*s, *s32, ru_nvcsw);
206 CP(*s, *s32, ru_nivcsw);
210 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
213 struct rusage32 ru32;
214 struct rusage ru, *rup;
216 if (uap->rusage != NULL)
220 error = kern_wait(td, uap->pid, &status, uap->options, rup);
223 if (uap->status != NULL)
224 error = copyout(&status, uap->status, sizeof(status));
225 if (uap->rusage != NULL && error == 0) {
226 freebsd32_rusage_out(&ru, &ru32);
227 error = copyout(&ru32, uap->rusage, sizeof(ru32));
233 freebsd32_wait6(struct thread *td, struct freebsd32_wait6_args *uap)
235 struct __wrusage32 wru32;
236 struct __wrusage wru, *wrup;
237 struct siginfo32 si32;
238 struct __siginfo si, *sip;
241 if (uap->wrusage != NULL)
245 if (uap->info != NULL) {
247 bzero(sip, sizeof(*sip));
250 error = kern_wait6(td, uap->idtype, PAIR32TO64(id_t, uap->id),
251 &status, uap->options, wrup, sip);
254 if (uap->status != NULL)
255 error = copyout(&status, uap->status, sizeof(status));
256 if (uap->wrusage != NULL && error == 0) {
257 freebsd32_rusage_out(&wru.wru_self, &wru32.wru_self);
258 freebsd32_rusage_out(&wru.wru_children, &wru32.wru_children);
259 error = copyout(&wru32, uap->wrusage, sizeof(wru32));
261 if (uap->info != NULL && error == 0) {
262 siginfo_to_siginfo32 (&si, &si32);
263 error = copyout(&si32, uap->info, sizeof(si32));
268 #ifdef COMPAT_FREEBSD4
270 copy_statfs(struct statfs *in, struct ostatfs32 *out)
273 statfs_scale_blocks(in, INT32_MAX);
274 bzero(out, sizeof(*out));
275 CP(*in, *out, f_bsize);
276 out->f_iosize = MIN(in->f_iosize, INT32_MAX);
277 CP(*in, *out, f_blocks);
278 CP(*in, *out, f_bfree);
279 CP(*in, *out, f_bavail);
280 out->f_files = MIN(in->f_files, INT32_MAX);
281 out->f_ffree = MIN(in->f_ffree, INT32_MAX);
282 CP(*in, *out, f_fsid);
283 CP(*in, *out, f_owner);
284 CP(*in, *out, f_type);
285 CP(*in, *out, f_flags);
286 out->f_syncwrites = MIN(in->f_syncwrites, INT32_MAX);
287 out->f_asyncwrites = MIN(in->f_asyncwrites, INT32_MAX);
288 strlcpy(out->f_fstypename,
289 in->f_fstypename, MFSNAMELEN);
290 strlcpy(out->f_mntonname,
291 in->f_mntonname, min(MNAMELEN, FREEBSD4_OMNAMELEN));
292 out->f_syncreads = MIN(in->f_syncreads, INT32_MAX);
293 out->f_asyncreads = MIN(in->f_asyncreads, INT32_MAX);
294 strlcpy(out->f_mntfromname,
295 in->f_mntfromname, min(MNAMELEN, FREEBSD4_OMNAMELEN));
300 freebsd32_getfsstat(struct thread *td, struct freebsd32_getfsstat_args *uap)
305 if (uap->bufsize < 0 || uap->bufsize > SIZE_MAX)
307 error = kern_getfsstat(td, &uap->buf, uap->bufsize, &count,
308 UIO_USERSPACE, uap->mode);
310 td->td_retval[0] = count;
314 #ifdef COMPAT_FREEBSD4
316 freebsd4_freebsd32_getfsstat(struct thread *td,
317 struct freebsd4_freebsd32_getfsstat_args *uap)
319 struct statfs *buf, *sp;
320 struct ostatfs32 stat32;
321 size_t count, size, copycount;
324 count = uap->bufsize / sizeof(struct ostatfs32);
325 size = count * sizeof(struct statfs);
326 error = kern_getfsstat(td, &buf, size, &count, UIO_SYSSPACE, uap->mode);
330 while (copycount > 0 && error == 0) {
331 copy_statfs(sp, &stat32);
332 error = copyout(&stat32, uap->buf, sizeof(stat32));
340 td->td_retval[0] = count;
345 #ifdef COMPAT_FREEBSD11
347 freebsd11_freebsd32_getfsstat(struct thread *td,
348 struct freebsd11_freebsd32_getfsstat_args *uap)
350 return(kern_freebsd11_getfsstat(td, uap->buf, uap->bufsize,
356 freebsd32_sigaltstack(struct thread *td,
357 struct freebsd32_sigaltstack_args *uap)
359 struct sigaltstack32 s32;
360 struct sigaltstack ss, oss, *ssp;
363 if (uap->ss != NULL) {
364 error = copyin(uap->ss, &s32, sizeof(s32));
367 PTRIN_CP(s32, ss, ss_sp);
368 CP(s32, ss, ss_size);
369 CP(s32, ss, ss_flags);
373 error = kern_sigaltstack(td, ssp, &oss);
374 if (error == 0 && uap->oss != NULL) {
375 PTROUT_CP(oss, s32, ss_sp);
376 CP(oss, s32, ss_size);
377 CP(oss, s32, ss_flags);
378 error = copyout(&s32, uap->oss, sizeof(s32));
384 * Custom version of exec_copyin_args() so that we can translate
388 freebsd32_exec_copyin_args(struct image_args *args, const char *fname,
389 enum uio_seg segflg, uint32_t *argv, uint32_t *envv)
395 bzero(args, sizeof(*args));
400 * Allocate demand-paged memory for the file name, argument, and
401 * environment strings.
403 error = exec_alloc_args(args);
408 * Copy the file name.
410 error = exec_args_add_fname(args, fname, segflg);
415 * extract arguments first
419 error = copyin(p32++, &arg, sizeof(arg));
425 error = exec_args_add_arg(args, argp, UIO_USERSPACE);
431 * extract environment strings
436 error = copyin(p32++, &arg, sizeof(arg));
442 error = exec_args_add_env(args, envp, UIO_USERSPACE);
451 exec_free_args(args);
456 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
458 struct image_args eargs;
459 struct vmspace *oldvmspace;
462 error = pre_execve(td, &oldvmspace);
465 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
466 uap->argv, uap->envv);
468 error = kern_execve(td, &eargs, NULL, oldvmspace);
469 post_execve(td, error, oldvmspace);
470 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
475 freebsd32_fexecve(struct thread *td, struct freebsd32_fexecve_args *uap)
477 struct image_args eargs;
478 struct vmspace *oldvmspace;
481 error = pre_execve(td, &oldvmspace);
484 error = freebsd32_exec_copyin_args(&eargs, NULL, UIO_SYSSPACE,
485 uap->argv, uap->envv);
488 error = kern_execve(td, &eargs, NULL, oldvmspace);
490 post_execve(td, error, oldvmspace);
491 AUDIT_SYSCALL_EXIT(error == EJUSTRETURN ? 0 : error, td);
496 freebsd32_mknodat(struct thread *td, struct freebsd32_mknodat_args *uap)
499 return (kern_mknodat(td, uap->fd, uap->path, UIO_USERSPACE,
500 uap->mode, PAIR32TO64(dev_t, uap->dev)));
504 freebsd32_mprotect(struct thread *td, struct freebsd32_mprotect_args *uap)
509 #if defined(__amd64__)
510 if (i386_read_exec && (prot & PROT_READ) != 0)
513 return (kern_mprotect(td, (uintptr_t)PTRIN(uap->addr), uap->len,
518 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
523 #if defined(__amd64__)
524 if (i386_read_exec && (prot & PROT_READ))
528 return (kern_mmap(td, &(struct mmap_req){
529 .mr_hint = (uintptr_t)uap->addr,
532 .mr_flags = uap->flags,
534 .mr_pos = PAIR32TO64(off_t, uap->pos),
538 #ifdef COMPAT_FREEBSD6
540 freebsd6_freebsd32_mmap(struct thread *td,
541 struct freebsd6_freebsd32_mmap_args *uap)
546 #if defined(__amd64__)
547 if (i386_read_exec && (prot & PROT_READ))
551 return (kern_mmap(td, &(struct mmap_req){
552 .mr_hint = (uintptr_t)uap->addr,
555 .mr_flags = uap->flags,
557 .mr_pos = PAIR32TO64(off_t, uap->pos),
564 ofreebsd32_mmap(struct thread *td, struct ofreebsd32_mmap_args *uap)
566 return (kern_ommap(td, (uintptr_t)uap->addr, uap->len, uap->prot,
567 uap->flags, uap->fd, uap->pos));
572 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
574 struct itimerval itv, oitv, *itvp;
575 struct itimerval32 i32;
578 if (uap->itv != NULL) {
579 error = copyin(uap->itv, &i32, sizeof(i32));
582 TV_CP(i32, itv, it_interval);
583 TV_CP(i32, itv, it_value);
587 error = kern_setitimer(td, uap->which, itvp, &oitv);
588 if (error || uap->oitv == NULL)
590 TV_CP(oitv, i32, it_interval);
591 TV_CP(oitv, i32, it_value);
592 return (copyout(&i32, uap->oitv, sizeof(i32)));
596 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
598 struct itimerval itv;
599 struct itimerval32 i32;
602 error = kern_getitimer(td, uap->which, &itv);
603 if (error || uap->itv == NULL)
605 TV_CP(itv, i32, it_interval);
606 TV_CP(itv, i32, it_value);
607 return (copyout(&i32, uap->itv, sizeof(i32)));
611 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
613 struct timeval32 tv32;
614 struct timeval tv, *tvp;
617 if (uap->tv != NULL) {
618 error = copyin(uap->tv, &tv32, sizeof(tv32));
621 CP(tv32, tv, tv_sec);
622 CP(tv32, tv, tv_usec);
627 * XXX Do pointers need PTRIN()?
629 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
630 sizeof(int32_t) * 8));
634 freebsd32_pselect(struct thread *td, struct freebsd32_pselect_args *uap)
636 struct timespec32 ts32;
638 struct timeval tv, *tvp;
642 if (uap->ts != NULL) {
643 error = copyin(uap->ts, &ts32, sizeof(ts32));
646 CP(ts32, ts, tv_sec);
647 CP(ts32, ts, tv_nsec);
648 TIMESPEC_TO_TIMEVAL(&tv, &ts);
652 if (uap->sm != NULL) {
653 error = copyin(uap->sm, &set, sizeof(set));
660 * XXX Do pointers need PTRIN()?
662 error = kern_pselect(td, uap->nd, uap->in, uap->ou, uap->ex, tvp,
663 uset, sizeof(int32_t) * 8);
668 * Copy 'count' items into the destination list pointed to by uap->eventlist.
671 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
673 struct freebsd32_kevent_args *uap;
674 struct kevent32 ks32[KQ_NEVENTS];
678 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
679 uap = (struct freebsd32_kevent_args *)arg;
681 for (i = 0; i < count; i++) {
682 CP(kevp[i], ks32[i], ident);
683 CP(kevp[i], ks32[i], filter);
684 CP(kevp[i], ks32[i], flags);
685 CP(kevp[i], ks32[i], fflags);
686 #if BYTE_ORDER == LITTLE_ENDIAN
687 ks32[i].data1 = kevp[i].data;
688 ks32[i].data2 = kevp[i].data >> 32;
690 ks32[i].data1 = kevp[i].data >> 32;
691 ks32[i].data2 = kevp[i].data;
693 PTROUT_CP(kevp[i], ks32[i], udata);
694 for (j = 0; j < nitems(kevp->ext); j++) {
696 #if BYTE_ORDER == LITTLE_ENDIAN
697 ks32[i].ext64[2 * j] = e;
698 ks32[i].ext64[2 * j + 1] = e >> 32;
700 ks32[i].ext64[2 * j] = e >> 32;
701 ks32[i].ext64[2 * j + 1] = e;
705 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
707 uap->eventlist += count;
712 * Copy 'count' items from the list pointed to by uap->changelist.
715 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
717 struct freebsd32_kevent_args *uap;
718 struct kevent32 ks32[KQ_NEVENTS];
722 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
723 uap = (struct freebsd32_kevent_args *)arg;
725 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
728 uap->changelist += count;
730 for (i = 0; i < count; i++) {
731 CP(ks32[i], kevp[i], ident);
732 CP(ks32[i], kevp[i], filter);
733 CP(ks32[i], kevp[i], flags);
734 CP(ks32[i], kevp[i], fflags);
735 kevp[i].data = PAIR32TO64(uint64_t, ks32[i].data);
736 PTRIN_CP(ks32[i], kevp[i], udata);
737 for (j = 0; j < nitems(kevp->ext); j++) {
738 #if BYTE_ORDER == LITTLE_ENDIAN
739 e = ks32[i].ext64[2 * j + 1];
741 e += ks32[i].ext64[2 * j];
743 e = ks32[i].ext64[2 * j];
745 e += ks32[i].ext64[2 * j + 1];
755 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
757 struct timespec32 ts32;
758 struct timespec ts, *tsp;
759 struct kevent_copyops k_ops = {
761 .k_copyout = freebsd32_kevent_copyout,
762 .k_copyin = freebsd32_kevent_copyin,
765 struct kevent32 *eventlist = uap->eventlist;
770 error = copyin(uap->timeout, &ts32, sizeof(ts32));
773 CP(ts32, ts, tv_sec);
774 CP(ts32, ts, tv_nsec);
779 if (KTRPOINT(td, KTR_STRUCT_ARRAY))
780 ktrstructarray("kevent32", UIO_USERSPACE, uap->changelist,
781 uap->nchanges, sizeof(struct kevent32));
783 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
786 if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
787 ktrstructarray("kevent32", UIO_USERSPACE, eventlist,
788 td->td_retval[0], sizeof(struct kevent32));
793 #ifdef COMPAT_FREEBSD11
795 freebsd32_kevent11_copyout(void *arg, struct kevent *kevp, int count)
797 struct freebsd11_freebsd32_kevent_args *uap;
798 struct freebsd11_kevent32 ks32[KQ_NEVENTS];
801 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
802 uap = (struct freebsd11_freebsd32_kevent_args *)arg;
804 for (i = 0; i < count; i++) {
805 CP(kevp[i], ks32[i], ident);
806 CP(kevp[i], ks32[i], filter);
807 CP(kevp[i], ks32[i], flags);
808 CP(kevp[i], ks32[i], fflags);
809 CP(kevp[i], ks32[i], data);
810 PTROUT_CP(kevp[i], ks32[i], udata);
812 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
814 uap->eventlist += count;
819 * Copy 'count' items from the list pointed to by uap->changelist.
822 freebsd32_kevent11_copyin(void *arg, struct kevent *kevp, int count)
824 struct freebsd11_freebsd32_kevent_args *uap;
825 struct freebsd11_kevent32 ks32[KQ_NEVENTS];
828 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
829 uap = (struct freebsd11_freebsd32_kevent_args *)arg;
831 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
834 uap->changelist += count;
836 for (i = 0; i < count; i++) {
837 CP(ks32[i], kevp[i], ident);
838 CP(ks32[i], kevp[i], filter);
839 CP(ks32[i], kevp[i], flags);
840 CP(ks32[i], kevp[i], fflags);
841 CP(ks32[i], kevp[i], data);
842 PTRIN_CP(ks32[i], kevp[i], udata);
843 for (j = 0; j < nitems(kevp->ext); j++)
851 freebsd11_freebsd32_kevent(struct thread *td,
852 struct freebsd11_freebsd32_kevent_args *uap)
854 struct timespec32 ts32;
855 struct timespec ts, *tsp;
856 struct kevent_copyops k_ops = {
858 .k_copyout = freebsd32_kevent11_copyout,
859 .k_copyin = freebsd32_kevent11_copyin,
862 struct freebsd11_kevent32 *eventlist = uap->eventlist;
867 error = copyin(uap->timeout, &ts32, sizeof(ts32));
870 CP(ts32, ts, tv_sec);
871 CP(ts32, ts, tv_nsec);
876 if (KTRPOINT(td, KTR_STRUCT_ARRAY))
877 ktrstructarray("freebsd11_kevent32", UIO_USERSPACE,
878 uap->changelist, uap->nchanges,
879 sizeof(struct freebsd11_kevent32));
881 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
884 if (error == 0 && KTRPOINT(td, KTR_STRUCT_ARRAY))
885 ktrstructarray("freebsd11_kevent32", UIO_USERSPACE,
886 eventlist, td->td_retval[0],
887 sizeof(struct freebsd11_kevent32));
894 freebsd32_gettimeofday(struct thread *td,
895 struct freebsd32_gettimeofday_args *uap)
898 struct timeval32 atv32;
904 CP(atv, atv32, tv_sec);
905 CP(atv, atv32, tv_usec);
906 error = copyout(&atv32, uap->tp, sizeof (atv32));
908 if (error == 0 && uap->tzp != NULL) {
909 rtz.tz_minuteswest = 0;
911 error = copyout(&rtz, uap->tzp, sizeof (rtz));
917 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
923 error = kern_getrusage(td, uap->who, &s);
925 freebsd32_rusage_out(&s, &s32);
926 error = copyout(&s32, uap->rusage, sizeof(s32));
932 ptrace_lwpinfo_to32(const struct ptrace_lwpinfo *pl,
933 struct ptrace_lwpinfo32 *pl32)
936 bzero(pl32, sizeof(*pl32));
937 pl32->pl_lwpid = pl->pl_lwpid;
938 pl32->pl_event = pl->pl_event;
939 pl32->pl_flags = pl->pl_flags;
940 pl32->pl_sigmask = pl->pl_sigmask;
941 pl32->pl_siglist = pl->pl_siglist;
942 siginfo_to_siginfo32(&pl->pl_siginfo, &pl32->pl_siginfo);
943 strcpy(pl32->pl_tdname, pl->pl_tdname);
944 pl32->pl_child_pid = pl->pl_child_pid;
945 pl32->pl_syscall_code = pl->pl_syscall_code;
946 pl32->pl_syscall_narg = pl->pl_syscall_narg;
950 ptrace_sc_ret_to32(const struct ptrace_sc_ret *psr,
951 struct ptrace_sc_ret32 *psr32)
954 bzero(psr32, sizeof(*psr32));
955 psr32->sr_retval[0] = psr->sr_retval[0];
956 psr32->sr_retval[1] = psr->sr_retval[1];
957 psr32->sr_error = psr->sr_error;
961 freebsd32_ptrace(struct thread *td, struct freebsd32_ptrace_args *uap)
964 struct ptrace_io_desc piod;
965 struct ptrace_lwpinfo pl;
966 struct ptrace_vm_entry pve;
967 struct ptrace_coredump pc;
968 struct ptrace_sc_remote sr;
969 struct dbreg32 dbreg;
970 struct fpreg32 fpreg;
973 register_t args[nitems(td->td_sa.args)];
974 struct ptrace_sc_ret psr;
978 struct ptrace_io_desc32 piod;
979 struct ptrace_lwpinfo32 pl;
980 struct ptrace_vm_entry32 pve;
981 struct ptrace_coredump32 pc;
982 struct ptrace_sc_remote32 sr;
983 uint32_t args[nitems(td->td_sa.args)];
984 struct ptrace_sc_ret32 psr;
987 syscallarg_t pscr_args[nitems(td->td_sa.args)];
988 u_int pscr_args32[nitems(td->td_sa.args)];
996 AUDIT_ARG_PID(uap->pid);
997 AUDIT_ARG_CMD(uap->req);
998 AUDIT_ARG_VALUE(uap->data);
1002 case PT_GET_EVENT_MASK:
1003 case PT_GET_SC_ARGS:
1007 if (uap->data > sizeof(r32.pl))
1011 * Pass size of native structure in 'data'. Truncate
1012 * if necessary to avoid siginfo.
1014 data = sizeof(r.pl);
1015 if (uap->data < offsetof(struct ptrace_lwpinfo32, pl_siginfo) +
1016 sizeof(struct siginfo32))
1017 data = offsetof(struct ptrace_lwpinfo, pl_siginfo);
1020 bzero(&r.reg, sizeof(r.reg));
1023 bzero(&r.fpreg, sizeof(r.fpreg));
1026 bzero(&r.dbreg, sizeof(r.dbreg));
1029 error = copyin(uap->addr, &r.reg, sizeof(r.reg));
1032 error = copyin(uap->addr, &r.fpreg, sizeof(r.fpreg));
1035 error = copyin(uap->addr, &r.dbreg, sizeof(r.dbreg));
1039 error = copyin(uap->addr, &r32.vec, sizeof(r32.vec));
1043 r.vec.iov_len = r32.vec.iov_len;
1044 r.vec.iov_base = PTRIN(r32.vec.iov_base);
1046 case PT_SET_EVENT_MASK:
1047 if (uap->data != sizeof(r.ptevents))
1050 error = copyin(uap->addr, &r.ptevents, uap->data);
1053 error = copyin(uap->addr, &r32.piod, sizeof(r32.piod));
1056 CP(r32.piod, r.piod, piod_op);
1057 PTRIN_CP(r32.piod, r.piod, piod_offs);
1058 PTRIN_CP(r32.piod, r.piod, piod_addr);
1059 CP(r32.piod, r.piod, piod_len);
1062 error = copyin(uap->addr, &r32.pve, sizeof(r32.pve));
1066 CP(r32.pve, r.pve, pve_entry);
1067 CP(r32.pve, r.pve, pve_timestamp);
1068 CP(r32.pve, r.pve, pve_start);
1069 CP(r32.pve, r.pve, pve_end);
1070 CP(r32.pve, r.pve, pve_offset);
1071 CP(r32.pve, r.pve, pve_prot);
1072 CP(r32.pve, r.pve, pve_pathlen);
1073 CP(r32.pve, r.pve, pve_fileid);
1074 CP(r32.pve, r.pve, pve_fsid);
1075 PTRIN_CP(r32.pve, r.pve, pve_path);
1078 if (uap->data != sizeof(r32.pc))
1081 error = copyin(uap->addr, &r32.pc, uap->data);
1082 CP(r32.pc, r.pc, pc_fd);
1083 CP(r32.pc, r.pc, pc_flags);
1084 r.pc.pc_limit = PAIR32TO64(off_t, r32.pc.pc_limit);
1085 data = sizeof(r.pc);
1088 if (uap->data != sizeof(r32.sr)) {
1092 error = copyin(uap->addr, &r32.sr, uap->data);
1095 CP(r32.sr, r.sr, pscr_syscall);
1096 CP(r32.sr, r.sr, pscr_nargs);
1097 if (r.sr.pscr_nargs > nitems(td->td_sa.args)) {
1101 error = copyin(PTRIN(r32.sr.pscr_args), pscr_args32,
1102 sizeof(u_int) * r32.sr.pscr_nargs);
1105 for (i = 0; i < r32.sr.pscr_nargs; i++)
1106 pscr_args[i] = pscr_args32[i];
1107 r.sr.pscr_args = pscr_args;
1116 error = kern_ptrace(td, uap->req, uap->pid, addr, data);
1122 CP(r.pve, r32.pve, pve_entry);
1123 CP(r.pve, r32.pve, pve_timestamp);
1124 CP(r.pve, r32.pve, pve_start);
1125 CP(r.pve, r32.pve, pve_end);
1126 CP(r.pve, r32.pve, pve_offset);
1127 CP(r.pve, r32.pve, pve_prot);
1128 CP(r.pve, r32.pve, pve_pathlen);
1129 CP(r.pve, r32.pve, pve_fileid);
1130 CP(r.pve, r32.pve, pve_fsid);
1131 error = copyout(&r32.pve, uap->addr, sizeof(r32.pve));
1134 CP(r.piod, r32.piod, piod_len);
1135 error = copyout(&r32.piod, uap->addr, sizeof(r32.piod));
1138 error = copyout(&r.reg, uap->addr, sizeof(r.reg));
1141 error = copyout(&r.fpreg, uap->addr, sizeof(r.fpreg));
1144 error = copyout(&r.dbreg, uap->addr, sizeof(r.dbreg));
1147 r32.vec.iov_len = r.vec.iov_len;
1148 error = copyout(&r32.vec, uap->addr, sizeof(r32.vec));
1150 case PT_GET_EVENT_MASK:
1151 /* NB: The size in uap->data is validated in kern_ptrace(). */
1152 error = copyout(&r.ptevents, uap->addr, uap->data);
1155 ptrace_lwpinfo_to32(&r.pl, &r32.pl);
1156 error = copyout(&r32.pl, uap->addr, uap->data);
1158 case PT_GET_SC_ARGS:
1159 for (i = 0; i < nitems(r.args); i++)
1160 r32.args[i] = (uint32_t)r.args[i];
1161 error = copyout(r32.args, uap->addr, MIN(uap->data,
1165 ptrace_sc_ret_to32(&r.psr, &r32.psr);
1166 error = copyout(&r32.psr, uap->addr, MIN(uap->data,
1170 ptrace_sc_ret_to32(&r.sr.pscr_ret, &r32.sr.pscr_ret);
1171 error = copyout(&r32.sr.pscr_ret, uap->addr +
1172 offsetof(struct ptrace_sc_remote32, pscr_ret),
1181 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
1183 struct iovec32 iov32;
1190 if (iovcnt > UIO_MAXIOV)
1192 iovlen = iovcnt * sizeof(struct iovec);
1193 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
1194 iov = (struct iovec *)(uio + 1);
1195 for (i = 0; i < iovcnt; i++) {
1196 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
1201 iov[i].iov_base = PTRIN(iov32.iov_base);
1202 iov[i].iov_len = iov32.iov_len;
1205 uio->uio_iovcnt = iovcnt;
1206 uio->uio_segflg = UIO_USERSPACE;
1207 uio->uio_offset = -1;
1209 for (i = 0; i < iovcnt; i++) {
1210 if (iov->iov_len > INT_MAX - uio->uio_resid) {
1214 uio->uio_resid += iov->iov_len;
1222 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
1227 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1230 error = kern_readv(td, uap->fd, auio);
1236 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
1241 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1244 error = kern_writev(td, uap->fd, auio);
1250 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
1255 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1258 error = kern_preadv(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
1264 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
1269 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
1272 error = kern_pwritev(td, uap->fd, auio, PAIR32TO64(off_t,uap->offset));
1278 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
1281 struct iovec32 iov32;
1287 if (iovcnt > UIO_MAXIOV)
1289 iovlen = iovcnt * sizeof(struct iovec);
1290 iov = malloc(iovlen, M_IOV, M_WAITOK);
1291 for (i = 0; i < iovcnt; i++) {
1292 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
1297 iov[i].iov_base = PTRIN(iov32.iov_base);
1298 iov[i].iov_len = iov32.iov_len;
1305 freebsd32_copyinmsghdr(const struct msghdr32 *msg32, struct msghdr *msg)
1307 struct msghdr32 m32;
1310 error = copyin(msg32, &m32, sizeof(m32));
1313 msg->msg_name = PTRIN(m32.msg_name);
1314 msg->msg_namelen = m32.msg_namelen;
1315 msg->msg_iov = PTRIN(m32.msg_iov);
1316 msg->msg_iovlen = m32.msg_iovlen;
1317 msg->msg_control = PTRIN(m32.msg_control);
1318 msg->msg_controllen = m32.msg_controllen;
1319 msg->msg_flags = m32.msg_flags;
1324 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
1326 struct msghdr32 m32;
1329 m32.msg_name = PTROUT(msg->msg_name);
1330 m32.msg_namelen = msg->msg_namelen;
1331 m32.msg_iov = PTROUT(msg->msg_iov);
1332 m32.msg_iovlen = msg->msg_iovlen;
1333 m32.msg_control = PTROUT(msg->msg_control);
1334 m32.msg_controllen = msg->msg_controllen;
1335 m32.msg_flags = msg->msg_flags;
1336 error = copyout(&m32, msg32, sizeof(m32));
1340 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
1341 #define FREEBSD32_ALIGN(p) \
1342 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
1343 #define FREEBSD32_CMSG_SPACE(l) \
1344 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
1346 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
1347 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
1350 freebsd32_cmsg_convert(const struct cmsghdr *cm, void *data, socklen_t datalen)
1354 struct timespec32 ts;
1355 struct timeval32 tv;
1356 struct bintime32 bt;
1367 switch (cm->cmsg_level) {
1369 switch (cm->cmsg_type) {
1371 TV_CP(*in, tmp32, tv);
1372 copylen = sizeof(tmp32.tv);
1376 BT_CP(*in, tmp32, bt);
1377 copylen = sizeof(tmp32.bt);
1382 TS_CP(*in, tmp32, ts);
1383 copylen = sizeof(tmp32.ts);
1397 KASSERT((datalen >= copylen), ("corrupted cmsghdr"));
1399 bcopy(&tmp32, data, copylen);
1404 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
1408 socklen_t clen, datalen, datalen_out, oldclen;
1415 len = msg->msg_controllen;
1416 msg->msg_controllen = 0;
1418 ctlbuf = msg->msg_control;
1419 for (m = control; m != NULL && len > 0; m = m->m_next) {
1420 cm = mtod(m, struct cmsghdr *);
1422 while (cm != NULL) {
1423 if (sizeof(struct cmsghdr) > clen ||
1424 cm->cmsg_len > clen) {
1429 data = CMSG_DATA(cm);
1430 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1431 datalen_out = freebsd32_cmsg_convert(cm, data, datalen);
1434 * Copy out the message header. Preserve the native
1435 * message size in case we need to inspect the message
1438 copylen = sizeof(struct cmsghdr);
1439 if (len < copylen) {
1440 msg->msg_flags |= MSG_CTRUNC;
1441 m_dispose_extcontrolm(m);
1444 oldclen = cm->cmsg_len;
1445 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
1447 error = copyout(cm, ctlbuf, copylen);
1448 cm->cmsg_len = oldclen;
1452 ctlbuf += FREEBSD32_ALIGN(copylen);
1453 len -= FREEBSD32_ALIGN(copylen);
1455 copylen = datalen_out;
1456 if (len < copylen) {
1457 msg->msg_flags |= MSG_CTRUNC;
1458 m_dispose_extcontrolm(m);
1462 /* Copy out the message data. */
1463 error = copyout(data, ctlbuf, copylen);
1467 ctlbuf += FREEBSD32_ALIGN(copylen);
1468 len -= FREEBSD32_ALIGN(copylen);
1470 if (CMSG_SPACE(datalen) < clen) {
1471 clen -= CMSG_SPACE(datalen);
1472 cm = (struct cmsghdr *)
1473 ((caddr_t)cm + CMSG_SPACE(datalen));
1479 msg->msg_controllen +=
1480 FREEBSD32_CMSG_SPACE(datalen_out);
1483 if (len == 0 && m != NULL) {
1484 msg->msg_flags |= MSG_CTRUNC;
1485 m_dispose_extcontrolm(m);
1493 freebsd32_recvmsg(struct thread *td, struct freebsd32_recvmsg_args *uap)
1496 struct iovec *uiov, *iov;
1497 struct mbuf *control = NULL;
1498 struct mbuf **controlp;
1501 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1504 error = freebsd32_copyiniov((void *)msg.msg_iov, msg.msg_iovlen, &iov,
1508 msg.msg_flags = uap->flags;
1512 controlp = (msg.msg_control != NULL) ? &control : NULL;
1513 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1517 if (control != NULL)
1518 error = freebsd32_copy_msg_out(&msg, control);
1520 msg.msg_controllen = 0;
1523 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1527 if (control != NULL) {
1529 m_dispose_extcontrolm(control);
1538 ofreebsd32_recvmsg(struct thread *td, struct ofreebsd32_recvmsg_args *uap)
1545 * Copy-in the array of control messages constructed using alignment
1546 * and padding suitable for a 32-bit environment and construct an
1547 * mbuf using alignment and padding suitable for a 64-bit kernel.
1548 * The alignment and padding are defined indirectly by CMSG_DATA(),
1549 * CMSG_SPACE() and CMSG_LEN().
1552 freebsd32_copyin_control(struct mbuf **mp, caddr_t buf, u_int buflen)
1556 void *in, *in1, *md;
1557 u_int msglen, outlen;
1560 /* Enforce the size limit of the native implementation. */
1561 if (buflen > MCLBYTES)
1564 in = malloc(buflen, M_TEMP, M_WAITOK);
1565 error = copyin(buf, in, buflen);
1570 * Make a pass over the input buffer to determine the amount of space
1571 * required for 64 bit-aligned copies of the control messages.
1575 while (buflen > 0) {
1576 if (buflen < sizeof(*cm)) {
1580 cm = (struct cmsghdr *)in1;
1581 if (cm->cmsg_len < FREEBSD32_ALIGN(sizeof(*cm)) ||
1582 cm->cmsg_len > buflen) {
1586 msglen = FREEBSD32_ALIGN(cm->cmsg_len);
1587 if (msglen < cm->cmsg_len) {
1591 /* The native ABI permits the final padding to be omitted. */
1592 if (msglen > buflen)
1596 in1 = (char *)in1 + msglen;
1597 outlen += CMSG_ALIGN(sizeof(*cm)) +
1598 CMSG_ALIGN(msglen - FREEBSD32_ALIGN(sizeof(*cm)));
1604 * Allocate up to MJUMPAGESIZE space for the re-aligned and
1605 * re-padded control messages. This allows a full MCLBYTES of
1606 * 32-bit sized and aligned messages to fit and avoids an ABI
1607 * mismatch with the native implementation.
1609 m = m_get2(outlen, M_WAITOK, MT_CONTROL, 0);
1615 md = mtod(m, void *);
1618 * Make a second pass over input messages, copying them into the output
1622 while (outlen > 0) {
1623 /* Copy the message header and align the length field. */
1625 memcpy(cm, in1, sizeof(*cm));
1626 msglen = cm->cmsg_len - FREEBSD32_ALIGN(sizeof(*cm));
1627 cm->cmsg_len = CMSG_ALIGN(sizeof(*cm)) + msglen;
1629 /* Copy the message body. */
1630 in1 = (char *)in1 + FREEBSD32_ALIGN(sizeof(*cm));
1631 md = (char *)md + CMSG_ALIGN(sizeof(*cm));
1632 memcpy(md, in1, msglen);
1633 in1 = (char *)in1 + FREEBSD32_ALIGN(msglen);
1634 md = (char *)md + CMSG_ALIGN(msglen);
1635 KASSERT(outlen >= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen),
1636 ("outlen %u underflow, msglen %u", outlen, msglen));
1637 outlen -= CMSG_ALIGN(sizeof(*cm)) + CMSG_ALIGN(msglen);
1647 freebsd32_sendmsg(struct thread *td, struct freebsd32_sendmsg_args *uap)
1651 struct mbuf *control = NULL;
1652 struct sockaddr *to = NULL;
1655 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1658 error = freebsd32_copyiniov((void *)msg.msg_iov, msg.msg_iovlen, &iov,
1663 if (msg.msg_name != NULL) {
1664 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1672 if (msg.msg_control) {
1673 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1678 error = freebsd32_copyin_control(&control, msg.msg_control,
1679 msg.msg_controllen);
1683 msg.msg_control = NULL;
1684 msg.msg_controllen = 0;
1687 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1699 ofreebsd32_sendmsg(struct thread *td, struct ofreebsd32_sendmsg_args *uap)
1707 freebsd32_settimeofday(struct thread *td,
1708 struct freebsd32_settimeofday_args *uap)
1710 struct timeval32 tv32;
1711 struct timeval tv, *tvp;
1712 struct timezone tz, *tzp;
1716 error = copyin(uap->tv, &tv32, sizeof(tv32));
1719 CP(tv32, tv, tv_sec);
1720 CP(tv32, tv, tv_usec);
1725 error = copyin(uap->tzp, &tz, sizeof(tz));
1731 return (kern_settimeofday(td, tvp, tzp));
1735 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1737 struct timeval32 s32[2];
1738 struct timeval s[2], *sp;
1741 if (uap->tptr != NULL) {
1742 error = copyin(uap->tptr, s32, sizeof(s32));
1745 CP(s32[0], s[0], tv_sec);
1746 CP(s32[0], s[0], tv_usec);
1747 CP(s32[1], s[1], tv_sec);
1748 CP(s32[1], s[1], tv_usec);
1752 return (kern_utimesat(td, AT_FDCWD, uap->path, UIO_USERSPACE,
1757 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1759 struct timeval32 s32[2];
1760 struct timeval s[2], *sp;
1763 if (uap->tptr != NULL) {
1764 error = copyin(uap->tptr, s32, sizeof(s32));
1767 CP(s32[0], s[0], tv_sec);
1768 CP(s32[0], s[0], tv_usec);
1769 CP(s32[1], s[1], tv_sec);
1770 CP(s32[1], s[1], tv_usec);
1774 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1778 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1780 struct timeval32 s32[2];
1781 struct timeval s[2], *sp;
1784 if (uap->tptr != NULL) {
1785 error = copyin(uap->tptr, s32, sizeof(s32));
1788 CP(s32[0], s[0], tv_sec);
1789 CP(s32[0], s[0], tv_usec);
1790 CP(s32[1], s[1], tv_sec);
1791 CP(s32[1], s[1], tv_usec);
1795 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1799 freebsd32_futimesat(struct thread *td, struct freebsd32_futimesat_args *uap)
1801 struct timeval32 s32[2];
1802 struct timeval s[2], *sp;
1805 if (uap->times != NULL) {
1806 error = copyin(uap->times, s32, sizeof(s32));
1809 CP(s32[0], s[0], tv_sec);
1810 CP(s32[0], s[0], tv_usec);
1811 CP(s32[1], s[1], tv_sec);
1812 CP(s32[1], s[1], tv_usec);
1816 return (kern_utimesat(td, uap->fd, uap->path, UIO_USERSPACE,
1821 freebsd32_futimens(struct thread *td, struct freebsd32_futimens_args *uap)
1823 struct timespec32 ts32[2];
1824 struct timespec ts[2], *tsp;
1827 if (uap->times != NULL) {
1828 error = copyin(uap->times, ts32, sizeof(ts32));
1831 CP(ts32[0], ts[0], tv_sec);
1832 CP(ts32[0], ts[0], tv_nsec);
1833 CP(ts32[1], ts[1], tv_sec);
1834 CP(ts32[1], ts[1], tv_nsec);
1838 return (kern_futimens(td, uap->fd, tsp, UIO_SYSSPACE));
1842 freebsd32_utimensat(struct thread *td, struct freebsd32_utimensat_args *uap)
1844 struct timespec32 ts32[2];
1845 struct timespec ts[2], *tsp;
1848 if (uap->times != NULL) {
1849 error = copyin(uap->times, ts32, sizeof(ts32));
1852 CP(ts32[0], ts[0], tv_sec);
1853 CP(ts32[0], ts[0], tv_nsec);
1854 CP(ts32[1], ts[1], tv_sec);
1855 CP(ts32[1], ts[1], tv_nsec);
1859 return (kern_utimensat(td, uap->fd, uap->path, UIO_USERSPACE,
1860 tsp, UIO_SYSSPACE, uap->flag));
1864 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1866 struct timeval32 tv32;
1867 struct timeval delta, olddelta, *deltap;
1871 error = copyin(uap->delta, &tv32, sizeof(tv32));
1874 CP(tv32, delta, tv_sec);
1875 CP(tv32, delta, tv_usec);
1879 error = kern_adjtime(td, deltap, &olddelta);
1880 if (uap->olddelta && error == 0) {
1881 CP(olddelta, tv32, tv_sec);
1882 CP(olddelta, tv32, tv_usec);
1883 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1888 #ifdef COMPAT_FREEBSD4
1890 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1892 struct ostatfs32 s32;
1896 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1897 error = kern_statfs(td, uap->path, UIO_USERSPACE, sp);
1899 copy_statfs(sp, &s32);
1900 error = copyout(&s32, uap->buf, sizeof(s32));
1907 #ifdef COMPAT_FREEBSD4
1909 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1911 struct ostatfs32 s32;
1915 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1916 error = kern_fstatfs(td, uap->fd, sp);
1918 copy_statfs(sp, &s32);
1919 error = copyout(&s32, uap->buf, sizeof(s32));
1926 #ifdef COMPAT_FREEBSD4
1928 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1930 struct ostatfs32 s32;
1935 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1937 sp = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
1938 error = kern_fhstatfs(td, fh, sp);
1940 copy_statfs(sp, &s32);
1941 error = copyout(&s32, uap->buf, sizeof(s32));
1949 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1952 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
1953 PAIR32TO64(off_t, uap->offset)));
1957 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1960 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
1961 PAIR32TO64(off_t, uap->offset)));
1966 ofreebsd32_lseek(struct thread *td, struct ofreebsd32_lseek_args *uap)
1969 return (kern_lseek(td, uap->fd, uap->offset, uap->whence));
1974 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1979 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
1981 /* Expand the quad return into two parts for eax and edx */
1982 pos = td->td_uretoff.tdu_off;
1983 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
1984 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
1989 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1992 return (kern_truncate(td, uap->path, UIO_USERSPACE,
1993 PAIR32TO64(off_t, uap->length)));
1998 ofreebsd32_truncate(struct thread *td, struct ofreebsd32_truncate_args *uap)
2000 return (kern_truncate(td, uap->path, UIO_USERSPACE, uap->length));
2005 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
2008 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
2013 ofreebsd32_ftruncate(struct thread *td, struct ofreebsd32_ftruncate_args *uap)
2015 return (kern_ftruncate(td, uap->fd, uap->length));
2019 ofreebsd32_getdirentries(struct thread *td,
2020 struct ofreebsd32_getdirentries_args *uap)
2022 struct ogetdirentries_args ap;
2029 ap.count = uap->count;
2031 error = kern_ogetdirentries(td, &ap, &loff);
2034 error = copyout(&loff_cut, uap->basep, sizeof(int32_t));
2040 #if defined(COMPAT_FREEBSD11)
2042 freebsd11_freebsd32_getdirentries(struct thread *td,
2043 struct freebsd11_freebsd32_getdirentries_args *uap)
2049 error = freebsd11_kern_getdirentries(td, uap->fd, uap->buf, uap->count,
2053 if (uap->basep != NULL) {
2055 error = copyout(&base32, uap->basep, sizeof(int32_t));
2059 #endif /* COMPAT_FREEBSD11 */
2061 #ifdef COMPAT_FREEBSD6
2062 /* versions with the 'int pad' argument */
2064 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
2067 return (kern_pread(td, uap->fd, uap->buf, uap->nbyte,
2068 PAIR32TO64(off_t, uap->offset)));
2072 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
2075 return (kern_pwrite(td, uap->fd, uap->buf, uap->nbyte,
2076 PAIR32TO64(off_t, uap->offset)));
2080 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
2085 error = kern_lseek(td, uap->fd, PAIR32TO64(off_t, uap->offset),
2087 /* Expand the quad return into two parts for eax and edx */
2088 pos = *(off_t *)(td->td_retval);
2089 td->td_retval[RETVAL_LO] = pos & 0xffffffff; /* %eax */
2090 td->td_retval[RETVAL_HI] = pos >> 32; /* %edx */
2095 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
2098 return (kern_truncate(td, uap->path, UIO_USERSPACE,
2099 PAIR32TO64(off_t, uap->length)));
2103 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
2106 return (kern_ftruncate(td, uap->fd, PAIR32TO64(off_t, uap->length)));
2108 #endif /* COMPAT_FREEBSD6 */
2118 freebsd32_do_sendfile(struct thread *td,
2119 struct freebsd32_sendfile_args *uap, int compat)
2121 struct sf_hdtr32 hdtr32;
2122 struct sf_hdtr hdtr;
2123 struct uio *hdr_uio, *trl_uio;
2125 cap_rights_t rights;
2126 struct iovec32 *iov32;
2127 off_t offset, sbytes;
2130 offset = PAIR32TO64(off_t, uap->offset);
2134 hdr_uio = trl_uio = NULL;
2136 if (uap->hdtr != NULL) {
2137 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
2140 PTRIN_CP(hdtr32, hdtr, headers);
2141 CP(hdtr32, hdtr, hdr_cnt);
2142 PTRIN_CP(hdtr32, hdtr, trailers);
2143 CP(hdtr32, hdtr, trl_cnt);
2145 if (hdtr.headers != NULL) {
2146 iov32 = PTRIN(hdtr32.headers);
2147 error = freebsd32_copyinuio(iov32,
2148 hdtr32.hdr_cnt, &hdr_uio);
2151 #ifdef COMPAT_FREEBSD4
2153 * In FreeBSD < 5.0 the nbytes to send also included
2154 * the header. If compat is specified subtract the
2155 * header size from nbytes.
2158 if (uap->nbytes > hdr_uio->uio_resid)
2159 uap->nbytes -= hdr_uio->uio_resid;
2165 if (hdtr.trailers != NULL) {
2166 iov32 = PTRIN(hdtr32.trailers);
2167 error = freebsd32_copyinuio(iov32,
2168 hdtr32.trl_cnt, &trl_uio);
2174 AUDIT_ARG_FD(uap->fd);
2176 if ((error = fget_read(td, uap->fd,
2177 cap_rights_init_one(&rights, CAP_PREAD), &fp)) != 0)
2180 error = fo_sendfile(fp, uap->s, hdr_uio, trl_uio, offset,
2181 uap->nbytes, &sbytes, uap->flags, td);
2184 if (uap->sbytes != NULL)
2185 copyout(&sbytes, uap->sbytes, sizeof(off_t));
2189 free(hdr_uio, M_IOV);
2191 free(trl_uio, M_IOV);
2195 #ifdef COMPAT_FREEBSD4
2197 freebsd4_freebsd32_sendfile(struct thread *td,
2198 struct freebsd4_freebsd32_sendfile_args *uap)
2200 return (freebsd32_do_sendfile(td,
2201 (struct freebsd32_sendfile_args *)uap, 1));
2206 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
2209 return (freebsd32_do_sendfile(td, uap, 0));
2213 copy_stat(struct stat *in, struct stat32 *out)
2218 * 32-bit architectures other than i386 have 64-bit time_t. This
2219 * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
2220 * and 4 bytes of padding. Zero the padding holes in struct stat32.
2222 bzero(&out->st_atim, sizeof(out->st_atim));
2223 bzero(&out->st_mtim, sizeof(out->st_mtim));
2224 bzero(&out->st_ctim, sizeof(out->st_ctim));
2225 bzero(&out->st_birthtim, sizeof(out->st_birthtim));
2227 CP(*in, *out, st_dev);
2228 CP(*in, *out, st_ino);
2229 CP(*in, *out, st_mode);
2230 CP(*in, *out, st_nlink);
2231 CP(*in, *out, st_uid);
2232 CP(*in, *out, st_gid);
2233 CP(*in, *out, st_rdev);
2234 TS_CP(*in, *out, st_atim);
2235 TS_CP(*in, *out, st_mtim);
2236 TS_CP(*in, *out, st_ctim);
2237 CP(*in, *out, st_size);
2238 CP(*in, *out, st_blocks);
2239 CP(*in, *out, st_blksize);
2240 CP(*in, *out, st_flags);
2241 CP(*in, *out, st_gen);
2242 TS_CP(*in, *out, st_birthtim);
2243 out->st_padding0 = 0;
2244 out->st_padding1 = 0;
2245 #ifdef __STAT32_TIME_T_EXT
2246 out->st_atim_ext = 0;
2247 out->st_mtim_ext = 0;
2248 out->st_ctim_ext = 0;
2249 out->st_btim_ext = 0;
2251 bzero(out->st_spare, sizeof(out->st_spare));
2256 copy_ostat(struct stat *in, struct ostat32 *out)
2259 bzero(out, sizeof(*out));
2260 CP(*in, *out, st_dev);
2261 CP(*in, *out, st_ino);
2262 CP(*in, *out, st_mode);
2263 CP(*in, *out, st_nlink);
2264 CP(*in, *out, st_uid);
2265 CP(*in, *out, st_gid);
2266 CP(*in, *out, st_rdev);
2267 out->st_size = MIN(in->st_size, INT32_MAX);
2268 TS_CP(*in, *out, st_atim);
2269 TS_CP(*in, *out, st_mtim);
2270 TS_CP(*in, *out, st_ctim);
2271 CP(*in, *out, st_blksize);
2272 CP(*in, *out, st_blocks);
2273 CP(*in, *out, st_flags);
2274 CP(*in, *out, st_gen);
2280 ofreebsd32_stat(struct thread *td, struct ofreebsd32_stat_args *uap)
2283 struct ostat32 sb32;
2286 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2289 copy_ostat(&sb, &sb32);
2290 error = copyout(&sb32, uap->ub, sizeof (sb32));
2296 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
2302 error = kern_fstat(td, uap->fd, &ub);
2305 copy_stat(&ub, &ub32);
2306 error = copyout(&ub32, uap->sb, sizeof(ub32));
2312 ofreebsd32_fstat(struct thread *td, struct ofreebsd32_fstat_args *uap)
2315 struct ostat32 ub32;
2318 error = kern_fstat(td, uap->fd, &ub);
2321 copy_ostat(&ub, &ub32);
2322 error = copyout(&ub32, uap->sb, sizeof(ub32));
2328 freebsd32_fstatat(struct thread *td, struct freebsd32_fstatat_args *uap)
2334 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
2338 copy_stat(&ub, &ub32);
2339 error = copyout(&ub32, uap->buf, sizeof(ub32));
2345 ofreebsd32_lstat(struct thread *td, struct ofreebsd32_lstat_args *uap)
2348 struct ostat32 sb32;
2351 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2352 UIO_USERSPACE, &sb);
2355 copy_ostat(&sb, &sb32);
2356 error = copyout(&sb32, uap->ub, sizeof (sb32));
2362 freebsd32_fhstat(struct thread *td, struct freebsd32_fhstat_args *uap)
2369 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2372 error = kern_fhstat(td, fh, &sb);
2375 copy_stat(&sb, &sb32);
2376 error = copyout(&sb32, uap->sb, sizeof (sb32));
2380 #if defined(COMPAT_FREEBSD11)
2381 extern int ino64_trunc_error;
2384 freebsd11_cvtstat32(struct stat *in, struct freebsd11_stat32 *out)
2389 * 32-bit architectures other than i386 have 64-bit time_t. This
2390 * results in struct timespec32 with 12 bytes for tv_sec and tv_nsec,
2391 * and 4 bytes of padding. Zero the padding holes in freebsd11_stat32.
2393 bzero(&out->st_atim, sizeof(out->st_atim));
2394 bzero(&out->st_mtim, sizeof(out->st_mtim));
2395 bzero(&out->st_ctim, sizeof(out->st_ctim));
2396 bzero(&out->st_birthtim, sizeof(out->st_birthtim));
2399 CP(*in, *out, st_ino);
2400 if (in->st_ino != out->st_ino) {
2401 switch (ino64_trunc_error) {
2408 out->st_ino = UINT32_MAX;
2412 CP(*in, *out, st_nlink);
2413 if (in->st_nlink != out->st_nlink) {
2414 switch (ino64_trunc_error) {
2421 out->st_nlink = UINT16_MAX;
2425 out->st_dev = in->st_dev;
2426 if (out->st_dev != in->st_dev) {
2427 switch (ino64_trunc_error) {
2434 CP(*in, *out, st_mode);
2435 CP(*in, *out, st_uid);
2436 CP(*in, *out, st_gid);
2437 out->st_rdev = in->st_rdev;
2438 if (out->st_rdev != in->st_rdev) {
2439 switch (ino64_trunc_error) {
2446 TS_CP(*in, *out, st_atim);
2447 TS_CP(*in, *out, st_mtim);
2448 TS_CP(*in, *out, st_ctim);
2449 CP(*in, *out, st_size);
2450 CP(*in, *out, st_blocks);
2451 CP(*in, *out, st_blksize);
2452 CP(*in, *out, st_flags);
2453 CP(*in, *out, st_gen);
2454 TS_CP(*in, *out, st_birthtim);
2456 bzero((char *)&out->st_birthtim + sizeof(out->st_birthtim),
2457 sizeof(*out) - offsetof(struct freebsd11_stat32,
2458 st_birthtim) - sizeof(out->st_birthtim));
2463 freebsd11_freebsd32_stat(struct thread *td,
2464 struct freebsd11_freebsd32_stat_args *uap)
2467 struct freebsd11_stat32 sb32;
2470 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2473 error = freebsd11_cvtstat32(&sb, &sb32);
2475 error = copyout(&sb32, uap->ub, sizeof (sb32));
2480 freebsd11_freebsd32_fstat(struct thread *td,
2481 struct freebsd11_freebsd32_fstat_args *uap)
2484 struct freebsd11_stat32 sb32;
2487 error = kern_fstat(td, uap->fd, &sb);
2490 error = freebsd11_cvtstat32(&sb, &sb32);
2492 error = copyout(&sb32, uap->sb, sizeof (sb32));
2497 freebsd11_freebsd32_fstatat(struct thread *td,
2498 struct freebsd11_freebsd32_fstatat_args *uap)
2501 struct freebsd11_stat32 sb32;
2504 error = kern_statat(td, uap->flag, uap->fd, uap->path, UIO_USERSPACE,
2508 error = freebsd11_cvtstat32(&sb, &sb32);
2510 error = copyout(&sb32, uap->buf, sizeof (sb32));
2515 freebsd11_freebsd32_lstat(struct thread *td,
2516 struct freebsd11_freebsd32_lstat_args *uap)
2519 struct freebsd11_stat32 sb32;
2522 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2523 UIO_USERSPACE, &sb);
2526 error = freebsd11_cvtstat32(&sb, &sb32);
2528 error = copyout(&sb32, uap->ub, sizeof (sb32));
2533 freebsd11_freebsd32_fhstat(struct thread *td,
2534 struct freebsd11_freebsd32_fhstat_args *uap)
2537 struct freebsd11_stat32 sb32;
2541 error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t));
2544 error = kern_fhstat(td, fh, &sb);
2547 error = freebsd11_cvtstat32(&sb, &sb32);
2549 error = copyout(&sb32, uap->sb, sizeof (sb32));
2554 freebsd11_cvtnstat32(struct stat *sb, struct nstat32 *nsb32)
2559 error = freebsd11_cvtnstat(sb, &nsb);
2563 bzero(nsb32, sizeof(*nsb32));
2564 CP(nsb, *nsb32, st_dev);
2565 CP(nsb, *nsb32, st_ino);
2566 CP(nsb, *nsb32, st_mode);
2567 CP(nsb, *nsb32, st_nlink);
2568 CP(nsb, *nsb32, st_uid);
2569 CP(nsb, *nsb32, st_gid);
2570 CP(nsb, *nsb32, st_rdev);
2571 CP(nsb, *nsb32, st_atim.tv_sec);
2572 CP(nsb, *nsb32, st_atim.tv_nsec);
2573 CP(nsb, *nsb32, st_mtim.tv_sec);
2574 CP(nsb, *nsb32, st_mtim.tv_nsec);
2575 CP(nsb, *nsb32, st_ctim.tv_sec);
2576 CP(nsb, *nsb32, st_ctim.tv_nsec);
2577 CP(nsb, *nsb32, st_size);
2578 CP(nsb, *nsb32, st_blocks);
2579 CP(nsb, *nsb32, st_blksize);
2580 CP(nsb, *nsb32, st_flags);
2581 CP(nsb, *nsb32, st_gen);
2582 CP(nsb, *nsb32, st_birthtim.tv_sec);
2583 CP(nsb, *nsb32, st_birthtim.tv_nsec);
2588 freebsd11_freebsd32_nstat(struct thread *td,
2589 struct freebsd11_freebsd32_nstat_args *uap)
2595 error = kern_statat(td, 0, AT_FDCWD, uap->path, UIO_USERSPACE, &sb);
2598 error = freebsd11_cvtnstat32(&sb, &nsb);
2600 error = copyout(&nsb, uap->ub, sizeof (nsb));
2605 freebsd11_freebsd32_nlstat(struct thread *td,
2606 struct freebsd11_freebsd32_nlstat_args *uap)
2612 error = kern_statat(td, AT_SYMLINK_NOFOLLOW, AT_FDCWD, uap->path,
2613 UIO_USERSPACE, &sb);
2616 error = freebsd11_cvtnstat32(&sb, &nsb);
2618 error = copyout(&nsb, uap->ub, sizeof (nsb));
2623 freebsd11_freebsd32_nfstat(struct thread *td,
2624 struct freebsd11_freebsd32_nfstat_args *uap)
2630 error = kern_fstat(td, uap->fd, &ub);
2633 error = freebsd11_cvtnstat32(&ub, &nub);
2635 error = copyout(&nub, uap->sb, sizeof(nub));
2641 freebsd32___sysctl(struct thread *td, struct freebsd32___sysctl_args *uap)
2643 int error, name[CTL_MAXNAME];
2647 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
2649 error = copyin(uap->name, name, uap->namelen * sizeof(int));
2653 error = fueword32(uap->oldlenp, &tmp);
2660 error = userland_sysctl(td, name, uap->namelen,
2661 uap->old, &oldlen, 1,
2662 uap->new, uap->newlen, &j, SCTL_MASK32);
2666 suword32(uap->oldlenp, j);
2671 freebsd32___sysctlbyname(struct thread *td,
2672 struct freebsd32___sysctlbyname_args *uap)
2678 if (uap->oldlenp != NULL) {
2679 error = fueword32(uap->oldlenp, &tmp);
2686 error = kern___sysctlbyname(td, uap->name, uap->namelen, uap->old,
2687 &oldlen, uap->new, uap->newlen, &rv, SCTL_MASK32, 1);
2690 if (uap->oldlenp != NULL)
2691 error = suword32(uap->oldlenp, rv);
2697 freebsd32_jail(struct thread *td, struct freebsd32_jail_args *uap)
2703 error = copyin(uap->jail, &version, sizeof(uint32_t));
2710 /* FreeBSD single IPv4 jails. */
2711 struct jail32_v0 j32_v0;
2713 bzero(&j, sizeof(struct jail));
2714 error = copyin(uap->jail, &j32_v0, sizeof(struct jail32_v0));
2717 CP(j32_v0, j, version);
2718 PTRIN_CP(j32_v0, j, path);
2719 PTRIN_CP(j32_v0, j, hostname);
2720 j.ip4s = htonl(j32_v0.ip_number); /* jail_v0 is host order */
2726 * Version 1 was used by multi-IPv4 jail implementations
2727 * that never made it into the official kernel.
2731 case 2: /* JAIL_API_VERSION */
2733 /* FreeBSD multi-IPv4/IPv6,noIP jails. */
2736 error = copyin(uap->jail, &j32, sizeof(struct jail32));
2739 CP(j32, j, version);
2740 PTRIN_CP(j32, j, path);
2741 PTRIN_CP(j32, j, hostname);
2742 PTRIN_CP(j32, j, jailname);
2745 PTRIN_CP(j32, j, ip4);
2746 PTRIN_CP(j32, j, ip6);
2751 /* Sci-Fi jails are not supported, sorry. */
2754 return (kern_jail(td, &j));
2758 freebsd32_jail_set(struct thread *td, struct freebsd32_jail_set_args *uap)
2763 /* Check that we have an even number of iovecs. */
2764 if (uap->iovcnt & 1)
2767 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2770 error = kern_jail_set(td, auio, uap->flags);
2776 freebsd32_jail_get(struct thread *td, struct freebsd32_jail_get_args *uap)
2778 struct iovec32 iov32;
2782 /* Check that we have an even number of iovecs. */
2783 if (uap->iovcnt & 1)
2786 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
2789 error = kern_jail_get(td, auio, uap->flags);
2791 for (i = 0; i < uap->iovcnt; i++) {
2792 PTROUT_CP(auio->uio_iov[i], iov32, iov_base);
2793 CP(auio->uio_iov[i], iov32, iov_len);
2794 error = copyout(&iov32, uap->iovp + i, sizeof(iov32));
2803 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
2805 struct sigaction32 s32;
2806 struct sigaction sa, osa, *sap;
2810 error = copyin(uap->act, &s32, sizeof(s32));
2813 sa.sa_handler = PTRIN(s32.sa_u);
2814 CP(s32, sa, sa_flags);
2815 CP(s32, sa, sa_mask);
2819 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
2820 if (error == 0 && uap->oact != NULL) {
2821 s32.sa_u = PTROUT(osa.sa_handler);
2822 CP(osa, s32, sa_flags);
2823 CP(osa, s32, sa_mask);
2824 error = copyout(&s32, uap->oact, sizeof(s32));
2829 #ifdef COMPAT_FREEBSD4
2831 freebsd4_freebsd32_sigaction(struct thread *td,
2832 struct freebsd4_freebsd32_sigaction_args *uap)
2834 struct sigaction32 s32;
2835 struct sigaction sa, osa, *sap;
2839 error = copyin(uap->act, &s32, sizeof(s32));
2842 sa.sa_handler = PTRIN(s32.sa_u);
2843 CP(s32, sa, sa_flags);
2844 CP(s32, sa, sa_mask);
2848 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
2849 if (error == 0 && uap->oact != NULL) {
2850 s32.sa_u = PTROUT(osa.sa_handler);
2851 CP(osa, s32, sa_flags);
2852 CP(osa, s32, sa_mask);
2853 error = copyout(&s32, uap->oact, sizeof(s32));
2860 struct osigaction32 {
2869 ofreebsd32_sigaction(struct thread *td,
2870 struct ofreebsd32_sigaction_args *uap)
2872 struct osigaction32 s32;
2873 struct sigaction sa, osa, *sap;
2876 if (uap->signum <= 0 || uap->signum >= ONSIG)
2880 error = copyin(uap->nsa, &s32, sizeof(s32));
2883 sa.sa_handler = PTRIN(s32.sa_u);
2884 CP(s32, sa, sa_flags);
2885 OSIG2SIG(s32.sa_mask, sa.sa_mask);
2889 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2890 if (error == 0 && uap->osa != NULL) {
2891 s32.sa_u = PTROUT(osa.sa_handler);
2892 CP(osa, s32, sa_flags);
2893 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2894 error = copyout(&s32, uap->osa, sizeof(s32));
2900 uint32_t sv_handler;
2906 ofreebsd32_sigvec(struct thread *td,
2907 struct ofreebsd32_sigvec_args *uap)
2909 struct sigvec32 vec;
2910 struct sigaction sa, osa, *sap;
2913 if (uap->signum <= 0 || uap->signum >= ONSIG)
2917 error = copyin(uap->nsv, &vec, sizeof(vec));
2920 sa.sa_handler = PTRIN(vec.sv_handler);
2921 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2922 sa.sa_flags = vec.sv_flags;
2923 sa.sa_flags ^= SA_RESTART;
2927 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2928 if (error == 0 && uap->osv != NULL) {
2929 vec.sv_handler = PTROUT(osa.sa_handler);
2930 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2931 vec.sv_flags = osa.sa_flags;
2932 vec.sv_flags &= ~SA_NOCLDWAIT;
2933 vec.sv_flags ^= SA_RESTART;
2934 error = copyout(&vec, uap->osv, sizeof(vec));
2945 ofreebsd32_sigstack(struct thread *td,
2946 struct ofreebsd32_sigstack_args *uap)
2948 struct sigstack32 s32;
2949 struct sigstack nss, oss;
2950 int error = 0, unss;
2952 if (uap->nss != NULL) {
2953 error = copyin(uap->nss, &s32, sizeof(s32));
2956 nss.ss_sp = PTRIN(s32.ss_sp);
2957 CP(s32, nss, ss_onstack);
2962 oss.ss_sp = td->td_sigstk.ss_sp;
2963 oss.ss_onstack = sigonstack(cpu_getstack(td));
2965 td->td_sigstk.ss_sp = nss.ss_sp;
2966 td->td_sigstk.ss_size = 0;
2967 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2968 td->td_pflags |= TDP_ALTSTACK;
2970 if (uap->oss != NULL) {
2971 s32.ss_sp = PTROUT(oss.ss_sp);
2972 CP(oss, s32, ss_onstack);
2973 error = copyout(&s32, uap->oss, sizeof(s32));
2980 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2983 return (freebsd32_user_clock_nanosleep(td, CLOCK_REALTIME,
2984 TIMER_RELTIME, uap->rqtp, uap->rmtp));
2988 freebsd32_clock_nanosleep(struct thread *td,
2989 struct freebsd32_clock_nanosleep_args *uap)
2993 error = freebsd32_user_clock_nanosleep(td, uap->clock_id, uap->flags,
2994 uap->rqtp, uap->rmtp);
2995 return (kern_posix_error(td, error));
2999 freebsd32_user_clock_nanosleep(struct thread *td, clockid_t clock_id,
3000 int flags, const struct timespec32 *ua_rqtp, struct timespec32 *ua_rmtp)
3002 struct timespec32 rmt32, rqt32;
3003 struct timespec rmt, rqt;
3006 error = copyin(ua_rqtp, &rqt32, sizeof(rqt32));
3010 CP(rqt32, rqt, tv_sec);
3011 CP(rqt32, rqt, tv_nsec);
3013 error = kern_clock_nanosleep(td, clock_id, flags, &rqt, &rmt);
3014 if (error == EINTR && ua_rmtp != NULL && (flags & TIMER_ABSTIME) == 0) {
3015 CP(rmt, rmt32, tv_sec);
3016 CP(rmt, rmt32, tv_nsec);
3018 error2 = copyout(&rmt32, ua_rmtp, sizeof(rmt32));
3026 freebsd32_clock_gettime(struct thread *td,
3027 struct freebsd32_clock_gettime_args *uap)
3029 struct timespec ats;
3030 struct timespec32 ats32;
3033 error = kern_clock_gettime(td, uap->clock_id, &ats);
3035 CP(ats, ats32, tv_sec);
3036 CP(ats, ats32, tv_nsec);
3037 error = copyout(&ats32, uap->tp, sizeof(ats32));
3043 freebsd32_clock_settime(struct thread *td,
3044 struct freebsd32_clock_settime_args *uap)
3046 struct timespec ats;
3047 struct timespec32 ats32;
3050 error = copyin(uap->tp, &ats32, sizeof(ats32));
3053 CP(ats32, ats, tv_sec);
3054 CP(ats32, ats, tv_nsec);
3056 return (kern_clock_settime(td, uap->clock_id, &ats));
3060 freebsd32_clock_getres(struct thread *td,
3061 struct freebsd32_clock_getres_args *uap)
3064 struct timespec32 ts32;
3067 if (uap->tp == NULL)
3069 error = kern_clock_getres(td, uap->clock_id, &ts);
3071 CP(ts, ts32, tv_sec);
3072 CP(ts, ts32, tv_nsec);
3073 error = copyout(&ts32, uap->tp, sizeof(ts32));
3078 int freebsd32_ktimer_create(struct thread *td,
3079 struct freebsd32_ktimer_create_args *uap)
3081 struct sigevent32 ev32;
3082 struct sigevent ev, *evp;
3085 if (uap->evp == NULL) {
3089 error = copyin(uap->evp, &ev32, sizeof(ev32));
3092 error = convert_sigevent32(&ev32, &ev);
3096 error = kern_ktimer_create(td, uap->clock_id, evp, &id, -1);
3098 error = copyout(&id, uap->timerid, sizeof(int));
3100 kern_ktimer_delete(td, id);
3106 freebsd32_ktimer_settime(struct thread *td,
3107 struct freebsd32_ktimer_settime_args *uap)
3109 struct itimerspec32 val32, oval32;
3110 struct itimerspec val, oval, *ovalp;
3113 error = copyin(uap->value, &val32, sizeof(val32));
3117 ovalp = uap->ovalue != NULL ? &oval : NULL;
3118 error = kern_ktimer_settime(td, uap->timerid, uap->flags, &val, ovalp);
3119 if (error == 0 && uap->ovalue != NULL) {
3120 ITS_CP(oval, oval32);
3121 error = copyout(&oval32, uap->ovalue, sizeof(oval32));
3127 freebsd32_ktimer_gettime(struct thread *td,
3128 struct freebsd32_ktimer_gettime_args *uap)
3130 struct itimerspec32 val32;
3131 struct itimerspec val;
3134 error = kern_ktimer_gettime(td, uap->timerid, &val);
3137 error = copyout(&val32, uap->value, sizeof(val32));
3143 freebsd32_timerfd_gettime(struct thread *td,
3144 struct freebsd32_timerfd_gettime_args *uap)
3146 struct itimerspec curr_value;
3147 struct itimerspec32 curr_value32;
3150 error = kern_timerfd_gettime(td, uap->fd, &curr_value);
3152 CP(curr_value, curr_value32, it_value.tv_sec);
3153 CP(curr_value, curr_value32, it_value.tv_nsec);
3154 CP(curr_value, curr_value32, it_interval.tv_sec);
3155 CP(curr_value, curr_value32, it_interval.tv_nsec);
3156 error = copyout(&curr_value32, uap->curr_value,
3157 sizeof(curr_value32));
3164 freebsd32_timerfd_settime(struct thread *td,
3165 struct freebsd32_timerfd_settime_args *uap)
3167 struct itimerspec new_value, old_value;
3168 struct itimerspec32 new_value32, old_value32;
3171 error = copyin(uap->new_value, &new_value32, sizeof(new_value32));
3174 CP(new_value32, new_value, it_value.tv_sec);
3175 CP(new_value32, new_value, it_value.tv_nsec);
3176 CP(new_value32, new_value, it_interval.tv_sec);
3177 CP(new_value32, new_value, it_interval.tv_nsec);
3178 if (uap->old_value == NULL) {
3179 error = kern_timerfd_settime(td, uap->fd, uap->flags,
3182 error = kern_timerfd_settime(td, uap->fd, uap->flags,
3183 &new_value, &old_value);
3185 CP(old_value, old_value32, it_value.tv_sec);
3186 CP(old_value, old_value32, it_value.tv_nsec);
3187 CP(old_value, old_value32, it_interval.tv_sec);
3188 CP(old_value, old_value32, it_interval.tv_nsec);
3189 error = copyout(&old_value32, uap->old_value,
3190 sizeof(old_value32));
3197 freebsd32_clock_getcpuclockid2(struct thread *td,
3198 struct freebsd32_clock_getcpuclockid2_args *uap)
3203 error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id),
3204 uap->which, &clk_id);
3206 error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t));
3211 freebsd32_thr_new(struct thread *td,
3212 struct freebsd32_thr_new_args *uap)
3214 struct thr_param32 param32;
3215 struct thr_param param;
3218 if (uap->param_size < 0 ||
3219 uap->param_size > sizeof(struct thr_param32))
3221 bzero(¶m, sizeof(struct thr_param));
3222 bzero(¶m32, sizeof(struct thr_param32));
3223 error = copyin(uap->param, ¶m32, uap->param_size);
3226 param.start_func = PTRIN(param32.start_func);
3227 param.arg = PTRIN(param32.arg);
3228 param.stack_base = PTRIN(param32.stack_base);
3229 param.stack_size = param32.stack_size;
3230 param.tls_base = PTRIN(param32.tls_base);
3231 param.tls_size = param32.tls_size;
3232 param.child_tid = PTRIN(param32.child_tid);
3233 param.parent_tid = PTRIN(param32.parent_tid);
3234 param.flags = param32.flags;
3235 param.rtp = PTRIN(param32.rtp);
3236 param.spare[0] = PTRIN(param32.spare[0]);
3237 param.spare[1] = PTRIN(param32.spare[1]);
3238 param.spare[2] = PTRIN(param32.spare[2]);
3240 return (kern_thr_new(td, ¶m));
3244 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
3246 struct timespec32 ts32;
3247 struct timespec ts, *tsp;
3252 if (uap->timeout != NULL) {
3253 error = copyin((const void *)uap->timeout, (void *)&ts32,
3254 sizeof(struct timespec32));
3257 ts.tv_sec = ts32.tv_sec;
3258 ts.tv_nsec = ts32.tv_nsec;
3261 return (kern_thr_suspend(td, tsp));
3265 siginfo_to_siginfo32(const siginfo_t *src, struct siginfo32 *dst)
3267 bzero(dst, sizeof(*dst));
3268 dst->si_signo = src->si_signo;
3269 dst->si_errno = src->si_errno;
3270 dst->si_code = src->si_code;
3271 dst->si_pid = src->si_pid;
3272 dst->si_uid = src->si_uid;
3273 dst->si_status = src->si_status;
3274 dst->si_addr = (uintptr_t)src->si_addr;
3275 dst->si_value.sival_int = src->si_value.sival_int;
3276 dst->si_timerid = src->si_timerid;
3277 dst->si_overrun = src->si_overrun;
3280 #ifndef _FREEBSD32_SYSPROTO_H_
3281 struct freebsd32_sigqueue_args {
3284 /* union sigval32 */ int value;
3288 freebsd32_sigqueue(struct thread *td, struct freebsd32_sigqueue_args *uap)
3293 * On 32-bit ABIs, sival_int and sival_ptr are the same.
3294 * On 64-bit little-endian ABIs, the low bits are the same.
3295 * In 64-bit big-endian ABIs, sival_int overlaps with
3296 * sival_ptr's HIGH bits. We choose to support sival_int
3297 * rather than sival_ptr in this case as it seems to be
3300 bzero(&sv, sizeof(sv));
3301 sv.sival_int = (uint32_t)(uint64_t)uap->value;
3303 return (kern_sigqueue(td, uap->pid, uap->signum, &sv));
3307 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
3309 struct timespec32 ts32;
3311 struct timespec *timeout;
3314 struct siginfo32 si32;
3318 error = copyin(uap->timeout, &ts32, sizeof(ts32));
3321 ts.tv_sec = ts32.tv_sec;
3322 ts.tv_nsec = ts32.tv_nsec;
3327 error = copyin(uap->set, &set, sizeof(set));
3331 error = kern_sigtimedwait(td, set, &ksi, timeout);
3336 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
3337 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
3341 td->td_retval[0] = ksi.ksi_signo;
3349 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
3352 struct siginfo32 si32;
3356 error = copyin(uap->set, &set, sizeof(set));
3360 error = kern_sigtimedwait(td, set, &ksi, NULL);
3365 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
3366 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
3369 td->td_retval[0] = ksi.ksi_signo;
3374 freebsd32_cpuset_setid(struct thread *td,
3375 struct freebsd32_cpuset_setid_args *uap)
3378 return (kern_cpuset_setid(td, uap->which,
3379 PAIR32TO64(id_t, uap->id), uap->setid));
3383 freebsd32_cpuset_getid(struct thread *td,
3384 struct freebsd32_cpuset_getid_args *uap)
3387 return (kern_cpuset_getid(td, uap->level, uap->which,
3388 PAIR32TO64(id_t, uap->id), uap->setid));
3392 copyin32_set(const void *u, void *k, size_t size)
3394 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
3396 struct bitset *kb = k;
3399 rv = copyin(u, k, size);
3403 p = (int *)kb->__bits;
3404 /* Loop through swapping words.
3405 * `size' is in bytes, we need bits. */
3406 for (int i = 0; i < __bitset_words(size * 8); i++) {
3414 return (copyin(u, k, size));
3419 copyout32_set(const void *k, void *u, size_t size)
3421 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
3422 const struct bitset *kb = k;
3423 struct bitset *ub = u;
3424 const int *kp = (const int *)kb->__bits;
3425 int *up = (int *)ub->__bits;
3428 for (int i = 0; i < __bitset_words(CPU_SETSIZE); i++) {
3429 /* `size' is in bytes, we need bits. */
3430 for (int i = 0; i < __bitset_words(size * 8); i++) {
3431 rv = suword32(up, kp[1]);
3433 rv = suword32(up + 1, kp[0]);
3440 return (copyout(k, u, size));
3444 static const struct cpuset_copy_cb cpuset_copy32_cb = {
3445 .cpuset_copyin = copyin32_set,
3446 .cpuset_copyout = copyout32_set
3450 freebsd32_cpuset_getaffinity(struct thread *td,
3451 struct freebsd32_cpuset_getaffinity_args *uap)
3454 return (user_cpuset_getaffinity(td, uap->level, uap->which,
3455 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
3456 &cpuset_copy32_cb));
3460 freebsd32_cpuset_setaffinity(struct thread *td,
3461 struct freebsd32_cpuset_setaffinity_args *uap)
3464 return (user_cpuset_setaffinity(td, uap->level, uap->which,
3465 PAIR32TO64(id_t,uap->id), uap->cpusetsize, uap->mask,
3466 &cpuset_copy32_cb));
3470 freebsd32_cpuset_getdomain(struct thread *td,
3471 struct freebsd32_cpuset_getdomain_args *uap)
3474 return (kern_cpuset_getdomain(td, uap->level, uap->which,
3475 PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
3476 &cpuset_copy32_cb));
3480 freebsd32_cpuset_setdomain(struct thread *td,
3481 struct freebsd32_cpuset_setdomain_args *uap)
3484 return (kern_cpuset_setdomain(td, uap->level, uap->which,
3485 PAIR32TO64(id_t,uap->id), uap->domainsetsize, uap->mask, uap->policy,
3486 &cpuset_copy32_cb));
3490 freebsd32_nmount(struct thread *td,
3491 struct freebsd32_nmount_args /* {
3493 unsigned int iovcnt;
3502 * Mount flags are now 64-bits. On 32-bit archtectures only
3503 * 32-bits are passed in, but from here on everything handles
3504 * 64-bit flags correctly.
3508 AUDIT_ARG_FFLAGS(flags);
3511 * Filter out MNT_ROOTFS. We do not want clients of nmount() in
3512 * userspace to set this flag, but we must filter it out if we want
3513 * MNT_UPDATE on the root file system to work.
3514 * MNT_ROOTFS should only be set by the kernel when mounting its
3517 flags &= ~MNT_ROOTFS;
3520 * check that we have an even number of iovec's
3521 * and that we have at least two options.
3523 if ((uap->iovcnt & 1) || (uap->iovcnt < 4))
3526 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
3529 error = vfs_donmount(td, flags, auio);
3537 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
3539 struct yyy32 *p32, s32;
3540 struct yyy *p = NULL, s;
3545 error = copyin(uap->zzz, &s32, sizeof(s32));
3551 error = kern_xxx(td, p);
3556 error = copyout(&s32, p32, sizeof(s32));
3563 syscall32_module_handler(struct module *mod, int what, void *arg)
3566 return (kern_syscall_module_handler(freebsd32_sysent, mod, what, arg));
3570 syscall32_helper_register(struct syscall_helper_data *sd, int flags)
3573 return (kern_syscall_helper_register(freebsd32_sysent, sd, flags));
3577 syscall32_helper_unregister(struct syscall_helper_data *sd)
3580 return (kern_syscall_helper_unregister(freebsd32_sysent, sd));
3584 freebsd32_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
3586 struct sysentvec *sysent;
3590 uintptr_t destp, ustringp;
3591 struct freebsd32_ps_strings *arginfo;
3592 char canary[sizeof(long) * 8];
3593 int32_t pagesizes32[MAXPAGESIZES];
3594 size_t execpath_len;
3595 int error, szsigcode;
3597 sysent = imgp->sysent;
3599 arginfo = (struct freebsd32_ps_strings *)PROC_PS_STRINGS(imgp->proc);
3600 imgp->ps_strings = arginfo;
3601 destp = (uintptr_t)arginfo;
3606 if (!PROC_HAS_SHP(imgp->proc)) {
3607 szsigcode = *sysent->sv_szsigcode;
3609 destp = rounddown2(destp, sizeof(uint32_t));
3610 error = copyout(sysent->sv_sigcode, (void *)destp,
3617 * Copy the image path for the rtld.
3619 if (imgp->execpath != NULL && imgp->auxargs != NULL) {
3620 execpath_len = strlen(imgp->execpath) + 1;
3621 destp -= execpath_len;
3622 imgp->execpathp = (void *)destp;
3623 error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
3629 * Prepare the canary for SSP.
3631 arc4rand(canary, sizeof(canary), 0);
3632 destp -= sizeof(canary);
3633 imgp->canary = (void *)destp;
3634 error = copyout(canary, imgp->canary, sizeof(canary));
3637 imgp->canarylen = sizeof(canary);
3640 * Prepare the pagesizes array.
3642 for (i = 0; i < MAXPAGESIZES; i++)
3643 pagesizes32[i] = (uint32_t)pagesizes[i];
3644 destp -= sizeof(pagesizes32);
3645 destp = rounddown2(destp, sizeof(uint32_t));
3646 imgp->pagesizes = (void *)destp;
3647 error = copyout(pagesizes32, imgp->pagesizes, sizeof(pagesizes32));
3650 imgp->pagesizeslen = sizeof(pagesizes32);
3653 * Allocate room for the argument and environment strings.
3655 destp -= ARG_MAX - imgp->args->stringspace;
3656 destp = rounddown2(destp, sizeof(uint32_t));
3659 if (imgp->auxargs) {
3661 * Allocate room on the stack for the ELF auxargs
3662 * array. It has up to AT_COUNT entries.
3664 destp -= AT_COUNT * sizeof(Elf32_Auxinfo);
3665 destp = rounddown2(destp, sizeof(uint32_t));
3668 vectp = (uint32_t *)destp;
3671 * Allocate room for the argv[] and env vectors including the
3672 * terminating NULL pointers.
3674 vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
3677 * vectp also becomes our initial stack base
3679 *stack_base = (uintptr_t)vectp;
3681 stringp = imgp->args->begin_argv;
3682 argc = imgp->args->argc;
3683 envc = imgp->args->envc;
3685 * Copy out strings - arguments and environment.
3687 error = copyout(stringp, (void *)ustringp,
3688 ARG_MAX - imgp->args->stringspace);
3693 * Fill in "ps_strings" struct for ps, w, etc.
3696 if (suword32(&arginfo->ps_argvstr, (uint32_t)(intptr_t)vectp) != 0 ||
3697 suword32(&arginfo->ps_nargvstr, argc) != 0)
3701 * Fill in argument portion of vector table.
3703 for (; argc > 0; --argc) {
3704 if (suword32(vectp++, ustringp) != 0)
3706 while (*stringp++ != 0)
3711 /* a null vector table pointer separates the argp's from the envp's */
3712 if (suword32(vectp++, 0) != 0)
3716 if (suword32(&arginfo->ps_envstr, (uint32_t)(intptr_t)vectp) != 0 ||
3717 suword32(&arginfo->ps_nenvstr, envc) != 0)
3721 * Fill in environment portion of vector table.
3723 for (; envc > 0; --envc) {
3724 if (suword32(vectp++, ustringp) != 0)
3726 while (*stringp++ != 0)
3731 /* end of vector table is a null pointer */
3732 if (suword32(vectp, 0) != 0)
3735 if (imgp->auxargs) {
3737 error = imgp->sysent->sv_copyout_auxargs(imgp,
3747 freebsd32_kldstat(struct thread *td, struct freebsd32_kldstat_args *uap)
3749 struct kld_file_stat *stat;
3750 struct kld_file_stat32 *stat32;
3753 if ((error = copyin(&uap->stat->version, &version, sizeof(version)))
3756 if (version != sizeof(struct kld_file_stat_1_32) &&
3757 version != sizeof(struct kld_file_stat32))
3760 stat = malloc(sizeof(*stat), M_TEMP, M_WAITOK | M_ZERO);
3761 stat32 = malloc(sizeof(*stat32), M_TEMP, M_WAITOK | M_ZERO);
3762 error = kern_kldstat(td, uap->fileid, stat);
3764 bcopy(&stat->name[0], &stat32->name[0], sizeof(stat->name));
3765 CP(*stat, *stat32, refs);
3766 CP(*stat, *stat32, id);
3767 PTROUT_CP(*stat, *stat32, address);
3768 CP(*stat, *stat32, size);
3769 bcopy(&stat->pathname[0], &stat32->pathname[0],
3770 sizeof(stat->pathname));
3771 stat32->version = version;
3772 error = copyout(stat32, uap->stat, version);
3775 free(stat32, M_TEMP);
3780 freebsd32_posix_fallocate(struct thread *td,
3781 struct freebsd32_posix_fallocate_args *uap)
3785 error = kern_posix_fallocate(td, uap->fd,
3786 PAIR32TO64(off_t, uap->offset), PAIR32TO64(off_t, uap->len));
3787 return (kern_posix_error(td, error));
3791 freebsd32_posix_fadvise(struct thread *td,
3792 struct freebsd32_posix_fadvise_args *uap)
3796 error = kern_posix_fadvise(td, uap->fd, PAIR32TO64(off_t, uap->offset),
3797 PAIR32TO64(off_t, uap->len), uap->advice);
3798 return (kern_posix_error(td, error));
3802 convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig)
3805 CP(*sig32, *sig, sigev_notify);
3806 switch (sig->sigev_notify) {
3809 case SIGEV_THREAD_ID:
3810 CP(*sig32, *sig, sigev_notify_thread_id);
3813 CP(*sig32, *sig, sigev_signo);
3814 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3817 CP(*sig32, *sig, sigev_notify_kqueue);
3818 CP(*sig32, *sig, sigev_notify_kevent_flags);
3819 PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr);
3828 freebsd32_procctl(struct thread *td, struct freebsd32_procctl_args *uap)
3832 struct procctl_reaper_status rs;
3833 struct procctl_reaper_pids rp;
3834 struct procctl_reaper_kill rk;
3837 struct procctl_reaper_pids32 rp;
3839 int error, error1, flags, signum;
3841 if (uap->com >= PROC_PROCCTL_MD_MIN)
3842 return (cpu_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3843 uap->com, PTRIN(uap->data)));
3847 case PROC_PROTMAX_CTL:
3849 case PROC_STACKGAP_CTL:
3850 case PROC_TRACE_CTL:
3851 case PROC_TRAPCAP_CTL:
3852 case PROC_NO_NEW_PRIVS_CTL:
3853 case PROC_WXMAP_CTL:
3854 error = copyin(PTRIN(uap->data), &flags, sizeof(flags));
3859 case PROC_REAP_ACQUIRE:
3860 case PROC_REAP_RELEASE:
3861 if (uap->data != NULL)
3865 case PROC_REAP_STATUS:
3868 case PROC_REAP_GETPIDS:
3869 error = copyin(uap->data, &x32.rp, sizeof(x32.rp));
3872 CP(x32.rp, x.rp, rp_count);
3873 PTRIN_CP(x32.rp, x.rp, rp_pids);
3876 case PROC_REAP_KILL:
3877 error = copyin(uap->data, &x.rk, sizeof(x.rk));
3882 case PROC_ASLR_STATUS:
3883 case PROC_PROTMAX_STATUS:
3884 case PROC_STACKGAP_STATUS:
3885 case PROC_TRACE_STATUS:
3886 case PROC_TRAPCAP_STATUS:
3887 case PROC_NO_NEW_PRIVS_STATUS:
3888 case PROC_WXMAP_STATUS:
3891 case PROC_PDEATHSIG_CTL:
3892 error = copyin(uap->data, &signum, sizeof(signum));
3897 case PROC_PDEATHSIG_STATUS:
3903 error = kern_procctl(td, uap->idtype, PAIR32TO64(id_t, uap->id),
3906 case PROC_REAP_STATUS:
3908 error = copyout(&x.rs, uap->data, sizeof(x.rs));
3910 case PROC_REAP_KILL:
3911 error1 = copyout(&x.rk, uap->data, sizeof(x.rk));
3915 case PROC_ASLR_STATUS:
3916 case PROC_PROTMAX_STATUS:
3917 case PROC_STACKGAP_STATUS:
3918 case PROC_TRACE_STATUS:
3919 case PROC_TRAPCAP_STATUS:
3920 case PROC_NO_NEW_PRIVS_STATUS:
3921 case PROC_WXMAP_STATUS:
3923 error = copyout(&flags, uap->data, sizeof(flags));
3925 case PROC_PDEATHSIG_STATUS:
3927 error = copyout(&signum, uap->data, sizeof(signum));
3934 freebsd32_fcntl(struct thread *td, struct freebsd32_fcntl_args *uap)
3940 * Do unsigned conversion for arg when operation
3941 * interprets it as flags or pointer.
3943 case F_SETLK_REMOTE:
3953 tmp = (unsigned int)(uap->arg);
3959 return (kern_fcntl_freebsd(td, uap->fd, uap->cmd, tmp));
3963 freebsd32_ppoll(struct thread *td, struct freebsd32_ppoll_args *uap)
3965 struct timespec32 ts32;
3966 struct timespec ts, *tsp;
3970 if (uap->ts != NULL) {
3971 error = copyin(uap->ts, &ts32, sizeof(ts32));
3974 CP(ts32, ts, tv_sec);
3975 CP(ts32, ts, tv_nsec);
3979 if (uap->set != NULL) {
3980 error = copyin(uap->set, &set, sizeof(set));
3987 return (kern_poll(td, uap->fds, uap->nfds, tsp, ssp));
3991 freebsd32_sched_rr_get_interval(struct thread *td,
3992 struct freebsd32_sched_rr_get_interval_args *uap)
3995 struct timespec32 ts32;
3998 error = kern_sched_rr_get_interval(td, uap->pid, &ts);
4000 CP(ts, ts32, tv_sec);
4001 CP(ts, ts32, tv_nsec);
4002 error = copyout(&ts32, uap->interval, sizeof(ts32));
4008 timex_to_32(struct timex32 *dst, struct timex *src)
4010 CP(*src, *dst, modes);
4011 CP(*src, *dst, offset);
4012 CP(*src, *dst, freq);
4013 CP(*src, *dst, maxerror);
4014 CP(*src, *dst, esterror);
4015 CP(*src, *dst, status);
4016 CP(*src, *dst, constant);
4017 CP(*src, *dst, precision);
4018 CP(*src, *dst, tolerance);
4019 CP(*src, *dst, ppsfreq);
4020 CP(*src, *dst, jitter);
4021 CP(*src, *dst, shift);
4022 CP(*src, *dst, stabil);
4023 CP(*src, *dst, jitcnt);
4024 CP(*src, *dst, calcnt);
4025 CP(*src, *dst, errcnt);
4026 CP(*src, *dst, stbcnt);
4030 timex_from_32(struct timex *dst, struct timex32 *src)
4032 CP(*src, *dst, modes);
4033 CP(*src, *dst, offset);
4034 CP(*src, *dst, freq);
4035 CP(*src, *dst, maxerror);
4036 CP(*src, *dst, esterror);
4037 CP(*src, *dst, status);
4038 CP(*src, *dst, constant);
4039 CP(*src, *dst, precision);
4040 CP(*src, *dst, tolerance);
4041 CP(*src, *dst, ppsfreq);
4042 CP(*src, *dst, jitter);
4043 CP(*src, *dst, shift);
4044 CP(*src, *dst, stabil);
4045 CP(*src, *dst, jitcnt);
4046 CP(*src, *dst, calcnt);
4047 CP(*src, *dst, errcnt);
4048 CP(*src, *dst, stbcnt);
4052 freebsd32_ntp_adjtime(struct thread *td, struct freebsd32_ntp_adjtime_args *uap)
4055 struct timex32 tx32;
4058 error = copyin(uap->tp, &tx32, sizeof(tx32));
4060 timex_from_32(&tx, &tx32);
4061 error = kern_ntp_adjtime(td, &tx, &retval);
4063 timex_to_32(&tx32, &tx);
4064 error = copyout(&tx32, uap->tp, sizeof(tx32));
4066 td->td_retval[0] = retval;
4073 extern struct mtx ffclock_mtx;
4074 extern struct ffclock_estimate ffclock_estimate;
4075 extern int8_t ffclock_updated;
4078 freebsd32_ffclock_setestimate(struct thread *td,
4079 struct freebsd32_ffclock_setestimate_args *uap)
4081 struct ffclock_estimate cest;
4082 struct ffclock_estimate32 cest32;
4085 /* Reuse of PRIV_CLOCK_SETTIME. */
4086 if ((error = priv_check(td, PRIV_CLOCK_SETTIME)) != 0)
4089 if ((error = copyin(uap->cest, &cest32,
4090 sizeof(struct ffclock_estimate32))) != 0)
4093 CP(cest.update_time, cest32.update_time, sec);
4094 memcpy(&cest.update_time.frac, &cest32.update_time.frac, sizeof(uint64_t));
4095 CP(cest, cest32, update_ffcount);
4096 CP(cest, cest32, leapsec_next);
4097 CP(cest, cest32, period);
4098 CP(cest, cest32, errb_abs);
4099 CP(cest, cest32, errb_rate);
4100 CP(cest, cest32, status);
4101 CP(cest, cest32, leapsec_total);
4102 CP(cest, cest32, leapsec);
4104 mtx_lock(&ffclock_mtx);
4105 memcpy(&ffclock_estimate, &cest, sizeof(struct ffclock_estimate));
4107 mtx_unlock(&ffclock_mtx);
4112 freebsd32_ffclock_getestimate(struct thread *td,
4113 struct freebsd32_ffclock_getestimate_args *uap)
4115 struct ffclock_estimate cest;
4116 struct ffclock_estimate32 cest32;
4119 mtx_lock(&ffclock_mtx);
4120 memcpy(&cest, &ffclock_estimate, sizeof(struct ffclock_estimate));
4121 mtx_unlock(&ffclock_mtx);
4123 CP(cest32.update_time, cest.update_time, sec);
4124 memcpy(&cest32.update_time.frac, &cest.update_time.frac, sizeof(uint64_t));
4125 CP(cest32, cest, update_ffcount);
4126 CP(cest32, cest, leapsec_next);
4127 CP(cest32, cest, period);
4128 CP(cest32, cest, errb_abs);
4129 CP(cest32, cest, errb_rate);
4130 CP(cest32, cest, status);
4131 CP(cest32, cest, leapsec_total);
4132 CP(cest32, cest, leapsec);
4134 error = copyout(&cest32, uap->cest, sizeof(struct ffclock_estimate32));
4137 #else /* !FFCLOCK */
4139 freebsd32_ffclock_setestimate(struct thread *td,
4140 struct freebsd32_ffclock_setestimate_args *uap)
4146 freebsd32_ffclock_getestimate(struct thread *td,
4147 struct freebsd32_ffclock_getestimate_args *uap)
4151 #endif /* FFCLOCK */
4155 ofreebsd32_sethostid(struct thread *td, struct ofreebsd32_sethostid_args *uap)
4157 int name[] = { CTL_KERN, KERN_HOSTID };
4160 hostid = uap->hostid;
4161 return (kernel_sysctl(td, name, nitems(name), NULL, NULL, &hostid,
4162 sizeof(hostid), NULL, 0));