2 * Copyright (c) 2002 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include "opt_compat.h"
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/clock.h>
37 #include <sys/fcntl.h>
38 #include <sys/filedesc.h>
39 #include <sys/namei.h>
40 #include <sys/imgact.h>
41 #include <sys/kernel.h>
42 #include <sys/limits.h>
44 #include <sys/malloc.h>
45 #include <sys/file.h> /* Must come after sys/malloc.h */
48 #include <sys/module.h>
49 #include <sys/mount.h>
50 #include <sys/mutex.h>
52 #include <sys/reboot.h>
53 #include <sys/resource.h>
54 #include <sys/resourcevar.h>
55 #include <sys/selinfo.h>
56 #include <sys/eventvar.h> /* Must come after sys/selinfo.h */
57 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
58 #include <sys/signal.h>
59 #include <sys/signalvar.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
63 #include <sys/syscall.h>
64 #include <sys/syscallsubr.h>
65 #include <sys/sysctl.h>
66 #include <sys/sysent.h>
67 #include <sys/sysproto.h>
69 #include <sys/unistd.h>
70 #include <sys/ucontext.h>
71 #include <sys/vnode.h>
77 #include <vm/vm_kern.h>
78 #include <vm/vm_param.h>
80 #include <vm/vm_map.h>
81 #include <vm/vm_object.h>
82 #include <vm/vm_extern.h>
84 #include <machine/cpu.h>
86 #include <compat/freebsd32/freebsd32_util.h>
87 #include <compat/freebsd32/freebsd32.h>
88 #include <compat/freebsd32/freebsd32_signal.h>
89 #include <compat/freebsd32/freebsd32_proto.h>
91 CTASSERT(sizeof(struct timeval32) == 8);
92 CTASSERT(sizeof(struct timespec32) == 8);
93 CTASSERT(sizeof(struct statfs32) == 256);
94 CTASSERT(sizeof(struct rusage32) == 72);
97 freebsd32_wait4(struct thread *td, struct freebsd32_wait4_args *uap)
100 struct rusage32 ru32;
101 struct rusage ru, *rup;
103 if (uap->rusage != NULL)
107 error = kern_wait(td, uap->pid, &status, uap->options, rup);
110 if (uap->status != NULL)
111 error = copyout(&status, uap->status, sizeof(status));
112 if (uap->rusage != NULL && error == 0) {
113 TV_CP(ru, ru32, ru_utime);
114 TV_CP(ru, ru32, ru_stime);
115 CP(ru, ru32, ru_maxrss);
116 CP(ru, ru32, ru_ixrss);
117 CP(ru, ru32, ru_idrss);
118 CP(ru, ru32, ru_isrss);
119 CP(ru, ru32, ru_minflt);
120 CP(ru, ru32, ru_majflt);
121 CP(ru, ru32, ru_nswap);
122 CP(ru, ru32, ru_inblock);
123 CP(ru, ru32, ru_oublock);
124 CP(ru, ru32, ru_msgsnd);
125 CP(ru, ru32, ru_msgrcv);
126 CP(ru, ru32, ru_nsignals);
127 CP(ru, ru32, ru_nvcsw);
128 CP(ru, ru32, ru_nivcsw);
129 error = copyout(&ru32, uap->rusage, sizeof(ru32));
134 #ifdef COMPAT_FREEBSD4
136 copy_statfs(struct statfs *in, struct statfs32 *out)
139 bzero(out, sizeof(*out));
140 CP(*in, *out, f_bsize);
141 CP(*in, *out, f_iosize);
142 CP(*in, *out, f_blocks);
143 CP(*in, *out, f_bfree);
144 CP(*in, *out, f_bavail);
145 CP(*in, *out, f_files);
146 CP(*in, *out, f_ffree);
147 CP(*in, *out, f_fsid);
148 CP(*in, *out, f_owner);
149 CP(*in, *out, f_type);
150 CP(*in, *out, f_flags);
151 CP(*in, *out, f_flags);
152 CP(*in, *out, f_syncwrites);
153 CP(*in, *out, f_asyncwrites);
154 strlcpy(out->f_fstypename,
155 in->f_fstypename, MFSNAMELEN);
156 strlcpy(out->f_mntonname,
157 in->f_mntonname, min(MNAMELEN, FREEBSD4_MNAMELEN));
158 CP(*in, *out, f_syncreads);
159 CP(*in, *out, f_asyncreads);
160 strlcpy(out->f_mntfromname,
161 in->f_mntfromname, min(MNAMELEN, FREEBSD4_MNAMELEN));
165 #ifdef COMPAT_FREEBSD4
167 freebsd4_freebsd32_getfsstat(struct thread *td, struct freebsd4_freebsd32_getfsstat_args *uap)
169 struct statfs *buf, *sp;
170 struct statfs32 stat32;
174 count = uap->bufsize / sizeof(struct statfs32);
175 size = count * sizeof(struct statfs);
176 error = kern_getfsstat(td, &buf, size, UIO_SYSSPACE, uap->flags);
178 count = td->td_retval[0];
180 while (count > 0 && error == 0) {
181 copy_statfs(sp, &stat32);
182 error = copyout(&stat32, uap->buf, sizeof(stat32));
193 CTASSERT(sizeof(struct sigaltstack32) == 12);
196 freebsd32_sigaltstack(struct thread *td,
197 struct freebsd32_sigaltstack_args *uap)
199 struct sigaltstack32 s32;
200 struct sigaltstack ss, oss, *ssp;
203 if (uap->ss != NULL) {
204 error = copyin(uap->ss, &s32, sizeof(s32));
207 PTRIN_CP(s32, ss, ss_sp);
208 CP(s32, ss, ss_size);
209 CP(s32, ss, ss_flags);
213 error = kern_sigaltstack(td, ssp, &oss);
214 if (error == 0 && uap->oss != NULL) {
215 PTROUT_CP(oss, s32, ss_sp);
216 CP(oss, s32, ss_size);
217 CP(oss, s32, ss_flags);
218 error = copyout(&s32, uap->oss, sizeof(s32));
224 * Custom version of exec_copyin_args() so that we can translate
228 freebsd32_exec_copyin_args(struct image_args *args, char *fname,
229 enum uio_seg segflg, u_int32_t *argv, u_int32_t *envv)
236 bzero(args, sizeof(*args));
241 * Allocate temporary demand zeroed space for argument and
242 * environment strings
244 args->buf = (char *) kmem_alloc_wait(exec_map,
245 PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
246 if (args->buf == NULL)
248 args->begin_argv = args->buf;
249 args->endp = args->begin_argv;
250 args->stringspace = ARG_MAX;
252 args->fname = args->buf + ARG_MAX;
255 * Copy the file name.
257 error = (segflg == UIO_SYSSPACE) ?
258 copystr(fname, args->fname, PATH_MAX, &length) :
259 copyinstr(fname, args->fname, PATH_MAX, &length);
264 * extract arguments first
268 error = copyin(p32++, &arg, sizeof(arg));
274 error = copyinstr(argp, args->endp, args->stringspace, &length);
276 if (error == ENAMETOOLONG)
280 args->stringspace -= length;
281 args->endp += length;
285 args->begin_envv = args->endp;
288 * extract environment strings
293 error = copyin(p32++, &arg, sizeof(arg));
299 error = copyinstr(envp, args->endp, args->stringspace,
302 if (error == ENAMETOOLONG)
306 args->stringspace -= length;
307 args->endp += length;
315 kmem_free_wakeup(exec_map, (vm_offset_t)args->buf,
316 PATH_MAX + ARG_MAX + MAXSHELLCMDLEN);
322 freebsd32_execve(struct thread *td, struct freebsd32_execve_args *uap)
324 struct image_args eargs;
327 error = freebsd32_exec_copyin_args(&eargs, uap->fname, UIO_USERSPACE,
328 uap->argv, uap->envv);
330 error = kern_execve(td, &eargs, NULL);
336 freebsd32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
337 int prot, int fd, off_t pos)
340 vm_map_entry_t entry;
343 map = &td->td_proc->p_vmspace->vm_map;
345 prot |= VM_PROT_WRITE;
347 if (vm_map_lookup_entry(map, start, &entry)) {
348 if ((entry->protection & prot) != prot) {
349 rv = vm_map_protect(map,
352 entry->protection | prot,
354 if (rv != KERN_SUCCESS)
358 vm_offset_t addr = trunc_page(start);
359 rv = vm_map_find(map, 0, 0,
360 &addr, PAGE_SIZE, FALSE, prot,
362 if (rv != KERN_SUCCESS)
369 r.buf = (void *) start;
370 r.nbyte = end - start;
372 return (pread(td, &r));
374 while (start < end) {
375 subyte((void *) start, 0);
384 freebsd32_mmap(struct thread *td, struct freebsd32_mmap_args *uap)
387 vm_offset_t addr = (vm_offset_t) uap->addr;
388 vm_size_t len = uap->len;
389 int prot = uap->prot;
390 int flags = uap->flags;
392 off_t pos = (uap->poslo
393 | ((off_t)uap->poshi << 32));
399 * Attempt to handle page size hassles.
401 pageoff = (pos & PAGE_MASK);
402 if (flags & MAP_FIXED) {
403 vm_offset_t start, end;
407 if (start != trunc_page(start)) {
408 error = freebsd32_mmap_partial(td, start,
409 round_page(start), prot,
412 pos += round_page(start) - start;
413 start = round_page(start);
415 if (end != round_page(end)) {
416 vm_offset_t t = trunc_page(end);
417 error = freebsd32_mmap_partial(td, t, end,
420 end = trunc_page(end);
422 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
424 * We can't map this region at all. The specified
425 * address doesn't have the same alignment as the file
426 * position. Fake the mapping by simply reading the
427 * entire region into memory. First we need to make
428 * sure the region exists.
434 prot |= VM_PROT_WRITE;
435 map = &td->td_proc->p_vmspace->vm_map;
436 rv = vm_map_remove(map, start, end);
437 if (rv != KERN_SUCCESS)
439 rv = vm_map_find(map, 0, 0,
440 &start, end - start, FALSE,
441 prot, VM_PROT_ALL, 0);
442 if (rv != KERN_SUCCESS)
445 r.buf = (void *) start;
446 r.nbyte = end - start;
448 error = pread(td, &r);
452 td->td_retval[0] = addr;
457 * After dealing with the ragged ends, there
458 * might be none left.
460 td->td_retval[0] = addr;
468 ap.addr = (void *) addr;
475 return (mmap(td, &ap));
478 #ifdef COMPAT_FREEBSD6
480 freebsd6_freebsd32_mmap(struct thread *td, struct freebsd6_freebsd32_mmap_args *uap)
482 struct freebsd32_mmap_args ap;
487 ap.flags = uap->flags;
489 ap.poslo = uap->poslo;
490 ap.poshi = uap->poshi;
492 return (freebsd32_mmap(td, &ap));
497 struct timeval32 it_interval;
498 struct timeval32 it_value;
501 CTASSERT(sizeof(struct itimerval32) == 16);
504 freebsd32_setitimer(struct thread *td, struct freebsd32_setitimer_args *uap)
506 struct itimerval itv, oitv, *itvp;
507 struct itimerval32 i32;
510 if (uap->itv != NULL) {
511 error = copyin(uap->itv, &i32, sizeof(i32));
514 TV_CP(i32, itv, it_interval);
515 TV_CP(i32, itv, it_value);
519 error = kern_setitimer(td, uap->which, itvp, &oitv);
520 if (error || uap->oitv == NULL)
522 TV_CP(oitv, i32, it_interval);
523 TV_CP(oitv, i32, it_value);
524 return (copyout(&i32, uap->oitv, sizeof(i32)));
528 freebsd32_getitimer(struct thread *td, struct freebsd32_getitimer_args *uap)
530 struct itimerval itv;
531 struct itimerval32 i32;
534 error = kern_getitimer(td, uap->which, &itv);
535 if (error || uap->itv == NULL)
537 TV_CP(itv, i32, it_interval);
538 TV_CP(itv, i32, it_value);
539 return (copyout(&i32, uap->itv, sizeof(i32)));
543 freebsd32_select(struct thread *td, struct freebsd32_select_args *uap)
545 struct timeval32 tv32;
546 struct timeval tv, *tvp;
549 if (uap->tv != NULL) {
550 error = copyin(uap->tv, &tv32, sizeof(tv32));
553 CP(tv32, tv, tv_sec);
554 CP(tv32, tv, tv_usec);
559 * XXX big-endian needs to convert the fd_sets too.
560 * XXX Do pointers need PTRIN()?
562 return (kern_select(td, uap->nd, uap->in, uap->ou, uap->ex, tvp));
566 u_int32_t ident; /* identifier for this event */
567 short filter; /* filter for event */
571 u_int32_t udata; /* opaque user data identifier */
574 CTASSERT(sizeof(struct kevent32) == 20);
575 static int freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count);
576 static int freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count);
579 * Copy 'count' items into the destination list pointed to by uap->eventlist.
582 freebsd32_kevent_copyout(void *arg, struct kevent *kevp, int count)
584 struct freebsd32_kevent_args *uap;
585 struct kevent32 ks32[KQ_NEVENTS];
588 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
589 uap = (struct freebsd32_kevent_args *)arg;
591 for (i = 0; i < count; i++) {
592 CP(kevp[i], ks32[i], ident);
593 CP(kevp[i], ks32[i], filter);
594 CP(kevp[i], ks32[i], flags);
595 CP(kevp[i], ks32[i], fflags);
596 CP(kevp[i], ks32[i], data);
597 PTROUT_CP(kevp[i], ks32[i], udata);
599 error = copyout(ks32, uap->eventlist, count * sizeof *ks32);
601 uap->eventlist += count;
606 * Copy 'count' items from the list pointed to by uap->changelist.
609 freebsd32_kevent_copyin(void *arg, struct kevent *kevp, int count)
611 struct freebsd32_kevent_args *uap;
612 struct kevent32 ks32[KQ_NEVENTS];
615 KASSERT(count <= KQ_NEVENTS, ("count (%d) > KQ_NEVENTS", count));
616 uap = (struct freebsd32_kevent_args *)arg;
618 error = copyin(uap->changelist, ks32, count * sizeof *ks32);
621 uap->changelist += count;
623 for (i = 0; i < count; i++) {
624 CP(ks32[i], kevp[i], ident);
625 CP(ks32[i], kevp[i], filter);
626 CP(ks32[i], kevp[i], flags);
627 CP(ks32[i], kevp[i], fflags);
628 CP(ks32[i], kevp[i], data);
629 PTRIN_CP(ks32[i], kevp[i], udata);
636 freebsd32_kevent(struct thread *td, struct freebsd32_kevent_args *uap)
638 struct timespec32 ts32;
639 struct timespec ts, *tsp;
640 struct kevent_copyops k_ops = { uap,
641 freebsd32_kevent_copyout,
642 freebsd32_kevent_copyin};
647 error = copyin(uap->timeout, &ts32, sizeof(ts32));
650 CP(ts32, ts, tv_sec);
651 CP(ts32, ts, tv_nsec);
655 error = kern_kevent(td, uap->fd, uap->nchanges, uap->nevents,
661 freebsd32_gettimeofday(struct thread *td,
662 struct freebsd32_gettimeofday_args *uap)
665 struct timeval32 atv32;
671 CP(atv, atv32, tv_sec);
672 CP(atv, atv32, tv_usec);
673 error = copyout(&atv32, uap->tp, sizeof (atv32));
675 if (error == 0 && uap->tzp != NULL) {
676 rtz.tz_minuteswest = tz_minuteswest;
677 rtz.tz_dsttime = tz_dsttime;
678 error = copyout(&rtz, uap->tzp, sizeof (rtz));
684 freebsd32_getrusage(struct thread *td, struct freebsd32_getrusage_args *uap)
690 error = kern_getrusage(td, uap->who, &s);
693 if (uap->rusage != NULL) {
694 TV_CP(s, s32, ru_utime);
695 TV_CP(s, s32, ru_stime);
696 CP(s, s32, ru_maxrss);
697 CP(s, s32, ru_ixrss);
698 CP(s, s32, ru_idrss);
699 CP(s, s32, ru_isrss);
700 CP(s, s32, ru_minflt);
701 CP(s, s32, ru_majflt);
702 CP(s, s32, ru_nswap);
703 CP(s, s32, ru_inblock);
704 CP(s, s32, ru_oublock);
705 CP(s, s32, ru_msgsnd);
706 CP(s, s32, ru_msgrcv);
707 CP(s, s32, ru_nsignals);
708 CP(s, s32, ru_nvcsw);
709 CP(s, s32, ru_nivcsw);
710 error = copyout(&s32, uap->rusage, sizeof(s32));
720 CTASSERT(sizeof(struct iovec32) == 8);
723 freebsd32_copyinuio(struct iovec32 *iovp, u_int iovcnt, struct uio **uiop)
725 struct iovec32 iov32;
732 if (iovcnt > UIO_MAXIOV)
734 iovlen = iovcnt * sizeof(struct iovec);
735 uio = malloc(iovlen + sizeof *uio, M_IOV, M_WAITOK);
736 iov = (struct iovec *)(uio + 1);
737 for (i = 0; i < iovcnt; i++) {
738 error = copyin(&iovp[i], &iov32, sizeof(struct iovec32));
743 iov[i].iov_base = PTRIN(iov32.iov_base);
744 iov[i].iov_len = iov32.iov_len;
747 uio->uio_iovcnt = iovcnt;
748 uio->uio_segflg = UIO_USERSPACE;
749 uio->uio_offset = -1;
751 for (i = 0; i < iovcnt; i++) {
752 if (iov->iov_len > INT_MAX - uio->uio_resid) {
756 uio->uio_resid += iov->iov_len;
764 freebsd32_readv(struct thread *td, struct freebsd32_readv_args *uap)
769 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
772 error = kern_readv(td, uap->fd, auio);
778 freebsd32_writev(struct thread *td, struct freebsd32_writev_args *uap)
783 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
786 error = kern_writev(td, uap->fd, auio);
792 freebsd32_preadv(struct thread *td, struct freebsd32_preadv_args *uap)
797 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
800 error = kern_preadv(td, uap->fd, auio, uap->offset);
806 freebsd32_pwritev(struct thread *td, struct freebsd32_pwritev_args *uap)
811 error = freebsd32_copyinuio(uap->iovp, uap->iovcnt, &auio);
814 error = kern_pwritev(td, uap->fd, auio, uap->offset);
820 freebsd32_copyiniov(struct iovec32 *iovp32, u_int iovcnt, struct iovec **iovp,
823 struct iovec32 iov32;
829 if (iovcnt > UIO_MAXIOV)
831 iovlen = iovcnt * sizeof(struct iovec);
832 iov = malloc(iovlen, M_IOV, M_WAITOK);
833 for (i = 0; i < iovcnt; i++) {
834 error = copyin(&iovp32[i], &iov32, sizeof(struct iovec32));
839 iov[i].iov_base = PTRIN(iov32.iov_base);
840 iov[i].iov_len = iov32.iov_len;
848 socklen_t msg_namelen;
851 u_int32_t msg_control;
852 socklen_t msg_controllen;
855 CTASSERT(sizeof(struct msghdr32) == 28);
858 freebsd32_copyinmsghdr(struct msghdr32 *msg32, struct msghdr *msg)
863 error = copyin(msg32, &m32, sizeof(m32));
866 msg->msg_name = PTRIN(m32.msg_name);
867 msg->msg_namelen = m32.msg_namelen;
868 msg->msg_iov = PTRIN(m32.msg_iov);
869 msg->msg_iovlen = m32.msg_iovlen;
870 msg->msg_control = PTRIN(m32.msg_control);
871 msg->msg_controllen = m32.msg_controllen;
872 msg->msg_flags = m32.msg_flags;
877 freebsd32_copyoutmsghdr(struct msghdr *msg, struct msghdr32 *msg32)
882 m32.msg_name = PTROUT(msg->msg_name);
883 m32.msg_namelen = msg->msg_namelen;
884 m32.msg_iov = PTROUT(msg->msg_iov);
885 m32.msg_iovlen = msg->msg_iovlen;
886 m32.msg_control = PTROUT(msg->msg_control);
887 m32.msg_controllen = msg->msg_controllen;
888 m32.msg_flags = msg->msg_flags;
889 error = copyout(&m32, msg32, sizeof(m32));
893 #define FREEBSD32_ALIGNBYTES (sizeof(int) - 1)
894 #define FREEBSD32_ALIGN(p) \
895 (((u_long)(p) + FREEBSD32_ALIGNBYTES) & ~FREEBSD32_ALIGNBYTES)
896 #define FREEBSD32_CMSG_SPACE(l) \
897 (FREEBSD32_ALIGN(sizeof(struct cmsghdr)) + FREEBSD32_ALIGN(l))
899 #define FREEBSD32_CMSG_DATA(cmsg) ((unsigned char *)(cmsg) + \
900 FREEBSD32_ALIGN(sizeof(struct cmsghdr)))
902 freebsd32_copy_msg_out(struct msghdr *msg, struct mbuf *control)
906 socklen_t clen, datalen;
909 int len, maxlen, copylen;
913 len = msg->msg_controllen;
914 maxlen = msg->msg_controllen;
915 msg->msg_controllen = 0;
918 ctlbuf = msg->msg_control;
920 while (m && len > 0) {
921 cm = mtod(m, struct cmsghdr *);
926 if (sizeof(struct cmsghdr) > clen ||
927 cm->cmsg_len > clen) {
932 data = CMSG_DATA(cm);
933 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
935 /* Adjust message length */
936 cm->cmsg_len = FREEBSD32_ALIGN(sizeof(struct cmsghdr)) +
941 copylen = sizeof(struct cmsghdr);
943 msg->msg_flags |= MSG_CTRUNC;
947 error = copyout(cm,ctlbuf,copylen);
951 ctlbuf += FREEBSD32_ALIGN(copylen);
952 len -= FREEBSD32_ALIGN(copylen);
960 msg->msg_flags |= MSG_CTRUNC;
964 error = copyout(data,ctlbuf,copylen);
968 ctlbuf += FREEBSD32_ALIGN(copylen);
969 len -= FREEBSD32_ALIGN(copylen);
971 if (CMSG_SPACE(datalen) < clen) {
972 clen -= CMSG_SPACE(datalen);
973 cm = (struct cmsghdr *)
974 ((caddr_t)cm + CMSG_SPACE(datalen));
983 msg->msg_controllen = (len <= 0) ? maxlen : ctlbuf - (caddr_t)msg->msg_control;
991 freebsd32_recvmsg(td, uap)
993 struct freebsd32_recvmsg_args /* {
995 struct msghdr32 *msg;
1000 struct msghdr32 m32;
1001 struct iovec *uiov, *iov;
1002 struct mbuf *control = NULL;
1003 struct mbuf **controlp;
1006 error = copyin(uap->msg, &m32, sizeof(m32));
1009 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1012 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1016 msg.msg_flags = uap->flags;
1020 controlp = (msg.msg_control != NULL) ? &control : NULL;
1021 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, controlp);
1025 if (control != NULL)
1026 error = freebsd32_copy_msg_out(&msg, control);
1029 error = freebsd32_copyoutmsghdr(&msg, uap->msg);
1033 if (control != NULL)
1041 freebsd32_convert_msg_in(struct mbuf **controlp)
1043 struct mbuf *control = *controlp;
1044 struct cmsghdr *cm = mtod(control, struct cmsghdr *);
1046 socklen_t clen = control->m_len, datalen;
1052 while (cm != NULL) {
1053 if (sizeof(struct cmsghdr) > clen || cm->cmsg_len > clen) {
1058 data = FREEBSD32_CMSG_DATA(cm);
1059 datalen = (caddr_t)cm + cm->cmsg_len - (caddr_t)data;
1061 *controlp = sbcreatecontrol(data, datalen, cm->cmsg_type,
1063 controlp = &(*controlp)->m_next;
1065 if (FREEBSD32_CMSG_SPACE(datalen) < clen) {
1066 clen -= FREEBSD32_CMSG_SPACE(datalen);
1067 cm = (struct cmsghdr *)
1068 ((caddr_t)cm + FREEBSD32_CMSG_SPACE(datalen));
1081 freebsd32_sendmsg(struct thread *td,
1082 struct freebsd32_sendmsg_args *uap)
1085 struct msghdr32 m32;
1087 struct mbuf *control = NULL;
1088 struct sockaddr *to = NULL;
1091 error = copyin(uap->msg, &m32, sizeof(m32));
1094 error = freebsd32_copyinmsghdr(uap->msg, &msg);
1097 error = freebsd32_copyiniov(PTRIN(m32.msg_iov), m32.msg_iovlen, &iov,
1102 if (msg.msg_name != NULL) {
1103 error = getsockaddr(&to, msg.msg_name, msg.msg_namelen);
1111 if (msg.msg_control) {
1112 if (msg.msg_controllen < sizeof(struct cmsghdr)) {
1117 error = sockargs(&control, msg.msg_control,
1118 msg.msg_controllen, MT_CONTROL);
1122 error = freebsd32_convert_msg_in(&control);
1127 error = kern_sendit(td, uap->s, &msg, uap->flags, control,
1138 freebsd32_recvfrom(struct thread *td,
1139 struct freebsd32_recvfrom_args *uap)
1145 if (uap->fromlenaddr) {
1146 error = copyin(PTRIN(uap->fromlenaddr), &msg.msg_namelen,
1147 sizeof(msg.msg_namelen));
1151 msg.msg_namelen = 0;
1154 msg.msg_name = PTRIN(uap->from);
1155 msg.msg_iov = &aiov;
1157 aiov.iov_base = PTRIN(uap->buf);
1158 aiov.iov_len = uap->len;
1159 msg.msg_control = NULL;
1160 msg.msg_flags = uap->flags;
1161 error = kern_recvit(td, uap->s, &msg, UIO_USERSPACE, NULL);
1162 if (error == 0 && uap->fromlenaddr)
1163 error = copyout(&msg.msg_namelen, PTRIN(uap->fromlenaddr),
1164 sizeof (msg.msg_namelen));
1169 freebsd32_settimeofday(struct thread *td,
1170 struct freebsd32_settimeofday_args *uap)
1172 struct timeval32 tv32;
1173 struct timeval tv, *tvp;
1174 struct timezone tz, *tzp;
1178 error = copyin(uap->tv, &tv32, sizeof(tv32));
1181 CP(tv32, tv, tv_sec);
1182 CP(tv32, tv, tv_usec);
1187 error = copyin(uap->tzp, &tz, sizeof(tz));
1193 return (kern_settimeofday(td, tvp, tzp));
1197 freebsd32_utimes(struct thread *td, struct freebsd32_utimes_args *uap)
1199 struct timeval32 s32[2];
1200 struct timeval s[2], *sp;
1203 if (uap->tptr != NULL) {
1204 error = copyin(uap->tptr, s32, sizeof(s32));
1207 CP(s32[0], s[0], tv_sec);
1208 CP(s32[0], s[0], tv_usec);
1209 CP(s32[1], s[1], tv_sec);
1210 CP(s32[1], s[1], tv_usec);
1214 return (kern_utimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1218 freebsd32_lutimes(struct thread *td, struct freebsd32_lutimes_args *uap)
1220 struct timeval32 s32[2];
1221 struct timeval s[2], *sp;
1224 if (uap->tptr != NULL) {
1225 error = copyin(uap->tptr, s32, sizeof(s32));
1228 CP(s32[0], s[0], tv_sec);
1229 CP(s32[0], s[0], tv_usec);
1230 CP(s32[1], s[1], tv_sec);
1231 CP(s32[1], s[1], tv_usec);
1235 return (kern_lutimes(td, uap->path, UIO_USERSPACE, sp, UIO_SYSSPACE));
1239 freebsd32_futimes(struct thread *td, struct freebsd32_futimes_args *uap)
1241 struct timeval32 s32[2];
1242 struct timeval s[2], *sp;
1245 if (uap->tptr != NULL) {
1246 error = copyin(uap->tptr, s32, sizeof(s32));
1249 CP(s32[0], s[0], tv_sec);
1250 CP(s32[0], s[0], tv_usec);
1251 CP(s32[1], s[1], tv_sec);
1252 CP(s32[1], s[1], tv_usec);
1256 return (kern_futimes(td, uap->fd, sp, UIO_SYSSPACE));
1261 freebsd32_adjtime(struct thread *td, struct freebsd32_adjtime_args *uap)
1263 struct timeval32 tv32;
1264 struct timeval delta, olddelta, *deltap;
1268 error = copyin(uap->delta, &tv32, sizeof(tv32));
1271 CP(tv32, delta, tv_sec);
1272 CP(tv32, delta, tv_usec);
1276 error = kern_adjtime(td, deltap, &olddelta);
1277 if (uap->olddelta && error == 0) {
1278 CP(olddelta, tv32, tv_sec);
1279 CP(olddelta, tv32, tv_usec);
1280 error = copyout(&tv32, uap->olddelta, sizeof(tv32));
1285 #ifdef COMPAT_FREEBSD4
1287 freebsd4_freebsd32_statfs(struct thread *td, struct freebsd4_freebsd32_statfs_args *uap)
1289 struct statfs32 s32;
1293 error = kern_statfs(td, uap->path, UIO_USERSPACE, &s);
1296 copy_statfs(&s, &s32);
1297 return (copyout(&s32, uap->buf, sizeof(s32)));
1301 #ifdef COMPAT_FREEBSD4
1303 freebsd4_freebsd32_fstatfs(struct thread *td, struct freebsd4_freebsd32_fstatfs_args *uap)
1305 struct statfs32 s32;
1309 error = kern_fstatfs(td, uap->fd, &s);
1312 copy_statfs(&s, &s32);
1313 return (copyout(&s32, uap->buf, sizeof(s32)));
1317 #ifdef COMPAT_FREEBSD4
1319 freebsd4_freebsd32_fhstatfs(struct thread *td, struct freebsd4_freebsd32_fhstatfs_args *uap)
1321 struct statfs32 s32;
1326 if ((error = copyin(uap->u_fhp, &fh, sizeof(fhandle_t))) != 0)
1328 error = kern_fhstatfs(td, fh, &s);
1331 copy_statfs(&s, &s32);
1332 return (copyout(&s32, uap->buf, sizeof(s32)));
1337 freebsd32_semsys(struct thread *td, struct freebsd32_semsys_args *uap)
1340 * Vector through to semsys if it is loaded.
1342 return sysent[SYS_semsys].sy_call(td, uap);
1346 freebsd32_msgsys(struct thread *td, struct freebsd32_msgsys_args *uap)
1348 switch (uap->which) {
1350 return (freebsd32_msgsnd(td,
1351 (struct freebsd32_msgsnd_args *)&uap->a2));
1354 return (freebsd32_msgrcv(td,
1355 (struct freebsd32_msgrcv_args *)&uap->a2));
1359 * Vector through to msgsys if it is loaded.
1361 return (sysent[SYS_msgsys].sy_call(td, uap));
1367 freebsd32_msgsnd(struct thread *td, struct freebsd32_msgsnd_args *uap)
1374 if (!SYSCALL_MODULE_PRESENT(msgsnd))
1375 return (nosys(td, (struct nosys_args *)uap));
1377 msgp = PTRIN(uap->msgp);
1378 if ((error = copyin(msgp, &mtype32, sizeof(mtype32))) != 0)
1381 return (kern_msgsnd(td, uap->msqid,
1382 (const char *)msgp + sizeof(mtype32),
1383 uap->msgsz, uap->msgflg, mtype));
1387 freebsd32_msgrcv(struct thread *td, struct freebsd32_msgrcv_args *uap)
1394 if (!SYSCALL_MODULE_PRESENT(msgrcv))
1395 return (nosys(td, (struct nosys_args *)uap));
1397 msgp = PTRIN(uap->msgp);
1398 if ((error = kern_msgrcv(td, uap->msqid,
1399 (char *)msgp + sizeof(mtype32), uap->msgsz,
1400 uap->msgtyp, uap->msgflg, &mtype)) != 0)
1402 mtype32 = (int32_t)mtype;
1403 return (copyout(&mtype32, msgp, sizeof(mtype32)));
1407 freebsd32_shmsys(struct thread *td, struct freebsd32_shmsys_args *uap)
1410 switch (uap->which) {
1411 case 0: { /* shmat */
1412 struct shmat_args ap;
1415 ap.shmaddr = PTRIN(uap->a3);
1416 ap.shmflg = uap->a4;
1417 return (sysent[SYS_shmat].sy_call(td, &ap));
1419 case 2: { /* shmdt */
1420 struct shmdt_args ap;
1422 ap.shmaddr = PTRIN(uap->a2);
1423 return (sysent[SYS_shmdt].sy_call(td, &ap));
1425 case 3: { /* shmget */
1426 struct shmget_args ap;
1430 ap.shmflg = uap->a4;
1431 return (sysent[SYS_shmget].sy_call(td, &ap));
1433 case 4: { /* shmctl */
1434 struct freebsd32_shmctl_args ap;
1438 ap.buf = PTRIN(uap->a4);
1439 return (freebsd32_shmctl(td, &ap));
1441 case 1: /* oshmctl */
1457 struct ipc_perm32 shm_perm;
1465 uint32_t shm_internal;
1472 uint32_t swap_attempts;
1473 uint32_t swap_successes;
1484 freebsd32_shmctl(struct thread *td, struct freebsd32_shmctl_args *uap)
1488 struct shmid_ds shmid_ds;
1489 struct shm_info shm_info;
1490 struct shminfo shminfo;
1493 struct shmid_ds32 shmid_ds32;
1494 struct shm_info32 shm_info32;
1495 struct shminfo32 shminfo32;
1499 if (uap->cmd == IPC_SET) {
1500 if ((error = copyin(uap->buf, &u32.shmid_ds32,
1501 sizeof(u32.shmid_ds32))))
1503 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.cuid);
1504 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.cgid);
1505 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.uid);
1506 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.gid);
1507 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.mode);
1508 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.seq);
1509 CP(u32.shmid_ds32, u.shmid_ds, shm_perm.key);
1510 CP(u32.shmid_ds32, u.shmid_ds, shm_segsz);
1511 CP(u32.shmid_ds32, u.shmid_ds, shm_lpid);
1512 CP(u32.shmid_ds32, u.shmid_ds, shm_cpid);
1513 CP(u32.shmid_ds32, u.shmid_ds, shm_nattch);
1514 CP(u32.shmid_ds32, u.shmid_ds, shm_atime);
1515 CP(u32.shmid_ds32, u.shmid_ds, shm_dtime);
1516 CP(u32.shmid_ds32, u.shmid_ds, shm_ctime);
1517 PTRIN_CP(u32.shmid_ds32, u.shmid_ds, shm_internal);
1520 error = kern_shmctl(td, uap->shmid, uap->cmd, (void *)&u, &sz);
1524 /* Cases in which we need to copyout */
1527 CP(u.shminfo, u32.shminfo32, shmmax);
1528 CP(u.shminfo, u32.shminfo32, shmmin);
1529 CP(u.shminfo, u32.shminfo32, shmmni);
1530 CP(u.shminfo, u32.shminfo32, shmseg);
1531 CP(u.shminfo, u32.shminfo32, shmall);
1532 error = copyout(&u32.shminfo32, uap->buf,
1533 sizeof(u32.shminfo32));
1536 CP(u.shm_info, u32.shm_info32, used_ids);
1537 CP(u.shm_info, u32.shm_info32, shm_rss);
1538 CP(u.shm_info, u32.shm_info32, shm_tot);
1539 CP(u.shm_info, u32.shm_info32, shm_swp);
1540 CP(u.shm_info, u32.shm_info32, swap_attempts);
1541 CP(u.shm_info, u32.shm_info32, swap_successes);
1542 error = copyout(&u32.shm_info32, uap->buf,
1543 sizeof(u32.shm_info32));
1547 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.cuid);
1548 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.cgid);
1549 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.uid);
1550 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.gid);
1551 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.mode);
1552 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.seq);
1553 CP(u.shmid_ds, u32.shmid_ds32, shm_perm.key);
1554 CP(u.shmid_ds, u32.shmid_ds32, shm_segsz);
1555 CP(u.shmid_ds, u32.shmid_ds32, shm_lpid);
1556 CP(u.shmid_ds, u32.shmid_ds32, shm_cpid);
1557 CP(u.shmid_ds, u32.shmid_ds32, shm_nattch);
1558 CP(u.shmid_ds, u32.shmid_ds32, shm_atime);
1559 CP(u.shmid_ds, u32.shmid_ds32, shm_dtime);
1560 CP(u.shmid_ds, u32.shmid_ds32, shm_ctime);
1561 PTROUT_CP(u.shmid_ds, u32.shmid_ds32, shm_internal);
1562 error = copyout(&u32.shmid_ds32, uap->buf,
1563 sizeof(u32.shmid_ds32));
1569 /* Invalidate the return value */
1570 td->td_retval[0] = -1;
1576 freebsd32_pread(struct thread *td, struct freebsd32_pread_args *uap)
1578 struct pread_args ap;
1582 ap.nbyte = uap->nbyte;
1583 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1584 return (pread(td, &ap));
1588 freebsd32_pwrite(struct thread *td, struct freebsd32_pwrite_args *uap)
1590 struct pwrite_args ap;
1594 ap.nbyte = uap->nbyte;
1595 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1596 return (pwrite(td, &ap));
1600 freebsd32_lseek(struct thread *td, struct freebsd32_lseek_args *uap)
1603 struct lseek_args ap;
1607 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1608 ap.whence = uap->whence;
1609 error = lseek(td, &ap);
1610 /* Expand the quad return into two parts for eax and edx */
1611 pos = *(off_t *)(td->td_retval);
1612 td->td_retval[0] = pos & 0xffffffff; /* %eax */
1613 td->td_retval[1] = pos >> 32; /* %edx */
1618 freebsd32_truncate(struct thread *td, struct freebsd32_truncate_args *uap)
1620 struct truncate_args ap;
1622 ap.path = uap->path;
1623 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
1624 return (truncate(td, &ap));
1628 freebsd32_ftruncate(struct thread *td, struct freebsd32_ftruncate_args *uap)
1630 struct ftruncate_args ap;
1633 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
1634 return (ftruncate(td, &ap));
1637 #ifdef COMPAT_FREEBSD6
1638 /* versions with the 'int pad' argument */
1640 freebsd6_freebsd32_pread(struct thread *td, struct freebsd6_freebsd32_pread_args *uap)
1642 struct pread_args ap;
1646 ap.nbyte = uap->nbyte;
1647 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1648 return (pread(td, &ap));
1652 freebsd6_freebsd32_pwrite(struct thread *td, struct freebsd6_freebsd32_pwrite_args *uap)
1654 struct pwrite_args ap;
1658 ap.nbyte = uap->nbyte;
1659 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1660 return (pwrite(td, &ap));
1664 freebsd6_freebsd32_lseek(struct thread *td, struct freebsd6_freebsd32_lseek_args *uap)
1667 struct lseek_args ap;
1671 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1672 ap.whence = uap->whence;
1673 error = lseek(td, &ap);
1674 /* Expand the quad return into two parts for eax and edx */
1675 pos = *(off_t *)(td->td_retval);
1676 td->td_retval[0] = pos & 0xffffffff; /* %eax */
1677 td->td_retval[1] = pos >> 32; /* %edx */
1682 freebsd6_freebsd32_truncate(struct thread *td, struct freebsd6_freebsd32_truncate_args *uap)
1684 struct truncate_args ap;
1686 ap.path = uap->path;
1687 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
1688 return (truncate(td, &ap));
1692 freebsd6_freebsd32_ftruncate(struct thread *td, struct freebsd6_freebsd32_ftruncate_args *uap)
1694 struct ftruncate_args ap;
1697 ap.length = (uap->lengthlo | ((off_t)uap->lengthhi << 32));
1698 return (ftruncate(td, &ap));
1700 #endif /* COMPAT_FREEBSD6 */
1710 freebsd32_do_sendfile(struct thread *td,
1711 struct freebsd32_sendfile_args *uap, int compat)
1713 struct sendfile_args ap;
1714 struct sf_hdtr32 hdtr32;
1715 struct sf_hdtr hdtr;
1716 struct uio *hdr_uio, *trl_uio;
1717 struct iovec32 *iov32;
1720 hdr_uio = trl_uio = NULL;
1724 ap.offset = (uap->offsetlo | ((off_t)uap->offsethi << 32));
1725 ap.nbytes = uap->nbytes;
1726 ap.hdtr = (struct sf_hdtr *)uap->hdtr; /* XXX not used */
1727 ap.sbytes = uap->sbytes;
1728 ap.flags = uap->flags;
1730 if (uap->hdtr != NULL) {
1731 error = copyin(uap->hdtr, &hdtr32, sizeof(hdtr32));
1734 PTRIN_CP(hdtr32, hdtr, headers);
1735 CP(hdtr32, hdtr, hdr_cnt);
1736 PTRIN_CP(hdtr32, hdtr, trailers);
1737 CP(hdtr32, hdtr, trl_cnt);
1739 if (hdtr.headers != NULL) {
1740 iov32 = PTRIN(hdtr32.headers);
1741 error = freebsd32_copyinuio(iov32,
1742 hdtr32.hdr_cnt, &hdr_uio);
1746 if (hdtr.trailers != NULL) {
1747 iov32 = PTRIN(hdtr32.trailers);
1748 error = freebsd32_copyinuio(iov32,
1749 hdtr32.trl_cnt, &trl_uio);
1755 error = kern_sendfile(td, &ap, hdr_uio, trl_uio, compat);
1758 free(hdr_uio, M_IOV);
1760 free(trl_uio, M_IOV);
1764 #ifdef COMPAT_FREEBSD4
1766 freebsd4_freebsd32_sendfile(struct thread *td,
1767 struct freebsd4_freebsd32_sendfile_args *uap)
1769 return (freebsd32_do_sendfile(td,
1770 (struct freebsd32_sendfile_args *)uap, 1));
1775 freebsd32_sendfile(struct thread *td, struct freebsd32_sendfile_args *uap)
1778 return (freebsd32_do_sendfile(td, uap, 0));
1789 struct timespec32 st_atimespec;
1790 struct timespec32 st_mtimespec;
1791 struct timespec32 st_ctimespec;
1794 u_int32_t st_blksize;
1797 struct timespec32 st_birthtimespec;
1798 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
1799 unsigned int :(8 / 2) * (16 - (int)sizeof(struct timespec32));
1803 CTASSERT(sizeof(struct stat32) == 96);
1806 copy_stat( struct stat *in, struct stat32 *out)
1808 CP(*in, *out, st_dev);
1809 CP(*in, *out, st_ino);
1810 CP(*in, *out, st_mode);
1811 CP(*in, *out, st_nlink);
1812 CP(*in, *out, st_uid);
1813 CP(*in, *out, st_gid);
1814 CP(*in, *out, st_rdev);
1815 TS_CP(*in, *out, st_atimespec);
1816 TS_CP(*in, *out, st_mtimespec);
1817 TS_CP(*in, *out, st_ctimespec);
1818 CP(*in, *out, st_size);
1819 CP(*in, *out, st_blocks);
1820 CP(*in, *out, st_blksize);
1821 CP(*in, *out, st_flags);
1822 CP(*in, *out, st_gen);
1826 freebsd32_stat(struct thread *td, struct freebsd32_stat_args *uap)
1832 error = kern_stat(td, uap->path, UIO_USERSPACE, &sb);
1835 copy_stat(&sb, &sb32);
1836 error = copyout(&sb32, uap->ub, sizeof (sb32));
1841 freebsd32_fstat(struct thread *td, struct freebsd32_fstat_args *uap)
1847 error = kern_fstat(td, uap->fd, &ub);
1850 copy_stat(&ub, &ub32);
1851 error = copyout(&ub32, uap->ub, sizeof(ub32));
1856 freebsd32_lstat(struct thread *td, struct freebsd32_lstat_args *uap)
1862 error = kern_lstat(td, uap->path, UIO_USERSPACE, &sb);
1865 copy_stat(&sb, &sb32);
1866 error = copyout(&sb32, uap->ub, sizeof (sb32));
1874 freebsd32_sysctl(struct thread *td, struct freebsd32_sysctl_args *uap)
1876 int error, name[CTL_MAXNAME];
1879 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1881 error = copyin(uap->name, name, uap->namelen * sizeof(int));
1886 oldlen = fuword32(uap->oldlenp);
1889 error = userland_sysctl(td, name, uap->namelen,
1890 uap->old, &oldlen, 1,
1891 uap->new, uap->newlen, &j, SCTL_MASK32);
1892 if (error && error != ENOMEM)
1895 suword32(uap->oldlenp, j);
1901 struct sigaction32 {
1907 CTASSERT(sizeof(struct sigaction32) == 24);
1910 freebsd32_sigaction(struct thread *td, struct freebsd32_sigaction_args *uap)
1912 struct sigaction32 s32;
1913 struct sigaction sa, osa, *sap;
1917 error = copyin(uap->act, &s32, sizeof(s32));
1920 sa.sa_handler = PTRIN(s32.sa_u);
1921 CP(s32, sa, sa_flags);
1922 CP(s32, sa, sa_mask);
1926 error = kern_sigaction(td, uap->sig, sap, &osa, 0);
1927 if (error == 0 && uap->oact != NULL) {
1928 s32.sa_u = PTROUT(osa.sa_handler);
1929 CP(osa, s32, sa_flags);
1930 CP(osa, s32, sa_mask);
1931 error = copyout(&s32, uap->oact, sizeof(s32));
1936 #ifdef COMPAT_FREEBSD4
1938 freebsd4_freebsd32_sigaction(struct thread *td,
1939 struct freebsd4_freebsd32_sigaction_args *uap)
1941 struct sigaction32 s32;
1942 struct sigaction sa, osa, *sap;
1946 error = copyin(uap->act, &s32, sizeof(s32));
1949 sa.sa_handler = PTRIN(s32.sa_u);
1950 CP(s32, sa, sa_flags);
1951 CP(s32, sa, sa_mask);
1955 error = kern_sigaction(td, uap->sig, sap, &osa, KSA_FREEBSD4);
1956 if (error == 0 && uap->oact != NULL) {
1957 s32.sa_u = PTROUT(osa.sa_handler);
1958 CP(osa, s32, sa_flags);
1959 CP(osa, s32, sa_mask);
1960 error = copyout(&s32, uap->oact, sizeof(s32));
1967 struct osigaction32 {
1976 ofreebsd32_sigaction(struct thread *td,
1977 struct ofreebsd32_sigaction_args *uap)
1979 struct osigaction32 s32;
1980 struct sigaction sa, osa, *sap;
1983 if (uap->signum <= 0 || uap->signum >= ONSIG)
1987 error = copyin(uap->nsa, &s32, sizeof(s32));
1990 sa.sa_handler = PTRIN(s32.sa_u);
1991 CP(s32, sa, sa_flags);
1992 OSIG2SIG(s32.sa_mask, sa.sa_mask);
1996 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
1997 if (error == 0 && uap->osa != NULL) {
1998 s32.sa_u = PTROUT(osa.sa_handler);
1999 CP(osa, s32, sa_flags);
2000 SIG2OSIG(osa.sa_mask, s32.sa_mask);
2001 error = copyout(&s32, uap->osa, sizeof(s32));
2007 ofreebsd32_sigprocmask(struct thread *td,
2008 struct ofreebsd32_sigprocmask_args *uap)
2013 OSIG2SIG(uap->mask, set);
2014 error = kern_sigprocmask(td, uap->how, &set, &oset, 1);
2015 SIG2OSIG(oset, td->td_retval[0]);
2020 ofreebsd32_sigpending(struct thread *td,
2021 struct ofreebsd32_sigpending_args *uap)
2023 struct proc *p = td->td_proc;
2027 siglist = p->p_siglist;
2028 SIGSETOR(siglist, td->td_siglist);
2030 SIG2OSIG(siglist, td->td_retval[0]);
2035 u_int32_t sv_handler;
2041 ofreebsd32_sigvec(struct thread *td,
2042 struct ofreebsd32_sigvec_args *uap)
2044 struct sigvec32 vec;
2045 struct sigaction sa, osa, *sap;
2048 if (uap->signum <= 0 || uap->signum >= ONSIG)
2052 error = copyin(uap->nsv, &vec, sizeof(vec));
2055 sa.sa_handler = PTRIN(vec.sv_handler);
2056 OSIG2SIG(vec.sv_mask, sa.sa_mask);
2057 sa.sa_flags = vec.sv_flags;
2058 sa.sa_flags ^= SA_RESTART;
2062 error = kern_sigaction(td, uap->signum, sap, &osa, KSA_OSIGSET);
2063 if (error == 0 && uap->osv != NULL) {
2064 vec.sv_handler = PTROUT(osa.sa_handler);
2065 SIG2OSIG(osa.sa_mask, vec.sv_mask);
2066 vec.sv_flags = osa.sa_flags;
2067 vec.sv_flags &= ~SA_NOCLDWAIT;
2068 vec.sv_flags ^= SA_RESTART;
2069 error = copyout(&vec, uap->osv, sizeof(vec));
2075 ofreebsd32_sigblock(struct thread *td,
2076 struct ofreebsd32_sigblock_args *uap)
2078 struct proc *p = td->td_proc;
2081 OSIG2SIG(uap->mask, set);
2084 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
2085 SIGSETOR(td->td_sigmask, set);
2091 ofreebsd32_sigsetmask(struct thread *td,
2092 struct ofreebsd32_sigsetmask_args *uap)
2094 struct proc *p = td->td_proc;
2097 OSIG2SIG(uap->mask, set);
2100 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
2101 SIGSETLO(td->td_sigmask, set);
2108 ofreebsd32_sigsuspend(struct thread *td,
2109 struct ofreebsd32_sigsuspend_args *uap)
2111 struct proc *p = td->td_proc;
2115 td->td_oldsigmask = td->td_sigmask;
2116 td->td_pflags |= TDP_OLDMASK;
2117 OSIG2SIG(uap->mask, mask);
2119 SIGSETLO(td->td_sigmask, mask);
2121 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "opause", 0) == 0)
2124 /* always return EINTR rather than ERESTART... */
2134 ofreebsd32_sigstack(struct thread *td,
2135 struct ofreebsd32_sigstack_args *uap)
2137 struct sigstack32 s32;
2138 struct sigstack nss, oss;
2139 int error = 0, unss;
2141 if (uap->nss != NULL) {
2142 error = copyin(uap->nss, &s32, sizeof(s32));
2145 nss.ss_sp = PTRIN(s32.ss_sp);
2146 CP(s32, nss, ss_onstack);
2151 oss.ss_sp = td->td_sigstk.ss_sp;
2152 oss.ss_onstack = sigonstack(cpu_getstack(td));
2154 td->td_sigstk.ss_sp = nss.ss_sp;
2155 td->td_sigstk.ss_size = 0;
2156 td->td_sigstk.ss_flags |= (nss.ss_onstack & SS_ONSTACK);
2157 td->td_pflags |= TDP_ALTSTACK;
2159 if (uap->oss != NULL) {
2160 s32.ss_sp = PTROUT(oss.ss_sp);
2161 CP(oss, s32, ss_onstack);
2162 error = copyout(&s32, uap->oss, sizeof(s32));
2169 freebsd32_nanosleep(struct thread *td, struct freebsd32_nanosleep_args *uap)
2171 struct timespec32 rmt32, rqt32;
2172 struct timespec rmt, rqt;
2175 error = copyin(uap->rqtp, &rqt32, sizeof(rqt32));
2179 CP(rqt32, rqt, tv_sec);
2180 CP(rqt32, rqt, tv_nsec);
2183 !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE))
2185 error = kern_nanosleep(td, &rqt, &rmt);
2186 if (error && uap->rmtp) {
2189 CP(rmt, rmt32, tv_sec);
2190 CP(rmt, rmt32, tv_nsec);
2192 error2 = copyout(&rmt32, uap->rmtp, sizeof(rmt32));
2200 freebsd32_clock_gettime(struct thread *td,
2201 struct freebsd32_clock_gettime_args *uap)
2203 struct timespec ats;
2204 struct timespec32 ats32;
2207 error = kern_clock_gettime(td, uap->clock_id, &ats);
2209 CP(ats, ats32, tv_sec);
2210 CP(ats, ats32, tv_nsec);
2211 error = copyout(&ats32, uap->tp, sizeof(ats32));
2217 freebsd32_clock_settime(struct thread *td,
2218 struct freebsd32_clock_settime_args *uap)
2220 struct timespec ats;
2221 struct timespec32 ats32;
2224 error = copyin(uap->tp, &ats32, sizeof(ats32));
2227 CP(ats32, ats, tv_sec);
2228 CP(ats32, ats, tv_nsec);
2230 return (kern_clock_settime(td, uap->clock_id, &ats));
2234 freebsd32_clock_getres(struct thread *td,
2235 struct freebsd32_clock_getres_args *uap)
2238 struct timespec32 ts32;
2241 if (uap->tp == NULL)
2243 error = kern_clock_getres(td, uap->clock_id, &ts);
2245 CP(ts, ts32, tv_sec);
2246 CP(ts, ts32, tv_nsec);
2247 error = copyout(&ts32, uap->tp, sizeof(ts32));
2253 freebsd32_thr_new(struct thread *td,
2254 struct freebsd32_thr_new_args *uap)
2256 struct thr_param32 param32;
2257 struct thr_param param;
2260 if (uap->param_size < 0 ||
2261 uap->param_size > sizeof(struct thr_param32))
2263 bzero(¶m, sizeof(struct thr_param));
2264 bzero(¶m32, sizeof(struct thr_param32));
2265 error = copyin(uap->param, ¶m32, uap->param_size);
2268 param.start_func = PTRIN(param32.start_func);
2269 param.arg = PTRIN(param32.arg);
2270 param.stack_base = PTRIN(param32.stack_base);
2271 param.stack_size = param32.stack_size;
2272 param.tls_base = PTRIN(param32.tls_base);
2273 param.tls_size = param32.tls_size;
2274 param.child_tid = PTRIN(param32.child_tid);
2275 param.parent_tid = PTRIN(param32.parent_tid);
2276 param.flags = param32.flags;
2277 param.rtp = PTRIN(param32.rtp);
2278 param.spare[0] = PTRIN(param32.spare[0]);
2279 param.spare[1] = PTRIN(param32.spare[1]);
2280 param.spare[2] = PTRIN(param32.spare[2]);
2282 return (kern_thr_new(td, ¶m));
2286 freebsd32_thr_suspend(struct thread *td, struct freebsd32_thr_suspend_args *uap)
2288 struct timespec32 ts32;
2289 struct timespec ts, *tsp;
2294 if (uap->timeout != NULL) {
2295 error = copyin((const void *)uap->timeout, (void *)&ts32,
2296 sizeof(struct timespec32));
2299 ts.tv_sec = ts32.tv_sec;
2300 ts.tv_nsec = ts32.tv_nsec;
2303 return (kern_thr_suspend(td, tsp));
2307 siginfo_to_siginfo32(siginfo_t *src, struct siginfo32 *dst)
2309 bzero(dst, sizeof(*dst));
2310 dst->si_signo = src->si_signo;
2311 dst->si_errno = src->si_errno;
2312 dst->si_code = src->si_code;
2313 dst->si_pid = src->si_pid;
2314 dst->si_uid = src->si_uid;
2315 dst->si_status = src->si_status;
2316 dst->si_addr = dst->si_addr;
2317 dst->si_value.sigval_int = src->si_value.sival_int;
2318 dst->si_timerid = src->si_timerid;
2319 dst->si_overrun = src->si_overrun;
2323 freebsd32_sigtimedwait(struct thread *td, struct freebsd32_sigtimedwait_args *uap)
2325 struct timespec32 ts32;
2327 struct timespec *timeout;
2330 struct siginfo32 si32;
2334 error = copyin(uap->timeout, &ts32, sizeof(ts32));
2337 ts.tv_sec = ts32.tv_sec;
2338 ts.tv_nsec = ts32.tv_nsec;
2343 error = copyin(uap->set, &set, sizeof(set));
2347 error = kern_sigtimedwait(td, set, &ksi, timeout);
2352 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2353 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2357 td->td_retval[0] = ksi.ksi_signo;
2365 freebsd32_sigwaitinfo(struct thread *td, struct freebsd32_sigwaitinfo_args *uap)
2368 struct siginfo32 si32;
2372 error = copyin(uap->set, &set, sizeof(set));
2376 error = kern_sigtimedwait(td, set, &ksi, NULL);
2381 siginfo_to_siginfo32(&ksi.ksi_info, &si32);
2382 error = copyout(&si32, uap->info, sizeof(struct siginfo32));
2385 td->td_retval[0] = ksi.ksi_signo;
2392 freebsd32_xxx(struct thread *td, struct freebsd32_xxx_args *uap)
2395 struct yyy32 *p32, s32;
2396 struct yyy *p = NULL, s;
2399 error = copyin(uap->zzz, &s32, sizeof(s32));
2405 error = kern_xxx(td, p);
2410 error = copyout(&s32, p32, sizeof(s32));