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$");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/dirent.h>
43 #include <sys/fcntl.h>
44 #include <sys/filedesc.h>
45 #include <sys/imgact.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/file.h> /* Must come after sys/malloc.h */
51 #include <sys/mount.h>
53 #include <sys/mutex.h>
54 #include <sys/namei.h>
57 #include <sys/ptrace.h>
58 #include <sys/resource.h>
59 #include <sys/resourcevar.h>
61 #include <sys/signalvar.h>
64 #include <sys/syscallsubr.h>
65 #include <sys/sysproto.h>
67 #include <sys/times.h>
69 #include <sys/vnode.h>
72 #include <compat/svr4/svr4.h>
73 #include <compat/svr4/svr4_types.h>
74 #include <compat/svr4/svr4_signal.h>
75 #include <compat/svr4/svr4_proto.h>
76 #include <compat/svr4/svr4_util.h>
77 #include <compat/svr4/svr4_sysconfig.h>
78 #include <compat/svr4/svr4_dirent.h>
79 #include <compat/svr4/svr4_acl.h>
80 #include <compat/svr4/svr4_ulimit.h>
81 #include <compat/svr4/svr4_statvfs.h>
82 #include <compat/svr4/svr4_hrt.h>
83 #include <compat/svr4/svr4_mman.h>
84 #include <compat/svr4/svr4_wait.h>
86 #include <security/mac/mac_framework.h>
88 #include <machine/vmparam.h>
90 #include <vm/vm_param.h>
91 #include <vm/vm_map.h>
92 #if defined(__FreeBSD__)
94 #include <vm/vm_extern.h>
99 # include <uvm/uvm_extern.h>
103 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
105 static int svr4_mknod(struct thread *, register_t *, char *,
106 svr4_mode_t, svr4_dev_t);
108 static __inline clock_t timeval_to_clock_t(struct timeval *);
109 static int svr4_setinfo (pid_t , struct rusage *, int, svr4_siginfo_t *);
111 struct svr4_hrtcntl_args;
112 static int svr4_hrtcntl (struct thread *, struct svr4_hrtcntl_args *,
114 static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
115 struct svr4_statvfs *);
116 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
117 struct svr4_statvfs64 *);
118 static struct proc *svr4_pfind(pid_t pid);
123 svr4_sys_setitimer(td, uap)
124 register struct thread *td;
125 struct svr4_sys_setitimer_args *uap;
127 td->td_retval[0] = 0;
133 svr4_sys_wait(td, uap)
135 struct svr4_sys_wait_args *uap;
139 error = kern_wait(td, WAIT_ANY, &st, 0, NULL);
143 if (WIFSIGNALED(st)) {
145 if (sig >= 0 && sig < NSIG)
146 st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig);
147 } else if (WIFSTOPPED(st)) {
149 if (sig >= 0 && sig < NSIG)
150 st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8);
154 * It looks like wait(2) on svr4/solaris/2.4 returns
155 * the status in retval[1], and the pid on retval[0].
157 td->td_retval[1] = st;
160 error = copyout(&st, uap->status, sizeof(st));
166 svr4_sys_execv(td, uap)
168 struct svr4_sys_execv_args *uap;
170 struct image_args eargs;
174 CHECKALTEXIST(td, uap->path, &path);
176 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
179 error = kern_execve(td, &eargs, NULL);
184 svr4_sys_execve(td, uap)
186 struct svr4_sys_execve_args *uap;
188 struct image_args eargs;
192 CHECKALTEXIST(td, uap->path, &path);
194 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
198 error = kern_execve(td, &eargs, NULL);
205 struct svr4_sys_time_args *v;
207 struct svr4_sys_time_args *uap = v;
213 error = copyout(&tv.tv_sec, uap->t,
215 td->td_retval[0] = (int) tv.tv_sec;
222 * Read SVR4-style directory entries. We suck them into kernel space so
223 * that they can be massaged before being copied out to user code.
225 * This code is ported from the Linux emulator: Changes to the VFS interface
226 * between FreeBSD and NetBSD have made it simpler to port it from there than
227 * to adapt the NetBSD version.
230 svr4_sys_getdents64(td, uap)
232 struct svr4_sys_getdents64_args *uap;
234 register struct dirent *bdp;
236 caddr_t inp, buf; /* BSD-format */
237 int len, reclen; /* BSD-format */
238 caddr_t outp; /* SVR4-format */
239 int resid, svr4reclen=0; /* SVR4-format */
244 struct svr4_dirent64 svr4_dirent;
245 int buflen, error, eofflag, nbytes, justone, vfslocked;
246 u_long *cookies = NULL, *cookiep;
249 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
250 uap->fd, uap->nbytes));
251 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) {
255 if ((fp->f_flag & FREAD) == 0) {
261 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
262 if (vp->v_type != VDIR) {
263 VFS_UNLOCK_GIANT(vfslocked);
268 nbytes = uap->nbytes;
270 nbytes = sizeof (struct svr4_dirent64);
277 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
278 buflen = max(DIRBLKSIZ, nbytes);
279 buflen = min(buflen, MAXBSIZE);
280 buf = malloc(buflen, M_TEMP, M_WAITOK);
281 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
284 aiov.iov_len = buflen;
285 auio.uio_iov = &aiov;
287 auio.uio_rw = UIO_READ;
288 auio.uio_segflg = UIO_SYSSPACE;
290 auio.uio_resid = buflen;
291 auio.uio_offset = off;
294 free(cookies, M_TEMP);
299 error = mac_check_vnode_readdir(td->td_ucred, vp);
304 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
305 &ncookies, &cookies);
311 outp = (caddr_t) uap->dp;
313 if ((len = buflen - auio.uio_resid) <= 0) {
321 * When using cookies, the vfs has the option of reading from
322 * a different offset than that supplied (UFS truncates the
323 * offset to a block boundary to make sure that it never reads
324 * partway through a directory entry, even if the directory
325 * has been compacted).
327 while (len > 0 && ncookies > 0 && *cookiep <= off) {
328 bdp = (struct dirent *) inp;
329 len -= bdp->d_reclen;
330 inp += bdp->d_reclen;
337 if (cookiep && ncookies == 0)
339 bdp = (struct dirent *) inp;
340 reclen = bdp->d_reclen;
342 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
347 if (bdp->d_fileno == 0) {
357 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
358 if (reclen > len || resid < svr4reclen) {
362 svr4_dirent.d_ino = (long) bdp->d_fileno;
365 * old svr4-style readdir usage.
367 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
368 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
370 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
371 svr4_dirent.d_reclen = (u_short) svr4reclen;
373 strcpy(svr4_dirent.d_name, bdp->d_name);
374 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
389 if (outp == (caddr_t) uap->dp)
394 nbytes = resid + svr4reclen;
397 td->td_retval[0] = nbytes - resid;
399 VOP_UNLOCK(vp, 0, td);
400 VFS_UNLOCK_GIANT(vfslocked);
403 free(cookies, M_TEMP);
410 svr4_sys_getdents(td, uap)
412 struct svr4_sys_getdents_args *uap;
416 caddr_t inp, buf; /* BSD-format */
417 int len, reclen; /* BSD-format */
418 caddr_t outp; /* SVR4-format */
419 int resid, svr4_reclen; /* SVR4-format */
423 struct svr4_dirent idb;
424 off_t off; /* true file offset */
425 int buflen, error, eofflag, vfslocked;
426 u_long *cookiebuf = NULL, *cookie;
427 int ncookies = 0, *retval = td->td_retval;
432 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
435 if ((fp->f_flag & FREAD) == 0) {
441 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
442 if (vp->v_type != VDIR) {
443 VFS_UNLOCK_GIANT(vfslocked);
448 buflen = min(MAXBSIZE, uap->nbytes);
449 buf = malloc(buflen, M_TEMP, M_WAITOK);
450 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
454 aiov.iov_len = buflen;
455 auio.uio_iov = &aiov;
457 auio.uio_rw = UIO_READ;
458 auio.uio_segflg = UIO_SYSSPACE;
460 auio.uio_resid = buflen;
461 auio.uio_offset = off;
464 error = mac_check_vnode_readdir(td->td_ucred, vp);
470 * First we read into the malloc'ed buffer, then
471 * we massage it into user space, one record at a time.
473 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
482 if ((len = buflen - auio.uio_resid) == 0)
485 for (cookie = cookiebuf; len > 0; len -= reclen) {
486 bdp = (struct dirent *)inp;
487 reclen = bdp->d_reclen;
489 panic("svr4_sys_getdents64: bad reclen");
490 off = *cookie++; /* each entry points to the next */
491 if ((off >> 32) != 0) {
492 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
496 if (bdp->d_fileno == 0) {
497 inp += reclen; /* it is a hole; squish it out */
500 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
501 if (reclen > len || resid < svr4_reclen) {
502 /* entry too big for buffer, so just stop */
507 * Massage in place to make a SVR4-shaped dirent (otherwise
508 * we have to worry about touching user memory outside of
509 * the copyout() call).
511 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
512 idb.d_off = (svr4_off_t)off;
513 idb.d_reclen = (u_short)svr4_reclen;
514 strcpy(idb.d_name, bdp->d_name);
515 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
517 /* advance past this real entry */
519 /* advance output past SVR4-shaped entry */
521 resid -= svr4_reclen;
524 /* if we squished out the whole block, try again */
525 if (outp == uap->buf)
527 fp->f_offset = off; /* update the vnode offset */
530 *retval = uap->nbytes - resid;
532 VOP_UNLOCK(vp, 0, td);
533 VFS_UNLOCK_GIANT(vfslocked);
536 free(cookiebuf, M_TEMP);
543 svr4_sys_mmap(td, uap)
545 struct svr4_sys_mmap_args *uap;
550 retval = td->td_retval;
551 #define _MAP_NEW 0x80000000
553 * Verify the arguments.
555 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
556 return EINVAL; /* XXX still needed? */
563 mm.flags = uap->flags & ~_MAP_NEW;
568 return mmap(td, &mm);
572 svr4_sys_mmap64(td, uap)
574 struct svr4_sys_mmap64_args *uap;
579 #define _MAP_NEW 0x80000000
581 * Verify the arguments.
583 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
584 return EINVAL; /* XXX still needed? */
591 mm.flags = uap->flags & ~_MAP_NEW;
596 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
597 if ((mm.flags & MAP_FIXED) == 0 &&
598 mm.addr != 0 && (void *)mm.addr < rp)
601 return mmap(td, &mm);
606 svr4_sys_fchroot(td, uap)
608 struct svr4_sys_fchroot_args *uap;
610 struct filedesc *fdp = td->td_proc->p_fd;
613 int error, vfslocked;
615 if ((error = priv_check_cred(td->td_ucred, PRIV_VFS_FCHROOT,
616 SUSER_ALLOWJAIL)) != 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, td);
625 error = change_dir(vp, td);
629 error = mac_check_vnode_chroot(td->td_ucred, vp);
633 VOP_UNLOCK(vp, 0, td);
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)
669 register struct thread *td;
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_UNUSED:
713 case SVR4_CONFIG_NGROUPS:
714 *retval = NGROUPS_MAX;
716 case SVR4_CONFIG_CHILD_MAX:
719 case SVR4_CONFIG_OPEN_FILES:
722 case SVR4_CONFIG_POSIX_VER:
725 case SVR4_CONFIG_PAGESIZE:
728 case SVR4_CONFIG_CLK_TCK:
729 *retval = 60; /* should this be `hz', ie. 100? */
731 case SVR4_CONFIG_XOPEN_VER:
732 *retval = 2; /* XXX: What should that be? */
734 case SVR4_CONFIG_PROF_TCK:
735 *retval = 60; /* XXX: What should that be? */
737 case SVR4_CONFIG_NPROC_CONF:
738 *retval = 1; /* Only one processor for now */
740 case SVR4_CONFIG_NPROC_ONLN:
741 *retval = 1; /* And it better be online */
743 case SVR4_CONFIG_AIO_LISTIO_MAX:
744 case SVR4_CONFIG_AIO_MAX:
745 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
746 *retval = 0; /* No aio support */
748 case SVR4_CONFIG_DELAYTIMER_MAX:
749 *retval = 0; /* No delaytimer support */
751 case SVR4_CONFIG_MQ_OPEN_MAX:
752 *retval = msginfo.msgmni;
754 case SVR4_CONFIG_MQ_PRIO_MAX:
755 *retval = 0; /* XXX: Don't know */
757 case SVR4_CONFIG_RTSIG_MAX:
760 case SVR4_CONFIG_SEM_NSEMS_MAX:
761 *retval = seminfo.semmni;
763 case SVR4_CONFIG_SEM_VALUE_MAX:
764 *retval = seminfo.semvmx;
766 case SVR4_CONFIG_SIGQUEUE_MAX:
767 *retval = 0; /* XXX: Don't know */
769 case SVR4_CONFIG_SIGRT_MIN:
770 case SVR4_CONFIG_SIGRT_MAX:
771 *retval = 0; /* No real time signals */
773 case SVR4_CONFIG_TIMER_MAX:
774 *retval = 3; /* XXX: real, virtual, profiling */
777 case SVR4_CONFIG_PHYS_PAGES:
779 *retval = uvmexp.free; /* XXX: free instead of total */
781 *retval = VMCNT_GET(free_count); /* XXX: free instead of total */
784 case SVR4_CONFIG_AVPHYS_PAGES:
786 *retval = uvmexp.active; /* XXX: active instead of avg */
788 *retval = VMCNT_GET(active_count); /* XXX: active instead of avg */
801 svr4_sys_break(td, uap)
803 struct svr4_sys_break_args *uap;
805 struct obreak_args ap;
807 ap.nsize = uap->nsize;
808 return (obreak(td, &ap));
811 static __inline clock_t
812 timeval_to_clock_t(tv)
815 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
820 svr4_sys_times(td, uap)
822 struct svr4_sys_times_args *uap;
824 struct timeval tv, utime, stime, cutime, cstime;
831 calcru(p, &utime, &stime);
832 calccru(p, &cutime, &cstime);
835 tms.tms_utime = timeval_to_clock_t(&utime);
836 tms.tms_stime = timeval_to_clock_t(&stime);
838 tms.tms_cutime = timeval_to_clock_t(&cutime);
839 tms.tms_cstime = timeval_to_clock_t(&cstime);
841 error = copyout(&tms, uap->tp, sizeof(tms));
846 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
852 svr4_sys_ulimit(td, uap)
854 struct svr4_sys_ulimit_args *uap;
856 int *retval = td->td_retval;
861 PROC_LOCK(td->td_proc);
862 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
863 PROC_UNLOCK(td->td_proc);
865 *retval = 0x7fffffff;
872 krl.rlim_cur = uap->newlimit * 512;
873 PROC_LOCK(td->td_proc);
874 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
875 PROC_UNLOCK(td->td_proc);
877 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
881 PROC_LOCK(td->td_proc);
882 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
883 PROC_UNLOCK(td->td_proc);
885 *retval = 0x7fffffff;
891 struct vmspace *vm = td->td_proc->p_vmspace;
894 PROC_LOCK(td->td_proc);
895 r = lim_cur(td->td_proc, RLIMIT_DATA);
896 PROC_UNLOCK(td->td_proc);
900 mtx_lock(&Giant); /* XXX */
901 r += (long) vm->vm_daddr;
910 PROC_LOCK(td->td_proc);
911 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
912 PROC_UNLOCK(td->td_proc);
914 *retval = 0x7fffffff;
928 /* look in the live processes */
929 if ((p = pfind(pid)) == NULL)
930 /* look in the zombies */
938 svr4_sys_pgrpsys(td, uap)
940 struct svr4_sys_pgrpsys_args *uap;
942 int *retval = td->td_retval;
943 struct proc *p = td->td_proc;
946 case 1: /* setpgrp() */
948 * SVR4 setpgrp() (which takes no arguments) has the
949 * semantics that the session ID is also created anew, so
950 * in almost every sense, setpgrp() is identical to
951 * setsid() for SVR4. (Under BSD, the difference is that
952 * a setpgid(0,0) will not create a new session.)
957 case 0: /* getpgrp() */
959 *retval = p->p_pgrp->pg_id;
963 case 2: /* getsid(pid) */
966 else if ((p = svr4_pfind(uap->pid)) == NULL)
969 * This has already been initialized to the pid of
970 * the session leader.
972 *retval = (register_t) p->p_session->s_sid;
976 case 3: /* setsid() */
977 return setsid(td, NULL);
979 case 4: /* getpgid(pid) */
983 else if ((p = svr4_pfind(uap->pid)) == NULL)
986 *retval = (int) p->p_pgrp->pg_id;
990 case 5: /* setpgid(pid, pgid); */
992 struct setpgid_args sa;
996 return setpgid(td, &sa);
1004 struct svr4_hrtcntl_args {
1008 svr4_hrt_interval_t * iv;
1009 svr4_hrt_time_t * ti;
1014 svr4_hrtcntl(td, uap, retval)
1016 struct svr4_hrtcntl_args *uap;
1020 case SVR4_HRT_CNTL_RES:
1021 DPRINTF(("htrcntl(RES)\n"));
1022 *retval = SVR4_HRT_USEC;
1025 case SVR4_HRT_CNTL_TOFD:
1026 DPRINTF(("htrcntl(TOFD)\n"));
1030 if (uap->clk != SVR4_HRT_CLK_STD) {
1031 DPRINTF(("clk == %d\n", uap->clk));
1034 if (uap->ti == NULL) {
1035 DPRINTF(("ti NULL\n"));
1039 t.h_sec = tv.tv_sec;
1040 t.h_rem = tv.tv_usec;
1041 t.h_res = SVR4_HRT_USEC;
1042 return copyout(&t, uap->ti, sizeof(t));
1045 case SVR4_HRT_CNTL_START:
1046 DPRINTF(("htrcntl(START)\n"));
1049 case SVR4_HRT_CNTL_GET:
1050 DPRINTF(("htrcntl(GET)\n"));
1053 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1060 svr4_sys_hrtsys(td, uap)
1062 struct svr4_sys_hrtsys_args *uap;
1064 int *retval = td->td_retval;
1068 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1072 DPRINTF(("hrtalarm\n"));
1076 DPRINTF(("hrtsleep\n"));
1080 DPRINTF(("hrtcancel\n"));
1084 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1091 svr4_setinfo(pid, ru, st, s)
1100 memset(&i, 0, sizeof(i));
1102 i.svr4_si_signo = SVR4_SIGCHLD;
1103 i.svr4_si_errno = 0; /* XXX? */
1105 i.svr4_si_pid = pid;
1107 i.svr4_si_stime = ru->ru_stime.tv_sec;
1108 i.svr4_si_utime = ru->ru_utime.tv_sec;
1111 if (WIFEXITED(st)) {
1112 i.svr4_si_status = WEXITSTATUS(st);
1113 i.svr4_si_code = SVR4_CLD_EXITED;
1114 } else if (WIFSTOPPED(st)) {
1116 if (sig >= 0 && sig < NSIG)
1117 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1119 if (i.svr4_si_status == SVR4_SIGCONT)
1120 i.svr4_si_code = SVR4_CLD_CONTINUED;
1122 i.svr4_si_code = SVR4_CLD_STOPPED;
1125 if (sig >= 0 && sig < NSIG)
1126 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1129 i.svr4_si_code = SVR4_CLD_DUMPED;
1131 i.svr4_si_code = SVR4_CLD_KILLED;
1134 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1135 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1138 return copyout(&i, s, sizeof(i));
1143 svr4_sys_waitsys(td, uap)
1145 struct svr4_sys_waitsys_args *uap;
1150 int error, *retval = td->td_retval;
1153 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1155 uap->info, uap->options));
1177 /* Hand off the easy cases to kern_wait(). */
1178 if (!(uap->options & (SVR4_WNOWAIT)) &&
1179 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1183 if (uap->options & SVR4_WSTOPPED)
1184 options |= WUNTRACED;
1185 if (uap->options & SVR4_WCONTINUED)
1186 options |= WCONTINUED;
1187 if (uap->options & SVR4_WNOHANG)
1190 error = kern_wait(td, pid, &status, options, &ru);
1193 if (uap->options & SVR4_WNOHANG && *retval == 0)
1194 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1196 error = svr4_setinfo(*retval, &ru, status, uap->info);
1202 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1203 * just want to see if there is a process to harvest, we dont'
1204 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1205 * meaning we want to ignore zombies. Either way, we don't have
1206 * to handle harvesting zombies here. We do have to duplicate the
1207 * other portions of kern_wait() though, especially for the
1208 * WCONTINUED and WSTOPPED.
1212 sx_slock(&proctree_lock);
1213 LIST_FOREACH(p, &q->p_children, p_sibling) {
1215 if (pid != WAIT_ANY &&
1216 p->p_pid != pid && p->p_pgid != -pid) {
1218 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1222 if (p_canwait(td, p)) {
1230 * See if we have a zombie. If so, WNOWAIT should be set,
1231 * as otherwise we should have called kern_wait() up above.
1233 if ((p->p_state == PRS_ZOMBIE) &&
1234 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1235 KASSERT(uap->options & SVR4_WNOWAIT,
1236 ("WNOWAIT is clear"));
1238 /* Found a zombie, so cache info in local variables. */
1240 status = p->p_xstat;
1242 calcru(p, &ru.ru_utime, &ru.ru_stime);
1244 sx_sunlock(&proctree_lock);
1246 /* Copy the info out to userland. */
1248 DPRINTF(("found %d\n", pid));
1249 return (svr4_setinfo(pid, &ru, status, uap->info));
1253 * See if we have a stopped or continued process.
1254 * XXX: This duplicates the same code in kern_wait().
1256 mtx_lock_spin(&sched_lock);
1257 if ((p->p_flag & P_STOPPED_SIG) &&
1258 (p->p_suspcount == p->p_numthreads) &&
1259 (p->p_flag & P_WAITED) == 0 &&
1260 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1261 mtx_unlock_spin(&sched_lock);
1262 if (((uap->options & SVR4_WNOWAIT)) == 0)
1263 p->p_flag |= P_WAITED;
1264 sx_sunlock(&proctree_lock);
1266 status = W_STOPCODE(p->p_xstat);
1268 calcru(p, &ru.ru_utime, &ru.ru_stime);
1271 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1273 sigqueue_take(p->p_ksi);
1278 DPRINTF(("jobcontrol %d\n", pid));
1279 return (svr4_setinfo(pid, &ru, status, uap->info));
1281 mtx_unlock_spin(&sched_lock);
1282 if (uap->options & SVR4_WCONTINUED &&
1283 (p->p_flag & P_CONTINUED)) {
1284 sx_sunlock(&proctree_lock);
1285 if (((uap->options & SVR4_WNOWAIT)) == 0)
1286 p->p_flag &= ~P_CONTINUED;
1290 calcru(p, &ru.ru_utime, &ru.ru_stime);
1293 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1295 sigqueue_take(p->p_ksi);
1300 DPRINTF(("jobcontrol %d\n", pid));
1301 return (svr4_setinfo(pid, &ru, status, uap->info));
1307 sx_sunlock(&proctree_lock);
1311 if (uap->options & SVR4_WNOHANG) {
1312 sx_sunlock(&proctree_lock);
1314 return (svr4_setinfo(0, NULL, 0, uap->info));
1318 sx_sunlock(&proctree_lock);
1319 if (q->p_flag & P_STATCHILD) {
1320 q->p_flag &= ~P_STATCHILD;
1323 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1332 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1333 const struct statfs *bfs;
1334 struct svr4_statvfs *sfs;
1336 sfs->f_bsize = bfs->f_iosize; /* XXX */
1337 sfs->f_frsize = bfs->f_bsize;
1338 sfs->f_blocks = bfs->f_blocks;
1339 sfs->f_bfree = bfs->f_bfree;
1340 sfs->f_bavail = bfs->f_bavail;
1341 sfs->f_files = bfs->f_files;
1342 sfs->f_ffree = bfs->f_ffree;
1343 sfs->f_favail = bfs->f_ffree;
1344 sfs->f_fsid = bfs->f_fsid.val[0];
1345 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1347 if (bfs->f_flags & MNT_RDONLY)
1348 sfs->f_flag |= SVR4_ST_RDONLY;
1349 if (bfs->f_flags & MNT_NOSUID)
1350 sfs->f_flag |= SVR4_ST_NOSUID;
1351 sfs->f_namemax = MAXNAMLEN;
1352 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1353 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1358 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1359 const struct statfs *bfs;
1360 struct svr4_statvfs64 *sfs;
1362 sfs->f_bsize = bfs->f_iosize; /* XXX */
1363 sfs->f_frsize = bfs->f_bsize;
1364 sfs->f_blocks = bfs->f_blocks;
1365 sfs->f_bfree = bfs->f_bfree;
1366 sfs->f_bavail = bfs->f_bavail;
1367 sfs->f_files = bfs->f_files;
1368 sfs->f_ffree = bfs->f_ffree;
1369 sfs->f_favail = bfs->f_ffree;
1370 sfs->f_fsid = bfs->f_fsid.val[0];
1371 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1373 if (bfs->f_flags & MNT_RDONLY)
1374 sfs->f_flag |= SVR4_ST_RDONLY;
1375 if (bfs->f_flags & MNT_NOSUID)
1376 sfs->f_flag |= SVR4_ST_NOSUID;
1377 sfs->f_namemax = MAXNAMLEN;
1378 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1379 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1384 svr4_sys_statvfs(td, uap)
1386 struct svr4_sys_statvfs_args *uap;
1388 struct svr4_statvfs sfs;
1393 CHECKALTEXIST(td, uap->path, &path);
1395 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1399 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1400 return copyout(&sfs, uap->fs, sizeof(sfs));
1405 svr4_sys_fstatvfs(td, uap)
1407 struct svr4_sys_fstatvfs_args *uap;
1409 struct svr4_statvfs sfs;
1413 error = kern_fstatfs(td, uap->fd, &bfs);
1416 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1417 return copyout(&sfs, uap->fs, sizeof(sfs));
1422 svr4_sys_statvfs64(td, uap)
1424 struct svr4_sys_statvfs64_args *uap;
1426 struct svr4_statvfs64 sfs;
1431 CHECKALTEXIST(td, uap->path, &path);
1433 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1437 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1438 return copyout(&sfs, uap->fs, sizeof(sfs));
1443 svr4_sys_fstatvfs64(td, uap)
1445 struct svr4_sys_fstatvfs64_args *uap;
1447 struct svr4_statvfs64 sfs;
1451 error = kern_fstatfs(td, uap->fd, &bfs);
1454 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1455 return copyout(&sfs, uap->fs, sizeof(sfs));
1459 svr4_sys_alarm(td, uap)
1461 struct svr4_sys_alarm_args *uap;
1463 struct itimerval itv, oitv;
1466 timevalclear(&itv.it_interval);
1467 itv.it_value.tv_sec = uap->sec;
1468 itv.it_value.tv_usec = 0;
1469 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1472 if (oitv.it_value.tv_usec != 0)
1473 oitv.it_value.tv_sec++;
1474 td->td_retval[0] = oitv.it_value.tv_sec;
1479 svr4_sys_gettimeofday(td, uap)
1481 struct svr4_sys_gettimeofday_args *uap;
1487 return copyout(&atv, uap->tp, sizeof (atv));
1494 svr4_sys_facl(td, uap)
1496 struct svr4_sys_facl_args *uap;
1500 retval = td->td_retval;
1504 case SVR4_SYS_SETACL:
1505 /* We don't support acls on any filesystem */
1508 case SVR4_SYS_GETACL:
1509 return copyout(retval, &uap->num,
1512 case SVR4_SYS_GETACLCNT:
1522 svr4_sys_acl(td, uap)
1524 struct svr4_sys_acl_args *uap;
1526 /* XXX: for now the same */
1527 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1531 svr4_sys_auditsys(td, uap)
1533 struct svr4_sys_auditsys_args *uap;
1536 * XXX: Big brother is *not* watching.
1542 svr4_sys_memcntl(td, uap)
1544 struct svr4_sys_memcntl_args *uap;
1549 struct msync_args msa;
1551 msa.addr = uap->addr;
1553 msa.flags = (int)uap->arg;
1555 return msync(td, &msa);
1557 case SVR4_MC_ADVISE:
1559 struct madvise_args maa;
1561 maa.addr = uap->addr;
1563 maa.behav = (int)uap->arg;
1565 return madvise(td, &maa);
1568 case SVR4_MC_UNLOCK:
1569 case SVR4_MC_LOCKAS:
1570 case SVR4_MC_UNLOCKAS:
1579 svr4_sys_nice(td, uap)
1581 struct svr4_sys_nice_args *uap;
1583 struct setpriority_args ap;
1586 ap.which = PRIO_PROCESS;
1588 ap.prio = uap->prio;
1590 if ((error = setpriority(td, &ap)) != 0)
1593 /* the cast is stupid, but the structures are the same */
1594 if ((error = getpriority(td, (struct getpriority_args *)&ap)) != 0)
1601 svr4_sys_resolvepath(td, uap)
1603 struct svr4_sys_resolvepath_args *uap;
1605 struct nameidata nd;
1606 int error, *retval = td->td_retval;
1610 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE,
1613 if ((error = namei(&nd)) != 0)
1615 vfslocked = NDHASGIANT(&nd);
1617 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1618 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1623 NDFREE(&nd, NDF_ONLY_PNBUF);
1625 VFS_UNLOCK_GIANT(vfslocked);