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
29 #include <sys/param.h>
30 #include <sys/systm.h>
32 #include <sys/dkstat.h>
34 #include <sys/fcntl.h>
35 #include <sys/filedesc.h>
36 #include <sys/imgact.h>
37 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/file.h> /* Must come after sys/malloc.h */
42 #include <sys/module.h>
43 #include <sys/mount.h>
44 #include <sys/mutex.h>
45 #include <sys/namei.h>
46 #include <sys/param.h>
48 #include <sys/reboot.h>
49 #include <sys/resource.h>
50 #include <sys/resourcevar.h>
51 #include <sys/selinfo.h>
52 #include <sys/pipe.h> /* Must come after sys/selinfo.h */
53 #include <sys/signal.h>
54 #include <sys/signalvar.h>
55 #include <sys/socket.h>
56 #include <sys/socketvar.h>
58 #include <sys/sysctl.h>
59 #include <sys/sysent.h>
60 #include <sys/sysproto.h>
61 #include <sys/systm.h>
62 #include <sys/unistd.h>
64 #include <sys/utsname.h>
65 #include <sys/vnode.h>
68 #include <vm/vm_kern.h>
69 #include <vm/vm_param.h>
71 #include <vm/vm_map.h>
72 #include <vm/vm_object.h>
73 #include <vm/vm_extern.h>
75 #include <ia64/ia32/ia32_util.h>
76 #include <ia64/ia32/ia32.h>
77 #include <ia64/ia32/ia32_proto.h>
79 static const char ia32_emul_path[] = "/compat/ia32";
81 * [ taken from the linux emulator ]
82 * Search an alternate path before passing pathname arguments on
83 * to system calls. Useful for keeping a separate 'emulation tree'.
85 * If cflag is set, we check if an attempt can be made to create
86 * the named file, i.e. we check if the directory it should
90 ia32_emul_find(td, sgp, prefix, path, pbuf, cflag)
92 caddr_t *sgp; /* Pointer to stackgap memory */
100 char *buf, *cp, *ptr;
103 struct nameidata ndroot;
105 struct vattr vatroot;
107 buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
110 for (ptr = buf; (*ptr = *prefix) != '\0'; ptr++, prefix++)
113 sz = MAXPATHLEN - (ptr - buf);
116 * If sgp is not given then the path is already in kernel space
119 error = copystr(path, ptr, sz, &len);
121 error = copyinstr(path, ptr, sz, &len);
134 * We know that there is a / somewhere in this pathname.
135 * Search backwards for it, to find the file's parent dir
136 * to see if it exists in the alternate tree. If it does,
137 * and we want to create a file (cflag is set). We don't
138 * need to worry about the root comparison in this case.
142 for (cp = &ptr[len] - 1; *cp != '/'; cp--)
146 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
148 if ((error = namei(&nd)) != 0) {
155 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td);
157 if ((error = namei(&nd)) != 0) {
163 * We now compare the vnode of the ia32_root to the one
164 * vnode asked. If they resolve to be the same, then we
165 * ignore the match so that the real root gets used.
166 * This avoids the problem of traversing "../.." to find the
167 * root directory and never finding it, because "/" resolves
168 * to the emulation root directory. This is expensive :-(
170 NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, ia32_emul_path,
173 if ((error = namei(&ndroot)) != 0) {
180 ucred = td->td_ucred;
181 if ((error = VOP_GETATTR(nd.ni_vp, &vat, ucred, td)) != 0) {
185 if ((error = VOP_GETATTR(ndroot.ni_vp, &vatroot, ucred,
190 if (vat.va_fsid == vatroot.va_fsid &&
191 vat.va_fileid == vatroot.va_fileid) {
200 sz = &ptr[len] - buf;
201 *pbuf = stackgap_alloc(sgp, sz + 1);
202 error = copyout(buf, *pbuf, sz);
220 ia32_open(struct thread *td, struct ia32_open_args *uap)
224 sg = stackgap_init();
225 CHECKALTEXIST(td, &sg, uap->path);
227 return open(td, (struct open_args *) uap);
231 ia32_wait4(struct thread *td, struct ia32_wait4_args *uap)
235 struct rusage32 *rusage32, ru32;
236 struct rusage *rusage = NULL, ru;
238 rusage32 = SCARG(uap, rusage);
240 sg = stackgap_init();
241 rusage = stackgap_alloc(&sg, sizeof(struct rusage));
242 SCARG(uap, rusage) = (struct rusage32 *)rusage;
244 error = wait4(td, (struct wait_args *)uap);
247 if (rusage32 && (error = copyin(rusage, &ru, sizeof(ru)) == 0)) {
248 TV_CP(ru, ru32, ru_utime);
249 TV_CP(ru, ru32, ru_stime);
250 CP(ru, ru32, ru_maxrss);
251 CP(ru, ru32, ru_ixrss);
252 CP(ru, ru32, ru_idrss);
253 CP(ru, ru32, ru_isrss);
254 CP(ru, ru32, ru_minflt);
255 CP(ru, ru32, ru_majflt);
256 CP(ru, ru32, ru_nswap);
257 CP(ru, ru32, ru_inblock);
258 CP(ru, ru32, ru_oublock);
259 CP(ru, ru32, ru_msgsnd);
260 CP(ru, ru32, ru_msgrcv);
261 CP(ru, ru32, ru_nsignals);
262 CP(ru, ru32, ru_nvcsw);
263 CP(ru, ru32, ru_nivcsw);
264 error = copyout(&ru32, rusage32, sizeof(ru32));
270 copy_statfs(struct statfs *in, struct statfs32 *out)
272 CP(*in, *out, f_bsize);
273 CP(*in, *out, f_iosize);
274 CP(*in, *out, f_blocks);
275 CP(*in, *out, f_bfree);
276 CP(*in, *out, f_bavail);
277 CP(*in, *out, f_files);
278 CP(*in, *out, f_ffree);
279 CP(*in, *out, f_fsid);
280 CP(*in, *out, f_owner);
281 CP(*in, *out, f_type);
282 CP(*in, *out, f_flags);
283 CP(*in, *out, f_flags);
284 CP(*in, *out, f_syncwrites);
285 CP(*in, *out, f_asyncwrites);
286 bcopy(in->f_fstypename,
287 out->f_fstypename, MFSNAMELEN);
288 bcopy(in->f_mntonname,
289 out->f_mntonname, MNAMELEN);
290 CP(*in, *out, f_syncreads);
291 CP(*in, *out, f_asyncreads);
292 bcopy(in->f_mntfromname,
293 out->f_mntfromname, MNAMELEN);
297 ia32_getfsstat(struct thread *td, struct ia32_getfsstat_args *uap)
301 struct statfs32 *sp32, stat32;
302 struct statfs *sp = NULL, stat;
303 int maxcount, count, i;
305 sp32 = SCARG(uap, buf);
306 maxcount = SCARG(uap, bufsize) / sizeof(struct statfs32);
309 sg = stackgap_init();
310 sp = stackgap_alloc(&sg, sizeof(struct statfs) * maxcount);
311 SCARG(uap, buf) = (struct statfs32 *)sp;
313 error = getfsstat(td, (struct getfsstat_args *) uap);
314 if (sp32 && !error) {
315 count = td->td_retval[0];
316 for (i = 0; i < count; i++) {
317 error = copyin(&sp[i], &stat, sizeof(stat));
320 copy_statfs(&stat, &stat32);
321 error = copyout(&stat32, &sp32[i], sizeof(stat32));
330 ia32_access(struct thread *td, struct ia32_access_args *uap)
334 sg = stackgap_init();
335 CHECKALTEXIST(td, &sg, uap->path);
337 return access(td, (struct access_args *)uap);
341 ia32_chflags(struct thread *td, struct ia32_chflags_args *uap)
345 sg = stackgap_init();
346 CHECKALTEXIST(td, &sg, uap->path);
348 return chflags(td, (struct chflags_args *)uap);
351 struct sigaltstack32 {
358 ia32_sigaltstack(struct thread *td, struct ia32_sigaltstack_args *uap)
362 struct sigaltstack32 *p32, *op32, s32;
363 struct sigaltstack *p = NULL, *op = NULL, s;
365 p32 = SCARG(uap, ss);
367 sg = stackgap_init();
368 p = stackgap_alloc(&sg, sizeof(struct sigaltstack));
369 SCARG(uap, ss) = (struct sigaltstack32 *)p;
370 error = copyin(p32, &s32, sizeof(s32));
373 PTRIN_CP(s32, s, ss_sp);
375 CP(s32, s, ss_flags);
376 error = copyout(&s, p, sizeof(s));
380 op32 = SCARG(uap, oss);
382 sg = stackgap_init();
383 op = stackgap_alloc(&sg, sizeof(struct sigaltstack));
384 SCARG(uap, oss) = (struct sigaltstack32 *)op;
386 error = sigaltstack(td, (struct sigaltstack_args *) uap);
390 error = copyin(op, &s, sizeof(s));
393 PTROUT_CP(s, s32, ss_sp);
395 CP(s, s32, ss_flags);
396 error = copyout(&s32, op32, sizeof(s32));
402 ia32_execve(struct thread *td, struct ia32_execve_args *uap)
406 struct execve_args ap;
411 sg = stackgap_init();
412 CHECKALTEXIST(td, &sg, SCARG(uap, fname));
413 SCARG(&ap, fname) = SCARG(uap, fname);
415 if (SCARG(uap, argv)) {
417 p32 = SCARG(uap, argv);
419 error = copyin(p32++, &arg, sizeof(arg));
424 p = stackgap_alloc(&sg, count * sizeof(char *));
425 SCARG(&ap, argv) = p;
426 p32 = SCARG(uap, argv);
428 error = copyin(p32++, &arg, sizeof(arg));
434 if (SCARG(uap, envv)) {
436 p32 = SCARG(uap, envv);
438 error = copyin(p32++, &arg, sizeof(arg));
443 p = stackgap_alloc(&sg, count * sizeof(char *));
444 SCARG(&ap, envv) = p;
445 p32 = SCARG(uap, envv);
447 error = copyin(p32++, &arg, sizeof(arg));
454 return execve(td, &ap);
458 ia32_mmap_partial(struct thread *td, vm_offset_t start, vm_offset_t end,
459 int prot, int fd, off_t pos)
462 vm_map_entry_t entry;
465 map = &td->td_proc->p_vmspace->vm_map;
467 prot |= VM_PROT_WRITE;
469 if (vm_map_lookup_entry(map, start, &entry)) {
470 if ((entry->protection & prot) != prot) {
471 rv = vm_map_protect(map,
474 entry->protection | prot,
476 if (rv != KERN_SUCCESS)
480 vm_offset_t addr = trunc_page(start);
481 rv = vm_map_find(map, 0, 0,
482 &addr, PAGE_SIZE, FALSE, prot,
484 if (rv != KERN_SUCCESS)
491 SCARG(&r, buf) = (void *) start;
492 SCARG(&r, nbyte) = end - start;
493 SCARG(&r, offset) = pos;
494 return (pread(td, &r));
496 while (start < end) {
497 subyte((void *) start, 0);
505 ia32_mmap(struct thread *td, struct ia32_mmap_args *uap)
508 vm_offset_t addr = (vm_offset_t) SCARG(uap, addr);
509 vm_size_t len = SCARG(uap, len);
510 int prot = SCARG(uap, prot);
511 int flags = SCARG(uap, flags);
512 int fd = SCARG(uap, fd);
513 off_t pos = (SCARG(uap, poslo)
514 | ((off_t)SCARG(uap, poshi) << 32));
519 * Attempt to handle page size hassles.
521 pageoff = (pos & PAGE_MASK);
522 if (flags & MAP_FIXED) {
523 vm_offset_t start, end;
527 if (start != trunc_page(start)) {
528 error = ia32_mmap_partial(td, start, round_page(start),
531 pos += round_page(start) - start;
532 start = round_page(start);
534 if (end != round_page(end)) {
535 vm_offset_t t = trunc_page(end);
536 error = ia32_mmap_partial(td, t, end,
539 end = trunc_page(end);
541 if (end > start && fd != -1 && (pos & PAGE_MASK)) {
543 * We can't map this region at all. The specified
544 * address doesn't have the same alignment as the file
545 * position. Fake the mapping by simply reading the
546 * entire region into memory. First we need to make
547 * sure the region exists.
553 prot |= VM_PROT_WRITE;
554 map = &td->td_proc->p_vmspace->vm_map;
555 rv = vm_map_remove(map, start, end);
556 if (rv != KERN_SUCCESS)
558 rv = vm_map_find(map, 0, 0,
559 &start, end - start, FALSE,
560 prot, VM_PROT_ALL, 0);
561 if (rv != KERN_SUCCESS)
564 SCARG(&r, buf) = (void *) start;
565 SCARG(&r, nbyte) = end - start;
566 SCARG(&r, offset) = pos;
567 error = pread(td, &r);
571 td->td_retval[0] = addr;
576 * After dealing with the ragged ends, there
577 * might be none left.
579 td->td_retval[0] = addr;
586 SCARG(&ap, addr) = (void *) addr;
587 SCARG(&ap, len) = len;
588 SCARG(&ap, prot) = prot;
589 SCARG(&ap, flags) = flags;
591 SCARG(&ap, pos) = pos;
593 return (mmap(td, &ap));
597 struct timeval32 it_interval;
598 struct timeval32 it_value;
602 ia32_setitimer(struct thread *td, struct ia32_setitimer_args *uap)
606 struct itimerval32 *p32, *op32, s32;
607 struct itimerval *p = NULL, *op = NULL, s;
609 p32 = SCARG(uap, itv);
611 sg = stackgap_init();
612 p = stackgap_alloc(&sg, sizeof(struct itimerval));
613 SCARG(uap, itv) = (struct itimerval32 *)p;
614 error = copyin(p32, &s32, sizeof(s32));
617 TV_CP(s32, s, it_interval);
618 TV_CP(s32, s, it_value);
619 error = copyout(&s, p, sizeof(s));
623 op32 = SCARG(uap, oitv);
625 sg = stackgap_init();
626 op = stackgap_alloc(&sg, sizeof(struct itimerval));
627 SCARG(uap, oitv) = (struct itimerval32 *)op;
629 error = setitimer(td, (struct setitimer_args *) uap);
633 error = copyin(op, &s, sizeof(s));
636 TV_CP(s, s32, it_interval);
637 TV_CP(s, s32, it_value);
638 error = copyout(&s32, op32, sizeof(s32));
644 ia32_select(struct thread *td, struct ia32_select_args *uap)
648 struct timeval32 *p32, s32;
649 struct timeval *p = NULL, s;
651 p32 = SCARG(uap, tv);
653 sg = stackgap_init();
654 p = stackgap_alloc(&sg, sizeof(struct timeval));
655 SCARG(uap, tv) = (struct timeval32 *)p;
656 error = copyin(p32, &s32, sizeof(s32));
661 error = copyout(&s, p, sizeof(s));
666 * XXX big-endian needs to convert the fd_sets too.
668 return (select(td, (struct select_args *) uap));
672 ia32_gettimeofday(struct thread *td, struct ia32_gettimeofday_args *uap)
676 struct timeval32 *p32, s32;
677 struct timeval *p = NULL, s;
679 p32 = SCARG(uap, tp);
681 sg = stackgap_init();
682 p = stackgap_alloc(&sg, sizeof(struct timeval));
683 SCARG(uap, tp) = (struct timeval32 *)p;
685 error = gettimeofday(td, (struct gettimeofday_args *) uap);
689 error = copyin(p, &s, sizeof(s));
694 error = copyout(&s32, p32, sizeof(s32));
702 ia32_getrusage(struct thread *td, struct ia32_getrusage_args *uap)
706 struct rusage32 *p32, s32;
707 struct rusage *p = NULL, s;
709 p32 = SCARG(uap, rusage);
711 sg = stackgap_init();
712 p = stackgap_alloc(&sg, sizeof(struct rusage));
713 SCARG(uap, rusage) = (struct rusage32 *)p;
715 error = getrusage(td, (struct getrusage_args *) uap);
719 error = copyin(p, &s, sizeof(s));
722 TV_CP(s, s32, ru_utime);
723 TV_CP(s, s32, ru_stime);
724 CP(s, s32, ru_maxrss);
725 CP(s, s32, ru_ixrss);
726 CP(s, s32, ru_idrss);
727 CP(s, s32, ru_isrss);
728 CP(s, s32, ru_minflt);
729 CP(s, s32, ru_majflt);
730 CP(s, s32, ru_nswap);
731 CP(s, s32, ru_inblock);
732 CP(s, s32, ru_oublock);
733 CP(s, s32, ru_msgsnd);
734 CP(s, s32, ru_msgrcv);
735 CP(s, s32, ru_nsignals);
736 CP(s, s32, ru_nvcsw);
737 CP(s, s32, ru_nivcsw);
738 error = copyout(&s32, p32, sizeof(s32));
747 #define STACKGAPLEN 400
750 ia32_readv(struct thread *td, struct ia32_readv_args *uap)
752 int error, osize, nsize, i;
754 struct readv_args /* {
756 syscallarg(struct iovec *) iovp;
757 syscallarg(u_int) iovcnt;
762 sg = stackgap_init();
764 if (SCARG(uap, iovcnt) > (STACKGAPLEN / sizeof (struct iovec)))
767 osize = SCARG(uap, iovcnt) * sizeof (struct iovec32);
768 nsize = SCARG(uap, iovcnt) * sizeof (struct iovec);
770 oio = malloc(osize, M_TEMP, M_WAITOK);
771 nio = malloc(nsize, M_TEMP, M_WAITOK);
774 if ((error = copyin(SCARG(uap, iovp), oio, osize)))
776 for (i = 0; i < SCARG(uap, iovcnt); i++) {
777 nio[i].iov_base = PTRIN(oio[i].iov_base);
778 nio[i].iov_len = oio[i].iov_len;
781 SCARG(&a, fd) = SCARG(uap, fd);
782 SCARG(&a, iovp) = stackgap_alloc(&sg, nsize);
783 SCARG(&a, iovcnt) = SCARG(uap, iovcnt);
785 if ((error = copyout(nio, (caddr_t)SCARG(&a, iovp), nsize)))
787 error = readv(td, &a);
796 ia32_writev(struct thread *td, struct ia32_writev_args *uap)
798 int error, i, nsize, osize;
800 struct writev_args /* {
802 syscallarg(struct iovec *) iovp;
803 syscallarg(u_int) iovcnt;
808 sg = stackgap_init();
810 if (SCARG(uap, iovcnt) > (STACKGAPLEN / sizeof (struct iovec)))
813 osize = SCARG(uap, iovcnt) * sizeof (struct iovec32);
814 nsize = SCARG(uap, iovcnt) * sizeof (struct iovec);
816 oio = malloc(osize, M_TEMP, M_WAITOK);
817 nio = malloc(nsize, M_TEMP, M_WAITOK);
820 if ((error = copyin(SCARG(uap, iovp), oio, osize)))
822 for (i = 0; i < SCARG(uap, iovcnt); i++) {
823 nio[i].iov_base = PTRIN(oio[i].iov_base);
824 nio[i].iov_len = oio[i].iov_len;
827 SCARG(&a, fd) = SCARG(uap, fd);
828 SCARG(&a, iovp) = stackgap_alloc(&sg, nsize);
829 SCARG(&a, iovcnt) = SCARG(uap, iovcnt);
831 if ((error = copyout(nio, (caddr_t)SCARG(&a, iovp), nsize)))
833 error = writev(td, &a);
842 ia32_settimeofday(struct thread *td, struct ia32_settimeofday_args *uap)
846 struct timeval32 *p32, s32;
847 struct timeval *p = NULL, s;
849 p32 = SCARG(uap, tv);
851 sg = stackgap_init();
852 p = stackgap_alloc(&sg, sizeof(struct timeval));
853 SCARG(uap, tv) = (struct timeval32 *)p;
854 error = copyin(p32, &s32, sizeof(s32));
859 error = copyout(&s, p, sizeof(s));
863 return (settimeofday(td, (struct settimeofday_args *) uap));
867 ia32_utimes(struct thread *td, struct ia32_utimes_args *uap)
871 struct timeval32 *p32, s32[2];
872 struct timeval *p = NULL, s[2];
874 p32 = SCARG(uap, tptr);
876 sg = stackgap_init();
877 p = stackgap_alloc(&sg, 2*sizeof(struct timeval));
878 SCARG(uap, tptr) = (struct timeval32 *)p;
879 error = copyin(p32, s32, sizeof(s32));
882 CP(s32[0], s[0], tv_sec);
883 CP(s32[0], s[0], tv_usec);
884 CP(s32[1], s[1], tv_sec);
885 CP(s32[1], s[1], tv_usec);
886 error = copyout(s, p, sizeof(s));
890 return (utimes(td, (struct utimes_args *) uap));
894 ia32_adjtime(struct thread *td, struct ia32_adjtime_args *uap)
898 struct timeval32 *p32, *op32, s32;
899 struct timeval *p = NULL, *op = NULL, s;
901 p32 = SCARG(uap, delta);
903 sg = stackgap_init();
904 p = stackgap_alloc(&sg, sizeof(struct timeval));
905 SCARG(uap, delta) = (struct timeval32 *)p;
906 error = copyin(p32, &s32, sizeof(s32));
911 error = copyout(&s, p, sizeof(s));
915 op32 = SCARG(uap, olddelta);
917 sg = stackgap_init();
918 op = stackgap_alloc(&sg, sizeof(struct timeval));
919 SCARG(uap, olddelta) = (struct timeval32 *)op;
921 error = utimes(td, (struct utimes_args *) uap);
925 error = copyin(op, &s, sizeof(s));
930 error = copyout(&s32, op32, sizeof(s32));
936 ia32_statfs(struct thread *td, struct ia32_statfs_args *uap)
940 struct statfs32 *p32, s32;
941 struct statfs *p = NULL, s;
943 p32 = SCARG(uap, buf);
945 sg = stackgap_init();
946 p = stackgap_alloc(&sg, sizeof(struct statfs));
947 SCARG(uap, buf) = (struct statfs32 *)p;
949 error = statfs(td, (struct statfs_args *) uap);
953 error = copyin(p, &s, sizeof(s));
956 copy_statfs(&s, &s32);
957 error = copyout(&s32, p32, sizeof(s32));
963 ia32_fstatfs(struct thread *td, struct ia32_fstatfs_args *uap)
967 struct statfs32 *p32, s32;
968 struct statfs *p = NULL, s;
970 p32 = SCARG(uap, buf);
972 sg = stackgap_init();
973 p = stackgap_alloc(&sg, sizeof(struct statfs));
974 SCARG(uap, buf) = (struct statfs32 *)p;
976 error = fstatfs(td, (struct fstatfs_args *) uap);
980 error = copyin(p, &s, sizeof(s));
983 copy_statfs(&s, &s32);
984 error = copyout(&s32, p32, sizeof(s32));
990 ia32_semsys(struct thread *td, struct ia32_semsys_args *uap)
993 * Vector through to semsys if it is loaded.
995 return sysent[169].sy_call(td, uap);
999 ia32_msgsys(struct thread *td, struct ia32_msgsys_args *uap)
1002 * Vector through to msgsys if it is loaded.
1004 return sysent[170].sy_call(td, uap);
1008 ia32_shmsys(struct thread *td, struct ia32_shmsys_args *uap)
1011 * Vector through to shmsys if it is loaded.
1013 return sysent[171].sy_call(td, uap);
1017 ia32_pread(struct thread *td, struct ia32_pread_args *uap)
1019 struct pread_args ap;
1021 SCARG(&ap, fd) = SCARG(uap, fd);
1022 SCARG(&ap, buf) = SCARG(uap, buf);
1023 SCARG(&ap, nbyte) = SCARG(uap, nbyte);
1024 SCARG(&ap, offset) = (SCARG(uap, offsetlo)
1025 | ((off_t)SCARG(uap, offsethi) << 32));
1026 return (pread(td, &ap));
1030 ia32_pwrite(struct thread *td, struct ia32_pwrite_args *uap)
1032 struct pwrite_args ap;
1034 SCARG(&ap, fd) = SCARG(uap, fd);
1035 SCARG(&ap, buf) = SCARG(uap, buf);
1036 SCARG(&ap, nbyte) = SCARG(uap, nbyte);
1037 SCARG(&ap, offset) = (SCARG(uap, offsetlo)
1038 | ((off_t)SCARG(uap, offsethi) << 32));
1039 return (pwrite(td, &ap));
1043 ia32_lseek(struct thread *td, struct ia32_lseek_args *uap)
1046 struct lseek_args ap;
1049 SCARG(&ap, fd) = SCARG(uap, fd);
1050 SCARG(&ap, offset) = (SCARG(uap, offsetlo)
1051 | ((off_t)SCARG(uap, offsethi) << 32));
1052 SCARG(&ap, whence) = SCARG(uap, whence);
1053 error = lseek(td, &ap);
1054 /* Expand the quad return into two parts for eax and edx */
1055 pos = *(off_t *)(td->td_retval);
1056 td->td_retval[0] = pos & 0xffffffff; /* %eax */
1057 td->td_retval[1] = pos >> 32; /* %edx */
1062 ia32_truncate(struct thread *td, struct ia32_truncate_args *uap)
1064 struct truncate_args ap;
1066 SCARG(&ap, path) = SCARG(uap, path);
1067 SCARG(&ap, length) = (SCARG(uap, lengthlo)
1068 | ((off_t)SCARG(uap, lengthhi) << 32));
1069 return (truncate(td, &ap));
1073 ia32_ftruncate(struct thread *td, struct ia32_ftruncate_args *uap)
1075 struct ftruncate_args ap;
1077 SCARG(&ap, fd) = SCARG(uap, fd);
1078 SCARG(&ap, length) = (SCARG(uap, lengthlo)
1079 | ((off_t)SCARG(uap, lengthhi) << 32));
1080 return (ftruncate(td, &ap));
1084 ia32_sendfile(struct thread *td, struct ia32_sendfile_args *uap)
1086 struct sendfile_args ap;
1088 SCARG(&ap, fd) = SCARG(uap, fd);
1089 SCARG(&ap, s) = SCARG(uap, s);
1090 SCARG(&ap, offset) = (SCARG(uap, offsetlo)
1091 | ((off_t)SCARG(uap, offsethi) << 32));
1092 SCARG(&ap, nbytes) = SCARG(uap, nbytes); /* XXX check */
1093 SCARG(&ap, hdtr) = SCARG(uap, hdtr); /* XXX check */
1094 SCARG(&ap, sbytes) = SCARG(uap, sbytes); /* XXX FIXME!! */
1095 SCARG(&ap, flags) = SCARG(uap, flags);
1096 return (sendfile(td, &ap));
1107 struct timespec32 st_atimespec;
1108 struct timespec32 st_mtimespec;
1109 struct timespec32 st_ctimespec;
1112 u_int32_t st_blksize;
1118 copy_stat( struct stat *in, struct stat32 *out)
1120 CP(*in, *out, st_dev);
1121 CP(*in, *out, st_ino);
1122 CP(*in, *out, st_mode);
1123 CP(*in, *out, st_nlink);
1124 CP(*in, *out, st_uid);
1125 CP(*in, *out, st_gid);
1126 CP(*in, *out, st_rdev);
1127 TS_CP(*in, *out, st_atimespec);
1128 TS_CP(*in, *out, st_mtimespec);
1129 TS_CP(*in, *out, st_ctimespec);
1130 CP(*in, *out, st_size);
1131 CP(*in, *out, st_blocks);
1132 CP(*in, *out, st_blksize);
1133 CP(*in, *out, st_flags);
1134 CP(*in, *out, st_gen);
1138 ia32_stat(struct thread *td, struct ia32_stat_args *uap)
1142 struct stat32 *p32, s32;
1143 struct stat *p = NULL, s;
1145 p32 = SCARG(uap, ub);
1147 sg = stackgap_init();
1148 p = stackgap_alloc(&sg, sizeof(struct stat));
1149 SCARG(uap, ub) = (struct stat32 *)p;
1151 error = stat(td, (struct stat_args *) uap);
1155 error = copyin(p, &s, sizeof(s));
1158 copy_stat(&s, &s32);
1159 error = copyout(&s32, p32, sizeof(s32));
1165 ia32_fstat(struct thread *td, struct ia32_fstat_args *uap)
1169 struct stat32 *p32, s32;
1170 struct stat *p = NULL, s;
1172 p32 = SCARG(uap, ub);
1174 sg = stackgap_init();
1175 p = stackgap_alloc(&sg, sizeof(struct stat));
1176 SCARG(uap, ub) = (struct stat32 *)p;
1178 error = fstat(td, (struct fstat_args *) uap);
1182 error = copyin(p, &s, sizeof(s));
1185 copy_stat(&s, &s32);
1186 error = copyout(&s32, p32, sizeof(s32));
1192 ia32_lstat(struct thread *td, struct ia32_lstat_args *uap)
1196 struct stat32 *p32, s32;
1197 struct stat *p = NULL, s;
1199 p32 = SCARG(uap, ub);
1201 sg = stackgap_init();
1202 p = stackgap_alloc(&sg, sizeof(struct stat));
1203 SCARG(uap, ub) = (struct stat32 *)p;
1205 error = lstat(td, (struct lstat_args *) uap);
1209 error = copyin(p, &s, sizeof(s));
1212 copy_stat(&s, &s32);
1213 error = copyout(&s32, p32, sizeof(s32));
1222 ia32_sysctl(struct thread *td, struct ia32_sysctl_args *uap)
1224 int error, name[CTL_MAXNAME];
1227 if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
1230 error = copyin(uap->name, &name, uap->namelen * sizeof(int));
1237 oldlen = fuword32(uap->oldlenp);
1240 error = userland_sysctl(td, name, uap->namelen,
1241 uap->old, &oldlen, 1,
1242 uap->new, uap->newlen, &j);
1243 if (error && error != ENOMEM)
1246 suword32(uap->oldlenp, j);
1253 struct sigaction32 {
1260 ia32_sigaction(struct thread *td, struct ia32_sigaction_args *uap)
1264 struct sigaction32 *p32, *op32, s32;
1265 struct sigaction *p = NULL, *op = NULL, s;
1267 p32 = SCARG(uap, act);
1269 sg = stackgap_init();
1270 p = stackgap_alloc(&sg, sizeof(struct sigaction));
1271 SCARG(uap, act) = (struct sigaction32 *)p;
1272 error = copyin(p32, &s32, sizeof(s32));
1275 s.sa_handler = PTRIN(s32.sa_u);
1276 CP(s32, s, sa_flags);
1277 CP(s32, s, sa_mask);
1278 error = copyout(&s, p, sizeof(s));
1282 op32 = SCARG(uap, oact);
1284 sg = stackgap_init();
1285 op = stackgap_alloc(&sg, sizeof(struct sigaction));
1286 SCARG(uap, oact) = (struct sigaction32 *)op;
1288 error = sigaction(td, (struct sigaction_args *) uap);
1292 error = copyin(op, &s, sizeof(s));
1295 s32.sa_u = PTROUT(s.sa_handler);
1296 CP(s, s32, sa_flags);
1297 CP(s, s32, sa_mask);
1298 error = copyout(&s32, op32, sizeof(s32));
1306 ia32_xxx(struct thread *td, struct ia32_xxx_args *uap)
1310 struct yyy32 *p32, s32;
1311 struct yyy *p = NULL, s;
1313 p32 = SCARG(uap, zzz);
1315 sg = stackgap_init();
1316 p = stackgap_alloc(&sg, sizeof(struct yyy));
1317 SCARG(uap, zzz) = (struct yyy32 *)p;
1318 error = copyin(p32, &s32, sizeof(s32));
1322 error = copyout(&s, p, sizeof(s));
1326 error = xxx(td, (struct xxx_args *) uap);
1330 error = copyin(p, &s, sizeof(s));
1334 error = copyout(&s32, p32, sizeof(s32));