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_SHARED | 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_SHARED | 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(td, PRIV_VFS_FCHROOT)) != 0)
617 if ((error = getvnode(fdp, uap->fd, &fp)) != 0)
622 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
623 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
624 error = change_dir(vp, td);
628 error = mac_check_vnode_chroot(td->td_ucred, vp);
632 VOP_UNLOCK(vp, 0, td);
633 error = change_root(vp, td);
635 VFS_UNLOCK_GIANT(vfslocked);
639 VFS_UNLOCK_GIANT(vfslocked);
645 svr4_mknod(td, retval, path, mode, dev)
655 CHECKALTEXIST(td, path, &newpath);
658 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
660 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
661 free(newpath, M_TEMP);
667 svr4_sys_mknod(td, uap)
668 register struct thread *td;
669 struct svr4_sys_mknod_args *uap;
671 int *retval = td->td_retval;
672 return svr4_mknod(td, retval,
673 uap->path, uap->mode,
674 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev));
679 svr4_sys_xmknod(td, uap)
681 struct svr4_sys_xmknod_args *uap;
683 int *retval = td->td_retval;
684 return svr4_mknod(td, retval,
685 uap->path, uap->mode,
686 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
691 svr4_sys_vhangup(td, uap)
693 struct svr4_sys_vhangup_args *uap;
700 svr4_sys_sysconfig(td, uap)
702 struct svr4_sys_sysconfig_args *uap;
706 retval = &(td->td_retval[0]);
709 case SVR4_CONFIG_UNUSED:
712 case SVR4_CONFIG_NGROUPS:
713 *retval = NGROUPS_MAX;
715 case SVR4_CONFIG_CHILD_MAX:
718 case SVR4_CONFIG_OPEN_FILES:
721 case SVR4_CONFIG_POSIX_VER:
724 case SVR4_CONFIG_PAGESIZE:
727 case SVR4_CONFIG_CLK_TCK:
728 *retval = 60; /* should this be `hz', ie. 100? */
730 case SVR4_CONFIG_XOPEN_VER:
731 *retval = 2; /* XXX: What should that be? */
733 case SVR4_CONFIG_PROF_TCK:
734 *retval = 60; /* XXX: What should that be? */
736 case SVR4_CONFIG_NPROC_CONF:
737 *retval = 1; /* Only one processor for now */
739 case SVR4_CONFIG_NPROC_ONLN:
740 *retval = 1; /* And it better be online */
742 case SVR4_CONFIG_AIO_LISTIO_MAX:
743 case SVR4_CONFIG_AIO_MAX:
744 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
745 *retval = 0; /* No aio support */
747 case SVR4_CONFIG_DELAYTIMER_MAX:
748 *retval = 0; /* No delaytimer support */
750 case SVR4_CONFIG_MQ_OPEN_MAX:
751 *retval = msginfo.msgmni;
753 case SVR4_CONFIG_MQ_PRIO_MAX:
754 *retval = 0; /* XXX: Don't know */
756 case SVR4_CONFIG_RTSIG_MAX:
759 case SVR4_CONFIG_SEM_NSEMS_MAX:
760 *retval = seminfo.semmni;
762 case SVR4_CONFIG_SEM_VALUE_MAX:
763 *retval = seminfo.semvmx;
765 case SVR4_CONFIG_SIGQUEUE_MAX:
766 *retval = 0; /* XXX: Don't know */
768 case SVR4_CONFIG_SIGRT_MIN:
769 case SVR4_CONFIG_SIGRT_MAX:
770 *retval = 0; /* No real time signals */
772 case SVR4_CONFIG_TIMER_MAX:
773 *retval = 3; /* XXX: real, virtual, profiling */
776 case SVR4_CONFIG_PHYS_PAGES:
778 *retval = uvmexp.free; /* XXX: free instead of total */
780 *retval = cnt.v_free_count; /* XXX: free instead of total */
783 case SVR4_CONFIG_AVPHYS_PAGES:
785 *retval = uvmexp.active; /* XXX: active instead of avg */
787 *retval = cnt.v_active_count; /* XXX: active instead of avg */
800 svr4_sys_break(td, uap)
802 struct svr4_sys_break_args *uap;
804 struct obreak_args ap;
806 ap.nsize = uap->nsize;
807 return (obreak(td, &ap));
810 static __inline clock_t
811 timeval_to_clock_t(tv)
814 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
819 svr4_sys_times(td, uap)
821 struct svr4_sys_times_args *uap;
823 struct timeval tv, utime, stime, cutime, cstime;
831 calcru(p, &utime, &stime);
833 calccru(p, &cutime, &cstime);
836 tms.tms_utime = timeval_to_clock_t(&utime);
837 tms.tms_stime = timeval_to_clock_t(&stime);
839 tms.tms_cutime = timeval_to_clock_t(&cutime);
840 tms.tms_cstime = timeval_to_clock_t(&cstime);
842 error = copyout(&tms, uap->tp, sizeof(tms));
847 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
853 svr4_sys_ulimit(td, uap)
855 struct svr4_sys_ulimit_args *uap;
857 int *retval = td->td_retval;
862 PROC_LOCK(td->td_proc);
863 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
864 PROC_UNLOCK(td->td_proc);
866 *retval = 0x7fffffff;
873 krl.rlim_cur = uap->newlimit * 512;
874 PROC_LOCK(td->td_proc);
875 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
876 PROC_UNLOCK(td->td_proc);
878 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
882 PROC_LOCK(td->td_proc);
883 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
884 PROC_UNLOCK(td->td_proc);
886 *retval = 0x7fffffff;
892 struct vmspace *vm = td->td_proc->p_vmspace;
895 PROC_LOCK(td->td_proc);
896 r = lim_cur(td->td_proc, RLIMIT_DATA);
897 PROC_UNLOCK(td->td_proc);
901 mtx_lock(&Giant); /* XXX */
902 r += (long) vm->vm_daddr;
911 PROC_LOCK(td->td_proc);
912 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
913 PROC_UNLOCK(td->td_proc);
915 *retval = 0x7fffffff;
929 /* look in the live processes */
930 if ((p = pfind(pid)) == NULL)
931 /* look in the zombies */
939 svr4_sys_pgrpsys(td, uap)
941 struct svr4_sys_pgrpsys_args *uap;
943 int *retval = td->td_retval;
944 struct proc *p = td->td_proc;
947 case 1: /* setpgrp() */
949 * SVR4 setpgrp() (which takes no arguments) has the
950 * semantics that the session ID is also created anew, so
951 * in almost every sense, setpgrp() is identical to
952 * setsid() for SVR4. (Under BSD, the difference is that
953 * a setpgid(0,0) will not create a new session.)
958 case 0: /* getpgrp() */
960 *retval = p->p_pgrp->pg_id;
964 case 2: /* getsid(pid) */
967 else if ((p = svr4_pfind(uap->pid)) == NULL)
970 * This has already been initialized to the pid of
971 * the session leader.
973 *retval = (register_t) p->p_session->s_sid;
977 case 3: /* setsid() */
978 return setsid(td, NULL);
980 case 4: /* getpgid(pid) */
984 else if ((p = svr4_pfind(uap->pid)) == NULL)
987 *retval = (int) p->p_pgrp->pg_id;
991 case 5: /* setpgid(pid, pgid); */
993 struct setpgid_args sa;
997 return setpgid(td, &sa);
1005 struct svr4_hrtcntl_args {
1009 svr4_hrt_interval_t * iv;
1010 svr4_hrt_time_t * ti;
1015 svr4_hrtcntl(td, uap, retval)
1017 struct svr4_hrtcntl_args *uap;
1021 case SVR4_HRT_CNTL_RES:
1022 DPRINTF(("htrcntl(RES)\n"));
1023 *retval = SVR4_HRT_USEC;
1026 case SVR4_HRT_CNTL_TOFD:
1027 DPRINTF(("htrcntl(TOFD)\n"));
1031 if (uap->clk != SVR4_HRT_CLK_STD) {
1032 DPRINTF(("clk == %d\n", uap->clk));
1035 if (uap->ti == NULL) {
1036 DPRINTF(("ti NULL\n"));
1040 t.h_sec = tv.tv_sec;
1041 t.h_rem = tv.tv_usec;
1042 t.h_res = SVR4_HRT_USEC;
1043 return copyout(&t, uap->ti, sizeof(t));
1046 case SVR4_HRT_CNTL_START:
1047 DPRINTF(("htrcntl(START)\n"));
1050 case SVR4_HRT_CNTL_GET:
1051 DPRINTF(("htrcntl(GET)\n"));
1054 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1061 svr4_sys_hrtsys(td, uap)
1063 struct svr4_sys_hrtsys_args *uap;
1065 int *retval = td->td_retval;
1069 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1073 DPRINTF(("hrtalarm\n"));
1077 DPRINTF(("hrtsleep\n"));
1081 DPRINTF(("hrtcancel\n"));
1085 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1092 svr4_setinfo(pid, ru, st, s)
1101 memset(&i, 0, sizeof(i));
1103 i.svr4_si_signo = SVR4_SIGCHLD;
1104 i.svr4_si_errno = 0; /* XXX? */
1106 i.svr4_si_pid = pid;
1108 i.svr4_si_stime = ru->ru_stime.tv_sec;
1109 i.svr4_si_utime = ru->ru_utime.tv_sec;
1112 if (WIFEXITED(st)) {
1113 i.svr4_si_status = WEXITSTATUS(st);
1114 i.svr4_si_code = SVR4_CLD_EXITED;
1115 } else if (WIFSTOPPED(st)) {
1117 if (sig >= 0 && sig < NSIG)
1118 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1120 if (i.svr4_si_status == SVR4_SIGCONT)
1121 i.svr4_si_code = SVR4_CLD_CONTINUED;
1123 i.svr4_si_code = SVR4_CLD_STOPPED;
1126 if (sig >= 0 && sig < NSIG)
1127 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1130 i.svr4_si_code = SVR4_CLD_DUMPED;
1132 i.svr4_si_code = SVR4_CLD_KILLED;
1135 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1136 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1139 return copyout(&i, s, sizeof(i));
1144 svr4_sys_waitsys(td, uap)
1146 struct svr4_sys_waitsys_args *uap;
1151 int error, *retval = td->td_retval;
1154 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1156 uap->info, uap->options));
1178 /* Hand off the easy cases to kern_wait(). */
1179 if (!(uap->options & (SVR4_WNOWAIT)) &&
1180 (uap->options & (SVR4_WEXITED | SVR4_WTRAPPED))) {
1184 if (uap->options & SVR4_WSTOPPED)
1185 options |= WUNTRACED;
1186 if (uap->options & SVR4_WCONTINUED)
1187 options |= WCONTINUED;
1188 if (uap->options & SVR4_WNOHANG)
1191 error = kern_wait(td, pid, &status, options, &ru);
1194 if (uap->options & SVR4_WNOHANG && *retval == 0)
1195 error = svr4_setinfo(*retval, NULL, 0, uap->info);
1197 error = svr4_setinfo(*retval, &ru, status, uap->info);
1203 * Ok, handle the weird cases. Either WNOWAIT is set (meaning we
1204 * just want to see if there is a process to harvest, we dont'
1205 * want to actually harvest it), or WEXIT and WTRAPPED are clear
1206 * meaning we want to ignore zombies. Either way, we don't have
1207 * to handle harvesting zombies here. We do have to duplicate the
1208 * other portions of kern_wait() though, especially for the
1209 * WCONTINUED and WSTOPPED.
1213 sx_slock(&proctree_lock);
1214 LIST_FOREACH(p, &q->p_children, p_sibling) {
1216 if (pid != WAIT_ANY &&
1217 p->p_pid != pid && p->p_pgid != -pid) {
1219 DPRINTF(("pid %d pgid %d != %d\n", p->p_pid,
1223 if (p_canwait(td, p)) {
1232 * See if we have a zombie. If so, WNOWAIT should be set,
1233 * as otherwise we should have called kern_wait() up above.
1235 if ((p->p_state == PRS_ZOMBIE) &&
1236 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1238 KASSERT(uap->options & SVR4_WNOWAIT,
1239 ("WNOWAIT is clear"));
1241 /* Found a zombie, so cache info in local variables. */
1243 status = p->p_xstat;
1246 calcru(p, &ru.ru_utime, &ru.ru_stime);
1249 sx_sunlock(&proctree_lock);
1251 /* Copy the info out to userland. */
1253 DPRINTF(("found %d\n", pid));
1254 return (svr4_setinfo(pid, &ru, status, uap->info));
1258 * See if we have a stopped or continued process.
1259 * XXX: This duplicates the same code in kern_wait().
1261 if ((p->p_flag & P_STOPPED_SIG) &&
1262 (p->p_suspcount == p->p_numthreads) &&
1263 (p->p_flag & P_WAITED) == 0 &&
1264 (p->p_flag & P_TRACED || uap->options & SVR4_WSTOPPED)) {
1266 if (((uap->options & SVR4_WNOWAIT)) == 0)
1267 p->p_flag |= P_WAITED;
1268 sx_sunlock(&proctree_lock);
1270 status = W_STOPCODE(p->p_xstat);
1273 calcru(p, &ru.ru_utime, &ru.ru_stime);
1277 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1279 sigqueue_take(p->p_ksi);
1284 DPRINTF(("jobcontrol %d\n", pid));
1285 return (svr4_setinfo(pid, &ru, status, uap->info));
1288 if (uap->options & SVR4_WCONTINUED &&
1289 (p->p_flag & P_CONTINUED)) {
1290 sx_sunlock(&proctree_lock);
1291 if (((uap->options & SVR4_WNOWAIT)) == 0)
1292 p->p_flag &= ~P_CONTINUED;
1297 calcru(p, &ru.ru_utime, &ru.ru_stime);
1301 if (((uap->options & SVR4_WNOWAIT)) == 0) {
1303 sigqueue_take(p->p_ksi);
1308 DPRINTF(("jobcontrol %d\n", pid));
1309 return (svr4_setinfo(pid, &ru, status, uap->info));
1315 sx_sunlock(&proctree_lock);
1319 if (uap->options & SVR4_WNOHANG) {
1320 sx_sunlock(&proctree_lock);
1322 return (svr4_setinfo(0, NULL, 0, uap->info));
1326 sx_sunlock(&proctree_lock);
1327 if (q->p_flag & P_STATCHILD) {
1328 q->p_flag &= ~P_STATCHILD;
1331 error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "svr4_wait", 0);
1340 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1341 const struct statfs *bfs;
1342 struct svr4_statvfs *sfs;
1344 sfs->f_bsize = bfs->f_iosize; /* XXX */
1345 sfs->f_frsize = bfs->f_bsize;
1346 sfs->f_blocks = bfs->f_blocks;
1347 sfs->f_bfree = bfs->f_bfree;
1348 sfs->f_bavail = bfs->f_bavail;
1349 sfs->f_files = bfs->f_files;
1350 sfs->f_ffree = bfs->f_ffree;
1351 sfs->f_favail = bfs->f_ffree;
1352 sfs->f_fsid = bfs->f_fsid.val[0];
1353 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1355 if (bfs->f_flags & MNT_RDONLY)
1356 sfs->f_flag |= SVR4_ST_RDONLY;
1357 if (bfs->f_flags & MNT_NOSUID)
1358 sfs->f_flag |= SVR4_ST_NOSUID;
1359 sfs->f_namemax = MAXNAMLEN;
1360 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1361 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1366 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1367 const struct statfs *bfs;
1368 struct svr4_statvfs64 *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 svr4_sys_statvfs(td, uap)
1394 struct svr4_sys_statvfs_args *uap;
1396 struct svr4_statvfs sfs;
1401 CHECKALTEXIST(td, uap->path, &path);
1403 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1407 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1408 return copyout(&sfs, uap->fs, sizeof(sfs));
1413 svr4_sys_fstatvfs(td, uap)
1415 struct svr4_sys_fstatvfs_args *uap;
1417 struct svr4_statvfs sfs;
1421 error = kern_fstatfs(td, uap->fd, &bfs);
1424 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1425 return copyout(&sfs, uap->fs, sizeof(sfs));
1430 svr4_sys_statvfs64(td, uap)
1432 struct svr4_sys_statvfs64_args *uap;
1434 struct svr4_statvfs64 sfs;
1439 CHECKALTEXIST(td, uap->path, &path);
1441 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1445 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1446 return copyout(&sfs, uap->fs, sizeof(sfs));
1451 svr4_sys_fstatvfs64(td, uap)
1453 struct svr4_sys_fstatvfs64_args *uap;
1455 struct svr4_statvfs64 sfs;
1459 error = kern_fstatfs(td, uap->fd, &bfs);
1462 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1463 return copyout(&sfs, uap->fs, sizeof(sfs));
1467 svr4_sys_alarm(td, uap)
1469 struct svr4_sys_alarm_args *uap;
1471 struct itimerval itv, oitv;
1474 timevalclear(&itv.it_interval);
1475 itv.it_value.tv_sec = uap->sec;
1476 itv.it_value.tv_usec = 0;
1477 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1480 if (oitv.it_value.tv_usec != 0)
1481 oitv.it_value.tv_sec++;
1482 td->td_retval[0] = oitv.it_value.tv_sec;
1487 svr4_sys_gettimeofday(td, uap)
1489 struct svr4_sys_gettimeofday_args *uap;
1495 return copyout(&atv, uap->tp, sizeof (atv));
1502 svr4_sys_facl(td, uap)
1504 struct svr4_sys_facl_args *uap;
1508 retval = td->td_retval;
1512 case SVR4_SYS_SETACL:
1513 /* We don't support acls on any filesystem */
1516 case SVR4_SYS_GETACL:
1517 return copyout(retval, &uap->num,
1520 case SVR4_SYS_GETACLCNT:
1530 svr4_sys_acl(td, uap)
1532 struct svr4_sys_acl_args *uap;
1534 /* XXX: for now the same */
1535 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1539 svr4_sys_auditsys(td, uap)
1541 struct svr4_sys_auditsys_args *uap;
1544 * XXX: Big brother is *not* watching.
1550 svr4_sys_memcntl(td, uap)
1552 struct svr4_sys_memcntl_args *uap;
1557 struct msync_args msa;
1559 msa.addr = uap->addr;
1561 msa.flags = (int)uap->arg;
1563 return msync(td, &msa);
1565 case SVR4_MC_ADVISE:
1567 struct madvise_args maa;
1569 maa.addr = uap->addr;
1571 maa.behav = (int)uap->arg;
1573 return madvise(td, &maa);
1576 case SVR4_MC_UNLOCK:
1577 case SVR4_MC_LOCKAS:
1578 case SVR4_MC_UNLOCKAS:
1587 svr4_sys_nice(td, uap)
1589 struct svr4_sys_nice_args *uap;
1591 struct setpriority_args ap;
1594 ap.which = PRIO_PROCESS;
1596 ap.prio = uap->prio;
1598 if ((error = setpriority(td, &ap)) != 0)
1601 /* the cast is stupid, but the structures are the same */
1602 if ((error = getpriority(td, (struct getpriority_args *)&ap)) != 0)
1609 svr4_sys_resolvepath(td, uap)
1611 struct svr4_sys_resolvepath_args *uap;
1613 struct nameidata nd;
1614 int error, *retval = td->td_retval;
1618 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE,
1621 if ((error = namei(&nd)) != 0)
1623 vfslocked = NDHASGIANT(&nd);
1625 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1626 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1631 NDFREE(&nd, NDF_ONLY_PNBUF);
1633 VFS_UNLOCK_GIANT(vfslocked);