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;
170 struct vmspace *oldvmspace;
174 CHECKALTEXIST(td, uap->path, &path);
176 error = pre_execve(td, &oldvmspace);
181 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
184 error = kern_execve(td, &eargs, NULL);
185 post_execve(td, error, oldvmspace);
190 svr4_sys_execve(td, uap)
192 struct svr4_sys_execve_args *uap;
194 struct image_args eargs;
195 struct vmspace *oldvmspace;
199 CHECKALTEXIST(td, uap->path, &path);
201 error = pre_execve(td, &oldvmspace);
206 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
210 error = kern_execve(td, &eargs, NULL);
211 post_execve(td, error, oldvmspace);
218 struct svr4_sys_time_args *v;
220 struct svr4_sys_time_args *uap = v;
226 error = copyout(&tv.tv_sec, uap->t,
228 td->td_retval[0] = (int) tv.tv_sec;
235 * Read SVR4-style directory entries. We suck them into kernel space so
236 * that they can be massaged before being copied out to user code.
238 * This code is ported from the Linux emulator: Changes to the VFS interface
239 * between FreeBSD and NetBSD have made it simpler to port it from there than
240 * to adapt the NetBSD version.
243 svr4_sys_getdents64(td, uap)
245 struct svr4_sys_getdents64_args *uap;
249 caddr_t inp, buf; /* BSD-format */
250 int len, reclen; /* BSD-format */
251 caddr_t outp; /* SVR4-format */
252 int resid, svr4reclen=0; /* SVR4-format */
258 struct svr4_dirent64 svr4_dirent;
259 int buflen, error, eofflag, nbytes, justone;
260 u_long *cookies = NULL, *cookiep;
263 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
264 uap->fd, uap->nbytes));
265 error = getvnode(td->td_proc->p_fd, uap->fd,
266 cap_rights_init(&rights, CAP_READ), &fp);
270 if ((fp->f_flag & FREAD) == 0) {
276 if (vp->v_type != VDIR) {
281 nbytes = uap->nbytes;
283 nbytes = sizeof (struct svr4_dirent64);
290 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
291 buflen = max(DIRBLKSIZ, nbytes);
292 buflen = min(buflen, MAXBSIZE);
293 buf = malloc(buflen, M_TEMP, M_WAITOK);
294 vn_lock(vp, LK_SHARED | LK_RETRY);
297 aiov.iov_len = buflen;
298 auio.uio_iov = &aiov;
300 auio.uio_rw = UIO_READ;
301 auio.uio_segflg = UIO_SYSSPACE;
303 auio.uio_resid = buflen;
304 auio.uio_offset = off;
307 free(cookies, M_TEMP);
312 error = mac_vnode_check_readdir(td->td_ucred, vp);
317 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
318 &ncookies, &cookies);
324 outp = (caddr_t) uap->dp;
326 if ((len = buflen - auio.uio_resid) <= 0) {
334 * When using cookies, the vfs has the option of reading from
335 * a different offset than that supplied (UFS truncates the
336 * offset to a block boundary to make sure that it never reads
337 * partway through a directory entry, even if the directory
338 * has been compacted).
340 while (len > 0 && ncookies > 0 && *cookiep <= off) {
341 bdp = (struct dirent *) inp;
342 len -= bdp->d_reclen;
343 inp += bdp->d_reclen;
350 if (cookiep && ncookies == 0)
352 bdp = (struct dirent *) inp;
353 reclen = bdp->d_reclen;
355 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
360 if (bdp->d_fileno == 0) {
370 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
371 if (reclen > len || resid < svr4reclen) {
375 svr4_dirent.d_ino = (long) bdp->d_fileno;
378 * old svr4-style readdir usage.
380 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
381 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
383 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
384 svr4_dirent.d_reclen = (u_short) svr4reclen;
386 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name));
387 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
402 if (outp == (caddr_t) uap->dp)
407 nbytes = resid + svr4reclen;
410 td->td_retval[0] = nbytes - resid;
415 free(cookies, M_TEMP);
422 svr4_sys_getdents(td, uap)
424 struct svr4_sys_getdents_args *uap;
428 caddr_t inp, buf; /* BSD-format */
429 int len, reclen; /* BSD-format */
430 caddr_t outp; /* SVR4-format */
431 int resid, svr4_reclen; /* SVR4-format */
436 struct svr4_dirent idb;
437 off_t off; /* true file offset */
438 int buflen, error, eofflag;
439 u_long *cookiebuf = NULL, *cookie;
440 int ncookies = 0, *retval = td->td_retval;
445 error = getvnode(td->td_proc->p_fd, uap->fd,
446 cap_rights_init(&rights, CAP_READ), &fp);
450 if ((fp->f_flag & FREAD) == 0) {
456 if (vp->v_type != VDIR) {
461 buflen = min(MAXBSIZE, uap->nbytes);
462 buf = malloc(buflen, M_TEMP, M_WAITOK);
463 vn_lock(vp, LK_SHARED | LK_RETRY);
467 aiov.iov_len = buflen;
468 auio.uio_iov = &aiov;
470 auio.uio_rw = UIO_READ;
471 auio.uio_segflg = UIO_SYSSPACE;
473 auio.uio_resid = buflen;
474 auio.uio_offset = off;
477 error = mac_vnode_check_readdir(td->td_ucred, vp);
483 * First we read into the malloc'ed buffer, then
484 * we massage it into user space, one record at a time.
486 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
495 if ((len = buflen - auio.uio_resid) == 0)
498 for (cookie = cookiebuf; len > 0; len -= reclen) {
499 bdp = (struct dirent *)inp;
500 reclen = bdp->d_reclen;
502 panic("svr4_sys_getdents64: bad reclen");
504 off = *cookie++; /* each entry points to the next */
507 if ((off >> 32) != 0) {
508 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
512 if (bdp->d_fileno == 0) {
513 inp += reclen; /* it is a hole; squish it out */
516 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
517 if (reclen > len || resid < svr4_reclen) {
518 /* entry too big for buffer, so just stop */
523 * Massage in place to make a SVR4-shaped dirent (otherwise
524 * we have to worry about touching user memory outside of
525 * the copyout() call).
527 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
528 idb.d_off = (svr4_off_t)off;
529 idb.d_reclen = (u_short)svr4_reclen;
530 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
531 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
533 /* advance past this real entry */
535 /* advance output past SVR4-shaped entry */
537 resid -= svr4_reclen;
540 /* if we squished out the whole block, try again */
541 if (outp == uap->buf)
543 fp->f_offset = off; /* update the vnode offset */
546 *retval = uap->nbytes - resid;
551 free(cookiebuf, M_TEMP);
558 svr4_sys_mmap(td, uap)
560 struct svr4_sys_mmap_args *uap;
565 retval = td->td_retval;
566 #define _MAP_NEW 0x80000000
568 * Verify the arguments.
570 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
571 return EINVAL; /* XXX still needed? */
578 mm.flags = uap->flags & ~_MAP_NEW;
583 return sys_mmap(td, &mm);
587 svr4_sys_mmap64(td, uap)
589 struct svr4_sys_mmap64_args *uap;
594 #define _MAP_NEW 0x80000000
596 * Verify the arguments.
598 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
599 return EINVAL; /* XXX still needed? */
606 mm.flags = uap->flags & ~_MAP_NEW;
611 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
612 if ((mm.flags & MAP_FIXED) == 0 &&
613 mm.addr != 0 && (void *)mm.addr < rp)
616 return sys_mmap(td, &mm);
621 svr4_sys_fchroot(td, uap)
623 struct svr4_sys_fchroot_args *uap;
625 struct filedesc *fdp = td->td_proc->p_fd;
630 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
632 /* XXX: we have the chroot priv... what cap might we need? all? */
633 if ((error = getvnode(fdp, uap->fd, 0, &fp)) != 0)
638 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
639 error = change_dir(vp, td);
643 error = mac_vnode_check_chroot(td->td_ucred, vp);
648 error = change_root(vp, td);
658 svr4_mknod(td, retval, path, mode, dev)
668 CHECKALTEXIST(td, path, &newpath);
671 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
673 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
674 free(newpath, M_TEMP);
680 svr4_sys_mknod(td, uap)
682 struct svr4_sys_mknod_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_odev_t(uap->dev));
692 svr4_sys_xmknod(td, uap)
694 struct svr4_sys_xmknod_args *uap;
696 int *retval = td->td_retval;
697 return svr4_mknod(td, retval,
698 uap->path, uap->mode,
699 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
704 svr4_sys_vhangup(td, uap)
706 struct svr4_sys_vhangup_args *uap;
713 svr4_sys_sysconfig(td, uap)
715 struct svr4_sys_sysconfig_args *uap;
719 retval = &(td->td_retval[0]);
722 case SVR4_CONFIG_NGROUPS:
723 *retval = ngroups_max;
725 case SVR4_CONFIG_CHILD_MAX:
728 case SVR4_CONFIG_OPEN_FILES:
731 case SVR4_CONFIG_POSIX_VER:
734 case SVR4_CONFIG_PAGESIZE:
737 case SVR4_CONFIG_CLK_TCK:
738 *retval = 60; /* should this be `hz', ie. 100? */
740 case SVR4_CONFIG_XOPEN_VER:
741 *retval = 2; /* XXX: What should that be? */
743 case SVR4_CONFIG_PROF_TCK:
744 *retval = 60; /* XXX: What should that be? */
746 case SVR4_CONFIG_NPROC_CONF:
747 *retval = 1; /* Only one processor for now */
749 case SVR4_CONFIG_NPROC_ONLN:
750 *retval = 1; /* And it better be online */
752 case SVR4_CONFIG_AIO_LISTIO_MAX:
753 case SVR4_CONFIG_AIO_MAX:
754 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
755 *retval = 0; /* No aio support */
757 case SVR4_CONFIG_DELAYTIMER_MAX:
758 *retval = 0; /* No delaytimer support */
760 case SVR4_CONFIG_MQ_OPEN_MAX:
761 *retval = msginfo.msgmni;
763 case SVR4_CONFIG_MQ_PRIO_MAX:
764 *retval = 0; /* XXX: Don't know */
766 case SVR4_CONFIG_RTSIG_MAX:
769 case SVR4_CONFIG_SEM_NSEMS_MAX:
770 *retval = seminfo.semmni;
772 case SVR4_CONFIG_SEM_VALUE_MAX:
773 *retval = seminfo.semvmx;
775 case SVR4_CONFIG_SIGQUEUE_MAX:
776 *retval = 0; /* XXX: Don't know */
778 case SVR4_CONFIG_SIGRT_MIN:
779 case SVR4_CONFIG_SIGRT_MAX:
780 *retval = 0; /* No real time signals */
782 case SVR4_CONFIG_TIMER_MAX:
783 *retval = 3; /* XXX: real, virtual, profiling */
786 case SVR4_CONFIG_PHYS_PAGES:
788 *retval = uvmexp.free; /* XXX: free instead of total */
790 *retval = cnt.v_free_count; /* XXX: free instead of total */
793 case SVR4_CONFIG_AVPHYS_PAGES:
795 *retval = uvmexp.active; /* XXX: active instead of avg */
797 *retval = cnt.v_active_count; /* XXX: active instead of avg */
801 case SVR4_CONFIG_COHERENCY:
802 *retval = 0; /* XXX */
804 case SVR4_CONFIG_SPLIT_CACHE:
805 *retval = 0; /* XXX */
807 case SVR4_CONFIG_ICACHESZ:
808 *retval = 256; /* XXX */
810 case SVR4_CONFIG_DCACHESZ:
811 *retval = 256; /* XXX */
813 case SVR4_CONFIG_ICACHELINESZ:
814 *retval = 64; /* XXX */
816 case SVR4_CONFIG_DCACHELINESZ:
817 *retval = 64; /* XXX */
819 case SVR4_CONFIG_ICACHEBLKSZ:
820 *retval = 64; /* XXX */
822 case SVR4_CONFIG_DCACHEBLKSZ:
823 *retval = 64; /* XXX */
825 case SVR4_CONFIG_DCACHETBLKSZ:
826 *retval = 64; /* XXX */
828 case SVR4_CONFIG_ICACHE_ASSOC:
829 *retval = 1; /* XXX */
831 case SVR4_CONFIG_DCACHE_ASSOC:
832 *retval = 1; /* XXX */
834 case SVR4_CONFIG_MAXPID:
837 case SVR4_CONFIG_STACK_PROT:
838 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
848 svr4_sys_break(td, uap)
850 struct svr4_sys_break_args *uap;
852 struct obreak_args ap;
854 ap.nsize = uap->nsize;
855 return (sys_obreak(td, &ap));
858 static __inline clock_t
859 timeval_to_clock_t(tv)
862 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
867 svr4_sys_times(td, uap)
869 struct svr4_sys_times_args *uap;
871 struct timeval tv, utime, stime, cutime, cstime;
879 calcru(p, &utime, &stime);
881 calccru(p, &cutime, &cstime);
884 tms.tms_utime = timeval_to_clock_t(&utime);
885 tms.tms_stime = timeval_to_clock_t(&stime);
887 tms.tms_cutime = timeval_to_clock_t(&cutime);
888 tms.tms_cstime = timeval_to_clock_t(&cstime);
890 error = copyout(&tms, uap->tp, sizeof(tms));
895 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
901 svr4_sys_ulimit(td, uap)
903 struct svr4_sys_ulimit_args *uap;
905 int *retval = td->td_retval;
910 PROC_LOCK(td->td_proc);
911 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
912 PROC_UNLOCK(td->td_proc);
914 *retval = 0x7fffffff;
921 krl.rlim_cur = uap->newlimit * 512;
922 PROC_LOCK(td->td_proc);
923 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
924 PROC_UNLOCK(td->td_proc);
926 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
930 PROC_LOCK(td->td_proc);
931 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
932 PROC_UNLOCK(td->td_proc);
934 *retval = 0x7fffffff;
940 struct vmspace *vm = td->td_proc->p_vmspace;
943 PROC_LOCK(td->td_proc);
944 r = lim_cur(td->td_proc, RLIMIT_DATA);
945 PROC_UNLOCK(td->td_proc);
949 r += (long) vm->vm_daddr;
957 PROC_LOCK(td->td_proc);
958 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
959 PROC_UNLOCK(td->td_proc);
961 *retval = 0x7fffffff;
975 /* look in the live processes */
976 if ((p = pfind(pid)) == NULL)
977 /* look in the zombies */
985 svr4_sys_pgrpsys(td, uap)
987 struct svr4_sys_pgrpsys_args *uap;
989 int *retval = td->td_retval;
990 struct proc *p = td->td_proc;
993 case 1: /* setpgrp() */
995 * SVR4 setpgrp() (which takes no arguments) has the
996 * semantics that the session ID is also created anew, so
997 * in almost every sense, setpgrp() is identical to
998 * setsid() for SVR4. (Under BSD, the difference is that
999 * a setpgid(0,0) will not create a new session.)
1001 sys_setsid(td, NULL);
1004 case 0: /* getpgrp() */
1006 *retval = p->p_pgrp->pg_id;
1010 case 2: /* getsid(pid) */
1013 else if ((p = svr4_pfind(uap->pid)) == NULL)
1016 * This has already been initialized to the pid of
1017 * the session leader.
1019 *retval = (register_t) p->p_session->s_sid;
1023 case 3: /* setsid() */
1024 return sys_setsid(td, NULL);
1026 case 4: /* getpgid(pid) */
1030 else if ((p = svr4_pfind(uap->pid)) == NULL)
1033 *retval = (int) p->p_pgrp->pg_id;
1037 case 5: /* setpgid(pid, pgid); */
1039 struct setpgid_args sa;
1042 sa.pgid = uap->pgid;
1043 return sys_setpgid(td, &sa);
1051 struct svr4_hrtcntl_args {
1055 svr4_hrt_interval_t * iv;
1056 svr4_hrt_time_t * ti;
1061 svr4_hrtcntl(td, uap, retval)
1063 struct svr4_hrtcntl_args *uap;
1067 case SVR4_HRT_CNTL_RES:
1068 DPRINTF(("htrcntl(RES)\n"));
1069 *retval = SVR4_HRT_USEC;
1072 case SVR4_HRT_CNTL_TOFD:
1073 DPRINTF(("htrcntl(TOFD)\n"));
1077 if (uap->clk != SVR4_HRT_CLK_STD) {
1078 DPRINTF(("clk == %d\n", uap->clk));
1081 if (uap->ti == NULL) {
1082 DPRINTF(("ti NULL\n"));
1086 t.h_sec = tv.tv_sec;
1087 t.h_rem = tv.tv_usec;
1088 t.h_res = SVR4_HRT_USEC;
1089 return copyout(&t, uap->ti, sizeof(t));
1092 case SVR4_HRT_CNTL_START:
1093 DPRINTF(("htrcntl(START)\n"));
1096 case SVR4_HRT_CNTL_GET:
1097 DPRINTF(("htrcntl(GET)\n"));
1100 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1107 svr4_sys_hrtsys(td, uap)
1109 struct svr4_sys_hrtsys_args *uap;
1111 int *retval = td->td_retval;
1115 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1119 DPRINTF(("hrtalarm\n"));
1123 DPRINTF(("hrtsleep\n"));
1127 DPRINTF(("hrtcancel\n"));
1131 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1138 svr4_setinfo(pid, ru, st, s)
1147 memset(&i, 0, sizeof(i));
1149 i.svr4_si_signo = SVR4_SIGCHLD;
1150 i.svr4_si_errno = 0; /* XXX? */
1152 i.svr4_si_pid = pid;
1154 i.svr4_si_stime = ru->ru_stime.tv_sec;
1155 i.svr4_si_utime = ru->ru_utime.tv_sec;
1158 if (WIFEXITED(st)) {
1159 i.svr4_si_status = WEXITSTATUS(st);
1160 i.svr4_si_code = SVR4_CLD_EXITED;
1161 } else if (WIFSTOPPED(st)) {
1163 if (sig >= 0 && sig < NSIG)
1164 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1166 if (i.svr4_si_status == SVR4_SIGCONT)
1167 i.svr4_si_code = SVR4_CLD_CONTINUED;
1169 i.svr4_si_code = SVR4_CLD_STOPPED;
1172 if (sig >= 0 && sig < NSIG)
1173 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1176 i.svr4_si_code = SVR4_CLD_DUMPED;
1178 i.svr4_si_code = SVR4_CLD_KILLED;
1181 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1182 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1185 return copyout(&i, s, sizeof(i));
1190 svr4_sys_waitsys(td, uap)
1192 struct svr4_sys_waitsys_args *uap;
1197 int error, *retval = td->td_retval;
1200 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1202 uap->info, uap->options));
1224 /* Hand off the easy cases to kern_wait(). */
1225 if (!(uap->options & (SVR4_WNOWAIT)) &&
1226 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1230 if (uap->options & SVR4_WSTOPPED)
1231 options |= WUNTRACED;
1232 if (uap->options & SVR4_WCONTINUED)
1233 options |= WCONTINUED;
1234 if (uap->options & SVR4_WNOHANG)
1237 error = kern_wait(td, pid, &status, options, &ru);
1240 if (uap->options & SVR4_WNOHANG && *retval == 0)
1241 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1243 error = svr4_setinfo(*retval, &ru, status, uap->info);
1249 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1250 * just want to see if there is a process to harvest, we don't
1251 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1252 * meaning we want to ignore zombies. Either way, we don't have
1253 * to handle harvesting zombies here. We do have to duplicate the
1254 * other portions of kern_wait() though, especially for WCONTINUED
1259 sx_slock(&proctree_lock);
1260 LIST_FOREACH(p, &q->p_children, p_sibling) {
1262 if (pid != WAIT_ANY &&
1263 p->p_pid != pid && p->p_pgid != -pid) {
1265 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1269 if (p_canwait(td, p)) {
1278 * See if we have a zombie. If so, WNOWAIT should be set,
1279 * as otherwise we should have called kern_wait() up above.
1281 if ((p->p_state == PRS_ZOMBIE) &&
1282 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1284 KASSERT(uap->options & SVR4_WNOWAIT,
1285 ("WNOWAIT is clear"));
1287 /* Found a zombie, so cache info in local variables. */
1289 status = p->p_xstat;
1292 calcru(p, &ru.ru_utime, &ru.ru_stime);
1295 sx_sunlock(&proctree_lock);
1297 /* Copy the info out to userland. */
1299 DPRINTF(("found %d\n", pid));
1300 return (svr4_setinfo(pid, &ru, status, uap->info));
1304 * See if we have a stopped or continued process.
1305 * XXX: This duplicates the same code in kern_wait().
1307 if ((p->p_flag & P_STOPPED_SIG) &&
1308 (p->p_suspcount == p->p_numthreads) &&
1309 (p->p_flag & P_WAITED) == 0 &&
1310 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1312 if (((uap->options & SVR4_WNOWAIT)) == 0)
1313 p->p_flag |= P_WAITED;
1314 sx_sunlock(&proctree_lock);
1316 status = W_STOPCODE(p->p_xstat);
1319 calcru(p, &ru.ru_utime, &ru.ru_stime);
1323 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1325 sigqueue_take(p->p_ksi);
1330 DPRINTF(("jobcontrol %d\n", pid));
1331 return (svr4_setinfo(pid, &ru, status, uap->info));
1334 if (uap->options & SVR4_WCONTINUED &&
1335 (p->p_flag & P_CONTINUED)) {
1336 sx_sunlock(&proctree_lock);
1337 if (((uap->options & SVR4_WNOWAIT)) == 0)
1338 p->p_flag &= ~P_CONTINUED;
1343 calcru(p, &ru.ru_utime, &ru.ru_stime);
1347 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1349 sigqueue_take(p->p_ksi);
1354 DPRINTF(("jobcontrol %d\n", pid));
1355 return (svr4_setinfo(pid, &ru, status, uap->info));
1361 sx_sunlock(&proctree_lock);
1365 if (uap->options & SVR4_WNOHANG) {
1366 sx_sunlock(&proctree_lock);
1368 return (svr4_setinfo(0, NULL, 0, uap->info));
1372 sx_sunlock(&proctree_lock);
1373 if (q->p_flag & P_STATCHILD) {
1374 q->p_flag &= ~P_STATCHILD;
1377 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1386 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1387 const struct statfs *bfs;
1388 struct svr4_statvfs *sfs;
1390 sfs->f_bsize = bfs->f_iosize; /* XXX */
1391 sfs->f_frsize = bfs->f_bsize;
1392 sfs->f_blocks = bfs->f_blocks;
1393 sfs->f_bfree = bfs->f_bfree;
1394 sfs->f_bavail = bfs->f_bavail;
1395 sfs->f_files = bfs->f_files;
1396 sfs->f_ffree = bfs->f_ffree;
1397 sfs->f_favail = bfs->f_ffree;
1398 sfs->f_fsid = bfs->f_fsid.val[0];
1399 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1401 if (bfs->f_flags & MNT_RDONLY)
1402 sfs->f_flag |= SVR4_ST_RDONLY;
1403 if (bfs->f_flags & MNT_NOSUID)
1404 sfs->f_flag |= SVR4_ST_NOSUID;
1405 sfs->f_namemax = MAXNAMLEN;
1406 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1407 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1412 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1413 const struct statfs *bfs;
1414 struct svr4_statvfs64 *sfs;
1416 sfs->f_bsize = bfs->f_iosize; /* XXX */
1417 sfs->f_frsize = bfs->f_bsize;
1418 sfs->f_blocks = bfs->f_blocks;
1419 sfs->f_bfree = bfs->f_bfree;
1420 sfs->f_bavail = bfs->f_bavail;
1421 sfs->f_files = bfs->f_files;
1422 sfs->f_ffree = bfs->f_ffree;
1423 sfs->f_favail = bfs->f_ffree;
1424 sfs->f_fsid = bfs->f_fsid.val[0];
1425 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1427 if (bfs->f_flags & MNT_RDONLY)
1428 sfs->f_flag |= SVR4_ST_RDONLY;
1429 if (bfs->f_flags & MNT_NOSUID)
1430 sfs->f_flag |= SVR4_ST_NOSUID;
1431 sfs->f_namemax = MAXNAMLEN;
1432 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1433 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1438 svr4_sys_statvfs(td, uap)
1440 struct svr4_sys_statvfs_args *uap;
1442 struct svr4_statvfs sfs;
1447 CHECKALTEXIST(td, uap->path, &path);
1449 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1453 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1454 return copyout(&sfs, uap->fs, sizeof(sfs));
1459 svr4_sys_fstatvfs(td, uap)
1461 struct svr4_sys_fstatvfs_args *uap;
1463 struct svr4_statvfs sfs;
1467 error = kern_fstatfs(td, uap->fd, &bfs);
1470 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1471 return copyout(&sfs, uap->fs, sizeof(sfs));
1476 svr4_sys_statvfs64(td, uap)
1478 struct svr4_sys_statvfs64_args *uap;
1480 struct svr4_statvfs64 sfs;
1485 CHECKALTEXIST(td, uap->path, &path);
1487 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1491 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1492 return copyout(&sfs, uap->fs, sizeof(sfs));
1497 svr4_sys_fstatvfs64(td, uap)
1499 struct svr4_sys_fstatvfs64_args *uap;
1501 struct svr4_statvfs64 sfs;
1505 error = kern_fstatfs(td, uap->fd, &bfs);
1508 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1509 return copyout(&sfs, uap->fs, sizeof(sfs));
1513 svr4_sys_alarm(td, uap)
1515 struct svr4_sys_alarm_args *uap;
1517 struct itimerval itv, oitv;
1520 timevalclear(&itv.it_interval);
1521 itv.it_value.tv_sec = uap->sec;
1522 itv.it_value.tv_usec = 0;
1523 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1526 if (oitv.it_value.tv_usec != 0)
1527 oitv.it_value.tv_sec++;
1528 td->td_retval[0] = oitv.it_value.tv_sec;
1533 svr4_sys_gettimeofday(td, uap)
1535 struct svr4_sys_gettimeofday_args *uap;
1541 return copyout(&atv, uap->tp, sizeof (atv));
1548 svr4_sys_facl(td, uap)
1550 struct svr4_sys_facl_args *uap;
1554 retval = td->td_retval;
1558 case SVR4_SYS_SETACL:
1559 /* We don't support acls on any filesystem */
1562 case SVR4_SYS_GETACL:
1563 return copyout(retval, &uap->num,
1566 case SVR4_SYS_GETACLCNT:
1576 svr4_sys_acl(td, uap)
1578 struct svr4_sys_acl_args *uap;
1580 /* XXX: for now the same */
1581 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1585 svr4_sys_auditsys(td, uap)
1587 struct svr4_sys_auditsys_args *uap;
1590 * XXX: Big brother is *not* watching.
1596 svr4_sys_memcntl(td, uap)
1598 struct svr4_sys_memcntl_args *uap;
1603 struct msync_args msa;
1605 msa.addr = uap->addr;
1607 msa.flags = (int)uap->arg;
1609 return sys_msync(td, &msa);
1611 case SVR4_MC_ADVISE:
1613 struct madvise_args maa;
1615 maa.addr = uap->addr;
1617 maa.behav = (int)uap->arg;
1619 return sys_madvise(td, &maa);
1622 case SVR4_MC_UNLOCK:
1623 case SVR4_MC_LOCKAS:
1624 case SVR4_MC_UNLOCKAS:
1633 svr4_sys_nice(td, uap)
1635 struct svr4_sys_nice_args *uap;
1637 struct setpriority_args ap;
1640 ap.which = PRIO_PROCESS;
1642 ap.prio = uap->prio;
1644 if ((error = sys_setpriority(td, &ap)) != 0)
1647 /* the cast is stupid, but the structures are the same */
1648 if ((error = sys_getpriority(td, (struct getpriority_args *)&ap)) != 0)
1655 svr4_sys_resolvepath(td, uap)
1657 struct svr4_sys_resolvepath_args *uap;
1659 struct nameidata nd;
1660 int error, *retval = td->td_retval;
1663 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1666 if ((error = namei(&nd)) != 0)
1668 NDFREE(&nd, NDF_NO_FREE_PNBUF);
1670 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1671 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1676 NDFREE(&nd, NDF_ONLY_PNBUF);