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>
49 #include <sys/malloc.h>
50 #include <sys/file.h> /* Must come after sys/malloc.h */
52 #include <sys/mount.h>
54 #include <sys/mutex.h>
55 #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 <machine/vmparam.h>
88 #include <vm/vm_param.h>
89 #include <vm/vm_map.h>
90 #if defined(__FreeBSD__)
92 #include <vm/vm_extern.h>
97 # include <uvm/uvm_extern.h>
101 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
103 static int svr4_mknod(struct thread *, register_t *, char *,
104 svr4_mode_t, svr4_dev_t);
106 static __inline clock_t timeval_to_clock_t(struct timeval *);
107 static int svr4_setinfo (struct proc *, int, svr4_siginfo_t *);
109 struct svr4_hrtcntl_args;
110 static int svr4_hrtcntl (struct thread *, struct svr4_hrtcntl_args *,
112 static void bsd_statfs_to_svr4_statvfs(const struct statfs *,
113 struct svr4_statvfs *);
114 static void bsd_statfs_to_svr4_statvfs64(const struct statfs *,
115 struct svr4_statvfs64 *);
116 static struct proc *svr4_pfind(pid_t pid);
121 svr4_sys_setitimer(td, uap)
122 register struct thread *td;
123 struct svr4_sys_setitimer_args *uap;
125 td->td_retval[0] = 0;
131 svr4_sys_wait(td, uap)
133 struct svr4_sys_wait_args *uap;
137 error = kern_wait(td, WAIT_ANY, &st, 0, NULL);
141 if (WIFSIGNALED(st)) {
143 if (sig >= 0 && sig < NSIG)
144 st = (st & ~0177) | SVR4_BSD2SVR4_SIG(sig);
145 } else if (WIFSTOPPED(st)) {
147 if (sig >= 0 && sig < NSIG)
148 st = (st & ~0xff00) | (SVR4_BSD2SVR4_SIG(sig) << 8);
152 * It looks like wait(2) on svr4/solaris/2.4 returns
153 * the status in retval[1], and the pid on retval[0].
155 td->td_retval[1] = st;
158 error = copyout(&st, uap->status, sizeof(st));
164 svr4_sys_execv(td, uap)
166 struct svr4_sys_execv_args *uap;
168 struct image_args eargs;
172 CHECKALTEXIST(td, uap->path, &path);
174 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp, NULL);
177 error = kern_execve(td, &eargs, NULL);
182 svr4_sys_execve(td, uap)
184 struct svr4_sys_execve_args *uap;
186 struct image_args eargs;
190 CHECKALTEXIST(td, uap->path, &path);
192 error = exec_copyin_args(&eargs, path, UIO_SYSSPACE, uap->argp,
196 error = kern_execve(td, &eargs, NULL);
203 struct svr4_sys_time_args *v;
205 struct svr4_sys_time_args *uap = v;
211 error = copyout(&tv.tv_sec, uap->t,
213 td->td_retval[0] = (int) tv.tv_sec;
220 * Read SVR4-style directory entries. We suck them into kernel space so
221 * that they can be massaged before being copied out to user code.
223 * This code is ported from the Linux emulator: Changes to the VFS interface
224 * between FreeBSD and NetBSD have made it simpler to port it from there than
225 * to adapt the NetBSD version.
228 svr4_sys_getdents64(td, uap)
230 struct svr4_sys_getdents64_args *uap;
232 register struct dirent *bdp;
234 caddr_t inp, buf; /* BSD-format */
235 int len, reclen; /* BSD-format */
236 caddr_t outp; /* SVR4-format */
237 int resid, svr4reclen=0; /* SVR4-format */
242 struct svr4_dirent64 svr4_dirent;
243 int buflen, error, eofflag, nbytes, justone;
244 u_long *cookies = NULL, *cookiep;
247 DPRINTF(("svr4_sys_getdents64(%d, *, %d)\n",
248 uap->fd, uap->nbytes));
249 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) {
253 if ((fp->f_flag & FREAD) == 0) {
260 if (vp->v_type != VDIR) {
265 nbytes = uap->nbytes;
267 nbytes = sizeof (struct svr4_dirent64);
274 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
275 buflen = max(DIRBLKSIZ, nbytes);
276 buflen = min(buflen, MAXBSIZE);
277 buf = malloc(buflen, M_TEMP, M_WAITOK);
278 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
281 aiov.iov_len = buflen;
282 auio.uio_iov = &aiov;
284 auio.uio_rw = UIO_READ;
285 auio.uio_segflg = UIO_SYSSPACE;
287 auio.uio_resid = buflen;
288 auio.uio_offset = off;
291 free(cookies, M_TEMP);
296 error = mac_check_vnode_readdir(td->td_ucred, vp);
301 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
302 &ncookies, &cookies);
308 outp = (caddr_t) uap->dp;
310 if ((len = buflen - auio.uio_resid) <= 0) {
318 * When using cookies, the vfs has the option of reading from
319 * a different offset than that supplied (UFS truncates the
320 * offset to a block boundary to make sure that it never reads
321 * partway through a directory entry, even if the directory
322 * has been compacted).
324 while (len > 0 && ncookies > 0 && *cookiep <= off) {
325 bdp = (struct dirent *) inp;
326 len -= bdp->d_reclen;
327 inp += bdp->d_reclen;
334 if (cookiep && ncookies == 0)
336 bdp = (struct dirent *) inp;
337 reclen = bdp->d_reclen;
339 DPRINTF(("svr4_readdir: reclen=%d\n", reclen));
344 if (bdp->d_fileno == 0) {
354 svr4reclen = SVR4_RECLEN(&svr4_dirent, bdp->d_namlen);
355 if (reclen > len || resid < svr4reclen) {
359 svr4_dirent.d_ino = (long) bdp->d_fileno;
362 * old svr4-style readdir usage.
364 svr4_dirent.d_off = (svr4_off_t) svr4reclen;
365 svr4_dirent.d_reclen = (u_short) bdp->d_namlen;
367 svr4_dirent.d_off = (svr4_off_t)(off + reclen);
368 svr4_dirent.d_reclen = (u_short) svr4reclen;
370 strcpy(svr4_dirent.d_name, bdp->d_name);
371 if ((error = copyout((caddr_t)&svr4_dirent, outp, svr4reclen)))
386 if (outp == (caddr_t) uap->dp)
391 nbytes = resid + svr4reclen;
394 td->td_retval[0] = nbytes - resid;
396 VOP_UNLOCK(vp, 0, td);
399 free(cookies, M_TEMP);
406 svr4_sys_getdents(td, uap)
408 struct svr4_sys_getdents_args *uap;
412 caddr_t inp, buf; /* BSD-format */
413 int len, reclen; /* BSD-format */
414 caddr_t outp; /* SVR4-format */
415 int resid, svr4_reclen; /* SVR4-format */
419 struct svr4_dirent idb;
420 off_t off; /* true file offset */
421 int buflen, error, eofflag;
422 u_long *cookiebuf = NULL, *cookie;
423 int ncookies = 0, *retval = td->td_retval;
428 if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0)
431 if ((fp->f_flag & FREAD) == 0) {
437 if (vp->v_type != VDIR) {
442 buflen = min(MAXBSIZE, uap->nbytes);
443 buf = malloc(buflen, M_TEMP, M_WAITOK);
444 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
448 aiov.iov_len = buflen;
449 auio.uio_iov = &aiov;
451 auio.uio_rw = UIO_READ;
452 auio.uio_segflg = UIO_SYSSPACE;
454 auio.uio_resid = buflen;
455 auio.uio_offset = off;
458 error = mac_check_vnode_readdir(td->td_ucred, vp);
464 * First we read into the malloc'ed buffer, then
465 * we massage it into user space, one record at a time.
467 error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &ncookies,
476 if ((len = buflen - auio.uio_resid) == 0)
479 for (cookie = cookiebuf; len > 0; len -= reclen) {
480 bdp = (struct dirent *)inp;
481 reclen = bdp->d_reclen;
483 panic("svr4_sys_getdents64: bad reclen");
484 off = *cookie++; /* each entry points to the next */
485 if ((off >> 32) != 0) {
486 uprintf("svr4_sys_getdents64: dir offset too large for emulated program");
490 if (bdp->d_fileno == 0) {
491 inp += reclen; /* it is a hole; squish it out */
494 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
495 if (reclen > len || resid < svr4_reclen) {
496 /* entry too big for buffer, so just stop */
501 * Massage in place to make a SVR4-shaped dirent (otherwise
502 * we have to worry about touching user memory outside of
503 * the copyout() call).
505 idb.d_ino = (svr4_ino_t)bdp->d_fileno;
506 idb.d_off = (svr4_off_t)off;
507 idb.d_reclen = (u_short)svr4_reclen;
508 strcpy(idb.d_name, bdp->d_name);
509 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
511 /* advance past this real entry */
513 /* advance output past SVR4-shaped entry */
515 resid -= svr4_reclen;
518 /* if we squished out the whole block, try again */
519 if (outp == uap->buf)
521 fp->f_offset = off; /* update the vnode offset */
524 *retval = uap->nbytes - resid;
526 VOP_UNLOCK(vp, 0, td);
529 free(cookiebuf, M_TEMP);
536 svr4_sys_mmap(td, uap)
538 struct svr4_sys_mmap_args *uap;
543 retval = td->td_retval;
544 #define _MAP_NEW 0x80000000
546 * Verify the arguments.
548 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
549 return EINVAL; /* XXX still needed? */
556 mm.flags = uap->flags & ~_MAP_NEW;
561 return mmap(td, &mm);
565 svr4_sys_mmap64(td, uap)
567 struct svr4_sys_mmap64_args *uap;
572 #define _MAP_NEW 0x80000000
574 * Verify the arguments.
576 if (uap->prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
577 return EINVAL; /* XXX still needed? */
584 mm.flags = uap->flags & ~_MAP_NEW;
589 rp = (void *) round_page((vm_offset_t)(td->td_proc->p_vmspace->vm_daddr + maxdsiz));
590 if ((mm.flags & MAP_FIXED) == 0 &&
591 mm.addr != 0 && (void *)mm.addr < rp)
594 return mmap(td, &mm);
599 svr4_sys_fchroot(td, uap)
601 struct svr4_sys_fchroot_args *uap;
603 struct filedesc *fdp = td->td_proc->p_fd;
604 struct vnode *vp, *vpold;
608 if ((error = suser(td)) != 0)
610 if ((error = getvnode(fdp, uap->fd, &fp)) != 0)
613 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
614 if (vp->v_type != VDIR)
617 error = VOP_ACCESS(vp, VEXEC, td->td_ucred, td);
618 VOP_UNLOCK(vp, 0, td);
624 FILEDESC_LOCK_FAST(fdp);
625 vpold = fdp->fd_rdir;
627 FILEDESC_UNLOCK_FAST(fdp);
636 svr4_mknod(td, retval, path, mode, dev)
646 CHECKALTEXIST(td, path, &newpath);
649 error = kern_mkfifo(td, newpath, UIO_SYSSPACE, mode);
651 error = kern_mknod(td, newpath, UIO_SYSSPACE, mode, dev);
652 free(newpath, M_TEMP);
658 svr4_sys_mknod(td, uap)
659 register struct thread *td;
660 struct svr4_sys_mknod_args *uap;
662 int *retval = td->td_retval;
663 return svr4_mknod(td, retval,
664 uap->path, uap->mode,
665 (svr4_dev_t)svr4_to_bsd_odev_t(uap->dev));
670 svr4_sys_xmknod(td, uap)
672 struct svr4_sys_xmknod_args *uap;
674 int *retval = td->td_retval;
675 return svr4_mknod(td, retval,
676 uap->path, uap->mode,
677 (svr4_dev_t)svr4_to_bsd_dev_t(uap->dev));
682 svr4_sys_vhangup(td, uap)
684 struct svr4_sys_vhangup_args *uap;
691 svr4_sys_sysconfig(td, uap)
693 struct svr4_sys_sysconfig_args *uap;
697 retval = &(td->td_retval[0]);
700 case SVR4_CONFIG_UNUSED:
703 case SVR4_CONFIG_NGROUPS:
704 *retval = NGROUPS_MAX;
706 case SVR4_CONFIG_CHILD_MAX:
709 case SVR4_CONFIG_OPEN_FILES:
712 case SVR4_CONFIG_POSIX_VER:
715 case SVR4_CONFIG_PAGESIZE:
718 case SVR4_CONFIG_CLK_TCK:
719 *retval = 60; /* should this be `hz', ie. 100? */
721 case SVR4_CONFIG_XOPEN_VER:
722 *retval = 2; /* XXX: What should that be? */
724 case SVR4_CONFIG_PROF_TCK:
725 *retval = 60; /* XXX: What should that be? */
727 case SVR4_CONFIG_NPROC_CONF:
728 *retval = 1; /* Only one processor for now */
730 case SVR4_CONFIG_NPROC_ONLN:
731 *retval = 1; /* And it better be online */
733 case SVR4_CONFIG_AIO_LISTIO_MAX:
734 case SVR4_CONFIG_AIO_MAX:
735 case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
736 *retval = 0; /* No aio support */
738 case SVR4_CONFIG_DELAYTIMER_MAX:
739 *retval = 0; /* No delaytimer support */
741 case SVR4_CONFIG_MQ_OPEN_MAX:
742 *retval = msginfo.msgmni;
744 case SVR4_CONFIG_MQ_PRIO_MAX:
745 *retval = 0; /* XXX: Don't know */
747 case SVR4_CONFIG_RTSIG_MAX:
750 case SVR4_CONFIG_SEM_NSEMS_MAX:
751 *retval = seminfo.semmni;
753 case SVR4_CONFIG_SEM_VALUE_MAX:
754 *retval = seminfo.semvmx;
756 case SVR4_CONFIG_SIGQUEUE_MAX:
757 *retval = 0; /* XXX: Don't know */
759 case SVR4_CONFIG_SIGRT_MIN:
760 case SVR4_CONFIG_SIGRT_MAX:
761 *retval = 0; /* No real time signals */
763 case SVR4_CONFIG_TIMER_MAX:
764 *retval = 3; /* XXX: real, virtual, profiling */
767 case SVR4_CONFIG_PHYS_PAGES:
769 *retval = uvmexp.free; /* XXX: free instead of total */
771 *retval = cnt.v_free_count; /* XXX: free instead of total */
774 case SVR4_CONFIG_AVPHYS_PAGES:
776 *retval = uvmexp.active; /* XXX: active instead of avg */
778 *retval = cnt.v_active_count; /* XXX: active instead of avg */
791 svr4_sys_break(td, uap)
793 struct svr4_sys_break_args *uap;
795 struct proc *p = td->td_proc;
796 struct vmspace *vm = p->p_vmspace;
797 vm_offset_t new, old, base, ns;
800 base = round_page((vm_offset_t) vm->vm_daddr);
801 ns = (vm_offset_t)uap->nsize;
802 new = round_page(ns);
805 if ((new - base) > (unsigned)lim_cur(p, RLIMIT_DATA)) {
810 if (new >= VM_MAXUSER_ADDRESS)
812 } else if (new < base) {
814 * This is simply an invalid value. If someone wants to
815 * do fancy address space manipulations, mmap and munmap
816 * can do most of what the user would want.
821 old = base + ctob(vm->vm_dsize);
827 if (vm->vm_map.size + diff > lim_cur(p, RLIMIT_VMEM)) {
832 rv = vm_map_find(&vm->vm_map, NULL, 0, &old, diff, FALSE,
833 VM_PROT_ALL, VM_PROT_ALL, 0);
834 if (rv != KERN_SUCCESS) {
837 vm->vm_dsize += btoc(diff);
838 } else if (new < old) {
839 rv = vm_map_remove(&vm->vm_map, new, old);
840 if (rv != KERN_SUCCESS) {
843 vm->vm_dsize -= btoc(old - new);
849 static __inline clock_t
850 timeval_to_clock_t(tv)
853 return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
858 svr4_sys_times(td, uap)
860 struct svr4_sys_times_args *uap;
862 struct timeval tv, utime, stime, cutime, cstime;
869 calcru(p, &utime, &stime);
870 calccru(p, &cutime, &cstime);
873 tms.tms_utime = timeval_to_clock_t(&utime);
874 tms.tms_stime = timeval_to_clock_t(&stime);
876 tms.tms_cutime = timeval_to_clock_t(&cutime);
877 tms.tms_cstime = timeval_to_clock_t(&cstime);
879 error = copyout(&tms, uap->tp, sizeof(tms));
884 td->td_retval[0] = (int)timeval_to_clock_t(&tv);
890 svr4_sys_ulimit(td, uap)
892 struct svr4_sys_ulimit_args *uap;
894 int *retval = td->td_retval;
899 PROC_LOCK(td->td_proc);
900 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE) / 512;
901 PROC_UNLOCK(td->td_proc);
903 *retval = 0x7fffffff;
910 krl.rlim_cur = uap->newlimit * 512;
911 PROC_LOCK(td->td_proc);
912 krl.rlim_max = lim_max(td->td_proc, RLIMIT_FSIZE);
913 PROC_UNLOCK(td->td_proc);
915 error = kern_setrlimit(td, RLIMIT_FSIZE, &krl);
919 PROC_LOCK(td->td_proc);
920 *retval = lim_cur(td->td_proc, RLIMIT_FSIZE);
921 PROC_UNLOCK(td->td_proc);
923 *retval = 0x7fffffff;
929 struct vmspace *vm = td->td_proc->p_vmspace;
932 PROC_LOCK(td->td_proc);
933 r = lim_cur(td->td_proc, RLIMIT_DATA);
934 PROC_UNLOCK(td->td_proc);
938 mtx_lock(&Giant); /* XXX */
939 r += (long) vm->vm_daddr;
948 PROC_LOCK(td->td_proc);
949 *retval = lim_cur(td->td_proc, RLIMIT_NOFILE);
950 PROC_UNLOCK(td->td_proc);
952 *retval = 0x7fffffff;
966 /* look in the live processes */
967 if ((p = pfind(pid)) == NULL)
968 /* look in the zombies */
976 svr4_sys_pgrpsys(td, uap)
978 struct svr4_sys_pgrpsys_args *uap;
980 int *retval = td->td_retval;
981 struct proc *p = td->td_proc;
984 case 1: /* setpgrp() */
986 * SVR4 setpgrp() (which takes no arguments) has the
987 * semantics that the session ID is also created anew, so
988 * in almost every sense, setpgrp() is identical to
989 * setsid() for SVR4. (Under BSD, the difference is that
990 * a setpgid(0,0) will not create a new session.)
995 case 0: /* getpgrp() */
997 *retval = p->p_pgrp->pg_id;
1001 case 2: /* getsid(pid) */
1004 else if ((p = svr4_pfind(uap->pid)) == NULL)
1007 * This has already been initialized to the pid of
1008 * the session leader.
1010 *retval = (register_t) p->p_session->s_sid;
1014 case 3: /* setsid() */
1015 return setsid(td, NULL);
1017 case 4: /* getpgid(pid) */
1021 else if ((p = svr4_pfind(uap->pid)) == NULL)
1024 *retval = (int) p->p_pgrp->pg_id;
1028 case 5: /* setpgid(pid, pgid); */
1030 struct setpgid_args sa;
1033 sa.pgid = uap->pgid;
1034 return setpgid(td, &sa);
1042 struct svr4_hrtcntl_args {
1046 svr4_hrt_interval_t * iv;
1047 svr4_hrt_time_t * ti;
1052 svr4_hrtcntl(td, uap, retval)
1054 struct svr4_hrtcntl_args *uap;
1058 case SVR4_HRT_CNTL_RES:
1059 DPRINTF(("htrcntl(RES)\n"));
1060 *retval = SVR4_HRT_USEC;
1063 case SVR4_HRT_CNTL_TOFD:
1064 DPRINTF(("htrcntl(TOFD)\n"));
1068 if (uap->clk != SVR4_HRT_CLK_STD) {
1069 DPRINTF(("clk == %d\n", uap->clk));
1072 if (uap->ti == NULL) {
1073 DPRINTF(("ti NULL\n"));
1077 t.h_sec = tv.tv_sec;
1078 t.h_rem = tv.tv_usec;
1079 t.h_res = SVR4_HRT_USEC;
1080 return copyout(&t, uap->ti, sizeof(t));
1083 case SVR4_HRT_CNTL_START:
1084 DPRINTF(("htrcntl(START)\n"));
1087 case SVR4_HRT_CNTL_GET:
1088 DPRINTF(("htrcntl(GET)\n"));
1091 DPRINTF(("Bad htrcntl command %d\n", uap->fun));
1098 svr4_sys_hrtsys(td, uap)
1100 struct svr4_sys_hrtsys_args *uap;
1102 int *retval = td->td_retval;
1106 return svr4_hrtcntl(td, (struct svr4_hrtcntl_args *) uap,
1110 DPRINTF(("hrtalarm\n"));
1114 DPRINTF(("hrtsleep\n"));
1118 DPRINTF(("hrtcancel\n"));
1122 DPRINTF(("Bad hrtsys command %d\n", uap->cmd));
1129 svr4_setinfo(p, st, s)
1134 struct timeval utime, stime;
1138 memset(&i, 0, sizeof(i));
1140 i.svr4_si_signo = SVR4_SIGCHLD;
1141 i.svr4_si_errno = 0; /* XXX? */
1144 i.svr4_si_pid = p->p_pid;
1146 calcru(p, &utime, &stime);
1148 i.svr4_si_stime = stime.tv_sec;
1149 i.svr4_si_utime = utime.tv_sec;
1152 if (WIFEXITED(st)) {
1153 i.svr4_si_status = WEXITSTATUS(st);
1154 i.svr4_si_code = SVR4_CLD_EXITED;
1155 } else if (WIFSTOPPED(st)) {
1157 if (sig >= 0 && sig < NSIG)
1158 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1160 if (i.svr4_si_status == SVR4_SIGCONT)
1161 i.svr4_si_code = SVR4_CLD_CONTINUED;
1163 i.svr4_si_code = SVR4_CLD_STOPPED;
1166 if (sig >= 0 && sig < NSIG)
1167 i.svr4_si_status = SVR4_BSD2SVR4_SIG(sig);
1170 i.svr4_si_code = SVR4_CLD_DUMPED;
1172 i.svr4_si_code = SVR4_CLD_KILLED;
1175 DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
1176 i.svr4_si_pid, i.svr4_si_signo, i.svr4_si_code, i.svr4_si_errno,
1179 return copyout(&i, s, sizeof(i));
1184 svr4_sys_waitsys(td, uap)
1186 struct svr4_sys_waitsys_args *uap;
1189 int error, *retval = td->td_retval;
1190 struct proc *p, *q, *t;
1199 uap->id = -p->p_pgid;
1211 DPRINTF(("waitsys(%d, %d, %p, %x)\n",
1213 uap->info, uap->options));
1217 sx_slock(&proctree_lock);
1218 LIST_FOREACH(q, &p->p_children, p_sibling) {
1220 if (uap->id != WAIT_ANY &&
1221 q->p_pid != uap->id &&
1222 q->p_pgid != -uap->id) {
1224 DPRINTF(("pid %d pgid %d != %d\n", q->p_pid,
1225 q->p_pgid, uap->id));
1229 if ((q->p_state == PRS_ZOMBIE) &&
1230 ((uap->options & (SVR4_WEXITED|SVR4_WTRAPPED)))) {
1232 sx_sunlock(&proctree_lock);
1234 DPRINTF(("found %d\n", q->p_pid));
1235 error = svr4_setinfo(q, q->p_xstat, uap->info);
1240 if ((uap->options & SVR4_WNOWAIT)) {
1241 DPRINTF(("Don't wait\n"));
1246 * If we got the child via ptrace(2) or procfs, and
1247 * the parent is different (meaning the process was
1248 * attached, rather than run as a child), then we need
1249 * to give it back to the old parent, and send the
1250 * parent a SIGCHLD. The rest of the cleanup will be
1251 * done when the old parent waits on the child.
1253 sx_xlock(&proctree_lock);
1255 if (q->p_flag & P_TRACED) {
1256 if (q->p_oppid != q->p_pptr->p_pid) {
1258 t = pfind(q->p_oppid);
1261 PROC_LOCK(initproc);
1264 proc_reparent(q, t);
1266 q->p_flag &= ~(P_TRACED | P_WAITED);
1268 psignal(t, SIGCHLD);
1271 sx_xunlock(&proctree_lock);
1276 sx_xunlock(&proctree_lock);
1278 ruadd(&p->p_stats->p_cru, &p->p_crux, q->p_ru,
1280 FREE(q->p_ru, M_ZOMBIE);
1284 * Decrement the count of procs running with this uid.
1286 (void)chgproccnt(q->p_ucred->cr_ruidinfo, -1, 0);
1289 * Release reference to text vnode.
1295 * Free up credentials.
1301 * Remove unused arguments
1303 pargs_drop(q->p_args);
1307 * Finally finished with old proc entry.
1308 * Unlink it from its process group and free it.
1310 sx_xlock(&proctree_lock);
1313 sx_xlock(&allproc_lock);
1314 LIST_REMOVE(q, p_list); /* off zombproc */
1315 sx_xunlock(&allproc_lock);
1317 LIST_REMOVE(q, p_sibling);
1318 sx_xunlock(&proctree_lock);
1321 sigacts_free(q->p_sigacts);
1322 q->p_sigacts = NULL;
1326 * Give machine-dependent layer a chance
1327 * to free anything that cpu_exit couldn't
1328 * release while still running in process context.
1331 #if defined(__NetBSD__)
1332 pool_put(&proc_pool, q);
1335 mtx_destroy(&q->p_mtx);
1337 mac_destroy_proc(q);
1339 uma_zfree(proc_zone, q);
1344 /* XXXKSE this needs clarification */
1345 if (P_SHOULDSTOP(q) && ((q->p_flag & P_WAITED) == 0) &&
1346 (q->p_flag & P_TRACED ||
1347 (uap->options & (SVR4_WSTOPPED|SVR4_WCONTINUED)))) {
1348 DPRINTF(("jobcontrol %d\n", q->p_pid));
1349 if (((uap->options & SVR4_WNOWAIT)) == 0)
1350 q->p_flag |= P_WAITED;
1353 return svr4_setinfo(q, W_STOPCODE(q->p_xstat),
1362 if (uap->options & SVR4_WNOHANG) {
1364 if ((error = svr4_setinfo(NULL, 0, uap->info)) != 0)
1369 if ((error = tsleep(p, PWAIT | PCATCH, "svr4_wait", 0)) != 0)
1376 bsd_statfs_to_svr4_statvfs(bfs, sfs)
1377 const struct statfs *bfs;
1378 struct svr4_statvfs *sfs;
1380 sfs->f_bsize = bfs->f_iosize; /* XXX */
1381 sfs->f_frsize = bfs->f_bsize;
1382 sfs->f_blocks = bfs->f_blocks;
1383 sfs->f_bfree = bfs->f_bfree;
1384 sfs->f_bavail = bfs->f_bavail;
1385 sfs->f_files = bfs->f_files;
1386 sfs->f_ffree = bfs->f_ffree;
1387 sfs->f_favail = bfs->f_ffree;
1388 sfs->f_fsid = bfs->f_fsid.val[0];
1389 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1391 if (bfs->f_flags & MNT_RDONLY)
1392 sfs->f_flag |= SVR4_ST_RDONLY;
1393 if (bfs->f_flags & MNT_NOSUID)
1394 sfs->f_flag |= SVR4_ST_NOSUID;
1395 sfs->f_namemax = MAXNAMLEN;
1396 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1397 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1402 bsd_statfs_to_svr4_statvfs64(bfs, sfs)
1403 const struct statfs *bfs;
1404 struct svr4_statvfs64 *sfs;
1406 sfs->f_bsize = bfs->f_iosize; /* XXX */
1407 sfs->f_frsize = bfs->f_bsize;
1408 sfs->f_blocks = bfs->f_blocks;
1409 sfs->f_bfree = bfs->f_bfree;
1410 sfs->f_bavail = bfs->f_bavail;
1411 sfs->f_files = bfs->f_files;
1412 sfs->f_ffree = bfs->f_ffree;
1413 sfs->f_favail = bfs->f_ffree;
1414 sfs->f_fsid = bfs->f_fsid.val[0];
1415 memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
1417 if (bfs->f_flags & MNT_RDONLY)
1418 sfs->f_flag |= SVR4_ST_RDONLY;
1419 if (bfs->f_flags & MNT_NOSUID)
1420 sfs->f_flag |= SVR4_ST_NOSUID;
1421 sfs->f_namemax = MAXNAMLEN;
1422 memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
1423 memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
1428 svr4_sys_statvfs(td, uap)
1430 struct svr4_sys_statvfs_args *uap;
1432 struct svr4_statvfs sfs;
1437 CHECKALTEXIST(td, uap->path, &path);
1439 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1443 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1444 return copyout(&sfs, uap->fs, sizeof(sfs));
1449 svr4_sys_fstatvfs(td, uap)
1451 struct svr4_sys_fstatvfs_args *uap;
1453 struct svr4_statvfs sfs;
1457 error = kern_fstatfs(td, uap->fd, &bfs);
1460 bsd_statfs_to_svr4_statvfs(&bfs, &sfs);
1461 return copyout(&sfs, uap->fs, sizeof(sfs));
1466 svr4_sys_statvfs64(td, uap)
1468 struct svr4_sys_statvfs64_args *uap;
1470 struct svr4_statvfs64 sfs;
1475 CHECKALTEXIST(td, uap->path, &path);
1477 error = kern_statfs(td, path, UIO_SYSSPACE, &bfs);
1481 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1482 return copyout(&sfs, uap->fs, sizeof(sfs));
1487 svr4_sys_fstatvfs64(td, uap)
1489 struct svr4_sys_fstatvfs64_args *uap;
1491 struct svr4_statvfs64 sfs;
1495 error = kern_fstatfs(td, uap->fd, &bfs);
1498 bsd_statfs_to_svr4_statvfs64(&bfs, &sfs);
1499 return copyout(&sfs, uap->fs, sizeof(sfs));
1503 svr4_sys_alarm(td, uap)
1505 struct svr4_sys_alarm_args *uap;
1507 struct itimerval itv, oitv;
1510 timevalclear(&itv.it_interval);
1511 itv.it_value.tv_sec = uap->sec;
1512 itv.it_value.tv_usec = 0;
1513 error = kern_setitimer(td, ITIMER_REAL, &itv, &oitv);
1516 if (oitv.it_value.tv_usec != 0)
1517 oitv.it_value.tv_sec++;
1518 td->td_retval[0] = oitv.it_value.tv_sec;
1523 svr4_sys_gettimeofday(td, uap)
1525 struct svr4_sys_gettimeofday_args *uap;
1531 return copyout(&atv, uap->tp, sizeof (atv));
1538 svr4_sys_facl(td, uap)
1540 struct svr4_sys_facl_args *uap;
1544 retval = td->td_retval;
1548 case SVR4_SYS_SETACL:
1549 /* We don't support acls on any filesystem */
1552 case SVR4_SYS_GETACL:
1553 return copyout(retval, &uap->num,
1556 case SVR4_SYS_GETACLCNT:
1566 svr4_sys_acl(td, uap)
1568 struct svr4_sys_acl_args *uap;
1570 /* XXX: for now the same */
1571 return svr4_sys_facl(td, (struct svr4_sys_facl_args *)uap);
1575 svr4_sys_auditsys(td, uap)
1577 struct svr4_sys_auditsys_args *uap;
1580 * XXX: Big brother is *not* watching.
1586 svr4_sys_memcntl(td, uap)
1588 struct svr4_sys_memcntl_args *uap;
1593 struct msync_args msa;
1595 msa.addr = uap->addr;
1597 msa.flags = (int)uap->arg;
1599 return msync(td, &msa);
1601 case SVR4_MC_ADVISE:
1603 struct madvise_args maa;
1605 maa.addr = uap->addr;
1607 maa.behav = (int)uap->arg;
1609 return madvise(td, &maa);
1612 case SVR4_MC_UNLOCK:
1613 case SVR4_MC_LOCKAS:
1614 case SVR4_MC_UNLOCKAS:
1623 svr4_sys_nice(td, uap)
1625 struct svr4_sys_nice_args *uap;
1627 struct setpriority_args ap;
1630 ap.which = PRIO_PROCESS;
1632 ap.prio = uap->prio;
1634 if ((error = setpriority(td, &ap)) != 0)
1637 /* the cast is stupid, but the structures are the same */
1638 if ((error = getpriority(td, (struct getpriority_args *)&ap)) != 0)
1645 svr4_sys_resolvepath(td, uap)
1647 struct svr4_sys_resolvepath_args *uap;
1649 struct nameidata nd;
1650 int error, *retval = td->td_retval;
1653 NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
1656 if ((error = namei(&nd)) != 0)
1659 ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1);
1660 if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0)
1665 NDFREE(&nd, NDF_ONLY_PNBUF);