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/capability.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 */
243 struct svr4_dirent64 svr4_dirent;
244 int buflen, error, eofflag, nbytes, justone;
245 u_long *cookies = NULL, *cookiep;
248 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
249 uap->fd, uap->nbytes));
250 if ((error = getvnode(td->td_proc->p_fd, uap->fd, CAP_READ, &fp)) != 0)
253 if ((fp->f_flag & FREAD) == 0) {
259 if (vp->v_type != VDIR) {
264 nbytes = uap->nbytes;
266 nbytes = sizeof (struct svr4_dirent64);
273 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
274 buflen = max(DIRBLKSIZ, nbytes);
275 buflen = min(buflen, MAXBSIZE);
276 buf = malloc(buflen, M_TEMP, M_WAITOK);
277 vn_lock(vp, LK_SHARED | LK_RETRY);
280 aiov.iov_len = buflen;
281 auio.uio_iov = &aiov;
283 auio.uio_rw = UIO_READ;
284 auio.uio_segflg = UIO_SYSSPACE;
286 auio.uio_resid = buflen;
287 auio.uio_offset = off;
290 free(cookies, M_TEMP);
295 error = mac_vnode_check_readdir(td->td_ucred, vp);
300 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
301 &ncookies, &cookies);
307 outp = (caddr_t) uap->dp;
309 if ((len = buflen - auio.uio_resid) <= 0) {
317 * When using cookies, the vfs has the option of reading from
318 * a different offset than that supplied (UFS truncates the
319 * offset to a block boundary to make sure that it never reads
320 * partway through a directory entry, even if the directory
321 * has been compacted).
323 while (len > 0 && ncookies > 0 && *cookiep <= off) {
324 bdp = (struct dirent *) inp;
325 len -= bdp->d_reclen;
326 inp += bdp->d_reclen;
333 if (cookiep && ncookies == 0)
335 bdp = (struct dirent *) inp;
336 reclen = bdp->d_reclen;
338 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
343 if (bdp->d_fileno == 0) {
353 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
354 if (reclen > len || resid < svr4reclen) {
358 svr4_dirent.d_ino = (long) bdp->d_fileno;
361 * old svr4-style readdir usage.
363 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
364 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
366 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
367 svr4_dirent.d_reclen = (u_short) svr4reclen;
369 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.d_name));
370 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
385 if (outp == (caddr_t) uap->dp)
390 nbytes = resid + svr4reclen;
393 td->td_retval[0] = nbytes - resid;
398 free(cookies, M_TEMP);
405 svr4_sys_getdents(td, uap)
407 struct svr4_sys_getdents_args *uap;
411 caddr_t inp, buf; /* BSD-format */
412 int len, reclen; /* BSD-format */
413 caddr_t outp; /* SVR4-format */
414 int resid, svr4_reclen; /* SVR4-format */
418 struct svr4_dirent idb;
419 off_t off; /* true file offset */
420 int buflen, error, eofflag;
421 u_long *cookiebuf = NULL, *cookie;
422 int ncookies = 0, *retval = td->td_retval;
427 if ((error = getvnode(td->td_proc->p_fd, uap->fd, CAP_READ, &fp)) != 0)
430 if ((fp->f_flag & FREAD) == 0) {
436 if (vp->v_type != VDIR) {
441 buflen = min(MAXBSIZE, uap->nbytes);
442 buf = malloc(buflen, M_TEMP, M_WAITOK);
443 vn_lock(vp, LK_SHARED | LK_RETRY);
447 aiov.iov_len = buflen;
448 auio.uio_iov = &aiov;
450 auio.uio_rw = UIO_READ;
451 auio.uio_segflg = UIO_SYSSPACE;
453 auio.uio_resid = buflen;
454 auio.uio_offset = off;
457 error = mac_vnode_check_readdir(td->td_ucred, vp);
463 * First we read into the malloc'ed buffer, then
464 * we massage it into user space, one record at a time.
466 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
475 if ((len = buflen - auio.uio_resid) == 0)
478 for (cookie = cookiebuf; len > 0; len -= reclen) {
479 bdp = (struct dirent *)inp;
480 reclen = bdp->d_reclen;
482 panic("svr4_sys_getdents64: bad reclen");
484 off = *cookie++; /* each entry points to the next */
487 if ((off >> 32) != 0) {
488 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
492 if (bdp->d_fileno == 0) {
493 inp += reclen; /* it is a hole; squish it out */
496 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
497 if (reclen > len || resid < svr4_reclen) {
498 /* entry too big for buffer, so just stop */
503 * Massage in place to make a SVR4-shaped dirent (otherwise
504 * we have to worry about touching user memory outside of
505 * the copyout() call).
507 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
508 idb.d_off = (svr4_off_t)off;
509 idb.d_reclen = (u_short)svr4_reclen;
510 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
511 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
513 /* advance past this real entry */
515 /* advance output past SVR4-shaped entry */
517 resid -= svr4_reclen;
520 /* if we squished out the whole block, try again */
521 if (outp == uap->buf)
523 fp->f_offset = off; /* update the vnode offset */
526 *retval = uap->nbytes - resid;
531 free(cookiebuf, M_TEMP);
538 svr4_sys_mmap(td, uap)
540 struct svr4_sys_mmap_args *uap;
545 retval = td->td_retval;
546 #define _MAP_NEW 0x80000000
548 * Verify the arguments.
550 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
551 return EINVAL; /* XXX still needed? */
558 mm.flags = uap->flags & ~_MAP_NEW;
563 return sys_mmap(td, &mm);
567 svr4_sys_mmap64(td, uap)
569 struct svr4_sys_mmap64_args *uap;
574 #define _MAP_NEW 0x80000000
576 * Verify the arguments.
578 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
579 return EINVAL; /* XXX still needed? */
586 mm.flags = uap->flags & ~_MAP_NEW;
591 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
592 if ((mm.flags & MAP_FIXED) == 0 &&
593 mm.addr != 0 && (void *)mm.addr < rp)
596 return sys_mmap(td, &mm);
601 svr4_sys_fchroot(td, uap)
603 struct svr4_sys_fchroot_args *uap;
605 struct filedesc *fdp = td->td_proc->p_fd;
610 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
612 /* XXX: we have the chroot priv... what cap might we need? all? */
613 if ((error = getvnode(fdp, uap->fd, 0, &fp)) != 0)
618 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
619 error = change_dir(vp, td);
623 error = mac_vnode_check_chroot(td->td_ucred, vp);
628 error = change_root(vp, td);
638 svr4_mknod(td, retval, path, mode, dev)
648 CHECKALTEXIST(td, path, &newpath);
651 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
653 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
654 free(newpath, M_TEMP);
660 svr4_sys_mknod(td, uap)
662 struct svr4_sys_mknod_args *uap;
664 int *retval = td->td_retval;
665 return svr4_mknod(td, retval,
666 uap->path, uap->mode,
667 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev));
672 svr4_sys_xmknod(td, uap)
674 struct svr4_sys_xmknod_args *uap;
676 int *retval = td->td_retval;
677 return svr4_mknod(td, retval,
678 uap->path, uap->mode,
679 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
684 svr4_sys_vhangup(td, uap)
686 struct svr4_sys_vhangup_args *uap;
693 svr4_sys_sysconfig(td, uap)
695 struct svr4_sys_sysconfig_args *uap;
699 retval = &(td->td_retval[0]);
702 case SVR4_CONFIG_NGROUPS:
703 *retval = ngroups_max;
705 case SVR4_CONFIG_CHILD_MAX:
708 case SVR4_CONFIG_OPEN_FILES:
711 case SVR4_CONFIG_POSIX_VER:
714 case SVR4_CONFIG_PAGESIZE:
717 case SVR4_CONFIG_CLK_TCK:
718 *retval = 60; /* should this be `hz', ie. 100? */
720 case SVR4_CONFIG_XOPEN_VER:
721 *retval = 2; /* XXX: What should that be? */
723 case SVR4_CONFIG_PROF_TCK:
724 *retval = 60; /* XXX: What should that be? */
726 case SVR4_CONFIG_NPROC_CONF:
727 *retval = 1; /* Only one processor for now */
729 case SVR4_CONFIG_NPROC_ONLN:
730 *retval = 1; /* And it better be online */
732 case SVR4_CONFIG_AIO_LISTIO_MAX:
733 case SVR4_CONFIG_AIO_MAX:
734 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
735 *retval = 0; /* No aio support */
737 case SVR4_CONFIG_DELAYTIMER_MAX:
738 *retval = 0; /* No delaytimer support */
740 case SVR4_CONFIG_MQ_OPEN_MAX:
741 *retval = msginfo.msgmni;
743 case SVR4_CONFIG_MQ_PRIO_MAX:
744 *retval = 0; /* XXX: Don't know */
746 case SVR4_CONFIG_RTSIG_MAX:
749 case SVR4_CONFIG_SEM_NSEMS_MAX:
750 *retval = seminfo.semmni;
752 case SVR4_CONFIG_SEM_VALUE_MAX:
753 *retval = seminfo.semvmx;
755 case SVR4_CONFIG_SIGQUEUE_MAX:
756 *retval = 0; /* XXX: Don't know */
758 case SVR4_CONFIG_SIGRT_MIN:
759 case SVR4_CONFIG_SIGRT_MAX:
760 *retval = 0; /* No real time signals */
762 case SVR4_CONFIG_TIMER_MAX:
763 *retval = 3; /* XXX: real, virtual, profiling */
766 case SVR4_CONFIG_PHYS_PAGES:
768 *retval = uvmexp.free; /* XXX: free instead of total */
770 *retval = cnt.v_free_count; /* XXX: free instead of total */
773 case SVR4_CONFIG_AVPHYS_PAGES:
775 *retval = uvmexp.active; /* XXX: active instead of avg */
777 *retval = cnt.v_active_count; /* XXX: active instead of avg */
781 case SVR4_CONFIG_COHERENCY:
782 *retval = 0; /* XXX */
784 case SVR4_CONFIG_SPLIT_CACHE:
785 *retval = 0; /* XXX */
787 case SVR4_CONFIG_ICACHESZ:
788 *retval = 256; /* XXX */
790 case SVR4_CONFIG_DCACHESZ:
791 *retval = 256; /* XXX */
793 case SVR4_CONFIG_ICACHELINESZ:
794 *retval = 64; /* XXX */
796 case SVR4_CONFIG_DCACHELINESZ:
797 *retval = 64; /* XXX */
799 case SVR4_CONFIG_ICACHEBLKSZ:
800 *retval = 64; /* XXX */
802 case SVR4_CONFIG_DCACHEBLKSZ:
803 *retval = 64; /* XXX */
805 case SVR4_CONFIG_DCACHETBLKSZ:
806 *retval = 64; /* XXX */
808 case SVR4_CONFIG_ICACHE_ASSOC:
809 *retval = 1; /* XXX */
811 case SVR4_CONFIG_DCACHE_ASSOC:
812 *retval = 1; /* XXX */
814 case SVR4_CONFIG_MAXPID:
817 case SVR4_CONFIG_STACK_PROT:
818 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
828 svr4_sys_break(td, uap)
830 struct svr4_sys_break_args *uap;
832 struct obreak_args ap;
834 ap.nsize = uap->nsize;
835 return (sys_obreak(td, &ap));
838 static __inline clock_t
839 timeval_to_clock_t(tv)
842 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
847 svr4_sys_times(td, uap)
849 struct svr4_sys_times_args *uap;
851 struct timeval tv, utime, stime, cutime, cstime;
859 calcru(p, &utime, &stime);
861 calccru(p, &cutime, &cstime);
864 tms.tms_utime = timeval_to_clock_t(&utime);
865 tms.tms_stime = timeval_to_clock_t(&stime);
867 tms.tms_cutime = timeval_to_clock_t(&cutime);
868 tms.tms_cstime = timeval_to_clock_t(&cstime);
870 error = copyout(&tms, uap->tp, sizeof(tms));
875 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
881 svr4_sys_ulimit(td, uap)
883 struct svr4_sys_ulimit_args *uap;
885 int *retval = td->td_retval;
890 PROC_LOCK(td->td_proc);
891 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
892 PROC_UNLOCK(td->td_proc);
894 *retval = 0x7fffffff;
901 krl.rlim_cur = uap->newlimit * 512;
902 PROC_LOCK(td->td_proc);
903 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
904 PROC_UNLOCK(td->td_proc);
906 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
910 PROC_LOCK(td->td_proc);
911 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
912 PROC_UNLOCK(td->td_proc);
914 *retval = 0x7fffffff;
920 struct vmspace *vm = td->td_proc->p_vmspace;
923 PROC_LOCK(td->td_proc);
924 r = lim_cur(td->td_proc, RLIMIT_DATA);
925 PROC_UNLOCK(td->td_proc);
929 r += (long) vm->vm_daddr;
937 PROC_LOCK(td->td_proc);
938 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
939 PROC_UNLOCK(td->td_proc);
941 *retval = 0x7fffffff;
955 /* look in the live processes */
956 if ((p = pfind(pid)) == NULL)
957 /* look in the zombies */
965 svr4_sys_pgrpsys(td, uap)
967 struct svr4_sys_pgrpsys_args *uap;
969 int *retval = td->td_retval;
970 struct proc *p = td->td_proc;
973 case 1: /* setpgrp() */
975 * SVR4 setpgrp() (which takes no arguments) has the
976 * semantics that the session ID is also created anew, so
977 * in almost every sense, setpgrp() is identical to
978 * setsid() for SVR4. (Under BSD, the difference is that
979 * a setpgid(0,0) will not create a new session.)
981 sys_setsid(td, NULL);
984 case 0: /* getpgrp() */
986 *retval = p->p_pgrp->pg_id;
990 case 2: /* getsid(pid) */
993 else if ((p = svr4_pfind(uap->pid)) == NULL)
996 * This has already been initialized to the pid of
997 * the session leader.
999 *retval = (register_t) p->p_session->s_sid;
1003 case 3: /* setsid() */
1004 return sys_setsid(td, NULL);
1006 case 4: /* getpgid(pid) */
1010 else if ((p = svr4_pfind(uap->pid)) == NULL)
1013 *retval = (int) p->p_pgrp->pg_id;
1017 case 5: /* setpgid(pid, pgid); */
1019 struct setpgid_args sa;
1022 sa.pgid = uap->pgid;
1023 return sys_setpgid(td, &sa);
1031 struct svr4_hrtcntl_args {
1035 svr4_hrt_interval_t * iv;
1036 svr4_hrt_time_t * ti;
1041 svr4_hrtcntl(td, uap, retval)
1043 struct svr4_hrtcntl_args *uap;
1047 case SVR4_HRT_CNTL_RES:
1048 DPRINTF(("htrcntl(RES)\n"));
1049 *retval = SVR4_HRT_USEC;
1052 case SVR4_HRT_CNTL_TOFD:
1053 DPRINTF(("htrcntl(TOFD)\n"));
1057 if (uap->clk != SVR4_HRT_CLK_STD) {
1058 DPRINTF(("clk == %d\n", uap->clk));
1061 if (uap->ti == NULL) {
1062 DPRINTF(("ti NULL\n"));
1066 t.h_sec = tv.tv_sec;
1067 t.h_rem = tv.tv_usec;
1068 t.h_res = SVR4_HRT_USEC;
1069 return copyout(&t, uap->ti, sizeof(t));
1072 case SVR4_HRT_CNTL_START:
1073 DPRINTF(("htrcntl(START)\n"));
1076 case SVR4_HRT_CNTL_GET:
1077 DPRINTF(("htrcntl(GET)\n"));
1080 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1087 svr4_sys_hrtsys(td, uap)
1089 struct svr4_sys_hrtsys_args *uap;
1091 int *retval = td->td_retval;
1095 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1099 DPRINTF(("hrtalarm\n"));
1103 DPRINTF(("hrtsleep\n"));
1107 DPRINTF(("hrtcancel\n"));
1111 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1118 svr4_setinfo(pid, ru, st, s)
1127 memset(&i, 0, sizeof(i));
1129 i.svr4_si_signo = SVR4_SIGCHLD;
1130 i.svr4_si_errno = 0; /* XXX? */
1132 i.svr4_si_pid = pid;
1134 i.svr4_si_stime = ru->ru_stime.tv_sec;
1135 i.svr4_si_utime = ru->ru_utime.tv_sec;
1138 if (WIFEXITED(st)) {
1139 i.svr4_si_status = WEXITSTATUS(st);
1140 i.svr4_si_code = SVR4_CLD_EXITED;
1141 } else if (WIFSTOPPED(st)) {
1143 if (sig >= 0 && sig < NSIG)
1144 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1146 if (i.svr4_si_status == SVR4_SIGCONT)
1147 i.svr4_si_code = SVR4_CLD_CONTINUED;
1149 i.svr4_si_code = SVR4_CLD_STOPPED;
1152 if (sig >= 0 && sig < NSIG)
1153 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1156 i.svr4_si_code = SVR4_CLD_DUMPED;
1158 i.svr4_si_code = SVR4_CLD_KILLED;
1161 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1162 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1165 return copyout(&i, s, sizeof(i));
1170 svr4_sys_waitsys(td, uap)
1172 struct svr4_sys_waitsys_args *uap;
1177 int error, *retval = td->td_retval;
1180 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1182 uap->info, uap->options));
1204 /* Hand off the easy cases to kern_wait(). */
1205 if (!(uap->options & (SVR4_WNOWAIT)) &&
1206 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1210 if (uap->options & SVR4_WSTOPPED)
1211 options |= WUNTRACED;
1212 if (uap->options & SVR4_WCONTINUED)
1213 options |= WCONTINUED;
1214 if (uap->options & SVR4_WNOHANG)
1217 error = kern_wait(td, pid, &status, options, &ru);
1220 if (uap->options & SVR4_WNOHANG && *retval == 0)
1221 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1223 error = svr4_setinfo(*retval, &ru, status, uap->info);
1229 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1230 * just want to see if there is a process to harvest, we don't
1231 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1232 * meaning we want to ignore zombies. Either way, we don't have
1233 * to handle harvesting zombies here. We do have to duplicate the
1234 * other portions of kern_wait() though, especially for WCONTINUED
1239 sx_slock(&proctree_lock);
1240 LIST_FOREACH(p, &q->p_children, p_sibling) {
1242 if (pid != WAIT_ANY &&
1243 p->p_pid != pid && p->p_pgid != -pid) {
1245 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1249 if (p_canwait(td, p)) {
1258 * See if we have a zombie. If so, WNOWAIT should be set,
1259 * as otherwise we should have called kern_wait() up above.
1261 if ((p->p_state == PRS_ZOMBIE) &&
1262 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1264 KASSERT(uap->options & SVR4_WNOWAIT,
1265 ("WNOWAIT is clear"));
1267 /* Found a zombie, so cache info in local variables. */
1269 status = p->p_xstat;
1272 calcru(p, &ru.ru_utime, &ru.ru_stime);
1275 sx_sunlock(&proctree_lock);
1277 /* Copy the info out to userland. */
1279 DPRINTF(("found %d\n", pid));
1280 return (svr4_setinfo(pid, &ru, status, uap->info));
1284 * See if we have a stopped or continued process.
1285 * XXX: This duplicates the same code in kern_wait().
1287 if ((p->p_flag & P_STOPPED_SIG) &&
1288 (p->p_suspcount == p->p_numthreads) &&
1289 (p->p_flag & P_WAITED) == 0 &&
1290 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1292 if (((uap->options & SVR4_WNOWAIT)) == 0)
1293 p->p_flag |= P_WAITED;
1294 sx_sunlock(&proctree_lock);
1296 status = W_STOPCODE(p->p_xstat);
1299 calcru(p, &ru.ru_utime, &ru.ru_stime);
1303 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1305 sigqueue_take(p->p_ksi);
1310 DPRINTF(("jobcontrol %d\n", pid));
1311 return (svr4_setinfo(pid, &ru, status, uap->info));
1314 if (uap->options & SVR4_WCONTINUED &&
1315 (p->p_flag & P_CONTINUED)) {
1316 sx_sunlock(&proctree_lock);
1317 if (((uap->options & SVR4_WNOWAIT)) == 0)
1318 p->p_flag &= ~P_CONTINUED;
1323 calcru(p, &ru.ru_utime, &ru.ru_stime);
1327 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1329 sigqueue_take(p->p_ksi);
1334 DPRINTF(("jobcontrol %d\n", pid));
1335 return (svr4_setinfo(pid, &ru, status, uap->info));
1341 sx_sunlock(&proctree_lock);
1345 if (uap->options & SVR4_WNOHANG) {
1346 sx_sunlock(&proctree_lock);
1348 return (svr4_setinfo(0, NULL, 0, uap->info));
1352 sx_sunlock(&proctree_lock);
1353 if (q->p_flag & P_STATCHILD) {
1354 q->p_flag &= ~P_STATCHILD;
1357 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1366 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1367 const struct statfs *bfs;
1368 struct svr4_statvfs *sfs;
1370 sfs->f_bsize = bfs->f_iosize; /* XXX */
1371 sfs->f_frsize = bfs->f_bsize;
1372 sfs->f_blocks = bfs->f_blocks;
1373 sfs->f_bfree = bfs->f_bfree;
1374 sfs->f_bavail = bfs->f_bavail;
1375 sfs->f_files = bfs->f_files;
1376 sfs->f_ffree = bfs->f_ffree;
1377 sfs->f_favail = bfs->f_ffree;
1378 sfs->f_fsid = bfs->f_fsid.val[0];
1379 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1381 if (bfs->f_flags & MNT_RDONLY)
1382 sfs->f_flag |= SVR4_ST_RDONLY;
1383 if (bfs->f_flags & MNT_NOSUID)
1384 sfs->f_flag |= SVR4_ST_NOSUID;
1385 sfs->f_namemax = MAXNAMLEN;
1386 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1387 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1392 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1393 const struct statfs *bfs;
1394 struct svr4_statvfs64 *sfs;
1396 sfs->f_bsize = bfs->f_iosize; /* XXX */
1397 sfs->f_frsize = bfs->f_bsize;
1398 sfs->f_blocks = bfs->f_blocks;
1399 sfs->f_bfree = bfs->f_bfree;
1400 sfs->f_bavail = bfs->f_bavail;
1401 sfs->f_files = bfs->f_files;
1402 sfs->f_ffree = bfs->f_ffree;
1403 sfs->f_favail = bfs->f_ffree;
1404 sfs->f_fsid = bfs->f_fsid.val[0];
1405 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1407 if (bfs->f_flags & MNT_RDONLY)
1408 sfs->f_flag |= SVR4_ST_RDONLY;
1409 if (bfs->f_flags & MNT_NOSUID)
1410 sfs->f_flag |= SVR4_ST_NOSUID;
1411 sfs->f_namemax = MAXNAMLEN;
1412 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1413 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1418 svr4_sys_statvfs(td, uap)
1420 struct svr4_sys_statvfs_args *uap;
1422 struct svr4_statvfs sfs;
1427 CHECKALTEXIST(td, uap->path, &path);
1429 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1433 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1434 return copyout(&sfs, uap->fs, sizeof(sfs));
1439 svr4_sys_fstatvfs(td, uap)
1441 struct svr4_sys_fstatvfs_args *uap;
1443 struct svr4_statvfs sfs;
1447 error = kern_fstatfs(td, uap->fd, &bfs);
1450 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1451 return copyout(&sfs, uap->fs, sizeof(sfs));
1456 svr4_sys_statvfs64(td, uap)
1458 struct svr4_sys_statvfs64_args *uap;
1460 struct svr4_statvfs64 sfs;
1465 CHECKALTEXIST(td, uap->path, &path);
1467 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1471 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1472 return copyout(&sfs, uap->fs, sizeof(sfs));
1477 svr4_sys_fstatvfs64(td, uap)
1479 struct svr4_sys_fstatvfs64_args *uap;
1481 struct svr4_statvfs64 sfs;
1485 error = kern_fstatfs(td, uap->fd, &bfs);
1488 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1489 return copyout(&sfs, uap->fs, sizeof(sfs));
1493 svr4_sys_alarm(td, uap)
1495 struct svr4_sys_alarm_args *uap;
1497 struct itimerval itv, oitv;
1500 timevalclear(&itv.it_interval);
1501 itv.it_value.tv_sec = uap->sec;
1502 itv.it_value.tv_usec = 0;
1503 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1506 if (oitv.it_value.tv_usec != 0)
1507 oitv.it_value.tv_sec++;
1508 td->td_retval[0] = oitv.it_value.tv_sec;
1513 svr4_sys_gettimeofday(td, uap)
1515 struct svr4_sys_gettimeofday_args *uap;
1521 return copyout(&atv, uap->tp, sizeof (atv));
1528 svr4_sys_facl(td, uap)
1530 struct svr4_sys_facl_args *uap;
1534 retval = td->td_retval;
1538 case SVR4_SYS_SETACL:
1539 /* We don't support acls on any filesystem */
1542 case SVR4_SYS_GETACL:
1543 return copyout(retval, &uap->num,
1546 case SVR4_SYS_GETACLCNT:
1556 svr4_sys_acl(td, uap)
1558 struct svr4_sys_acl_args *uap;
1560 /* XXX: for now the same */
1561 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1565 svr4_sys_auditsys(td, uap)
1567 struct svr4_sys_auditsys_args *uap;
1570 * XXX: Big brother is *not* watching.
1576 svr4_sys_memcntl(td, uap)
1578 struct svr4_sys_memcntl_args *uap;
1583 struct msync_args msa;
1585 msa.addr = uap->addr;
1587 msa.flags = (int)uap->arg;
1589 return sys_msync(td, &msa);
1591 case SVR4_MC_ADVISE:
1593 struct madvise_args maa;
1595 maa.addr = uap->addr;
1597 maa.behav = (int)uap->arg;
1599 return sys_madvise(td, &maa);
1602 case SVR4_MC_UNLOCK:
1603 case SVR4_MC_LOCKAS:
1604 case SVR4_MC_UNLOCKAS:
1613 svr4_sys_nice(td, uap)
1615 struct svr4_sys_nice_args *uap;
1617 struct setpriority_args ap;
1620 ap.which = PRIO_PROCESS;
1622 ap.prio = uap->prio;
1624 if ((error = sys_setpriority(td, &ap)) != 0)
1627 /* the cast is stupid, but the structures are the same */
1628 if ((error = sys_getpriority(td, (struct getpriority_args *)&ap)) != 0)
1635 svr4_sys_resolvepath(td, uap)
1637 struct svr4_sys_resolvepath_args *uap;
1639 struct nameidata nd;
1640 int error, *retval = td->td_retval;
1643 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1646 if ((error = namei(&nd)) != 0)
1648 NDFREE(&nd, NDF_NO_FREE_PNBUF);
1650 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1651 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1656 NDFREE(&nd, NDF_ONLY_PNBUF);