2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * SVR4 compatibility module.
31 * SVR4 system calls that are implemented differently in BSD are
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/dirent.h>
41 #include <sys/fcntl.h>
42 #include <sys/filedesc.h>
43 #include <sys/imgact.h>
44 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/file.h> /* Must come after sys/malloc.h */
49 #include <sys/mount.h>
51 #include <sys/mutex.h>
52 #include <sys/namei.h>
55 #include <sys/ptrace.h>
56 #include <sys/resource.h>
57 #include <sys/resourcevar.h>
59 #include <sys/signalvar.h>
62 #include <sys/syscallsubr.h>
63 #include <sys/sysproto.h>
65 #include <sys/times.h>
67 #include <sys/vnode.h>
70 #include <compat/svr4/svr4.h>
71 #include <compat/svr4/svr4_types.h>
72 #include <compat/svr4/svr4_signal.h>
73 #include <compat/svr4/svr4_proto.h>
74 #include <compat/svr4/svr4_util.h>
75 #include <compat/svr4/svr4_sysconfig.h>
76 #include <compat/svr4/svr4_dirent.h>
77 #include <compat/svr4/svr4_acl.h>
78 #include <compat/svr4/svr4_ulimit.h>
79 #include <compat/svr4/svr4_statvfs.h>
80 #include <compat/svr4/svr4_hrt.h>
81 #include <compat/svr4/svr4_mman.h>
82 #include <compat/svr4/svr4_wait.h>
84 #include <security/mac/mac_framework.h>
86 #include <machine/vmparam.h>
88 #include <vm/vm_param.h>
89 #include <vm/vm_map.h>
90 #if defined(__FreeBSD__)
92 #include <vm/vm_extern.h>
97 # include <uvm/uvm_extern.h>
101 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
103 static int svr4_mknod(struct thread *, register_t *, char *,
104 svr4_mode_t, svr4_dev_t);
106 static __inline clock_t timeval_to_clock_t(struct timeval *);
107 static int svr4_setinfo (pid_t , struct rusage *, int, svr4_siginfo_t *);
109 struct svr4_hrtcntl_args;
110 static int svr4_hrtcntl (struct thread *, struct svr4_hrtcntl_args *,
112 static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
113 struct svr4_statvfs *);
114 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
115 struct svr4_statvfs64 *);
116 static struct proc *svr4_pfind(pid_t pid);
121 svr4_sys_setitimer(td, uap)
123 struct svr4_sys_setitimer_args *uap;
125 td->td_retval[0] = 0;
131 svr4_sys_wait(td, uap)
133 struct svr4_sys_wait_args *uap;
137 error = kern_wait(td, WAIT_ANY, &st, 0, NULL);
141 if (WIFSIGNALED(st)) {
143 if (sig >= 0 && sig < NSIG)
144 st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig);
145 } else if (WIFSTOPPED(st)) {
147 if (sig >= 0 && sig < NSIG)
148 st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8);
152 * It looks like wait(2) on svr4/solaris/2.4 returns
153 * the status in retval[1], and the pid on retval[0].
155 td->td_retval[1] = st;
158 error = copyout(&st, uap->status, sizeof(st));
164 svr4_sys_execv(td, uap)
166 struct svr4_sys_execv_args *uap;
168 struct image_args eargs;
172 CHECKALTEXIST(td, uap->path, &path);
174 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
177 error = kern_execve(td, &eargs, NULL);
182 svr4_sys_execve(td, uap)
184 struct svr4_sys_execve_args *uap;
186 struct image_args eargs;
190 CHECKALTEXIST(td, uap->path, &path);
192 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
196 error = kern_execve(td, &eargs, NULL);
203 struct svr4_sys_time_args *v;
205 struct svr4_sys_time_args *uap = v;
211 error = copyout(&tv.tv_sec, uap->t,
213 td->td_retval[0] = (int) tv.tv_sec;
220 * Read SVR4-style directory entries. We suck them into kernel space so
221 * that they can be massaged before being copied out to user code.
223 * This code is ported from the Linux emulator: Changes to the VFS interface
224 * between FreeBSD and NetBSD have made it simpler to port it from there than
225 * to adapt the NetBSD version.
228 svr4_sys_getdents64(td, uap)
230 struct svr4_sys_getdents64_args *uap;
234 caddr_t inp, buf; /* BSD-format */
235 int len, reclen; /* BSD-format */
236 caddr_t outp; /* SVR4-format */
237 int resid, svr4reclen=0; /* SVR4-format */
242 struct svr4_dirent64 svr4_dirent;
243 int buflen, error, eofflag, nbytes, justone, vfslocked;
244 u_long *cookies = NULL, *cookiep;
247 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
248 uap->fd, uap->nbytes));
249 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) {
253 if ((fp->f_flag & FREAD) == 0) {
259 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
260 if (vp->v_type != VDIR) {
261 VFS_UNLOCK_GIANT(vfslocked);
266 nbytes = uap->nbytes;
268 nbytes = sizeof (struct svr4_dirent64);
275 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
276 buflen = max(DIRBLKSIZ, nbytes);
277 buflen = min(buflen, MAXBSIZE);
278 buf = malloc(buflen, M_TEMP, M_WAITOK);
279 vn_lock(vp, LK_SHARED | LK_RETRY);
282 aiov.iov_len = buflen;
283 auio.uio_iov = &aiov;
285 auio.uio_rw = UIO_READ;
286 auio.uio_segflg = UIO_SYSSPACE;
288 auio.uio_resid = buflen;
289 auio.uio_offset = off;
292 free(cookies, M_TEMP);
297 error = mac_vnode_check_readdir(td->td_ucred, vp);
302 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
303 &ncookies, &cookies);
309 outp = (caddr_t) uap->dp;
311 if ((len = buflen - auio.uio_resid) <= 0) {
319 * When using cookies, the vfs has the option of reading from
320 * a different offset than that supplied (UFS truncates the
321 * offset to a block boundary to make sure that it never reads
322 * partway through a directory entry, even if the directory
323 * has been compacted).
325 while (len > 0 && ncookies > 0 && *cookiep <= off) {
326 bdp = (struct dirent *) inp;
327 len -= bdp->d_reclen;
328 inp += bdp->d_reclen;
335 if (cookiep && ncookies == 0)
337 bdp = (struct dirent *) inp;
338 reclen = bdp->d_reclen;
340 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
345 if (bdp->d_fileno == 0) {
355 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
356 if (reclen > len || resid < svr4reclen) {
360 svr4_dirent.d_ino = (long) bdp->d_fileno;
363 * old svr4-style readdir usage.
365 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
366 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
368 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
369 svr4_dirent.d_reclen = (u_short) svr4reclen;
371 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name));
372 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
387 if (outp == (caddr_t) uap->dp)
392 nbytes = resid + svr4reclen;
395 td->td_retval[0] = nbytes - resid;
398 VFS_UNLOCK_GIANT(vfslocked);
401 free(cookies, M_TEMP);
408 svr4_sys_getdents(td, uap)
410 struct svr4_sys_getdents_args *uap;
414 caddr_t inp, buf; /* BSD-format */
415 int len, reclen; /* BSD-format */
416 caddr_t outp; /* SVR4-format */
417 int resid, svr4_reclen; /* SVR4-format */
421 struct svr4_dirent idb;
422 off_t off; /* true file offset */
423 int buflen, error, eofflag, vfslocked;
424 u_long *cookiebuf = NULL, *cookie;
425 int ncookies = 0, *retval = td->td_retval;
430 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
433 if ((fp->f_flag & FREAD) == 0) {
439 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
440 if (vp->v_type != VDIR) {
441 VFS_UNLOCK_GIANT(vfslocked);
446 buflen = min(MAXBSIZE, uap->nbytes);
447 buf = malloc(buflen, M_TEMP, M_WAITOK);
448 vn_lock(vp, LK_SHARED | LK_RETRY);
452 aiov.iov_len = buflen;
453 auio.uio_iov = &aiov;
455 auio.uio_rw = UIO_READ;
456 auio.uio_segflg = UIO_SYSSPACE;
458 auio.uio_resid = buflen;
459 auio.uio_offset = off;
462 error = mac_vnode_check_readdir(td->td_ucred, vp);
468 * First we read into the malloc'ed buffer, then
469 * we massage it into user space, one record at a time.
471 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
480 if ((len = buflen - auio.uio_resid) == 0)
483 for (cookie = cookiebuf; len > 0; len -= reclen) {
484 bdp = (struct dirent *)inp;
485 reclen = bdp->d_reclen;
487 panic("svr4_sys_getdents64: bad reclen");
489 off = *cookie++; /* each entry points to the next */
492 if ((off >> 32) != 0) {
493 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
497 if (bdp->d_fileno == 0) {
498 inp += reclen; /* it is a hole; squish it out */
501 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
502 if (reclen > len || resid < svr4_reclen) {
503 /* entry too big for buffer, so just stop */
508 * Massage in place to make a SVR4-shaped dirent (otherwise
509 * we have to worry about touching user memory outside of
510 * the copyout() call).
512 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
513 idb.d_off = (svr4_off_t)off;
514 idb.d_reclen = (u_short)svr4_reclen;
515 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
516 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
518 /* advance past this real entry */
520 /* advance output past SVR4-shaped entry */
522 resid -= svr4_reclen;
525 /* if we squished out the whole block, try again */
526 if (outp == uap->buf)
528 fp->f_offset = off; /* update the vnode offset */
531 *retval = uap->nbytes - resid;
534 VFS_UNLOCK_GIANT(vfslocked);
537 free(cookiebuf, M_TEMP);
544 svr4_sys_mmap(td, uap)
546 struct svr4_sys_mmap_args *uap;
551 retval = td->td_retval;
552 #define _MAP_NEW 0x80000000
554 * Verify the arguments.
556 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
557 return EINVAL; /* XXX still needed? */
564 mm.flags = uap->flags & ~_MAP_NEW;
569 return mmap(td, &mm);
573 svr4_sys_mmap64(td, uap)
575 struct svr4_sys_mmap64_args *uap;
580 #define _MAP_NEW 0x80000000
582 * Verify the arguments.
584 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
585 return EINVAL; /* XXX still needed? */
592 mm.flags = uap->flags & ~_MAP_NEW;
597 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
598 if ((mm.flags & MAP_FIXED) == 0 &&
599 mm.addr != 0 && (void *)mm.addr < rp)
602 return mmap(td, &mm);
607 svr4_sys_fchroot(td, uap)
609 struct svr4_sys_fchroot_args *uap;
611 struct filedesc *fdp = td->td_proc->p_fd;
614 int error, vfslocked;
616 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
618 if ((error = getvnode(fdp, uap->fd, &fp)) != 0)
623 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
624 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
625 error = change_dir(vp, td);
629 error = mac_vnode_check_chroot(td->td_ucred, vp);
634 error = change_root(vp, td);
636 VFS_UNLOCK_GIANT(vfslocked);
640 VFS_UNLOCK_GIANT(vfslocked);
646 svr4_mknod(td, retval, path, mode, dev)
656 CHECKALTEXIST(td, path, &newpath);
659 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
661 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
662 free(newpath, M_TEMP);
668 svr4_sys_mknod(td, uap)
670 struct svr4_sys_mknod_args *uap;
672 int *retval = td->td_retval;
673 return svr4_mknod(td, retval,
674 uap->path, uap->mode,
675 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev));
680 svr4_sys_xmknod(td, uap)
682 struct svr4_sys_xmknod_args *uap;
684 int *retval = td->td_retval;
685 return svr4_mknod(td, retval,
686 uap->path, uap->mode,
687 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
692 svr4_sys_vhangup(td, uap)
694 struct svr4_sys_vhangup_args *uap;
701 svr4_sys_sysconfig(td, uap)
703 struct svr4_sys_sysconfig_args *uap;
707 retval = &(td->td_retval[0]);
710 case SVR4_CONFIG_NGROUPS:
711 *retval = ngroups_max;
713 case SVR4_CONFIG_CHILD_MAX:
716 case SVR4_CONFIG_OPEN_FILES:
719 case SVR4_CONFIG_POSIX_VER:
722 case SVR4_CONFIG_PAGESIZE:
725 case SVR4_CONFIG_CLK_TCK:
726 *retval = 60; /* should this be `hz', ie. 100? */
728 case SVR4_CONFIG_XOPEN_VER:
729 *retval = 2; /* XXX: What should that be? */
731 case SVR4_CONFIG_PROF_TCK:
732 *retval = 60; /* XXX: What should that be? */
734 case SVR4_CONFIG_NPROC_CONF:
735 *retval = 1; /* Only one processor for now */
737 case SVR4_CONFIG_NPROC_ONLN:
738 *retval = 1; /* And it better be online */
740 case SVR4_CONFIG_AIO_LISTIO_MAX:
741 case SVR4_CONFIG_AIO_MAX:
742 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
743 *retval = 0; /* No aio support */
745 case SVR4_CONFIG_DELAYTIMER_MAX:
746 *retval = 0; /* No delaytimer support */
748 case SVR4_CONFIG_MQ_OPEN_MAX:
749 *retval = msginfo.msgmni;
751 case SVR4_CONFIG_MQ_PRIO_MAX:
752 *retval = 0; /* XXX: Don't know */
754 case SVR4_CONFIG_RTSIG_MAX:
757 case SVR4_CONFIG_SEM_NSEMS_MAX:
758 *retval = seminfo.semmni;
760 case SVR4_CONFIG_SEM_VALUE_MAX:
761 *retval = seminfo.semvmx;
763 case SVR4_CONFIG_SIGQUEUE_MAX:
764 *retval = 0; /* XXX: Don't know */
766 case SVR4_CONFIG_SIGRT_MIN:
767 case SVR4_CONFIG_SIGRT_MAX:
768 *retval = 0; /* No real time signals */
770 case SVR4_CONFIG_TIMER_MAX:
771 *retval = 3; /* XXX: real, virtual, profiling */
774 case SVR4_CONFIG_PHYS_PAGES:
776 *retval = uvmexp.free; /* XXX: free instead of total */
778 *retval = cnt.v_free_count; /* XXX: free instead of total */
781 case SVR4_CONFIG_AVPHYS_PAGES:
783 *retval = uvmexp.active; /* XXX: active instead of avg */
785 *retval = cnt.v_active_count; /* XXX: active instead of avg */
789 case SVR4_CONFIG_COHERENCY:
790 *retval = 0; /* XXX */
792 case SVR4_CONFIG_SPLIT_CACHE:
793 *retval = 0; /* XXX */
795 case SVR4_CONFIG_ICACHESZ:
796 *retval = 256; /* XXX */
798 case SVR4_CONFIG_DCACHESZ:
799 *retval = 256; /* XXX */
801 case SVR4_CONFIG_ICACHELINESZ:
802 *retval = 64; /* XXX */
804 case SVR4_CONFIG_DCACHELINESZ:
805 *retval = 64; /* XXX */
807 case SVR4_CONFIG_ICACHEBLKSZ:
808 *retval = 64; /* XXX */
810 case SVR4_CONFIG_DCACHEBLKSZ:
811 *retval = 64; /* XXX */
813 case SVR4_CONFIG_DCACHETBLKSZ:
814 *retval = 64; /* XXX */
816 case SVR4_CONFIG_ICACHE_ASSOC:
817 *retval = 1; /* XXX */
819 case SVR4_CONFIG_DCACHE_ASSOC:
820 *retval = 1; /* XXX */
822 case SVR4_CONFIG_MAXPID:
825 case SVR4_CONFIG_STACK_PROT:
826 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
836 svr4_sys_break(td, uap)
838 struct svr4_sys_break_args *uap;
840 struct obreak_args ap;
842 ap.nsize = uap->nsize;
843 return (obreak(td, &ap));
846 static __inline clock_t
847 timeval_to_clock_t(tv)
850 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
855 svr4_sys_times(td, uap)
857 struct svr4_sys_times_args *uap;
859 struct timeval tv, utime, stime, cutime, cstime;
867 calcru(p, &utime, &stime);
869 calccru(p, &cutime, &cstime);
872 tms.tms_utime = timeval_to_clock_t(&utime);
873 tms.tms_stime = timeval_to_clock_t(&stime);
875 tms.tms_cutime = timeval_to_clock_t(&cutime);
876 tms.tms_cstime = timeval_to_clock_t(&cstime);
878 error = copyout(&tms, uap->tp, sizeof(tms));
883 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
889 svr4_sys_ulimit(td, uap)
891 struct svr4_sys_ulimit_args *uap;
893 int *retval = td->td_retval;
898 PROC_LOCK(td->td_proc);
899 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
900 PROC_UNLOCK(td->td_proc);
902 *retval = 0x7fffffff;
909 krl.rlim_cur = uap->newlimit * 512;
910 PROC_LOCK(td->td_proc);
911 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
912 PROC_UNLOCK(td->td_proc);
914 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
918 PROC_LOCK(td->td_proc);
919 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
920 PROC_UNLOCK(td->td_proc);
922 *retval = 0x7fffffff;
928 struct vmspace *vm = td->td_proc->p_vmspace;
931 PROC_LOCK(td->td_proc);
932 r = lim_cur(td->td_proc, RLIMIT_DATA);
933 PROC_UNLOCK(td->td_proc);
937 r += (long) vm->vm_daddr;
945 PROC_LOCK(td->td_proc);
946 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
947 PROC_UNLOCK(td->td_proc);
949 *retval = 0x7fffffff;
963 /* look in the live processes */
964 if ((p = pfind(pid)) == NULL)
965 /* look in the zombies */
973 svr4_sys_pgrpsys(td, uap)
975 struct svr4_sys_pgrpsys_args *uap;
977 int *retval = td->td_retval;
978 struct proc *p = td->td_proc;
981 case 1: /* setpgrp() */
983 * SVR4 setpgrp() (which takes no arguments) has the
984 * semantics that the session ID is also created anew, so
985 * in almost every sense, setpgrp() is identical to
986 * setsid() for SVR4. (Under BSD, the difference is that
987 * a setpgid(0,0) will not create a new session.)
992 case 0: /* getpgrp() */
994 *retval = p->p_pgrp->pg_id;
998 case 2: /* getsid(pid) */
1001 else if ((p = svr4_pfind(uap->pid)) == NULL)
1004 * This has already been initialized to the pid of
1005 * the session leader.
1007 *retval = (register_t) p->p_session->s_sid;
1011 case 3: /* setsid() */
1012 return setsid(td, NULL);
1014 case 4: /* getpgid(pid) */
1018 else if ((p = svr4_pfind(uap->pid)) == NULL)
1021 *retval = (int) p->p_pgrp->pg_id;
1025 case 5: /* setpgid(pid, pgid); */
1027 struct setpgid_args sa;
1030 sa.pgid = uap->pgid;
1031 return setpgid(td, &sa);
1039 struct svr4_hrtcntl_args {
1043 svr4_hrt_interval_t * iv;
1044 svr4_hrt_time_t * ti;
1049 svr4_hrtcntl(td, uap, retval)
1051 struct svr4_hrtcntl_args *uap;
1055 case SVR4_HRT_CNTL_RES:
1056 DPRINTF(("htrcntl(RES)\n"));
1057 *retval = SVR4_HRT_USEC;
1060 case SVR4_HRT_CNTL_TOFD:
1061 DPRINTF(("htrcntl(TOFD)\n"));
1065 if (uap->clk != SVR4_HRT_CLK_STD) {
1066 DPRINTF(("clk == %d\n", uap->clk));
1069 if (uap->ti == NULL) {
1070 DPRINTF(("ti NULL\n"));
1074 t.h_sec = tv.tv_sec;
1075 t.h_rem = tv.tv_usec;
1076 t.h_res = SVR4_HRT_USEC;
1077 return copyout(&t, uap->ti, sizeof(t));
1080 case SVR4_HRT_CNTL_START:
1081 DPRINTF(("htrcntl(START)\n"));
1084 case SVR4_HRT_CNTL_GET:
1085 DPRINTF(("htrcntl(GET)\n"));
1088 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1095 svr4_sys_hrtsys(td, uap)
1097 struct svr4_sys_hrtsys_args *uap;
1099 int *retval = td->td_retval;
1103 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1107 DPRINTF(("hrtalarm\n"));
1111 DPRINTF(("hrtsleep\n"));
1115 DPRINTF(("hrtcancel\n"));
1119 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1126 svr4_setinfo(pid, ru, st, s)
1135 memset(&i, 0, sizeof(i));
1137 i.svr4_si_signo = SVR4_SIGCHLD;
1138 i.svr4_si_errno = 0; /* XXX? */
1140 i.svr4_si_pid = pid;
1142 i.svr4_si_stime = ru->ru_stime.tv_sec;
1143 i.svr4_si_utime = ru->ru_utime.tv_sec;
1146 if (WIFEXITED(st)) {
1147 i.svr4_si_status = WEXITSTATUS(st);
1148 i.svr4_si_code = SVR4_CLD_EXITED;
1149 } else if (WIFSTOPPED(st)) {
1151 if (sig >= 0 && sig < NSIG)
1152 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1154 if (i.svr4_si_status == SVR4_SIGCONT)
1155 i.svr4_si_code = SVR4_CLD_CONTINUED;
1157 i.svr4_si_code = SVR4_CLD_STOPPED;
1160 if (sig >= 0 && sig < NSIG)
1161 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1164 i.svr4_si_code = SVR4_CLD_DUMPED;
1166 i.svr4_si_code = SVR4_CLD_KILLED;
1169 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1170 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1173 return copyout(&i, s, sizeof(i));
1178 svr4_sys_waitsys(td, uap)
1180 struct svr4_sys_waitsys_args *uap;
1185 int error, *retval = td->td_retval;
1188 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1190 uap->info, uap->options));
1212 /* Hand off the easy cases to kern_wait(). */
1213 if (!(uap->options & (SVR4_WNOWAIT)) &&
1214 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1218 if (uap->options & SVR4_WSTOPPED)
1219 options |= WUNTRACED;
1220 if (uap->options & SVR4_WCONTINUED)
1221 options |= WCONTINUED;
1222 if (uap->options & SVR4_WNOHANG)
1225 error = kern_wait(td, pid, &status, options, &ru);
1228 if (uap->options & SVR4_WNOHANG && *retval == 0)
1229 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1231 error = svr4_setinfo(*retval, &ru, status, uap->info);
1237 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1238 * just want to see if there is a process to harvest, we don't
1239 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1240 * meaning we want to ignore zombies. Either way, we don't have
1241 * to handle harvesting zombies here. We do have to duplicate the
1242 * other portions of kern_wait() though, especially for WCONTINUED
1247 sx_slock(&proctree_lock);
1248 LIST_FOREACH(p, &q->p_children, p_sibling) {
1250 if (pid != WAIT_ANY &&
1251 p->p_pid != pid && p->p_pgid != -pid) {
1253 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1257 if (p_canwait(td, p)) {
1266 * See if we have a zombie. If so, WNOWAIT should be set,
1267 * as otherwise we should have called kern_wait() up above.
1269 if ((p->p_state == PRS_ZOMBIE) &&
1270 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1272 KASSERT(uap->options & SVR4_WNOWAIT,
1273 ("WNOWAIT is clear"));
1275 /* Found a zombie, so cache info in local variables. */
1277 status = p->p_xstat;
1280 calcru(p, &ru.ru_utime, &ru.ru_stime);
1283 sx_sunlock(&proctree_lock);
1285 /* Copy the info out to userland. */
1287 DPRINTF(("found %d\n", pid));
1288 return (svr4_setinfo(pid, &ru, status, uap->info));
1292 * See if we have a stopped or continued process.
1293 * XXX: This duplicates the same code in kern_wait().
1295 if ((p->p_flag & P_STOPPED_SIG) &&
1296 (p->p_suspcount == p->p_numthreads) &&
1297 (p->p_flag & P_WAITED) == 0 &&
1298 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1300 if (((uap->options & SVR4_WNOWAIT)) == 0)
1301 p->p_flag |= P_WAITED;
1302 sx_sunlock(&proctree_lock);
1304 status = W_STOPCODE(p->p_xstat);
1307 calcru(p, &ru.ru_utime, &ru.ru_stime);
1311 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1313 sigqueue_take(p->p_ksi);
1318 DPRINTF(("jobcontrol %d\n", pid));
1319 return (svr4_setinfo(pid, &ru, status, uap->info));
1322 if (uap->options & SVR4_WCONTINUED &&
1323 (p->p_flag & P_CONTINUED)) {
1324 sx_sunlock(&proctree_lock);
1325 if (((uap->options & SVR4_WNOWAIT)) == 0)
1326 p->p_flag &= ~P_CONTINUED;
1331 calcru(p, &ru.ru_utime, &ru.ru_stime);
1335 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1337 sigqueue_take(p->p_ksi);
1342 DPRINTF(("jobcontrol %d\n", pid));
1343 return (svr4_setinfo(pid, &ru, status, uap->info));
1349 sx_sunlock(&proctree_lock);
1353 if (uap->options & SVR4_WNOHANG) {
1354 sx_sunlock(&proctree_lock);
1356 return (svr4_setinfo(0, NULL, 0, uap->info));
1360 sx_sunlock(&proctree_lock);
1361 if (q->p_flag & P_STATCHILD) {
1362 q->p_flag &= ~P_STATCHILD;
1365 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1374 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1375 const struct statfs *bfs;
1376 struct svr4_statvfs *sfs;
1378 sfs->f_bsize = bfs->f_iosize; /* XXX */
1379 sfs->f_frsize = bfs->f_bsize;
1380 sfs->f_blocks = bfs->f_blocks;
1381 sfs->f_bfree = bfs->f_bfree;
1382 sfs->f_bavail = bfs->f_bavail;
1383 sfs->f_files = bfs->f_files;
1384 sfs->f_ffree = bfs->f_ffree;
1385 sfs->f_favail = bfs->f_ffree;
1386 sfs->f_fsid = bfs->f_fsid.val[0];
1387 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1389 if (bfs->f_flags & MNT_RDONLY)
1390 sfs->f_flag |= SVR4_ST_RDONLY;
1391 if (bfs->f_flags & MNT_NOSUID)
1392 sfs->f_flag |= SVR4_ST_NOSUID;
1393 sfs->f_namemax = MAXNAMLEN;
1394 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1395 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1400 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1401 const struct statfs *bfs;
1402 struct svr4_statvfs64 *sfs;
1404 sfs->f_bsize = bfs->f_iosize; /* XXX */
1405 sfs->f_frsize = bfs->f_bsize;
1406 sfs->f_blocks = bfs->f_blocks;
1407 sfs->f_bfree = bfs->f_bfree;
1408 sfs->f_bavail = bfs->f_bavail;
1409 sfs->f_files = bfs->f_files;
1410 sfs->f_ffree = bfs->f_ffree;
1411 sfs->f_favail = bfs->f_ffree;
1412 sfs->f_fsid = bfs->f_fsid.val[0];
1413 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1415 if (bfs->f_flags & MNT_RDONLY)
1416 sfs->f_flag |= SVR4_ST_RDONLY;
1417 if (bfs->f_flags & MNT_NOSUID)
1418 sfs->f_flag |= SVR4_ST_NOSUID;
1419 sfs->f_namemax = MAXNAMLEN;
1420 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1421 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1426 svr4_sys_statvfs(td, uap)
1428 struct svr4_sys_statvfs_args *uap;
1430 struct svr4_statvfs sfs;
1435 CHECKALTEXIST(td, uap->path, &path);
1437 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1441 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1442 return copyout(&sfs, uap->fs, sizeof(sfs));
1447 svr4_sys_fstatvfs(td, uap)
1449 struct svr4_sys_fstatvfs_args *uap;
1451 struct svr4_statvfs sfs;
1455 error = kern_fstatfs(td, uap->fd, &bfs);
1458 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1459 return copyout(&sfs, uap->fs, sizeof(sfs));
1464 svr4_sys_statvfs64(td, uap)
1466 struct svr4_sys_statvfs64_args *uap;
1468 struct svr4_statvfs64 sfs;
1473 CHECKALTEXIST(td, uap->path, &path);
1475 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1479 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1480 return copyout(&sfs, uap->fs, sizeof(sfs));
1485 svr4_sys_fstatvfs64(td, uap)
1487 struct svr4_sys_fstatvfs64_args *uap;
1489 struct svr4_statvfs64 sfs;
1493 error = kern_fstatfs(td, uap->fd, &bfs);
1496 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1497 return copyout(&sfs, uap->fs, sizeof(sfs));
1501 svr4_sys_alarm(td, uap)
1503 struct svr4_sys_alarm_args *uap;
1505 struct itimerval itv, oitv;
1508 timevalclear(&itv.it_interval);
1509 itv.it_value.tv_sec = uap->sec;
1510 itv.it_value.tv_usec = 0;
1511 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1514 if (oitv.it_value.tv_usec != 0)
1515 oitv.it_value.tv_sec++;
1516 td->td_retval[0] = oitv.it_value.tv_sec;
1521 svr4_sys_gettimeofday(td, uap)
1523 struct svr4_sys_gettimeofday_args *uap;
1529 return copyout(&atv, uap->tp, sizeof (atv));
1536 svr4_sys_facl(td, uap)
1538 struct svr4_sys_facl_args *uap;
1542 retval = td->td_retval;
1546 case SVR4_SYS_SETACL:
1547 /* We don't support acls on any filesystem */
1550 case SVR4_SYS_GETACL:
1551 return copyout(retval, &uap->num,
1554 case SVR4_SYS_GETACLCNT:
1564 svr4_sys_acl(td, uap)
1566 struct svr4_sys_acl_args *uap;
1568 /* XXX: for now the same */
1569 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1573 svr4_sys_auditsys(td, uap)
1575 struct svr4_sys_auditsys_args *uap;
1578 * XXX: Big brother is *not* watching.
1584 svr4_sys_memcntl(td, uap)
1586 struct svr4_sys_memcntl_args *uap;
1591 struct msync_args msa;
1593 msa.addr = uap->addr;
1595 msa.flags = (int)uap->arg;
1597 return msync(td, &msa);
1599 case SVR4_MC_ADVISE:
1601 struct madvise_args maa;
1603 maa.addr = uap->addr;
1605 maa.behav = (int)uap->arg;
1607 return madvise(td, &maa);
1610 case SVR4_MC_UNLOCK:
1611 case SVR4_MC_LOCKAS:
1612 case SVR4_MC_UNLOCKAS:
1621 svr4_sys_nice(td, uap)
1623 struct svr4_sys_nice_args *uap;
1625 struct setpriority_args ap;
1628 ap.which = PRIO_PROCESS;
1630 ap.prio = uap->prio;
1632 if ((error = setpriority(td, &ap)) != 0)
1635 /* the cast is stupid, but the structures are the same */
1636 if ((error = getpriority(td, (struct getpriority_args *)&ap)) != 0)
1643 svr4_sys_resolvepath(td, uap)
1645 struct svr4_sys_resolvepath_args *uap;
1647 struct nameidata nd;
1648 int error, *retval = td->td_retval;
1651 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE,
1654 if ((error = namei(&nd)) != 0)
1656 NDFREE(&nd, NDF_NO_FREE_PNBUF);
1657 VFS_UNLOCK_GIANT(NDHASGIANT(&nd));
1659 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1660 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1665 NDFREE(&nd, NDF_ONLY_PNBUF);