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, vfslocked;
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,
251 CAP_READ | CAP_SEEK, &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_SHARED | LK_RETRY);
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_vnode_check_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 strlcpy(svr4_dirent.d_name, bdp->d_name, sizeof(svr4_dirent.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;
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,
433 CAP_READ | CAP_SEEK, &fp)) != 0)
436 if ((fp->f_flag & FREAD) == 0) {
442 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
443 if (vp->v_type != VDIR) {
444 VFS_UNLOCK_GIANT(vfslocked);
449 buflen = min(MAXBSIZE, uap->nbytes);
450 buf = malloc(buflen, M_TEMP, M_WAITOK);
451 vn_lock(vp, LK_SHARED | LK_RETRY);
455 aiov.iov_len = buflen;
456 auio.uio_iov = &aiov;
458 auio.uio_rw = UIO_READ;
459 auio.uio_segflg = UIO_SYSSPACE;
461 auio.uio_resid = buflen;
462 auio.uio_offset = off;
465 error = mac_vnode_check_readdir(td->td_ucred, vp);
471 * First we read into the malloc'ed buffer, then
472 * we massage it into user space, one record at a time.
474 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
483 if ((len = buflen - auio.uio_resid) == 0)
486 for (cookie = cookiebuf; len > 0; len -= reclen) {
487 bdp = (struct dirent *)inp;
488 reclen = bdp->d_reclen;
490 panic("svr4_sys_getdents64: bad reclen");
492 off = *cookie++; /* each entry points to the next */
495 if ((off >> 32) != 0) {
496 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
500 if (bdp->d_fileno == 0) {
501 inp += reclen; /* it is a hole; squish it out */
504 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
505 if (reclen > len || resid < svr4_reclen) {
506 /* entry too big for buffer, so just stop */
511 * Massage in place to make a SVR4-shaped dirent (otherwise
512 * we have to worry about touching user memory outside of
513 * the copyout() call).
515 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
516 idb.d_off = (svr4_off_t)off;
517 idb.d_reclen = (u_short)svr4_reclen;
518 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
519 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
521 /* advance past this real entry */
523 /* advance output past SVR4-shaped entry */
525 resid -= svr4_reclen;
528 /* if we squished out the whole block, try again */
529 if (outp == uap->buf)
531 fp->f_offset = off; /* update the vnode offset */
534 *retval = uap->nbytes - resid;
537 VFS_UNLOCK_GIANT(vfslocked);
540 free(cookiebuf, M_TEMP);
547 svr4_sys_mmap(td, uap)
549 struct svr4_sys_mmap_args *uap;
554 retval = td->td_retval;
555 #define _MAP_NEW 0x80000000
557 * Verify the arguments.
559 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
560 return EINVAL; /* XXX still needed? */
567 mm.flags = uap->flags & ~_MAP_NEW;
572 return sys_mmap(td, &mm);
576 svr4_sys_mmap64(td, uap)
578 struct svr4_sys_mmap64_args *uap;
583 #define _MAP_NEW 0x80000000
585 * Verify the arguments.
587 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
588 return EINVAL; /* XXX still needed? */
595 mm.flags = uap->flags & ~_MAP_NEW;
600 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
601 if ((mm.flags & MAP_FIXED) == 0 &&
602 mm.addr != 0 && (void *)mm.addr < rp)
605 return sys_mmap(td, &mm);
610 svr4_sys_fchroot(td, uap)
612 struct svr4_sys_fchroot_args *uap;
614 struct filedesc *fdp = td->td_proc->p_fd;
617 int error, vfslocked;
619 if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0)
621 /* XXX: we have the chroot priv... what cap might we need? all? */
622 if ((error = getvnode(fdp, uap->fd, 0, &fp)) != 0)
627 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
628 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
629 error = change_dir(vp, td);
633 error = mac_vnode_check_chroot(td->td_ucred, vp);
638 error = change_root(vp, td);
640 VFS_UNLOCK_GIANT(vfslocked);
644 VFS_UNLOCK_GIANT(vfslocked);
650 svr4_mknod(td, retval, path, mode, dev)
660 CHECKALTEXIST(td, path, &newpath);
663 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
665 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
666 free(newpath, M_TEMP);
672 svr4_sys_mknod(td, uap)
674 struct svr4_sys_mknod_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_odev_t(uap->dev));
684 svr4_sys_xmknod(td, uap)
686 struct svr4_sys_xmknod_args *uap;
688 int *retval = td->td_retval;
689 return svr4_mknod(td, retval,
690 uap->path, uap->mode,
691 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
696 svr4_sys_vhangup(td, uap)
698 struct svr4_sys_vhangup_args *uap;
705 svr4_sys_sysconfig(td, uap)
707 struct svr4_sys_sysconfig_args *uap;
711 retval = &(td->td_retval[0]);
714 case SVR4_CONFIG_NGROUPS:
715 *retval = ngroups_max;
717 case SVR4_CONFIG_CHILD_MAX:
720 case SVR4_CONFIG_OPEN_FILES:
723 case SVR4_CONFIG_POSIX_VER:
726 case SVR4_CONFIG_PAGESIZE:
729 case SVR4_CONFIG_CLK_TCK:
730 *retval = 60; /* should this be `hz', ie. 100? */
732 case SVR4_CONFIG_XOPEN_VER:
733 *retval = 2; /* XXX: What should that be? */
735 case SVR4_CONFIG_PROF_TCK:
736 *retval = 60; /* XXX: What should that be? */
738 case SVR4_CONFIG_NPROC_CONF:
739 *retval = 1; /* Only one processor for now */
741 case SVR4_CONFIG_NPROC_ONLN:
742 *retval = 1; /* And it better be online */
744 case SVR4_CONFIG_AIO_LISTIO_MAX:
745 case SVR4_CONFIG_AIO_MAX:
746 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
747 *retval = 0; /* No aio support */
749 case SVR4_CONFIG_DELAYTIMER_MAX:
750 *retval = 0; /* No delaytimer support */
752 case SVR4_CONFIG_MQ_OPEN_MAX:
753 *retval = msginfo.msgmni;
755 case SVR4_CONFIG_MQ_PRIO_MAX:
756 *retval = 0; /* XXX: Don't know */
758 case SVR4_CONFIG_RTSIG_MAX:
761 case SVR4_CONFIG_SEM_NSEMS_MAX:
762 *retval = seminfo.semmni;
764 case SVR4_CONFIG_SEM_VALUE_MAX:
765 *retval = seminfo.semvmx;
767 case SVR4_CONFIG_SIGQUEUE_MAX:
768 *retval = 0; /* XXX: Don't know */
770 case SVR4_CONFIG_SIGRT_MIN:
771 case SVR4_CONFIG_SIGRT_MAX:
772 *retval = 0; /* No real time signals */
774 case SVR4_CONFIG_TIMER_MAX:
775 *retval = 3; /* XXX: real, virtual, profiling */
778 case SVR4_CONFIG_PHYS_PAGES:
780 *retval = uvmexp.free; /* XXX: free instead of total */
782 *retval = cnt.v_free_count; /* XXX: free instead of total */
785 case SVR4_CONFIG_AVPHYS_PAGES:
787 *retval = uvmexp.active; /* XXX: active instead of avg */
789 *retval = cnt.v_active_count; /* XXX: active instead of avg */
793 case SVR4_CONFIG_COHERENCY:
794 *retval = 0; /* XXX */
796 case SVR4_CONFIG_SPLIT_CACHE:
797 *retval = 0; /* XXX */
799 case SVR4_CONFIG_ICACHESZ:
800 *retval = 256; /* XXX */
802 case SVR4_CONFIG_DCACHESZ:
803 *retval = 256; /* XXX */
805 case SVR4_CONFIG_ICACHELINESZ:
806 *retval = 64; /* XXX */
808 case SVR4_CONFIG_DCACHELINESZ:
809 *retval = 64; /* XXX */
811 case SVR4_CONFIG_ICACHEBLKSZ:
812 *retval = 64; /* XXX */
814 case SVR4_CONFIG_DCACHEBLKSZ:
815 *retval = 64; /* XXX */
817 case SVR4_CONFIG_DCACHETBLKSZ:
818 *retval = 64; /* XXX */
820 case SVR4_CONFIG_ICACHE_ASSOC:
821 *retval = 1; /* XXX */
823 case SVR4_CONFIG_DCACHE_ASSOC:
824 *retval = 1; /* XXX */
826 case SVR4_CONFIG_MAXPID:
829 case SVR4_CONFIG_STACK_PROT:
830 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
840 svr4_sys_break(td, uap)
842 struct svr4_sys_break_args *uap;
844 struct obreak_args ap;
846 ap.nsize = uap->nsize;
847 return (sys_obreak(td, &ap));
850 static __inline clock_t
851 timeval_to_clock_t(tv)
854 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
859 svr4_sys_times(td, uap)
861 struct svr4_sys_times_args *uap;
863 struct timeval tv, utime, stime, cutime, cstime;
871 calcru(p, &utime, &stime);
873 calccru(p, &cutime, &cstime);
876 tms.tms_utime = timeval_to_clock_t(&utime);
877 tms.tms_stime = timeval_to_clock_t(&stime);
879 tms.tms_cutime = timeval_to_clock_t(&cutime);
880 tms.tms_cstime = timeval_to_clock_t(&cstime);
882 error = copyout(&tms, uap->tp, sizeof(tms));
887 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
893 svr4_sys_ulimit(td, uap)
895 struct svr4_sys_ulimit_args *uap;
897 int *retval = td->td_retval;
902 PROC_LOCK(td->td_proc);
903 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
904 PROC_UNLOCK(td->td_proc);
906 *retval = 0x7fffffff;
913 krl.rlim_cur = uap->newlimit * 512;
914 PROC_LOCK(td->td_proc);
915 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
916 PROC_UNLOCK(td->td_proc);
918 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
922 PROC_LOCK(td->td_proc);
923 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
924 PROC_UNLOCK(td->td_proc);
926 *retval = 0x7fffffff;
932 struct vmspace *vm = td->td_proc->p_vmspace;
935 PROC_LOCK(td->td_proc);
936 r = lim_cur(td->td_proc, RLIMIT_DATA);
937 PROC_UNLOCK(td->td_proc);
941 r += (long) vm->vm_daddr;
949 PROC_LOCK(td->td_proc);
950 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
951 PROC_UNLOCK(td->td_proc);
953 *retval = 0x7fffffff;
967 /* look in the live processes */
968 if ((p = pfind(pid)) == NULL)
969 /* look in the zombies */
977 svr4_sys_pgrpsys(td, uap)
979 struct svr4_sys_pgrpsys_args *uap;
981 int *retval = td->td_retval;
982 struct proc *p = td->td_proc;
985 case 1: /* setpgrp() */
987 * SVR4 setpgrp() (which takes no arguments) has the
988 * semantics that the session ID is also created anew, so
989 * in almost every sense, setpgrp() is identical to
990 * setsid() for SVR4. (Under BSD, the difference is that
991 * a setpgid(0,0) will not create a new session.)
993 sys_setsid(td, NULL);
996 case 0: /* getpgrp() */
998 *retval = p->p_pgrp->pg_id;
1002 case 2: /* getsid(pid) */
1005 else if ((p = svr4_pfind(uap->pid)) == NULL)
1008 * This has already been initialized to the pid of
1009 * the session leader.
1011 *retval = (register_t) p->p_session->s_sid;
1015 case 3: /* setsid() */
1016 return sys_setsid(td, NULL);
1018 case 4: /* getpgid(pid) */
1022 else if ((p = svr4_pfind(uap->pid)) == NULL)
1025 *retval = (int) p->p_pgrp->pg_id;
1029 case 5: /* setpgid(pid, pgid); */
1031 struct setpgid_args sa;
1034 sa.pgid = uap->pgid;
1035 return sys_setpgid(td, &sa);
1043 struct svr4_hrtcntl_args {
1047 svr4_hrt_interval_t * iv;
1048 svr4_hrt_time_t * ti;
1053 svr4_hrtcntl(td, uap, retval)
1055 struct svr4_hrtcntl_args *uap;
1059 case SVR4_HRT_CNTL_RES:
1060 DPRINTF(("htrcntl(RES)\n"));
1061 *retval = SVR4_HRT_USEC;
1064 case SVR4_HRT_CNTL_TOFD:
1065 DPRINTF(("htrcntl(TOFD)\n"));
1069 if (uap->clk != SVR4_HRT_CLK_STD) {
1070 DPRINTF(("clk == %d\n", uap->clk));
1073 if (uap->ti == NULL) {
1074 DPRINTF(("ti NULL\n"));
1078 t.h_sec = tv.tv_sec;
1079 t.h_rem = tv.tv_usec;
1080 t.h_res = SVR4_HRT_USEC;
1081 return copyout(&t, uap->ti, sizeof(t));
1084 case SVR4_HRT_CNTL_START:
1085 DPRINTF(("htrcntl(START)\n"));
1088 case SVR4_HRT_CNTL_GET:
1089 DPRINTF(("htrcntl(GET)\n"));
1092 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1099 svr4_sys_hrtsys(td, uap)
1101 struct svr4_sys_hrtsys_args *uap;
1103 int *retval = td->td_retval;
1107 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1111 DPRINTF(("hrtalarm\n"));
1115 DPRINTF(("hrtsleep\n"));
1119 DPRINTF(("hrtcancel\n"));
1123 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1130 svr4_setinfo(pid, ru, st, s)
1139 memset(&i, 0, sizeof(i));
1141 i.svr4_si_signo = SVR4_SIGCHLD;
1142 i.svr4_si_errno = 0; /* XXX? */
1144 i.svr4_si_pid = pid;
1146 i.svr4_si_stime = ru->ru_stime.tv_sec;
1147 i.svr4_si_utime = ru->ru_utime.tv_sec;
1150 if (WIFEXITED(st)) {
1151 i.svr4_si_status = WEXITSTATUS(st);
1152 i.svr4_si_code = SVR4_CLD_EXITED;
1153 } else if (WIFSTOPPED(st)) {
1155 if (sig >= 0 && sig < NSIG)
1156 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1158 if (i.svr4_si_status == SVR4_SIGCONT)
1159 i.svr4_si_code = SVR4_CLD_CONTINUED;
1161 i.svr4_si_code = SVR4_CLD_STOPPED;
1164 if (sig >= 0 && sig < NSIG)
1165 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1168 i.svr4_si_code = SVR4_CLD_DUMPED;
1170 i.svr4_si_code = SVR4_CLD_KILLED;
1173 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1174 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1177 return copyout(&i, s, sizeof(i));
1182 svr4_sys_waitsys(td, uap)
1184 struct svr4_sys_waitsys_args *uap;
1189 int error, *retval = td->td_retval;
1192 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1194 uap->info, uap->options));
1216 /* Hand off the easy cases to kern_wait(). */
1217 if (!(uap->options & (SVR4_WNOWAIT)) &&
1218 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1222 if (uap->options & SVR4_WSTOPPED)
1223 options |= WUNTRACED;
1224 if (uap->options & SVR4_WCONTINUED)
1225 options |= WCONTINUED;
1226 if (uap->options & SVR4_WNOHANG)
1229 error = kern_wait(td, pid, &status, options, &ru);
1232 if (uap->options & SVR4_WNOHANG && *retval == 0)
1233 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1235 error = svr4_setinfo(*retval, &ru, status, uap->info);
1241 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1242 * just want to see if there is a process to harvest, we don't
1243 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1244 * meaning we want to ignore zombies. Either way, we don't have
1245 * to handle harvesting zombies here. We do have to duplicate the
1246 * other portions of kern_wait() though, especially for WCONTINUED
1251 sx_slock(&proctree_lock);
1252 LIST_FOREACH(p, &q->p_children, p_sibling) {
1254 if (pid != WAIT_ANY &&
1255 p->p_pid != pid && p->p_pgid != -pid) {
1257 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1261 if (p_canwait(td, p)) {
1270 * See if we have a zombie. If so, WNOWAIT should be set,
1271 * as otherwise we should have called kern_wait() up above.
1273 if ((p->p_state == PRS_ZOMBIE) &&
1274 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1276 KASSERT(uap->options & SVR4_WNOWAIT,
1277 ("WNOWAIT is clear"));
1279 /* Found a zombie, so cache info in local variables. */
1281 status = p->p_xstat;
1284 calcru(p, &ru.ru_utime, &ru.ru_stime);
1287 sx_sunlock(&proctree_lock);
1289 /* Copy the info out to userland. */
1291 DPRINTF(("found %d\n", pid));
1292 return (svr4_setinfo(pid, &ru, status, uap->info));
1296 * See if we have a stopped or continued process.
1297 * XXX: This duplicates the same code in kern_wait().
1299 if ((p->p_flag & P_STOPPED_SIG) &&
1300 (p->p_suspcount == p->p_numthreads) &&
1301 (p->p_flag & P_WAITED) == 0 &&
1302 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1304 if (((uap->options & SVR4_WNOWAIT)) == 0)
1305 p->p_flag |= P_WAITED;
1306 sx_sunlock(&proctree_lock);
1308 status = W_STOPCODE(p->p_xstat);
1311 calcru(p, &ru.ru_utime, &ru.ru_stime);
1315 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1317 sigqueue_take(p->p_ksi);
1322 DPRINTF(("jobcontrol %d\n", pid));
1323 return (svr4_setinfo(pid, &ru, status, uap->info));
1326 if (uap->options & SVR4_WCONTINUED &&
1327 (p->p_flag & P_CONTINUED)) {
1328 sx_sunlock(&proctree_lock);
1329 if (((uap->options & SVR4_WNOWAIT)) == 0)
1330 p->p_flag &= ~P_CONTINUED;
1335 calcru(p, &ru.ru_utime, &ru.ru_stime);
1339 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1341 sigqueue_take(p->p_ksi);
1346 DPRINTF(("jobcontrol %d\n", pid));
1347 return (svr4_setinfo(pid, &ru, status, uap->info));
1353 sx_sunlock(&proctree_lock);
1357 if (uap->options & SVR4_WNOHANG) {
1358 sx_sunlock(&proctree_lock);
1360 return (svr4_setinfo(0, NULL, 0, uap->info));
1364 sx_sunlock(&proctree_lock);
1365 if (q->p_flag & P_STATCHILD) {
1366 q->p_flag &= ~P_STATCHILD;
1369 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1378 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1379 const struct statfs *bfs;
1380 struct svr4_statvfs *sfs;
1382 sfs->f_bsize = bfs->f_iosize; /* XXX */
1383 sfs->f_frsize = bfs->f_bsize;
1384 sfs->f_blocks = bfs->f_blocks;
1385 sfs->f_bfree = bfs->f_bfree;
1386 sfs->f_bavail = bfs->f_bavail;
1387 sfs->f_files = bfs->f_files;
1388 sfs->f_ffree = bfs->f_ffree;
1389 sfs->f_favail = bfs->f_ffree;
1390 sfs->f_fsid = bfs->f_fsid.val[0];
1391 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1393 if (bfs->f_flags & MNT_RDONLY)
1394 sfs->f_flag |= SVR4_ST_RDONLY;
1395 if (bfs->f_flags & MNT_NOSUID)
1396 sfs->f_flag |= SVR4_ST_NOSUID;
1397 sfs->f_namemax = MAXNAMLEN;
1398 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1399 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1404 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1405 const struct statfs *bfs;
1406 struct svr4_statvfs64 *sfs;
1408 sfs->f_bsize = bfs->f_iosize; /* XXX */
1409 sfs->f_frsize = bfs->f_bsize;
1410 sfs->f_blocks = bfs->f_blocks;
1411 sfs->f_bfree = bfs->f_bfree;
1412 sfs->f_bavail = bfs->f_bavail;
1413 sfs->f_files = bfs->f_files;
1414 sfs->f_ffree = bfs->f_ffree;
1415 sfs->f_favail = bfs->f_ffree;
1416 sfs->f_fsid = bfs->f_fsid.val[0];
1417 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1419 if (bfs->f_flags & MNT_RDONLY)
1420 sfs->f_flag |= SVR4_ST_RDONLY;
1421 if (bfs->f_flags & MNT_NOSUID)
1422 sfs->f_flag |= SVR4_ST_NOSUID;
1423 sfs->f_namemax = MAXNAMLEN;
1424 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1425 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1430 svr4_sys_statvfs(td, uap)
1432 struct svr4_sys_statvfs_args *uap;
1434 struct svr4_statvfs sfs;
1439 CHECKALTEXIST(td, uap->path, &path);
1441 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1445 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1446 return copyout(&sfs, uap->fs, sizeof(sfs));
1451 svr4_sys_fstatvfs(td, uap)
1453 struct svr4_sys_fstatvfs_args *uap;
1455 struct svr4_statvfs sfs;
1459 error = kern_fstatfs(td, uap->fd, &bfs);
1462 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1463 return copyout(&sfs, uap->fs, sizeof(sfs));
1468 svr4_sys_statvfs64(td, uap)
1470 struct svr4_sys_statvfs64_args *uap;
1472 struct svr4_statvfs64 sfs;
1477 CHECKALTEXIST(td, uap->path, &path);
1479 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1483 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1484 return copyout(&sfs, uap->fs, sizeof(sfs));
1489 svr4_sys_fstatvfs64(td, uap)
1491 struct svr4_sys_fstatvfs64_args *uap;
1493 struct svr4_statvfs64 sfs;
1497 error = kern_fstatfs(td, uap->fd, &bfs);
1500 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1501 return copyout(&sfs, uap->fs, sizeof(sfs));
1505 svr4_sys_alarm(td, uap)
1507 struct svr4_sys_alarm_args *uap;
1509 struct itimerval itv, oitv;
1512 timevalclear(&itv.it_interval);
1513 itv.it_value.tv_sec = uap->sec;
1514 itv.it_value.tv_usec = 0;
1515 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1518 if (oitv.it_value.tv_usec != 0)
1519 oitv.it_value.tv_sec++;
1520 td->td_retval[0] = oitv.it_value.tv_sec;
1525 svr4_sys_gettimeofday(td, uap)
1527 struct svr4_sys_gettimeofday_args *uap;
1533 return copyout(&atv, uap->tp, sizeof (atv));
1540 svr4_sys_facl(td, uap)
1542 struct svr4_sys_facl_args *uap;
1546 retval = td->td_retval;
1550 case SVR4_SYS_SETACL:
1551 /* We don't support acls on any filesystem */
1554 case SVR4_SYS_GETACL:
1555 return copyout(retval, &uap->num,
1558 case SVR4_SYS_GETACLCNT:
1568 svr4_sys_acl(td, uap)
1570 struct svr4_sys_acl_args *uap;
1572 /* XXX: for now the same */
1573 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1577 svr4_sys_auditsys(td, uap)
1579 struct svr4_sys_auditsys_args *uap;
1582 * XXX: Big brother is *not* watching.
1588 svr4_sys_memcntl(td, uap)
1590 struct svr4_sys_memcntl_args *uap;
1595 struct msync_args msa;
1597 msa.addr = uap->addr;
1599 msa.flags = (int)uap->arg;
1601 return sys_msync(td, &msa);
1603 case SVR4_MC_ADVISE:
1605 struct madvise_args maa;
1607 maa.addr = uap->addr;
1609 maa.behav = (int)uap->arg;
1611 return sys_madvise(td, &maa);
1614 case SVR4_MC_UNLOCK:
1615 case SVR4_MC_LOCKAS:
1616 case SVR4_MC_UNLOCKAS:
1625 svr4_sys_nice(td, uap)
1627 struct svr4_sys_nice_args *uap;
1629 struct setpriority_args ap;
1632 ap.which = PRIO_PROCESS;
1634 ap.prio = uap->prio;
1636 if ((error = sys_setpriority(td, &ap)) != 0)
1639 /* the cast is stupid, but the structures are the same */
1640 if ((error = sys_getpriority(td, (struct getpriority_args *)&ap)) != 0)
1647 svr4_sys_resolvepath(td, uap)
1649 struct svr4_sys_resolvepath_args *uap;
1651 struct nameidata nd;
1652 int error, *retval = td->td_retval;
1655 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE,
1658 if ((error = namei(&nd)) != 0)
1660 NDFREE(&nd, NDF_NO_FREE_PNBUF);
1661 VFS_UNLOCK_GIANT(NDHASGIANT(&nd));
1663 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1664 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1669 NDFREE(&nd, NDF_ONLY_PNBUF);