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>
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;
169 struct vmspace *oldvmspace;
173 CHECKALTEXIST(td, uap->path, &path);
175 error = pre_execve(td, &oldvmspace);
180 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
183 error = kern_execve(td, &eargs, NULL);
184 post_execve(td, error, oldvmspace);
189 svr4_sys_execve(td, uap)
191 struct svr4_sys_execve_args *uap;
193 struct image_args eargs;
194 struct vmspace *oldvmspace;
198 CHECKALTEXIST(td, uap->path, &path);
200 error = pre_execve(td, &oldvmspace);
205 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
209 error = kern_execve(td, &eargs, NULL);
210 post_execve(td, error, oldvmspace);
217 struct svr4_sys_time_args *v;
219 struct svr4_sys_time_args *uap = v;
225 error = copyout(&tv.tv_sec, uap->t,
227 td->td_retval[0] = (int) tv.tv_sec;
234 * Read SVR4-style directory entries. We suck them into kernel space so
235 * that they can be massaged before being copied out to user code.
237 * This code is ported from the Linux emulator: Changes to the VFS interface
238 * between FreeBSD and NetBSD have made it simpler to port it from there than
239 * to adapt the NetBSD version.
242 svr4_sys_getdents64(td, uap)
244 struct svr4_sys_getdents64_args *uap;
248 caddr_t inp, buf; /* BSD-format */
249 int len, reclen; /* BSD-format */
250 caddr_t outp; /* SVR4-format */
251 int resid, svr4reclen=0; /* SVR4-format */
257 struct svr4_dirent64 svr4_dirent;
258 int buflen, error, eofflag, nbytes, justone;
259 u_long *cookies = NULL, *cookiep;
262 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
263 uap->fd, uap->nbytes));
264 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
268 if ((fp->f_flag & FREAD) == 0) {
274 if (vp->v_type != VDIR) {
279 nbytes = uap->nbytes;
281 nbytes = sizeof (struct svr4_dirent64);
288 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
289 buflen = max(DIRBLKSIZ, nbytes);
290 buflen = min(buflen, MAXBSIZE);
291 buf = malloc(buflen, M_TEMP, M_WAITOK);
292 vn_lock(vp, LK_SHARED | LK_RETRY);
295 aiov.iov_len = buflen;
296 auio.uio_iov = &aiov;
298 auio.uio_rw = UIO_READ;
299 auio.uio_segflg = UIO_SYSSPACE;
301 auio.uio_resid = buflen;
302 auio.uio_offset = off;
305 free(cookies, M_TEMP);
310 error = mac_vnode_check_readdir(td->td_ucred, vp);
315 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
316 &ncookies, &cookies);
322 outp = (caddr_t) uap->dp;
324 if ((len = buflen - auio.uio_resid) <= 0) {
332 * When using cookies, the vfs has the option of reading from
333 * a different offset than that supplied (UFS truncates the
334 * offset to a block boundary to make sure that it never reads
335 * partway through a directory entry, even if the directory
336 * has been compacted).
338 while (len > 0 && ncookies > 0 && *cookiep <= off) {
339 bdp = (struct dirent *) inp;
340 len -= bdp->d_reclen;
341 inp += bdp->d_reclen;
348 if (cookiep && ncookies == 0)
350 bdp = (struct dirent *) inp;
351 reclen = bdp->d_reclen;
353 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
358 if (bdp->d_fileno == 0) {
368 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
369 if (reclen > len || resid < svr4reclen) {
373 svr4_dirent.d_ino = (long) bdp->d_fileno;
376 * old svr4-style readdir usage.
378 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
379 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
381 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
382 svr4_dirent.d_reclen = (u_short) svr4reclen;
384 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name));
385 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
400 if (outp == (caddr_t) uap->dp)
405 nbytes = resid + svr4reclen;
408 td->td_retval[0] = nbytes - resid;
413 free(cookies, M_TEMP);
420 svr4_sys_getdents(td, uap)
422 struct svr4_sys_getdents_args *uap;
426 caddr_t inp, buf; /* BSD-format */
427 int len, reclen; /* BSD-format */
428 caddr_t outp; /* SVR4-format */
429 int resid, svr4_reclen; /* SVR4-format */
434 struct svr4_dirent idb;
435 off_t off; /* true file offset */
436 int buflen, error, eofflag;
437 u_long *cookiebuf = NULL, *cookie;
438 int ncookies = 0, *retval = td->td_retval;
443 error = getvnode(td, uap->fd, cap_rights_init(&rights, CAP_READ), &fp);
447 if ((fp->f_flag & FREAD) == 0) {
453 if (vp->v_type != VDIR) {
458 buflen = min(MAXBSIZE, uap->nbytes);
459 buf = malloc(buflen, M_TEMP, M_WAITOK);
460 vn_lock(vp, LK_SHARED | LK_RETRY);
464 aiov.iov_len = buflen;
465 auio.uio_iov = &aiov;
467 auio.uio_rw = UIO_READ;
468 auio.uio_segflg = UIO_SYSSPACE;
470 auio.uio_resid = buflen;
471 auio.uio_offset = off;
474 error = mac_vnode_check_readdir(td->td_ucred, vp);
480 * First we read into the malloc'ed buffer, then
481 * we massage it into user space, one record at a time.
483 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
492 if ((len = buflen - auio.uio_resid) == 0)
495 for (cookie = cookiebuf; len > 0; len -= reclen) {
496 bdp = (struct dirent *)inp;
497 reclen = bdp->d_reclen;
499 panic("svr4_sys_getdents64: bad reclen");
501 off = *cookie++; /* each entry points to the next */
504 if ((off >> 32) != 0) {
505 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
509 if (bdp->d_fileno == 0) {
510 inp += reclen; /* it is a hole; squish it out */
513 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
514 if (reclen > len || resid < svr4_reclen) {
515 /* entry too big for buffer, so just stop */
520 * Massage in place to make a SVR4-shaped dirent (otherwise
521 * we have to worry about touching user memory outside of
522 * the copyout() call).
524 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
525 idb.d_off = (svr4_off_t)off;
526 idb.d_reclen = (u_short)svr4_reclen;
527 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
528 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
530 /* advance past this real entry */
532 /* advance output past SVR4-shaped entry */
534 resid -= svr4_reclen;
537 /* if we squished out the whole block, try again */
538 if (outp == uap->buf)
540 fp->f_offset = off; /* update the vnode offset */
543 *retval = uap->nbytes - resid;
548 free(cookiebuf, M_TEMP);
555 svr4_sys_mmap(td, uap)
557 struct svr4_sys_mmap_args *uap;
562 retval = td->td_retval;
563 #define _MAP_NEW 0x80000000
565 * Verify the arguments.
567 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
568 return EINVAL; /* XXX still needed? */
575 mm.flags = uap->flags & ~_MAP_NEW;
580 return sys_mmap(td, &mm);
584 svr4_sys_mmap64(td, uap)
586 struct svr4_sys_mmap64_args *uap;
591 #define _MAP_NEW 0x80000000
593 * Verify the arguments.
595 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
596 return EINVAL; /* XXX still needed? */
603 mm.flags = uap->flags & ~_MAP_NEW;
608 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
609 if ((mm.flags & MAP_FIXED) == 0 &&
610 mm.addr != 0 && (void *)mm.addr < rp)
613 return sys_mmap(td, &mm);
618 svr4_sys_fchroot(td, uap)
620 struct svr4_sys_fchroot_args *uap;
627 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
629 /* XXX: we have the chroot priv... what cap might we need? all? */
630 if ((error = getvnode(td, uap->fd, cap_rights_init(&rights), &fp)) != 0)
635 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
636 error = change_dir(vp, td);
640 error = mac_vnode_check_chroot(td->td_ucred, vp);
645 error = pwd_chroot(td, vp);
655 svr4_mknod(td, retval, path, mode, dev)
665 CHECKALTEXIST(td, path, &newpath);
667 if (S_ISFIFO(mode)) {
668 error = kern_mkfifoat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
671 error = kern_mknodat(td, AT_FDCWD, newpath, UIO_SYSSPACE,
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 = vm_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 = vm_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 *retval = lim_cur(td, RLIMIT_FSIZE) / 512;
912 *retval = 0x7fffffff;
919 krl.rlim_cur = uap->newlimit * 512;
920 krl.rlim_max = lim_max(td, RLIMIT_FSIZE);
922 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
926 *retval = lim_cur(td, RLIMIT_FSIZE);
928 *retval = 0x7fffffff;
934 struct vmspace *vm = td->td_proc->p_vmspace;
937 r = lim_cur(td, RLIMIT_DATA);
941 r += (long) vm->vm_daddr;
949 *retval = lim_cur(td, RLIMIT_NOFILE);
951 *retval = 0x7fffffff;
965 /* look in the live processes */
966 if ((p = pfind(pid)) == NULL)
967 /* look in the zombies */
975 svr4_sys_pgrpsys(td, uap)
977 struct svr4_sys_pgrpsys_args *uap;
979 int *retval = td->td_retval;
980 struct proc *p = td->td_proc;
983 case 1: /* setpgrp() */
985 * SVR4 setpgrp() (which takes no arguments) has the
986 * semantics that the session ID is also created anew, so
987 * in almost every sense, setpgrp() is identical to
988 * setsid() for SVR4. (Under BSD, the difference is that
989 * a setpgid(0,0) will not create a new session.)
991 sys_setsid(td, NULL);
994 case 0: /* getpgrp() */
996 *retval = p->p_pgrp->pg_id;
1000 case 2: /* getsid(pid) */
1003 else if ((p = svr4_pfind(uap->pid)) == NULL)
1006 * This has already been initialized to the pid of
1007 * the session leader.
1009 *retval = (register_t) p->p_session->s_sid;
1013 case 3: /* setsid() */
1014 return sys_setsid(td, NULL);
1016 case 4: /* getpgid(pid) */
1020 else if ((p = svr4_pfind(uap->pid)) == NULL)
1023 *retval = (int) p->p_pgrp->pg_id;
1027 case 5: /* setpgid(pid, pgid); */
1029 struct setpgid_args sa;
1032 sa.pgid = uap->pgid;
1033 return sys_setpgid(td, &sa);
1041 struct svr4_hrtcntl_args {
1045 svr4_hrt_interval_t * iv;
1046 svr4_hrt_time_t * ti;
1051 svr4_hrtcntl(td, uap, retval)
1053 struct svr4_hrtcntl_args *uap;
1057 case SVR4_HRT_CNTL_RES:
1058 DPRINTF(("htrcntl(RES)\n"));
1059 *retval = SVR4_HRT_USEC;
1062 case SVR4_HRT_CNTL_TOFD:
1063 DPRINTF(("htrcntl(TOFD)\n"));
1067 if (uap->clk != SVR4_HRT_CLK_STD) {
1068 DPRINTF(("clk == %d\n", uap->clk));
1071 if (uap->ti == NULL) {
1072 DPRINTF(("ti NULL\n"));
1076 t.h_sec = tv.tv_sec;
1077 t.h_rem = tv.tv_usec;
1078 t.h_res = SVR4_HRT_USEC;
1079 return copyout(&t, uap->ti, sizeof(t));
1082 case SVR4_HRT_CNTL_START:
1083 DPRINTF(("htrcntl(START)\n"));
1086 case SVR4_HRT_CNTL_GET:
1087 DPRINTF(("htrcntl(GET)\n"));
1090 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1097 svr4_sys_hrtsys(td, uap)
1099 struct svr4_sys_hrtsys_args *uap;
1101 int *retval = td->td_retval;
1105 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1109 DPRINTF(("hrtalarm\n"));
1113 DPRINTF(("hrtsleep\n"));
1117 DPRINTF(("hrtcancel\n"));
1121 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1128 svr4_setinfo(pid, ru, st, s)
1137 memset(&i, 0, sizeof(i));
1139 i.svr4_si_signo = SVR4_SIGCHLD;
1140 i.svr4_si_errno = 0; /* XXX? */
1142 i.svr4_si_pid = pid;
1144 i.svr4_si_stime = ru->ru_stime.tv_sec;
1145 i.svr4_si_utime = ru->ru_utime.tv_sec;
1148 if (WIFEXITED(st)) {
1149 i.svr4_si_status = WEXITSTATUS(st);
1150 i.svr4_si_code = SVR4_CLD_EXITED;
1151 } else if (WIFSTOPPED(st)) {
1153 if (sig >= 0 && sig < NSIG)
1154 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1156 if (i.svr4_si_status == SVR4_SIGCONT)
1157 i.svr4_si_code = SVR4_CLD_CONTINUED;
1159 i.svr4_si_code = SVR4_CLD_STOPPED;
1162 if (sig >= 0 && sig < NSIG)
1163 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1166 i.svr4_si_code = SVR4_CLD_DUMPED;
1168 i.svr4_si_code = SVR4_CLD_KILLED;
1171 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1172 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1175 return copyout(&i, s, sizeof(i));
1180 svr4_sys_waitsys(td, uap)
1182 struct svr4_sys_waitsys_args *uap;
1187 int error, *retval = td->td_retval;
1190 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1192 uap->info, uap->options));
1214 /* Hand off the easy cases to kern_wait(). */
1215 if (!(uap->options & (SVR4_WNOWAIT)) &&
1216 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1220 if (uap->options & SVR4_WSTOPPED)
1221 options |= WUNTRACED;
1222 if (uap->options & SVR4_WCONTINUED)
1223 options |= WCONTINUED;
1224 if (uap->options & SVR4_WNOHANG)
1227 error = kern_wait(td, pid, &status, options, &ru);
1230 if (uap->options & SVR4_WNOHANG && *retval == 0)
1231 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1233 error = svr4_setinfo(*retval, &ru, status, uap->info);
1239 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1240 * just want to see if there is a process to harvest, we don't
1241 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1242 * meaning we want to ignore zombies. Either way, we don't have
1243 * to handle harvesting zombies here. We do have to duplicate the
1244 * other portions of kern_wait() though, especially for WCONTINUED
1249 sx_slock(&proctree_lock);
1250 LIST_FOREACH(p, &q->p_children, p_sibling) {
1252 if (pid != WAIT_ANY &&
1253 p->p_pid != pid && p->p_pgid != -pid) {
1255 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1259 if (p_canwait(td, p)) {
1268 * See if we have a zombie. If so, WNOWAIT should be set,
1269 * as otherwise we should have called kern_wait() up above.
1271 if ((p->p_state == PRS_ZOMBIE) &&
1272 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1274 KASSERT(uap->options & SVR4_WNOWAIT,
1275 ("WNOWAIT is clear"));
1277 /* Found a zombie, so cache info in local variables. */
1279 status = KW_EXITCODE(p->p_xexit, p->p_xsig);
1282 calcru(p, &ru.ru_utime, &ru.ru_stime);
1285 sx_sunlock(&proctree_lock);
1287 /* Copy the info out to userland. */
1289 DPRINTF(("found %d\n", pid));
1290 return (svr4_setinfo(pid, &ru, status, uap->info));
1294 * See if we have a stopped or continued process.
1295 * XXX: This duplicates the same code in kern_wait().
1297 if ((p->p_flag & P_STOPPED_SIG) &&
1298 (p->p_suspcount == p->p_numthreads) &&
1299 (p->p_flag & P_WAITED) == 0 &&
1300 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1302 if (((uap->options & SVR4_WNOWAIT)) == 0)
1303 p->p_flag |= P_WAITED;
1304 sx_sunlock(&proctree_lock);
1306 status = W_STOPCODE(p->p_xsig);
1309 calcru(p, &ru.ru_utime, &ru.ru_stime);
1313 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1315 sigqueue_take(p->p_ksi);
1320 DPRINTF(("jobcontrol %d\n", pid));
1321 return (svr4_setinfo(pid, &ru, status, uap->info));
1324 if (uap->options & SVR4_WCONTINUED &&
1325 (p->p_flag & P_CONTINUED)) {
1326 sx_sunlock(&proctree_lock);
1327 if (((uap->options & SVR4_WNOWAIT)) == 0)
1328 p->p_flag &= ~P_CONTINUED;
1333 calcru(p, &ru.ru_utime, &ru.ru_stime);
1337 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1339 sigqueue_take(p->p_ksi);
1344 DPRINTF(("jobcontrol %d\n", pid));
1345 return (svr4_setinfo(pid, &ru, status, uap->info));
1351 sx_sunlock(&proctree_lock);
1355 if (uap->options & SVR4_WNOHANG) {
1356 sx_sunlock(&proctree_lock);
1358 return (svr4_setinfo(0, NULL, 0, uap->info));
1362 sx_sunlock(&proctree_lock);
1363 if (q->p_flag & P_STATCHILD) {
1364 q->p_flag &= ~P_STATCHILD;
1367 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1376 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1377 const struct statfs *bfs;
1378 struct svr4_statvfs *sfs;
1380 sfs->f_bsize = bfs->f_iosize; /* XXX */
1381 sfs->f_frsize = bfs->f_bsize;
1382 sfs->f_blocks = bfs->f_blocks;
1383 sfs->f_bfree = bfs->f_bfree;
1384 sfs->f_bavail = bfs->f_bavail;
1385 sfs->f_files = bfs->f_files;
1386 sfs->f_ffree = bfs->f_ffree;
1387 sfs->f_favail = bfs->f_ffree;
1388 sfs->f_fsid = bfs->f_fsid.val[0];
1389 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1391 if (bfs->f_flags & MNT_RDONLY)
1392 sfs->f_flag |= SVR4_ST_RDONLY;
1393 if (bfs->f_flags & MNT_NOSUID)
1394 sfs->f_flag |= SVR4_ST_NOSUID;
1395 sfs->f_namemax = MAXNAMLEN;
1396 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1397 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1402 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1403 const struct statfs *bfs;
1404 struct svr4_statvfs64 *sfs;
1406 sfs->f_bsize = bfs->f_iosize; /* XXX */
1407 sfs->f_frsize = bfs->f_bsize;
1408 sfs->f_blocks = bfs->f_blocks;
1409 sfs->f_bfree = bfs->f_bfree;
1410 sfs->f_bavail = bfs->f_bavail;
1411 sfs->f_files = bfs->f_files;
1412 sfs->f_ffree = bfs->f_ffree;
1413 sfs->f_favail = bfs->f_ffree;
1414 sfs->f_fsid = bfs->f_fsid.val[0];
1415 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1417 if (bfs->f_flags & MNT_RDONLY)
1418 sfs->f_flag |= SVR4_ST_RDONLY;
1419 if (bfs->f_flags & MNT_NOSUID)
1420 sfs->f_flag |= SVR4_ST_NOSUID;
1421 sfs->f_namemax = MAXNAMLEN;
1422 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1423 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1428 svr4_sys_statvfs(td, uap)
1430 struct svr4_sys_statvfs_args *uap;
1432 struct svr4_statvfs sfs;
1437 CHECKALTEXIST(td, uap->path, &path);
1439 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1443 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1444 return copyout(&sfs, uap->fs, sizeof(sfs));
1449 svr4_sys_fstatvfs(td, uap)
1451 struct svr4_sys_fstatvfs_args *uap;
1453 struct svr4_statvfs sfs;
1457 error = kern_fstatfs(td, uap->fd, &bfs);
1460 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1461 return copyout(&sfs, uap->fs, sizeof(sfs));
1466 svr4_sys_statvfs64(td, uap)
1468 struct svr4_sys_statvfs64_args *uap;
1470 struct svr4_statvfs64 sfs;
1475 CHECKALTEXIST(td, uap->path, &path);
1477 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1481 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1482 return copyout(&sfs, uap->fs, sizeof(sfs));
1487 svr4_sys_fstatvfs64(td, uap)
1489 struct svr4_sys_fstatvfs64_args *uap;
1491 struct svr4_statvfs64 sfs;
1495 error = kern_fstatfs(td, uap->fd, &bfs);
1498 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1499 return copyout(&sfs, uap->fs, sizeof(sfs));
1503 svr4_sys_alarm(td, uap)
1505 struct svr4_sys_alarm_args *uap;
1507 struct itimerval itv, oitv;
1510 timevalclear(&itv.it_interval);
1511 itv.it_value.tv_sec = uap->sec;
1512 itv.it_value.tv_usec = 0;
1513 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1516 if (oitv.it_value.tv_usec != 0)
1517 oitv.it_value.tv_sec++;
1518 td->td_retval[0] = oitv.it_value.tv_sec;
1523 svr4_sys_gettimeofday(td, uap)
1525 struct svr4_sys_gettimeofday_args *uap;
1531 return copyout(&atv, uap->tp, sizeof (atv));
1538 svr4_sys_facl(td, uap)
1540 struct svr4_sys_facl_args *uap;
1544 retval = td->td_retval;
1548 case SVR4_SYS_SETACL:
1549 /* We don't support acls on any filesystem */
1552 case SVR4_SYS_GETACL:
1553 return copyout(retval, &uap->num,
1556 case SVR4_SYS_GETACLCNT:
1566 svr4_sys_acl(td, uap)
1568 struct svr4_sys_acl_args *uap;
1570 /* XXX: for now the same */
1571 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1575 svr4_sys_auditsys(td, uap)
1577 struct svr4_sys_auditsys_args *uap;
1580 * XXX: Big brother is *not* watching.
1586 svr4_sys_memcntl(td, uap)
1588 struct svr4_sys_memcntl_args *uap;
1593 struct msync_args msa;
1595 msa.addr = uap->addr;
1597 msa.flags = (int)uap->arg;
1599 return sys_msync(td, &msa);
1601 case SVR4_MC_ADVISE:
1603 struct madvise_args maa;
1605 maa.addr = uap->addr;
1607 maa.behav = (int)uap->arg;
1609 return sys_madvise(td, &maa);
1612 case SVR4_MC_UNLOCK:
1613 case SVR4_MC_LOCKAS:
1614 case SVR4_MC_UNLOCKAS:
1623 svr4_sys_nice(td, uap)
1625 struct svr4_sys_nice_args *uap;
1627 struct setpriority_args ap;
1630 ap.which = PRIO_PROCESS;
1632 ap.prio = uap->prio;
1634 if ((error = sys_setpriority(td, &ap)) != 0)
1637 /* the cast is stupid, but the structures are the same */
1638 if ((error = sys_getpriority(td, (struct getpriority_args *)&ap)) != 0)
1645 svr4_sys_resolvepath(td, uap)
1647 struct svr4_sys_resolvepath_args *uap;
1649 struct nameidata nd;
1650 int error, *retval = td->td_retval;
1653 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1656 if ((error = namei(&nd)) != 0)
1658 NDFREE(&nd, NDF_NO_FREE_PNBUF);
1660 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1661 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1666 NDFREE(&nd, NDF_ONLY_PNBUF);