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/capsicum.h>
41 #include <sys/dirent.h>
42 #include <sys/fcntl.h>
43 #include <sys/filedesc.h>
44 #include <sys/imgact.h>
45 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/file.h> /* Must come after sys/malloc.h */
50 #include <sys/mount.h>
52 #include <sys/mutex.h>
53 #include <sys/namei.h>
56 #include <sys/ptrace.h>
57 #include <sys/resource.h>
58 #include <sys/resourcevar.h>
60 #include <sys/signalvar.h>
63 #include <sys/syscallsubr.h>
64 #include <sys/sysproto.h>
66 #include <sys/times.h>
68 #include <sys/vnode.h>
71 #include <compat/svr4/svr4.h>
72 #include <compat/svr4/svr4_types.h>
73 #include <compat/svr4/svr4_signal.h>
74 #include <compat/svr4/svr4_proto.h>
75 #include <compat/svr4/svr4_util.h>
76 #include <compat/svr4/svr4_sysconfig.h>
77 #include <compat/svr4/svr4_dirent.h>
78 #include <compat/svr4/svr4_acl.h>
79 #include <compat/svr4/svr4_ulimit.h>
80 #include <compat/svr4/svr4_statvfs.h>
81 #include <compat/svr4/svr4_hrt.h>
82 #include <compat/svr4/svr4_mman.h>
83 #include <compat/svr4/svr4_wait.h>
85 #include <security/mac/mac_framework.h>
87 #include <machine/vmparam.h>
89 #include <vm/vm_param.h>
90 #include <vm/vm_map.h>
91 #if defined(__FreeBSD__)
93 #include <vm/vm_extern.h>
98 # include <uvm/uvm_extern.h>
102 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
104 static int svr4_mknod(struct thread *, register_t *, char *,
105 svr4_mode_t, svr4_dev_t);
107 static __inline clock_t timeval_to_clock_t(struct timeval *);
108 static int svr4_setinfo (pid_t , struct rusage *, int, svr4_siginfo_t *);
110 struct svr4_hrtcntl_args;
111 static int svr4_hrtcntl (struct thread *, struct svr4_hrtcntl_args *,
113 static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
114 struct svr4_statvfs *);
115 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
116 struct svr4_statvfs64 *);
117 static struct proc *svr4_pfind(pid_t pid);
122 svr4_sys_setitimer(td, uap)
124 struct svr4_sys_setitimer_args *uap;
126 td->td_retval[0] = 0;
132 svr4_sys_wait(td, uap)
134 struct svr4_sys_wait_args *uap;
138 error = kern_wait(td, WAIT_ANY, &st, 0, NULL);
142 if (WIFSIGNALED(st)) {
144 if (sig >= 0 && sig < NSIG)
145 st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig);
146 } else if (WIFSTOPPED(st)) {
148 if (sig >= 0 && sig < NSIG)
149 st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8);
153 * It looks like wait(2) on svr4/solaris/2.4 returns
154 * the status in retval[1], and the pid on retval[0].
156 td->td_retval[1] = st;
159 error = copyout(&st, uap->status, sizeof(st));
165 svr4_sys_execv(td, uap)
167 struct svr4_sys_execv_args *uap;
169 struct image_args eargs;
173 CHECKALTEXIST(td, uap->path, &path);
175 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
178 error = kern_execve(td, &eargs, NULL);
183 svr4_sys_execve(td, uap)
185 struct svr4_sys_execve_args *uap;
187 struct image_args eargs;
191 CHECKALTEXIST(td, uap->path, &path);
193 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
197 error = kern_execve(td, &eargs, NULL);
204 struct svr4_sys_time_args *v;
206 struct svr4_sys_time_args *uap = v;
212 error = copyout(&tv.tv_sec, uap->t,
214 td->td_retval[0] = (int) tv.tv_sec;
221 * Read SVR4-style directory entries. We suck them into kernel space so
222 * that they can be massaged before being copied out to user code.
224 * This code is ported from the Linux emulator: Changes to the VFS interface
225 * between FreeBSD and NetBSD have made it simpler to port it from there than
226 * to adapt the NetBSD version.
229 svr4_sys_getdents64(td, uap)
231 struct svr4_sys_getdents64_args *uap;
235 caddr_t inp, buf; /* BSD-format */
236 int len, reclen; /* BSD-format */
237 caddr_t outp; /* SVR4-format */
238 int resid, svr4reclen=0; /* SVR4-format */
244 struct svr4_dirent64 svr4_dirent;
245 int buflen, error, eofflag, nbytes, justone;
246 u_long *cookies = NULL, *cookiep;
249 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
250 uap->fd, uap->nbytes));
251 error = getvnode(td->td_proc->p_fd, uap->fd,
252 cap_rights_init(&rights, CAP_READ), &fp);
256 if ((fp->f_flag & FREAD) == 0) {
262 if (vp->v_type != VDIR) {
267 nbytes = uap->nbytes;
269 nbytes = sizeof (struct svr4_dirent64);
276 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
277 buflen = max(DIRBLKSIZ, nbytes);
278 buflen = min(buflen, MAXBSIZE);
279 buf = malloc(buflen, M_TEMP, M_WAITOK);
280 vn_lock(vp, LK_SHARED | LK_RETRY);
283 aiov.iov_len = buflen;
284 auio.uio_iov = &aiov;
286 auio.uio_rw = UIO_READ;
287 auio.uio_segflg = UIO_SYSSPACE;
289 auio.uio_resid = buflen;
290 auio.uio_offset = off;
293 free(cookies, M_TEMP);
298 error = mac_vnode_check_readdir(td->td_ucred, vp);
303 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
304 &ncookies, &cookies);
310 outp = (caddr_t) uap->dp;
312 if ((len = buflen - auio.uio_resid) <= 0) {
320 * When using cookies, the vfs has the option of reading from
321 * a different offset than that supplied (UFS truncates the
322 * offset to a block boundary to make sure that it never reads
323 * partway through a directory entry, even if the directory
324 * has been compacted).
326 while (len > 0 && ncookies > 0 && *cookiep <= off) {
327 bdp = (struct dirent *) inp;
328 len -= bdp->d_reclen;
329 inp += bdp->d_reclen;
336 if (cookiep && ncookies == 0)
338 bdp = (struct dirent *) inp;
339 reclen = bdp->d_reclen;
341 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
346 if (bdp->d_fileno == 0) {
356 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
357 if (reclen > len || resid < svr4reclen) {
361 svr4_dirent.d_ino = (long) bdp->d_fileno;
364 * old svr4-style readdir usage.
366 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
367 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
369 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
370 svr4_dirent.d_reclen = (u_short) svr4reclen;
372 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name));
373 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
388 if (outp == (caddr_t) uap->dp)
393 nbytes = resid + svr4reclen;
396 td->td_retval[0] = nbytes - resid;
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 */
422 struct svr4_dirent idb;
423 off_t off; /* true file offset */
424 int buflen, error, eofflag;
425 u_long *cookiebuf = NULL, *cookie;
426 int ncookies = 0, *retval = td->td_retval;
431 error = getvnode(td->td_proc->p_fd, uap->fd,
432 cap_rights_init(&rights, CAP_READ), &fp);
436 if ((fp->f_flag & FREAD) == 0) {
442 if (vp->v_type != VDIR) {
447 buflen = min(MAXBSIZE, uap->nbytes);
448 buf = malloc(buflen, M_TEMP, M_WAITOK);
449 vn_lock(vp, LK_SHARED | LK_RETRY);
453 aiov.iov_len = buflen;
454 auio.uio_iov = &aiov;
456 auio.uio_rw = UIO_READ;
457 auio.uio_segflg = UIO_SYSSPACE;
459 auio.uio_resid = buflen;
460 auio.uio_offset = off;
463 error = mac_vnode_check_readdir(td->td_ucred, vp);
469 * First we read into the malloc'ed buffer, then
470 * we massage it into user space, one record at a time.
472 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
481 if ((len = buflen - auio.uio_resid) == 0)
484 for (cookie = cookiebuf; len > 0; len -= reclen) {
485 bdp = (struct dirent *)inp;
486 reclen = bdp->d_reclen;
488 panic("svr4_sys_getdents64: bad reclen");
490 off = *cookie++; /* each entry points to the next */
493 if ((off >> 32) != 0) {
494 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
498 if (bdp->d_fileno == 0) {
499 inp += reclen; /* it is a hole; squish it out */
502 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
503 if (reclen > len || resid < svr4_reclen) {
504 /* entry too big for buffer, so just stop */
509 * Massage in place to make a SVR4-shaped dirent (otherwise
510 * we have to worry about touching user memory outside of
511 * the copyout() call).
513 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
514 idb.d_off = (svr4_off_t)off;
515 idb.d_reclen = (u_short)svr4_reclen;
516 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
517 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
519 /* advance past this real entry */
521 /* advance output past SVR4-shaped entry */
523 resid -= svr4_reclen;
526 /* if we squished out the whole block, try again */
527 if (outp == uap->buf)
529 fp->f_offset = off; /* update the vnode offset */
532 *retval = uap->nbytes - resid;
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 sys_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 sys_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;
616 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
618 /* XXX: we have the chroot priv... what cap might we need? all? */
619 if ((error = getvnode(fdp, uap->fd, 0, &fp)) != 0)
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);
644 svr4_mknod(td, retval, path, mode, dev)
654 CHECKALTEXIST(td, path, &newpath);
656 if (S_ISFIFO(mode)) {
657 error = kern_mkfifoat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
660 error = kern_mknodat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
663 free(newpath, M_TEMP);
669 svr4_sys_mknod(td, uap)
671 struct svr4_sys_mknod_args *uap;
673 int *retval = td->td_retval;
674 return svr4_mknod(td, retval,
675 uap->path, uap->mode,
676 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev));
681 svr4_sys_xmknod(td, uap)
683 struct svr4_sys_xmknod_args *uap;
685 int *retval = td->td_retval;
686 return svr4_mknod(td, retval,
687 uap->path, uap->mode,
688 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
693 svr4_sys_vhangup(td, uap)
695 struct svr4_sys_vhangup_args *uap;
702 svr4_sys_sysconfig(td, uap)
704 struct svr4_sys_sysconfig_args *uap;
708 retval = &(td->td_retval[0]);
711 case SVR4_CONFIG_NGROUPS:
712 *retval = ngroups_max;
714 case SVR4_CONFIG_CHILD_MAX:
717 case SVR4_CONFIG_OPEN_FILES:
720 case SVR4_CONFIG_POSIX_VER:
723 case SVR4_CONFIG_PAGESIZE:
726 case SVR4_CONFIG_CLK_TCK:
727 *retval = 60; /* should this be `hz', ie. 100? */
729 case SVR4_CONFIG_XOPEN_VER:
730 *retval = 2; /* XXX: What should that be? */
732 case SVR4_CONFIG_PROF_TCK:
733 *retval = 60; /* XXX: What should that be? */
735 case SVR4_CONFIG_NPROC_CONF:
736 *retval = 1; /* Only one processor for now */
738 case SVR4_CONFIG_NPROC_ONLN:
739 *retval = 1; /* And it better be online */
741 case SVR4_CONFIG_AIO_LISTIO_MAX:
742 case SVR4_CONFIG_AIO_MAX:
743 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
744 *retval = 0; /* No aio support */
746 case SVR4_CONFIG_DELAYTIMER_MAX:
747 *retval = 0; /* No delaytimer support */
749 case SVR4_CONFIG_MQ_OPEN_MAX:
750 *retval = msginfo.msgmni;
752 case SVR4_CONFIG_MQ_PRIO_MAX:
753 *retval = 0; /* XXX: Don't know */
755 case SVR4_CONFIG_RTSIG_MAX:
758 case SVR4_CONFIG_SEM_NSEMS_MAX:
759 *retval = seminfo.semmni;
761 case SVR4_CONFIG_SEM_VALUE_MAX:
762 *retval = seminfo.semvmx;
764 case SVR4_CONFIG_SIGQUEUE_MAX:
765 *retval = 0; /* XXX: Don't know */
767 case SVR4_CONFIG_SIGRT_MIN:
768 case SVR4_CONFIG_SIGRT_MAX:
769 *retval = 0; /* No real time signals */
771 case SVR4_CONFIG_TIMER_MAX:
772 *retval = 3; /* XXX: real, virtual, profiling */
775 case SVR4_CONFIG_PHYS_PAGES:
777 *retval = uvmexp.free; /* XXX: free instead of total */
779 *retval = vm_cnt.v_free_count; /* XXX: free instead of total */
782 case SVR4_CONFIG_AVPHYS_PAGES:
784 *retval = uvmexp.active; /* XXX: active instead of avg */
786 *retval = vm_cnt.v_active_count;/* XXX: active instead of avg */
790 case SVR4_CONFIG_COHERENCY:
791 *retval = 0; /* XXX */
793 case SVR4_CONFIG_SPLIT_CACHE:
794 *retval = 0; /* XXX */
796 case SVR4_CONFIG_ICACHESZ:
797 *retval = 256; /* XXX */
799 case SVR4_CONFIG_DCACHESZ:
800 *retval = 256; /* XXX */
802 case SVR4_CONFIG_ICACHELINESZ:
803 *retval = 64; /* XXX */
805 case SVR4_CONFIG_DCACHELINESZ:
806 *retval = 64; /* XXX */
808 case SVR4_CONFIG_ICACHEBLKSZ:
809 *retval = 64; /* XXX */
811 case SVR4_CONFIG_DCACHEBLKSZ:
812 *retval = 64; /* XXX */
814 case SVR4_CONFIG_DCACHETBLKSZ:
815 *retval = 64; /* XXX */
817 case SVR4_CONFIG_ICACHE_ASSOC:
818 *retval = 1; /* XXX */
820 case SVR4_CONFIG_DCACHE_ASSOC:
821 *retval = 1; /* XXX */
823 case SVR4_CONFIG_MAXPID:
826 case SVR4_CONFIG_STACK_PROT:
827 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
837 svr4_sys_break(td, uap)
839 struct svr4_sys_break_args *uap;
841 struct obreak_args ap;
843 ap.nsize = uap->nsize;
844 return (sys_obreak(td, &ap));
847 static __inline clock_t
848 timeval_to_clock_t(tv)
851 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
856 svr4_sys_times(td, uap)
858 struct svr4_sys_times_args *uap;
860 struct timeval tv, utime, stime, cutime, cstime;
868 calcru(p, &utime, &stime);
870 calccru(p, &cutime, &cstime);
873 tms.tms_utime = timeval_to_clock_t(&utime);
874 tms.tms_stime = timeval_to_clock_t(&stime);
876 tms.tms_cutime = timeval_to_clock_t(&cutime);
877 tms.tms_cstime = timeval_to_clock_t(&cstime);
879 error = copyout(&tms, uap->tp, sizeof(tms));
884 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
890 svr4_sys_ulimit(td, uap)
892 struct svr4_sys_ulimit_args *uap;
894 int *retval = td->td_retval;
899 PROC_LOCK(td->td_proc);
900 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
901 PROC_UNLOCK(td->td_proc);
903 *retval = 0x7fffffff;
910 krl.rlim_cur = uap->newlimit * 512;
911 PROC_LOCK(td->td_proc);
912 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
913 PROC_UNLOCK(td->td_proc);
915 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
919 PROC_LOCK(td->td_proc);
920 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
921 PROC_UNLOCK(td->td_proc);
923 *retval = 0x7fffffff;
929 struct vmspace *vm = td->td_proc->p_vmspace;
932 PROC_LOCK(td->td_proc);
933 r = lim_cur(td->td_proc, RLIMIT_DATA);
934 PROC_UNLOCK(td->td_proc);
938 r += (long) vm->vm_daddr;
946 PROC_LOCK(td->td_proc);
947 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
948 PROC_UNLOCK(td->td_proc);
950 *retval = 0x7fffffff;
964 /* look in the live processes */
965 if ((p = pfind(pid)) == NULL)
966 /* look in the zombies */
974 svr4_sys_pgrpsys(td, uap)
976 struct svr4_sys_pgrpsys_args *uap;
978 int *retval = td->td_retval;
979 struct proc *p = td->td_proc;
982 case 1: /* setpgrp() */
984 * SVR4 setpgrp() (which takes no arguments) has the
985 * semantics that the session ID is also created anew, so
986 * in almost every sense, setpgrp() is identical to
987 * setsid() for SVR4. (Under BSD, the difference is that
988 * a setpgid(0,0) will not create a new session.)
990 sys_setsid(td, NULL);
993 case 0: /* getpgrp() */
995 *retval = p->p_pgrp->pg_id;
999 case 2: /* getsid(pid) */
1002 else if ((p = svr4_pfind(uap->pid)) == NULL)
1005 * This has already been initialized to the pid of
1006 * the session leader.
1008 *retval = (register_t) p->p_session->s_sid;
1012 case 3: /* setsid() */
1013 return sys_setsid(td, NULL);
1015 case 4: /* getpgid(pid) */
1019 else if ((p = svr4_pfind(uap->pid)) == NULL)
1022 *retval = (int) p->p_pgrp->pg_id;
1026 case 5: /* setpgid(pid, pgid); */
1028 struct setpgid_args sa;
1031 sa.pgid = uap->pgid;
1032 return sys_setpgid(td, &sa);
1040 struct svr4_hrtcntl_args {
1044 svr4_hrt_interval_t * iv;
1045 svr4_hrt_time_t * ti;
1050 svr4_hrtcntl(td, uap, retval)
1052 struct svr4_hrtcntl_args *uap;
1056 case SVR4_HRT_CNTL_RES:
1057 DPRINTF(("htrcntl(RES)\n"));
1058 *retval = SVR4_HRT_USEC;
1061 case SVR4_HRT_CNTL_TOFD:
1062 DPRINTF(("htrcntl(TOFD)\n"));
1066 if (uap->clk != SVR4_HRT_CLK_STD) {
1067 DPRINTF(("clk == %d\n", uap->clk));
1070 if (uap->ti == NULL) {
1071 DPRINTF(("ti NULL\n"));
1075 t.h_sec = tv.tv_sec;
1076 t.h_rem = tv.tv_usec;
1077 t.h_res = SVR4_HRT_USEC;
1078 return copyout(&t, uap->ti, sizeof(t));
1081 case SVR4_HRT_CNTL_START:
1082 DPRINTF(("htrcntl(START)\n"));
1085 case SVR4_HRT_CNTL_GET:
1086 DPRINTF(("htrcntl(GET)\n"));
1089 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1096 svr4_sys_hrtsys(td, uap)
1098 struct svr4_sys_hrtsys_args *uap;
1100 int *retval = td->td_retval;
1104 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1108 DPRINTF(("hrtalarm\n"));
1112 DPRINTF(("hrtsleep\n"));
1116 DPRINTF(("hrtcancel\n"));
1120 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1127 svr4_setinfo(pid, ru, st, s)
1136 memset(&i, 0, sizeof(i));
1138 i.svr4_si_signo = SVR4_SIGCHLD;
1139 i.svr4_si_errno = 0; /* XXX? */
1141 i.svr4_si_pid = pid;
1143 i.svr4_si_stime = ru->ru_stime.tv_sec;
1144 i.svr4_si_utime = ru->ru_utime.tv_sec;
1147 if (WIFEXITED(st)) {
1148 i.svr4_si_status = WEXITSTATUS(st);
1149 i.svr4_si_code = SVR4_CLD_EXITED;
1150 } else if (WIFSTOPPED(st)) {
1152 if (sig >= 0 && sig < NSIG)
1153 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1155 if (i.svr4_si_status == SVR4_SIGCONT)
1156 i.svr4_si_code = SVR4_CLD_CONTINUED;
1158 i.svr4_si_code = SVR4_CLD_STOPPED;
1161 if (sig >= 0 && sig < NSIG)
1162 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1165 i.svr4_si_code = SVR4_CLD_DUMPED;
1167 i.svr4_si_code = SVR4_CLD_KILLED;
1170 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1171 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1174 return copyout(&i, s, sizeof(i));
1179 svr4_sys_waitsys(td, uap)
1181 struct svr4_sys_waitsys_args *uap;
1186 int error, *retval = td->td_retval;
1189 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1191 uap->info, uap->options));
1213 /* Hand off the easy cases to kern_wait(). */
1214 if (!(uap->options & (SVR4_WNOWAIT)) &&
1215 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1219 if (uap->options & SVR4_WSTOPPED)
1220 options |= WUNTRACED;
1221 if (uap->options & SVR4_WCONTINUED)
1222 options |= WCONTINUED;
1223 if (uap->options & SVR4_WNOHANG)
1226 error = kern_wait(td, pid, &status, options, &ru);
1229 if (uap->options & SVR4_WNOHANG && *retval == 0)
1230 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1232 error = svr4_setinfo(*retval, &ru, status, uap->info);
1238 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1239 * just want to see if there is a process to harvest, we don't
1240 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1241 * meaning we want to ignore zombies. Either way, we don't have
1242 * to handle harvesting zombies here. We do have to duplicate the
1243 * other portions of kern_wait() though, especially for WCONTINUED
1248 sx_slock(&proctree_lock);
1249 LIST_FOREACH(p, &q->p_children, p_sibling) {
1251 if (pid != WAIT_ANY &&
1252 p->p_pid != pid && p->p_pgid != -pid) {
1254 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1258 if (p_canwait(td, p)) {
1267 * See if we have a zombie. If so, WNOWAIT should be set,
1268 * as otherwise we should have called kern_wait() up above.
1270 if ((p->p_state == PRS_ZOMBIE) &&
1271 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1273 KASSERT(uap->options & SVR4_WNOWAIT,
1274 ("WNOWAIT is clear"));
1276 /* Found a zombie, so cache info in local variables. */
1278 status = p->p_xstat;
1281 calcru(p, &ru.ru_utime, &ru.ru_stime);
1284 sx_sunlock(&proctree_lock);
1286 /* Copy the info out to userland. */
1288 DPRINTF(("found %d\n", pid));
1289 return (svr4_setinfo(pid, &ru, status, uap->info));
1293 * See if we have a stopped or continued process.
1294 * XXX: This duplicates the same code in kern_wait().
1296 if ((p->p_flag & P_STOPPED_SIG) &&
1297 (p->p_suspcount == p->p_numthreads) &&
1298 (p->p_flag & P_WAITED) == 0 &&
1299 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1301 if (((uap->options & SVR4_WNOWAIT)) == 0)
1302 p->p_flag |= P_WAITED;
1303 sx_sunlock(&proctree_lock);
1305 status = W_STOPCODE(p->p_xstat);
1308 calcru(p, &ru.ru_utime, &ru.ru_stime);
1312 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1314 sigqueue_take(p->p_ksi);
1319 DPRINTF(("jobcontrol %d\n", pid));
1320 return (svr4_setinfo(pid, &ru, status, uap->info));
1323 if (uap->options & SVR4_WCONTINUED &&
1324 (p->p_flag & P_CONTINUED)) {
1325 sx_sunlock(&proctree_lock);
1326 if (((uap->options & SVR4_WNOWAIT)) == 0)
1327 p->p_flag &= ~P_CONTINUED;
1332 calcru(p, &ru.ru_utime, &ru.ru_stime);
1336 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1338 sigqueue_take(p->p_ksi);
1343 DPRINTF(("jobcontrol %d\n", pid));
1344 return (svr4_setinfo(pid, &ru, status, uap->info));
1350 sx_sunlock(&proctree_lock);
1354 if (uap->options & SVR4_WNOHANG) {
1355 sx_sunlock(&proctree_lock);
1357 return (svr4_setinfo(0, NULL, 0, uap->info));
1361 sx_sunlock(&proctree_lock);
1362 if (q->p_flag & P_STATCHILD) {
1363 q->p_flag &= ~P_STATCHILD;
1366 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1375 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1376 const struct statfs *bfs;
1377 struct svr4_statvfs *sfs;
1379 sfs->f_bsize = bfs->f_iosize; /* XXX */
1380 sfs->f_frsize = bfs->f_bsize;
1381 sfs->f_blocks = bfs->f_blocks;
1382 sfs->f_bfree = bfs->f_bfree;
1383 sfs->f_bavail = bfs->f_bavail;
1384 sfs->f_files = bfs->f_files;
1385 sfs->f_ffree = bfs->f_ffree;
1386 sfs->f_favail = bfs->f_ffree;
1387 sfs->f_fsid = bfs->f_fsid.val[0];
1388 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1390 if (bfs->f_flags & MNT_RDONLY)
1391 sfs->f_flag |= SVR4_ST_RDONLY;
1392 if (bfs->f_flags & MNT_NOSUID)
1393 sfs->f_flag |= SVR4_ST_NOSUID;
1394 sfs->f_namemax = MAXNAMLEN;
1395 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1396 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1401 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1402 const struct statfs *bfs;
1403 struct svr4_statvfs64 *sfs;
1405 sfs->f_bsize = bfs->f_iosize; /* XXX */
1406 sfs->f_frsize = bfs->f_bsize;
1407 sfs->f_blocks = bfs->f_blocks;
1408 sfs->f_bfree = bfs->f_bfree;
1409 sfs->f_bavail = bfs->f_bavail;
1410 sfs->f_files = bfs->f_files;
1411 sfs->f_ffree = bfs->f_ffree;
1412 sfs->f_favail = bfs->f_ffree;
1413 sfs->f_fsid = bfs->f_fsid.val[0];
1414 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1416 if (bfs->f_flags & MNT_RDONLY)
1417 sfs->f_flag |= SVR4_ST_RDONLY;
1418 if (bfs->f_flags & MNT_NOSUID)
1419 sfs->f_flag |= SVR4_ST_NOSUID;
1420 sfs->f_namemax = MAXNAMLEN;
1421 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1422 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1427 svr4_sys_statvfs(td, uap)
1429 struct svr4_sys_statvfs_args *uap;
1431 struct svr4_statvfs sfs;
1436 CHECKALTEXIST(td, uap->path, &path);
1438 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1442 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1443 return copyout(&sfs, uap->fs, sizeof(sfs));
1448 svr4_sys_fstatvfs(td, uap)
1450 struct svr4_sys_fstatvfs_args *uap;
1452 struct svr4_statvfs sfs;
1456 error = kern_fstatfs(td, uap->fd, &bfs);
1459 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1460 return copyout(&sfs, uap->fs, sizeof(sfs));
1465 svr4_sys_statvfs64(td, uap)
1467 struct svr4_sys_statvfs64_args *uap;
1469 struct svr4_statvfs64 sfs;
1474 CHECKALTEXIST(td, uap->path, &path);
1476 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1480 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1481 return copyout(&sfs, uap->fs, sizeof(sfs));
1486 svr4_sys_fstatvfs64(td, uap)
1488 struct svr4_sys_fstatvfs64_args *uap;
1490 struct svr4_statvfs64 sfs;
1494 error = kern_fstatfs(td, uap->fd, &bfs);
1497 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1498 return copyout(&sfs, uap->fs, sizeof(sfs));
1502 svr4_sys_alarm(td, uap)
1504 struct svr4_sys_alarm_args *uap;
1506 struct itimerval itv, oitv;
1509 timevalclear(&itv.it_interval);
1510 itv.it_value.tv_sec = uap->sec;
1511 itv.it_value.tv_usec = 0;
1512 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1515 if (oitv.it_value.tv_usec != 0)
1516 oitv.it_value.tv_sec++;
1517 td->td_retval[0] = oitv.it_value.tv_sec;
1522 svr4_sys_gettimeofday(td, uap)
1524 struct svr4_sys_gettimeofday_args *uap;
1530 return copyout(&atv, uap->tp, sizeof (atv));
1537 svr4_sys_facl(td, uap)
1539 struct svr4_sys_facl_args *uap;
1543 retval = td->td_retval;
1547 case SVR4_SYS_SETACL:
1548 /* We don't support acls on any filesystem */
1551 case SVR4_SYS_GETACL:
1552 return copyout(retval, &uap->num,
1555 case SVR4_SYS_GETACLCNT:
1565 svr4_sys_acl(td, uap)
1567 struct svr4_sys_acl_args *uap;
1569 /* XXX: for now the same */
1570 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1574 svr4_sys_auditsys(td, uap)
1576 struct svr4_sys_auditsys_args *uap;
1579 * XXX: Big brother is *not* watching.
1585 svr4_sys_memcntl(td, uap)
1587 struct svr4_sys_memcntl_args *uap;
1592 struct msync_args msa;
1594 msa.addr = uap->addr;
1596 msa.flags = (int)uap->arg;
1598 return sys_msync(td, &msa);
1600 case SVR4_MC_ADVISE:
1602 struct madvise_args maa;
1604 maa.addr = uap->addr;
1606 maa.behav = (int)uap->arg;
1608 return sys_madvise(td, &maa);
1611 case SVR4_MC_UNLOCK:
1612 case SVR4_MC_LOCKAS:
1613 case SVR4_MC_UNLOCKAS:
1622 svr4_sys_nice(td, uap)
1624 struct svr4_sys_nice_args *uap;
1626 struct setpriority_args ap;
1629 ap.which = PRIO_PROCESS;
1631 ap.prio = uap->prio;
1633 if ((error = sys_setpriority(td, &ap)) != 0)
1636 /* the cast is stupid, but the structures are the same */
1637 if ((error = sys_getpriority(td, (struct getpriority_args *)&ap)) != 0)
1644 svr4_sys_resolvepath(td, uap)
1646 struct svr4_sys_resolvepath_args *uap;
1648 struct nameidata nd;
1649 int error, *retval = td->td_retval;
1652 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1655 if ((error = namei(&nd)) != 0)
1657 NDFREE(&nd, NDF_NO_FREE_PNBUF);
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);