The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/svr4_32/svr4_32_misc.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: svr4_32_misc.c,v 1.30.2.1 2005/10/01 10:39:27 tron Exp $        */
    2 
    3 /*-
    4  * Copyright (c) 1994 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Christos Zoulas.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  * 3. All advertising materials mentioning features or use of this software
   19  *    must display the following acknowledgement:
   20  *        This product includes software developed by the NetBSD
   21  *        Foundation, Inc. and its contributors.
   22  * 4. Neither the name of The NetBSD Foundation nor the names of its
   23  *    contributors may be used to endorse or promote products derived
   24  *    from this software without specific prior written permission.
   25  *
   26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   36  * POSSIBILITY OF SUCH DAMAGE.
   37  */
   38 
   39 /*
   40  * SVR4 compatibility module.
   41  *
   42  * SVR4 system calls that are implemented differently in BSD are
   43  * handled here.
   44  */
   45 
   46 #include <sys/cdefs.h>
   47 __KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.30.2.1 2005/10/01 10:39:27 tron Exp $");
   48 
   49 #include <sys/param.h>
   50 #include <sys/systm.h>
   51 #include <sys/namei.h>
   52 #include <sys/dirent.h>
   53 #include <sys/proc.h>
   54 #include <sys/file.h>
   55 #include <sys/stat.h>
   56 #include <sys/time.h>
   57 #include <sys/filedesc.h>
   58 #include <sys/ioctl.h>
   59 #include <sys/kernel.h>
   60 #include <sys/malloc.h>
   61 #include <sys/pool.h>
   62 #include <sys/mbuf.h>
   63 #include <sys/mman.h>
   64 #include <sys/mount.h>
   65 #include <sys/resource.h>
   66 #include <sys/resourcevar.h>
   67 #include <sys/socket.h>
   68 #include <sys/vnode.h>
   69 #include <sys/uio.h>
   70 #include <sys/wait.h>
   71 #include <sys/utsname.h>
   72 #include <sys/unistd.h>
   73 #include <sys/times.h>
   74 #include <sys/sem.h>
   75 #include <sys/msg.h>
   76 #include <sys/ptrace.h>
   77 #include <sys/signalvar.h>
   78 
   79 #include <netinet/in.h>
   80 #include <sys/sa.h>
   81 #include <sys/syscallargs.h>
   82 
   83 #include <miscfs/specfs/specdev.h>
   84 
   85 #include <compat/svr4_32/svr4_32_types.h>
   86 #include <compat/svr4_32/svr4_32_signal.h>
   87 #include <compat/svr4_32/svr4_32_lwp.h>
   88 #include <compat/svr4_32/svr4_32_ucontext.h>
   89 #include <compat/svr4_32/svr4_32_syscallargs.h>
   90 #include <compat/svr4_32/svr4_32_util.h>
   91 #include <compat/svr4_32/svr4_32_time.h>
   92 #include <compat/svr4_32/svr4_32_dirent.h>
   93 #include <compat/svr4/svr4_ulimit.h>
   94 #include <compat/svr4_32/svr4_32_hrt.h>
   95 #include <compat/svr4/svr4_wait.h>
   96 #include <compat/svr4_32/svr4_32_statvfs.h>
   97 #include <compat/svr4/svr4_sysconfig.h>
   98 #include <compat/svr4_32/svr4_32_acl.h>
   99 #include <compat/svr4/svr4_mman.h>
  100 
  101 #include <machine/cpu.h>
  102 
  103 #include <uvm/uvm_extern.h>
  104 
  105 static int svr4_to_bsd_mmap_flags __P((int));
  106 
  107 static __inline clock_t timeval_to_clock_t __P((struct timeval *));
  108 static int svr4_32_setinfo      __P((struct proc *, int, svr4_32_siginfo_tp));
  109 
  110 struct svr4_32_hrtcntl_args;
  111 static int svr4_32_hrtcntl      __P((struct proc *, struct svr4_32_hrtcntl_args *,
  112     register_t *));
  113 static void bsd_statvfs_to_svr4_32_statvfs __P((const struct statvfs *,
  114     struct svr4_32_statvfs *));
  115 static void bsd_statvfs_to_svr4_32_statvfs64 __P((const struct statvfs *,
  116     struct svr4_32_statvfs64 *));
  117 #define svr4_32_pfind(pid) p_find((pid), PFIND_UNLOCK | PFIND_ZOMBIE)
  118 
  119 static int svr4_32_mknod __P((struct lwp *, register_t *, const char *,
  120     svr4_32_mode_t, svr4_32_dev_t));
  121 
  122 int
  123 svr4_32_sys_wait(l, v, retval)
  124         struct lwp *l;
  125         void *v;
  126         register_t *retval;
  127 {
  128         struct svr4_32_sys_wait_args *uap = v;
  129         struct proc *p = l->l_proc;
  130         struct sys_wait4_args w4;
  131         int error;
  132         size_t sz = sizeof(*SCARG(&w4, status));
  133         int st, sig;
  134 
  135         SCARG(&w4, rusage) = NULL;
  136         SCARG(&w4, options) = 0;
  137 
  138         if (SCARG(uap, status) == 0) {
  139                 caddr_t sg = stackgap_init(p, 0);
  140 
  141                 SCARG(&w4, status) = stackgap_alloc(p, &sg, sz);
  142         }
  143         else
  144                 SCARG(&w4, status) = (int *)(u_long)SCARG(uap, status);
  145 
  146         SCARG(&w4, pid) = WAIT_ANY;
  147 
  148         if ((error = sys_wait4(l, &w4, retval)) != 0)
  149                 return error;
  150 
  151         if ((error = copyin(SCARG(&w4, status), &st, sizeof(st))) != 0)
  152                 return error;
  153 
  154         if (WIFSIGNALED(st)) {
  155                 sig = WTERMSIG(st);
  156                 if (sig >= 0 && sig < NSIG)
  157                         st = (st & ~0177) | native_to_svr4_signo[sig];
  158         } else if (WIFSTOPPED(st)) {
  159                 sig = WSTOPSIG(st);
  160                 if (sig >= 0 && sig < NSIG)
  161                         st = (st & ~0xff00) | (native_to_svr4_signo[sig] << 8);
  162         }
  163 
  164         /*
  165          * It looks like wait(2) on svr4/solaris/2.4 returns
  166          * the status in retval[1], and the pid on retval[0].
  167          */
  168         retval[1] = st;
  169 
  170         if (SCARG(uap, status))
  171                 if ((error = copyout(&st, (caddr_t)(u_long)SCARG(uap, status),
  172                                      sizeof(st))) != 0)
  173                         return error;
  174 
  175         return 0;
  176 }
  177 
  178 
  179 int
  180 svr4_32_sys_execv(l, v, retval)
  181         struct lwp *l;
  182         void *v;
  183         register_t *retval;
  184 {
  185         struct svr4_32_sys_execv_args /* {
  186                 syscallarg(char *) path;
  187                 syscallarg(char **) argv;
  188         } */ *uap = v;
  189         struct netbsd32_execve_args_noconst {
  190                 syscallarg(netbsd32_charp) path;
  191                 syscallarg(netbsd32_charpp) argp;
  192                 syscallarg(netbsd32_charpp) envp;
  193         } ap;
  194 
  195         SCARG(&ap, path) = SCARG(uap, path);
  196         SCARG(&ap, argp) = SCARG(uap, argp);
  197         SCARG(&ap, envp) = 0;
  198 
  199         return netbsd32_execve(l, &ap, retval);
  200 }
  201 
  202 #if 0
  203 int
  204 svr4_32_sys_execve(p, v, retval)
  205         struct proc *p;
  206         void *v;
  207         register_t *retval;
  208 {
  209         struct svr4_32_sys_execve_args /* {
  210                 syscallarg(const char *) path;
  211                 syscallarg(char **) argv;
  212                 syscallarg(char **) envp;
  213         } */ *uap = v;
  214         struct sys_execve_args ap;
  215         caddr_t sg;
  216 
  217         sg = stackgap_init(p, 0);
  218 
  219         SCARG(&ap, path) = (const char *)(u_long)SCARG(uap, path);
  220         CHECK_ALT_EXIST(p, &sg, SCARG(&ap, path));
  221         SCARG(&ap, argp) = (char **)(u_long)SCARG(uap, argp);
  222         SCARG(&ap, envp) = (char **)(u_long)SCARG(uap, envp);
  223 
  224         return netbsd32_execve(p, &ap, retval);
  225 }
  226 #endif
  227 
  228 int
  229 svr4_32_sys_time(l, v, retval)
  230         struct lwp *l;
  231         void *v;
  232         register_t *retval;
  233 {
  234         struct svr4_32_sys_time_args *uap = v;
  235         int error = 0;
  236         struct timeval tv;
  237         struct netbsd32_timeval ntv;
  238 
  239         microtime(&tv);
  240         ntv.tv_sec = tv.tv_sec;
  241         ntv.tv_usec = tv.tv_usec;
  242         if (SCARG(uap, t))
  243                 error = copyout(&ntv.tv_sec, (caddr_t)(u_long)SCARG(uap, t),
  244                                 sizeof(ntv.tv_sec));
  245         *retval = (int) ntv.tv_sec;
  246 
  247         return error;
  248 }
  249 
  250 
  251 /*
  252  * Read SVR4-style directory entries.  We suck them into kernel space so
  253  * that they can be massaged before being copied out to user code.  Like
  254  * SunOS, we squish out `empty' entries.
  255  *
  256  * This is quite ugly, but what do you expect from compatibility code?
  257  */
  258 int
  259 svr4_32_sys_getdents64(l, v, retval)
  260         struct lwp *l;
  261         void *v;
  262         register_t *retval;
  263 {
  264         struct svr4_32_sys_getdents64_args *uap = v;
  265         struct proc *p = l->l_proc;
  266         struct dirent *bdp;
  267         struct vnode *vp;
  268         caddr_t inp, buf;       /* BSD-format */
  269         int len, reclen;        /* BSD-format */
  270         caddr_t outp;           /* SVR4-format */
  271         int resid, svr4_32_reclen;      /* SVR4-format */
  272         struct file *fp;
  273         struct uio auio;
  274         struct iovec aiov;
  275         struct svr4_32_dirent64 idb;
  276         off_t off;              /* true file offset */
  277         int buflen, error, eofflag;
  278         off_t *cookiebuf = NULL, *cookie;
  279         int ncookies;
  280 
  281         /* getvnode() will use the descriptor for us */
  282         if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
  283                 return (error);
  284 
  285         if ((fp->f_flag & FREAD) == 0) {
  286                 error = EBADF;
  287                 goto out1;
  288         }
  289 
  290         vp = (struct vnode *)fp->f_data;
  291         if (vp->v_type != VDIR) {
  292                 error = EINVAL;
  293                 goto out1;
  294         }
  295 
  296         buflen = min(MAXBSIZE, SCARG(uap, nbytes));
  297         buf = malloc(buflen, M_TEMP, M_WAITOK);
  298         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
  299         off = fp->f_offset;
  300 again:
  301         aiov.iov_base = buf;
  302         aiov.iov_len = buflen;
  303         auio.uio_iov = &aiov;
  304         auio.uio_iovcnt = 1;
  305         auio.uio_rw = UIO_READ;
  306         auio.uio_segflg = UIO_SYSSPACE;
  307         auio.uio_procp = NULL;
  308         auio.uio_resid = buflen;
  309         auio.uio_offset = off;
  310         /*
  311          * First we read into the malloc'ed buffer, then
  312          * we massage it into user space, one record at a time.
  313          */
  314         error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
  315             &ncookies);
  316         if (error)
  317                 goto out;
  318 
  319         inp = buf;
  320         outp = (char *)(u_long) SCARG(uap, dp);
  321         resid = SCARG(uap, nbytes);
  322         if ((len = buflen - auio.uio_resid) == 0)
  323                 goto eof;
  324 
  325         for (cookie = cookiebuf; len > 0; len -= reclen) {
  326                 bdp = (struct dirent *)inp;
  327                 reclen = bdp->d_reclen;
  328                 if (reclen & 3)
  329                         panic("svr4_32_getdents64: bad reclen");
  330                 if (bdp->d_fileno == 0) {
  331                         inp += reclen;  /* it is a hole; squish it out */
  332                         if (cookie)
  333                                 off = *cookie++;
  334                         else
  335                                 off += reclen;
  336                         continue;
  337                 }
  338                 svr4_32_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
  339                 if (reclen > len || resid < svr4_32_reclen) {
  340                         /* entry too big for buffer, so just stop */
  341                         outp++;
  342                         break;
  343                 }
  344                 if (cookie)
  345                         off = *cookie++; /* each entry points to the next */
  346                 else
  347                         off += reclen;
  348                 /*
  349                  * Massage in place to make a SVR4-shaped dirent (otherwise
  350                  * we have to worry about touching user memory outside of
  351                  * the copyout() call).
  352                  */
  353                 idb.d_ino = (svr4_32_ino64_t)bdp->d_fileno;
  354                 idb.d_off = (svr4_32_off64_t)off;
  355                 idb.d_reclen = (u_short)svr4_32_reclen;
  356                 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
  357                 if ((error = copyout((caddr_t)&idb, outp, svr4_32_reclen)))
  358                         goto out;
  359                 /* advance past this real entry */
  360                 inp += reclen;
  361                 /* advance output past SVR4-shaped entry */
  362                 outp += svr4_32_reclen;
  363                 resid -= svr4_32_reclen;
  364         }
  365 
  366         /* if we squished out the whole block, try again */
  367         if (outp == (char *)(u_long) SCARG(uap, dp))
  368                 goto again;
  369         fp->f_offset = off;     /* update the vnode offset */
  370 
  371 eof:
  372         *retval = SCARG(uap, nbytes) - resid;
  373 out:
  374         VOP_UNLOCK(vp, 0);
  375         if (cookiebuf)
  376                 free(cookiebuf, M_TEMP);
  377         free(buf, M_TEMP);
  378  out1:
  379         FILE_UNUSE(fp, p);
  380         return error;
  381 }
  382 
  383 
  384 int
  385 svr4_32_sys_getdents(l, v, retval)
  386         struct lwp *l;
  387         void *v;
  388         register_t *retval;
  389 {
  390         struct svr4_32_sys_getdents_args *uap = v;
  391         struct proc *p = l->l_proc;
  392         struct dirent *bdp;
  393         struct vnode *vp;
  394         caddr_t inp, buf;       /* BSD-format */
  395         int len, reclen;        /* BSD-format */
  396         caddr_t outp;           /* SVR4-format */
  397         int resid, svr4_reclen; /* SVR4-format */
  398         struct file *fp;
  399         struct uio auio;
  400         struct iovec aiov;
  401         struct svr4_32_dirent idb;
  402         off_t off;              /* true file offset */
  403         int buflen, error, eofflag;
  404         off_t *cookiebuf = NULL, *cookie;
  405         int ncookies;
  406 
  407         /* getvnode() will use the descriptor for us */
  408         if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
  409                 return (error);
  410 
  411         if ((fp->f_flag & FREAD) == 0) {
  412                 error = EBADF;
  413                 goto out1;
  414         }
  415 
  416         vp = (struct vnode *)fp->f_data;
  417         if (vp->v_type != VDIR) {
  418                 error = EINVAL;
  419                 goto out1;
  420         }
  421 
  422         buflen = min(MAXBSIZE, SCARG(uap, nbytes));
  423         buf = malloc(buflen, M_TEMP, M_WAITOK);
  424         vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
  425         off = fp->f_offset;
  426 again:
  427         aiov.iov_base = buf;
  428         aiov.iov_len = buflen;
  429         auio.uio_iov = &aiov;
  430         auio.uio_iovcnt = 1;
  431         auio.uio_rw = UIO_READ;
  432         auio.uio_segflg = UIO_SYSSPACE;
  433         auio.uio_procp = NULL;
  434         auio.uio_resid = buflen;
  435         auio.uio_offset = off;
  436         /*
  437          * First we read into the malloc'ed buffer, then
  438          * we massage it into user space, one record at a time.
  439          */
  440         error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
  441             &ncookies);
  442         if (error)
  443                 goto out;
  444 
  445         inp = buf;
  446         outp = (caddr_t)(u_long)SCARG(uap, buf);
  447         resid = SCARG(uap, nbytes);
  448         if ((len = buflen - auio.uio_resid) == 0)
  449                 goto eof;
  450 
  451         for (cookie = cookiebuf; len > 0; len -= reclen) {
  452                 bdp = (struct dirent *)inp;
  453                 reclen = bdp->d_reclen;
  454                 if (reclen & 3)
  455                         panic("svr4_32_getdents: bad reclen");
  456                 if (cookie)
  457                         off = *cookie++; /* each entry points to the next */
  458                 else
  459                         off += reclen;
  460                 if ((off >> 32) != 0) {
  461                         compat_offseterr(vp, "svr4_32_getdents");
  462                         error = EINVAL;
  463                         goto out;
  464                 }
  465                 if (bdp->d_fileno == 0) {
  466                         inp += reclen;  /* it is a hole; squish it out */
  467                         continue;
  468                 }
  469                 svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
  470                 if (reclen > len || resid < svr4_reclen) {
  471                         /* entry too big for buffer, so just stop */
  472                         outp++;
  473                         break;
  474                 }
  475                 /*
  476                  * Massage in place to make a SVR4-shaped dirent (otherwise
  477                  * we have to worry about touching user memory outside of
  478                  * the copyout() call).
  479                  */
  480                 idb.d_ino = (svr4_32_ino_t)bdp->d_fileno;
  481                 idb.d_off = (svr4_32_off_t)off;
  482                 idb.d_reclen = (u_short)svr4_reclen;
  483                 strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
  484                 if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
  485                         goto out;
  486                 /* advance past this real entry */
  487                 inp += reclen;
  488                 /* advance output past SVR4-shaped entry */
  489                 outp += svr4_reclen;
  490                 resid -= svr4_reclen;
  491         }
  492 
  493         /* if we squished out the whole block, try again */
  494         if (outp == (caddr_t)(u_long)SCARG(uap, buf))
  495                 goto again;
  496         fp->f_offset = off;     /* update the vnode offset */
  497 
  498 eof:
  499         *retval = SCARG(uap, nbytes) - resid;
  500 out:
  501         VOP_UNLOCK(vp, 0);
  502         if (cookiebuf)
  503                 free(cookiebuf, M_TEMP);
  504         free(buf, M_TEMP);
  505  out1:
  506         FILE_UNUSE(fp, p);
  507         return error;
  508 }
  509 
  510 
  511 static int
  512 svr4_to_bsd_mmap_flags(f)
  513         int f;
  514 {
  515         int type = f & SVR4_MAP_TYPE;
  516         int nf;
  517 
  518         if (type != MAP_PRIVATE && type != MAP_SHARED)
  519                 return -1;
  520 
  521         nf = f & SVR4_MAP_COPYFLAGS;
  522         if (f & SVR4_MAP_ANON)
  523         nf |= MAP_ANON;
  524 
  525         return nf;
  526 }
  527 
  528 
  529 int
  530 svr4_32_sys_mmap(l, v, retval)
  531         struct lwp *l;
  532         void *v;
  533         register_t *retval;
  534 {
  535         struct svr4_32_sys_mmap_args    *uap = v;
  536         struct sys_mmap_args             mm;
  537         int                              error;
  538         /*
  539          * Verify the arguments.
  540          */
  541         if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
  542                 return EINVAL;  /* XXX still needed? */
  543 
  544         if (SCARG(uap, len) == 0)
  545                 return EINVAL;
  546 
  547         if ((SCARG(&mm, flags) = svr4_to_bsd_mmap_flags(SCARG(uap, flags))) == -1)
  548                 return EINVAL;
  549 
  550         SCARG(&mm, prot) = SCARG(uap, prot);
  551         SCARG(&mm, len) = SCARG(uap, len);
  552         SCARG(&mm, fd) = SCARG(uap, fd);
  553         SCARG(&mm, addr) = (void *)(u_long)SCARG(uap, addr);
  554         SCARG(&mm, pos) = SCARG(uap, pos);
  555 
  556         error = sys_mmap(l, &mm, retval);
  557         if ((u_long)*retval > (u_long)UINT_MAX) {
  558                 printf("svr4_32_mmap: retval out of range: 0x%lx",
  559                        (u_long)*retval);
  560                 /* Should try to recover and return an error here. */
  561         }
  562         return (error);
  563 }
  564 
  565 
  566 int
  567 svr4_32_sys_mmap64(l, v, retval)
  568         struct lwp *l;
  569         void *v;
  570         register_t *retval;
  571 {
  572         struct svr4_32_sys_mmap64_args  *uap = v;
  573         struct sys_mmap_args             mm;
  574         int                              error;
  575         /*
  576          * Verify the arguments.
  577          */
  578         if (SCARG(uap, prot) & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
  579                 return EINVAL;  /* XXX still needed? */
  580 
  581         if (SCARG(uap, len) == 0)
  582                 return EINVAL;
  583 
  584         if ((SCARG(&mm, flags) = svr4_to_bsd_mmap_flags(SCARG(uap, flags))) == -1)
  585                 return EINVAL;
  586 
  587         SCARG(&mm, prot) = SCARG(uap, prot);
  588         SCARG(&mm, len) = SCARG(uap, len);
  589         SCARG(&mm, fd) = SCARG(uap, fd);
  590         SCARG(&mm, addr) = (void *)(u_long)SCARG(uap, addr);
  591         SCARG(&mm, pos) = SCARG(uap, pos);
  592 
  593         error = sys_mmap(l, &mm, retval);
  594         if ((u_long)*retval > (u_long)UINT_MAX) {
  595                 printf("svr4_32_mmap64: retval out of range: 0x%lx",
  596                        (u_long)*retval);
  597                 /* Should try to recover and return an error here. */
  598         }
  599         return (error);
  600 }
  601 
  602 
  603 static int
  604 svr4_32_mknod(l, retval, path, mode, dev)
  605         struct lwp *l;
  606         register_t *retval;
  607         const char *path;
  608         svr4_32_mode_t mode;
  609         svr4_32_dev_t dev;
  610 {
  611         caddr_t sg = stackgap_init(l->l_proc, 0);
  612 
  613         CHECK_ALT_CREAT(l->l_proc, &sg, path);
  614 
  615         if (S_ISFIFO(mode)) {
  616                 struct sys_mkfifo_args ap;
  617                 SCARG(&ap, path) = path;
  618                 SCARG(&ap, mode) = mode;
  619                 return sys_mkfifo(l, &ap, retval);
  620         } else {
  621                 struct sys_mknod_args ap;
  622                 SCARG(&ap, path) = path;
  623                 SCARG(&ap, mode) = mode;
  624                 SCARG(&ap, dev) = dev;
  625                 return sys_mknod(l, &ap, retval);
  626         }
  627 }
  628 
  629 
  630 int
  631 svr4_32_sys_mknod(l, v, retval)
  632         struct lwp *l;
  633         void *v;
  634         register_t *retval;
  635 {
  636         struct svr4_32_sys_mknod_args *uap = v;
  637         return svr4_32_mknod(l, retval,
  638                           (caddr_t)(u_long)SCARG(uap, path), SCARG(uap, mode),
  639                           svr4_32_to_bsd_odev_t(SCARG(uap, dev)));
  640 }
  641 
  642 
  643 int
  644 svr4_32_sys_xmknod(l, v, retval)
  645         struct lwp *l;
  646         void *v;
  647         register_t *retval;
  648 {
  649         struct svr4_32_sys_xmknod_args *uap = v;
  650         return svr4_32_mknod(l, retval,
  651                           (caddr_t)(u_long)SCARG(uap, path), SCARG(uap, mode),
  652                           svr4_32_to_bsd_dev_t(SCARG(uap, dev)));
  653 }
  654 
  655 
  656 int
  657 svr4_32_sys_vhangup(l, v, retval)
  658         struct lwp *l;
  659         void *v;
  660         register_t *retval;
  661 {
  662         return 0;
  663 }
  664 
  665 
  666 int
  667 svr4_32_sys_sysconfig(l, v, retval)
  668         struct lwp *l;
  669         void *v;
  670         register_t *retval;
  671 {
  672         struct svr4_32_sys_sysconfig_args *uap = v;
  673         extern int      maxfiles;
  674 
  675         switch (SCARG(uap, name)) {
  676         case SVR4_CONFIG_NGROUPS:
  677                 *retval = NGROUPS_MAX;
  678                 break;
  679         case SVR4_CONFIG_CHILD_MAX:
  680                 *retval = maxproc;
  681                 break;
  682         case SVR4_CONFIG_OPEN_FILES:
  683                 *retval = maxfiles;
  684                 break;
  685         case SVR4_CONFIG_POSIX_VER:
  686                 *retval = 198808;
  687                 break;
  688         case SVR4_CONFIG_PAGESIZE:
  689                 *retval = PAGE_SIZE;
  690                 break;
  691         case SVR4_CONFIG_CLK_TCK:
  692                 *retval = 60;   /* should this be `hz', ie. 100? */
  693                 break;
  694         case SVR4_CONFIG_XOPEN_VER:
  695                 *retval = 2;    /* XXX: What should that be? */
  696                 break;
  697         case SVR4_CONFIG_PROF_TCK:
  698                 *retval = 60;   /* XXX: What should that be? */
  699                 break;
  700         case SVR4_CONFIG_NPROC_CONF:
  701                 *retval = 1;    /* Only one processor for now */
  702                 break;
  703         case SVR4_CONFIG_NPROC_ONLN:
  704                 *retval = 1;    /* And it better be online */
  705                 break;
  706         case SVR4_CONFIG_AIO_LISTIO_MAX:
  707         case SVR4_CONFIG_AIO_MAX:
  708         case SVR4_CONFIG_AIO_PRIO_DELTA_MAX:
  709                 *retval = 0;    /* No aio support */
  710                 break;
  711         case SVR4_CONFIG_DELAYTIMER_MAX:
  712                 *retval = 0;    /* No delaytimer support */
  713                 break;
  714         case SVR4_CONFIG_MQ_OPEN_MAX:
  715 #ifdef SYSVMSG
  716                 *retval = msginfo.msgmni;
  717 #else
  718                 *retval = 0;
  719 #endif
  720                 break;
  721         case SVR4_CONFIG_MQ_PRIO_MAX:
  722                 *retval = 0;    /* XXX: Don't know */
  723                 break;
  724         case SVR4_CONFIG_RTSIG_MAX:
  725                 *retval = 0;
  726                 break;
  727         case SVR4_CONFIG_SEM_NSEMS_MAX:
  728 #ifdef SYSVSEM
  729                 *retval = seminfo.semmni;
  730 #else
  731                 *retval = 0;
  732 #endif
  733                 break;
  734         case SVR4_CONFIG_SEM_VALUE_MAX:
  735 #ifdef SYSVSEM
  736                 *retval = seminfo.semvmx;
  737 #else
  738                 *retval = 0;
  739 #endif
  740                 break;
  741         case SVR4_CONFIG_SIGQUEUE_MAX:
  742                 *retval = 0;    /* XXX: Don't know */
  743                 break;
  744         case SVR4_CONFIG_SIGRT_MIN:
  745         case SVR4_CONFIG_SIGRT_MAX:
  746                 *retval = 0;    /* No real time signals */
  747                 break;
  748         case SVR4_CONFIG_TIMER_MAX:
  749                 *retval = 3;    /* XXX: real, virtual, profiling */
  750                 break;
  751         case SVR4_CONFIG_PHYS_PAGES:
  752                 *retval = uvmexp.free;  /* XXX: free instead of total */
  753                 break;
  754         case SVR4_CONFIG_AVPHYS_PAGES:
  755                 *retval = uvmexp.active;        /* XXX: active instead of avg */
  756                 break;
  757         case SVR4_CONFIG_COHERENCY:
  758                 *retval = 0;    /* XXX */
  759                 break;
  760         case SVR4_CONFIG_SPLIT_CACHE:
  761                 *retval = 0;    /* XXX */
  762                 break;
  763         case SVR4_CONFIG_ICACHESZ:
  764                 *retval = 256;  /* XXX */
  765                 break;
  766         case SVR4_CONFIG_DCACHESZ:
  767                 *retval = 256;  /* XXX */
  768                 break;
  769         case SVR4_CONFIG_ICACHELINESZ:
  770                 *retval = 64;   /* XXX */
  771                 break;
  772         case SVR4_CONFIG_DCACHELINESZ:
  773                 *retval = 64;   /* XXX */
  774                 break;
  775         case SVR4_CONFIG_ICACHEBLKSZ:
  776                 *retval = 64;   /* XXX */
  777                 break;
  778         case SVR4_CONFIG_DCACHEBLKSZ:
  779                 *retval = 64;   /* XXX */
  780                 break;
  781         case SVR4_CONFIG_DCACHETBLKSZ:
  782                 *retval = 64;   /* XXX */
  783                 break;
  784         case SVR4_CONFIG_ICACHE_ASSOC:
  785                 *retval = 1;    /* XXX */
  786                 break;
  787         case SVR4_CONFIG_DCACHE_ASSOC:
  788                 *retval = 1;    /* XXX */
  789                 break;
  790         case SVR4_CONFIG_MAXPID:
  791                 *retval = PID_MAX;
  792                 break;
  793         case SVR4_CONFIG_STACK_PROT:
  794                 *retval = PROT_READ|PROT_WRITE|PROT_EXEC;
  795                 break;
  796         default:
  797                 return EINVAL;
  798         }
  799         return 0;
  800 }
  801 
  802 
  803 /* ARGSUSED */
  804 int
  805 svr4_32_sys_break(l, v, retval)
  806         struct lwp *l;
  807         void *v;
  808         register_t *retval;
  809 {
  810         struct svr4_32_sys_break_args *uap = v;
  811         struct proc *p = l->l_proc;
  812         struct vmspace *vm = p->p_vmspace;
  813         vaddr_t new, old;
  814         int error;
  815 
  816         old = (vaddr_t) vm->vm_daddr;
  817         new = round_page((vaddr_t)SCARG(uap, nsize));
  818 
  819         if (new - old > p->p_rlimit[RLIMIT_DATA].rlim_cur && new > old)
  820                 return ENOMEM;
  821 
  822         old = round_page(old + ctob(vm->vm_dsize));
  823         DPRINTF(("break(2): dsize = %x ctob %x\n",
  824                  vm->vm_dsize, ctob(vm->vm_dsize)));
  825 
  826         if (new > old) {
  827                 error = uvm_map(&vm->vm_map, &old, new - old, NULL,
  828                         UVM_UNKNOWN_OFFSET, 0,
  829                         UVM_MAPFLAG(UVM_PROT_ALL, UVM_PROT_ALL, UVM_INH_COPY,
  830                         UVM_ADV_NORMAL,
  831                         UVM_FLAG_AMAPPAD|UVM_FLAG_FIXED|
  832                         UVM_FLAG_OVERLAY|UVM_FLAG_COPYONW));
  833                 if (error) {
  834                         uprintf("sbrk: grow failed, return = %d\n", error);
  835                         return error;
  836                 }
  837                 vm->vm_dsize += btoc(new - old);
  838         } else if (new < old) {
  839                 uvm_deallocate(&vm->vm_map, new, old - new);
  840                 vm->vm_dsize -= btoc(old - new);
  841         }
  842         return 0;
  843 }
  844 
  845 
  846 static __inline clock_t
  847 timeval_to_clock_t(tv)
  848         struct timeval *tv;
  849 {
  850         return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
  851 }
  852 
  853 
  854 int
  855 svr4_32_sys_times(l, v, retval)
  856         struct lwp *l;
  857         void *v;
  858         register_t *retval;
  859 {
  860         struct svr4_32_sys_times_args *uap = v;
  861         struct proc             *p = l->l_proc;
  862         int                      error;
  863         struct tms               tms;
  864         struct timeval           t;
  865         struct rusage           *ru;
  866         struct rusage            r;
  867         struct sys_getrusage_args        ga;
  868 
  869         caddr_t sg = stackgap_init(p, 0);
  870         ru = stackgap_alloc(p, &sg, sizeof(struct rusage));
  871 
  872         SCARG(&ga, who) = RUSAGE_SELF;
  873         SCARG(&ga, rusage) = ru;
  874 
  875         error = sys_getrusage(l, &ga, retval);
  876         if (error)
  877                 return error;
  878 
  879         if ((error = copyin(ru, &r, sizeof r)) != 0)
  880                 return error;
  881 
  882         tms.tms_utime = timeval_to_clock_t(&r.ru_utime);
  883         tms.tms_stime = timeval_to_clock_t(&r.ru_stime);
  884 
  885         SCARG(&ga, who) = RUSAGE_CHILDREN;
  886         error = sys_getrusage(l, &ga, retval);
  887         if (error)
  888                 return error;
  889 
  890         if ((error = copyin(ru, &r, sizeof r)) != 0)
  891                 return error;
  892 
  893         tms.tms_cutime = timeval_to_clock_t(&r.ru_utime);
  894         tms.tms_cstime = timeval_to_clock_t(&r.ru_stime);
  895 
  896         microtime(&t);
  897         *retval = timeval_to_clock_t(&t);
  898 
  899         return copyout(&tms, (caddr_t)(u_long)SCARG(uap, tp), sizeof(tms));
  900 }
  901 
  902 
  903 int
  904 svr4_32_sys_ulimit(l, v, retval)
  905         struct lwp *l;
  906         void *v;
  907         register_t *retval;
  908 {
  909         struct svr4_32_sys_ulimit_args *uap = v;
  910         struct proc *p = l->l_proc;
  911 
  912         switch (SCARG(uap, cmd)) {
  913         case SVR4_GFILLIM:
  914                 *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
  915                 if (*retval == -1)
  916                         *retval = 0x7fffffff;
  917                 return 0;
  918 
  919         case SVR4_SFILLIM:
  920                 {
  921                         int error;
  922                         struct sys_setrlimit_args srl;
  923                         struct rlimit krl;
  924                         caddr_t sg = stackgap_init(p, 0);
  925                         struct rlimit *url = (struct rlimit *)
  926                                 stackgap_alloc(p, &sg, sizeof *url);
  927 
  928                         krl.rlim_cur = SCARG(uap, newlimit) * 512;
  929                         krl.rlim_max = p->p_rlimit[RLIMIT_FSIZE].rlim_max;
  930 
  931                         error = copyout(&krl, url, sizeof(*url));
  932                         if (error)
  933                                 return error;
  934 
  935                         SCARG(&srl, which) = RLIMIT_FSIZE;
  936                         SCARG(&srl, rlp) = url;
  937 
  938                         error = sys_setrlimit(l, &srl, retval);
  939                         if (error)
  940                                 return error;
  941 
  942                         *retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
  943                         if (*retval == -1)
  944                                 *retval = 0x7fffffff;
  945                         return 0;
  946                 }
  947 
  948         case SVR4_GMEMLIM:
  949                 {
  950                         struct vmspace *vm = p->p_vmspace;
  951                         register_t r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
  952 
  953                         if (r == -1)
  954                                 r = 0x7fffffff;
  955                         r += (long) vm->vm_daddr;
  956                         if (r < 0)
  957                                 r = 0x7fffffff;
  958                         *retval = r;
  959                         return 0;
  960                 }
  961 
  962         case SVR4_GDESLIM:
  963                 *retval = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
  964                 if (*retval == -1)
  965                         *retval = 0x7fffffff;
  966                 return 0;
  967 
  968         default:
  969                 return EINVAL;
  970         }
  971 }
  972 
  973 
  974 int
  975 svr4_32_sys_pgrpsys(l, v, retval)
  976         struct lwp *l;
  977         void *v;
  978         register_t *retval;
  979 {
  980         struct svr4_32_sys_pgrpsys_args *uap = v;
  981         struct proc *p = l->l_proc;
  982 
  983         switch (SCARG(uap, cmd)) {
  984         case 1:                 /* setpgrp() */
  985                 /*
  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.)
  991                  */
  992                 sys_setsid(l, NULL, retval);
  993                 /*FALLTHROUGH*/
  994 
  995         case 0:                 /* getpgrp() */
  996                 *retval = p->p_pgrp->pg_id;
  997                 return 0;
  998 
  999         case 2:                 /* getsid(pid) */
 1000                 if (SCARG(uap, pid) != 0 &&
 1001                     (p = svr4_32_pfind(SCARG(uap, pid))) == NULL)
 1002                         return ESRCH;
 1003                 /*
 1004                  * This has already been initialized to the pid of
 1005                  * the session leader.
 1006                  */
 1007                 *retval = (register_t) p->p_session->s_sid;
 1008                 return 0;
 1009 
 1010         case 3:                 /* setsid() */
 1011                 return sys_setsid(l, NULL, retval);
 1012 
 1013         case 4:                 /* getpgid(pid) */
 1014 
 1015                 if (SCARG(uap, pid) != 0 &&
 1016                     (p = svr4_32_pfind(SCARG(uap, pid))) == NULL)
 1017                         return ESRCH;
 1018 
 1019                 *retval = (int) p->p_pgrp->pg_id;
 1020                 return 0;
 1021 
 1022         case 5:                 /* setpgid(pid, pgid); */
 1023                 {
 1024                         struct sys_setpgid_args sa;
 1025 
 1026                         SCARG(&sa, pid) = SCARG(uap, pid);
 1027                         SCARG(&sa, pgid) = SCARG(uap, pgid);
 1028                         return sys_setpgid(l, &sa, retval);
 1029                 }
 1030 
 1031         default:
 1032                 return EINVAL;
 1033         }
 1034 }
 1035 
 1036 struct svr4_32_hrtcntl_args {
 1037         syscallarg(int)                         cmd;
 1038         syscallarg(int)                         fun;
 1039         syscallarg(int)                         clk;
 1040         syscallarg(svr4_32_hrt_interval_tp)     iv;
 1041         syscallarg(svr4_32_hrt_time_tp)         ti;
 1042 };
 1043 
 1044 
 1045 static int
 1046 svr4_32_hrtcntl(p, uap, retval)
 1047         struct proc *p;
 1048         struct svr4_32_hrtcntl_args *uap;
 1049         register_t *retval;
 1050 {
 1051         switch (SCARG(uap, fun)) {
 1052         case SVR4_HRT_CNTL_RES:
 1053                 DPRINTF(("htrcntl(RES)\n"));
 1054                 *retval = SVR4_HRT_USEC;
 1055                 return 0;
 1056 
 1057         case SVR4_HRT_CNTL_TOFD:
 1058                 DPRINTF(("htrcntl(TOFD)\n"));
 1059                 {
 1060                         struct timeval tv;
 1061                         svr4_hrt_time_t t;
 1062                         if (SCARG(uap, clk) != SVR4_HRT_CLK_STD) {
 1063                                 DPRINTF(("clk == %d\n", SCARG(uap, clk)));
 1064                                 return EINVAL;
 1065                         }
 1066                         if (SCARG(uap, ti) == 0) {
 1067                                 DPRINTF(("ti NULL\n"));
 1068                                 return EINVAL;
 1069                         }
 1070                         microtime(&tv);
 1071                         t.h_sec = tv.tv_sec;
 1072                         t.h_rem = tv.tv_usec;
 1073                         t.h_res = SVR4_HRT_USEC;
 1074                         return copyout(&t, (caddr_t)(u_long)SCARG(uap, ti),
 1075                                        sizeof(t));
 1076                 }
 1077 
 1078         case SVR4_HRT_CNTL_START:
 1079                 DPRINTF(("htrcntl(START)\n"));
 1080                 return ENOSYS;
 1081 
 1082         case SVR4_HRT_CNTL_GET:
 1083                 DPRINTF(("htrcntl(GET)\n"));
 1084                 return ENOSYS;
 1085         default:
 1086                 DPRINTF(("Bad htrcntl command %d\n", SCARG(uap, fun)));
 1087                 return ENOSYS;
 1088         }
 1089 }
 1090 
 1091 
 1092 int
 1093 svr4_32_sys_hrtsys(l, v, retval)
 1094         struct lwp *l;
 1095         void *v;
 1096         register_t *retval;
 1097 {
 1098         struct svr4_32_sys_hrtsys_args *uap = v;
 1099 
 1100         switch (SCARG(uap, cmd)) {
 1101         case SVR4_HRT_CNTL:
 1102                 return svr4_32_hrtcntl(l->l_proc, (struct svr4_32_hrtcntl_args *) uap,
 1103                                     retval);
 1104 
 1105         case SVR4_HRT_ALRM:
 1106                 DPRINTF(("hrtalarm\n"));
 1107                 return ENOSYS;
 1108 
 1109         case SVR4_HRT_SLP:
 1110                 DPRINTF(("hrtsleep\n"));
 1111                 return ENOSYS;
 1112 
 1113         case SVR4_HRT_CAN:
 1114                 DPRINTF(("hrtcancel\n"));
 1115                 return ENOSYS;
 1116 
 1117         default:
 1118                 DPRINTF(("Bad hrtsys command %d\n", SCARG(uap, cmd)));
 1119                 return EINVAL;
 1120         }
 1121 }
 1122 
 1123 
 1124 static int
 1125 svr4_32_setinfo(p, st, si)
 1126         struct proc *p;
 1127         int st;
 1128         svr4_32_siginfo_tp si;
 1129 {
 1130         svr4_32_siginfo_t *s = (svr4_32_siginfo_t *)(u_long)si;
 1131         svr4_32_siginfo_t i;
 1132         int sig;
 1133 
 1134         memset(&i, 0, sizeof(i));
 1135 
 1136         i.si_signo = SVR4_SIGCHLD;
 1137         i.si_errno = 0; /* XXX? */
 1138 
 1139         if (p) {
 1140                 i.si_pid = p->p_pid;
 1141                 if (p->p_stat == SZOMB) {
 1142                         i.si_stime = p->p_ru->ru_stime.tv_sec;
 1143                         i.si_utime = p->p_ru->ru_utime.tv_sec;
 1144                 }
 1145                 else {
 1146                         i.si_stime = p->p_stats->p_ru.ru_stime.tv_sec;
 1147                         i.si_utime = p->p_stats->p_ru.ru_utime.tv_sec;
 1148                 }
 1149         }
 1150 
 1151         if (WIFEXITED(st)) {
 1152                 i.si_status = WEXITSTATUS(st);
 1153                 i.si_code = SVR4_CLD_EXITED;
 1154         } else if (WIFSTOPPED(st)) {
 1155                 sig = WSTOPSIG(st);
 1156                 if (sig >= 0 && sig < NSIG)
 1157                         i.si_status = native_to_svr4_signo[sig];
 1158 
 1159                 if (i.si_status == SVR4_SIGCONT)
 1160                         i.si_code = SVR4_CLD_CONTINUED;
 1161                 else
 1162                         i.si_code = SVR4_CLD_STOPPED;
 1163         } else {
 1164                 sig = WTERMSIG(st);
 1165                 if (sig >= 0 && sig < NSIG)
 1166                         i.si_status = native_to_svr4_signo[sig];
 1167 
 1168                 if (WCOREDUMP(st))
 1169                         i.si_code = SVR4_CLD_DUMPED;
 1170                 else
 1171                         i.si_code = SVR4_CLD_KILLED;
 1172         }
 1173 
 1174         DPRINTF(("siginfo [pid %ld signo %d code %d errno %d status %d]\n",
 1175                  i.si_pid, i.si_signo, i.si_code, i.si_errno, i.si_status));
 1176 
 1177         return copyout(&i, s, sizeof(i));
 1178 }
 1179 
 1180 
 1181 int
 1182 svr4_32_sys_waitsys(l, v, retval)
 1183         struct lwp *l;
 1184         void *v;
 1185         register_t *retval;
 1186 {
 1187         struct svr4_32_sys_waitsys_args *uap = v;
 1188         struct proc *parent = l->l_proc;
 1189         int options, error;
 1190         struct proc *child;
 1191 
 1192         switch (SCARG(uap, grp)) {
 1193         case SVR4_P_PID:
 1194                 break;
 1195 
 1196         case SVR4_P_PGID:
 1197                 SCARG(uap, id) = -parent->p_pgid;
 1198                 break;
 1199 
 1200         case SVR4_P_ALL:
 1201                 SCARG(uap, id) = WAIT_ANY;
 1202                 break;
 1203 
 1204         default:
 1205                 return EINVAL;
 1206         }
 1207 
 1208         DPRINTF(("waitsys(%d, %d, %p, %x)\n",
 1209                  SCARG(uap, grp), SCARG(uap, id),
 1210                  SCARG(uap, info), SCARG(uap, options)));
 1211 
 1212         /* Translate options */
 1213         options = 0;
 1214         if (SCARG(uap, options) & SVR4_WNOWAIT)
 1215                 options |= WNOWAIT;
 1216         if (SCARG(uap, options) & SVR4_WNOHANG)
 1217                 options |= WNOHANG;
 1218         if ((SCARG(uap, options) & (SVR4_WEXITED|SVR4_WTRAPPED)) == 0)
 1219                 options |= WNOZOMBIE;
 1220         if (SCARG(uap, options) & (SVR4_WSTOPPED|SVR4_WCONTINUED))
 1221                 options |= WUNTRACED;
 1222 
 1223         error = find_stopped_child(parent, SCARG(uap, id), options, &child);
 1224         if (error != 0)
 1225                 return error;
 1226         *retval = 0;
 1227         if (child == NULL)
 1228                 return svr4_32_setinfo(NULL, 0, SCARG(uap, info));
 1229 
 1230         if (child->p_stat == SZOMB) {
 1231                 DPRINTF(("found %d\n", child->p_pid));
 1232                 error = svr4_32_setinfo(child, child->p_xstat, SCARG(uap,info));
 1233                 if (error)
 1234                         return error;
 1235 
 1236                 if ((SCARG(uap, options) & SVR4_WNOWAIT)) {
 1237                         DPRINTF(("Don't wait\n"));
 1238                         return 0;
 1239                 }
 1240 
 1241                 proc_free(child);
 1242                 return 0;
 1243         }
 1244 
 1245         DPRINTF(("jobcontrol %d\n", child->p_pid));
 1246         return svr4_32_setinfo(child, W_STOPCODE(child->p_xstat),
 1247                                                SCARG(uap, info));
 1248 }
 1249 
 1250 
 1251 static void
 1252 bsd_statvfs_to_svr4_32_statvfs(bfs, sfs)
 1253         const struct statvfs *bfs;
 1254         struct svr4_32_statvfs *sfs;
 1255 {
 1256         sfs->f_bsize = bfs->f_iosize; /* XXX */
 1257         sfs->f_frsize = bfs->f_bsize;
 1258         sfs->f_blocks = bfs->f_blocks;
 1259         sfs->f_bfree = bfs->f_bfree;
 1260         sfs->f_bavail = bfs->f_bavail;
 1261         sfs->f_files = bfs->f_files;
 1262         sfs->f_ffree = bfs->f_ffree;
 1263         sfs->f_favail = bfs->f_ffree;
 1264         sfs->f_fsid = bfs->f_fsidx.__fsid_val[0];
 1265         memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
 1266         sfs->f_flag = 0;
 1267         if (bfs->f_flag & MNT_RDONLY)
 1268                 sfs->f_flag |= SVR4_ST_RDONLY;
 1269         if (bfs->f_flag & MNT_NOSUID)
 1270                 sfs->f_flag |= SVR4_ST_NOSUID;
 1271         sfs->f_namemax = MAXNAMLEN;
 1272         memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
 1273         memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
 1274 }
 1275 
 1276 
 1277 static void
 1278 bsd_statvfs_to_svr4_32_statvfs64(bfs, sfs)
 1279         const struct statvfs *bfs;
 1280         struct svr4_32_statvfs64 *sfs;
 1281 {
 1282         sfs->f_bsize = bfs->f_iosize; /* XXX */
 1283         sfs->f_frsize = bfs->f_bsize;
 1284         sfs->f_blocks = bfs->f_blocks;
 1285         sfs->f_bfree = bfs->f_bfree;
 1286         sfs->f_bavail = bfs->f_bavail;
 1287         sfs->f_files = bfs->f_files;
 1288         sfs->f_ffree = bfs->f_ffree;
 1289         sfs->f_favail = bfs->f_ffree;
 1290         sfs->f_fsid = bfs->f_fsidx.__fsid_val[0];
 1291         memcpy(sfs->f_basetype, bfs->f_fstypename, sizeof(sfs->f_basetype));
 1292         sfs->f_flag = 0;
 1293         if (bfs->f_flag & MNT_RDONLY)
 1294                 sfs->f_flag |= SVR4_ST_RDONLY;
 1295         if (bfs->f_flag & MNT_NOSUID)
 1296                 sfs->f_flag |= SVR4_ST_NOSUID;
 1297         sfs->f_namemax = MAXNAMLEN;
 1298         memcpy(sfs->f_fstr, bfs->f_fstypename, sizeof(sfs->f_fstr)); /* XXX */
 1299         memset(sfs->f_filler, 0, sizeof(sfs->f_filler));
 1300 }
 1301 
 1302 
 1303 int
 1304 svr4_32_sys_statvfs(l, v, retval)
 1305         struct lwp *l;
 1306         void *v;
 1307         register_t *retval;
 1308 {
 1309         struct svr4_32_sys_statvfs_args *uap = v;
 1310         struct proc *p = l->l_proc;
 1311         struct sys_statvfs1_args        fs_args;
 1312         caddr_t sg = stackgap_init(p, 0);
 1313         struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
 1314         struct statvfs bfs;
 1315         struct svr4_32_statvfs sfs;
 1316         int error;
 1317 
 1318         SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
 1319         CHECK_ALT_EXIST(p, &sg, SCARG(&fs_args, path));
 1320         SCARG(&fs_args, buf) = fs;
 1321         SCARG(&fs_args, flags) = ST_WAIT;
 1322 
 1323         if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
 1324                 return error;
 1325 
 1326         if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
 1327                 return error;
 1328 
 1329         bsd_statvfs_to_svr4_32_statvfs(&bfs, &sfs);
 1330 
 1331         return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
 1332 }
 1333 
 1334 
 1335 int
 1336 svr4_32_sys_fstatvfs(l, v, retval)
 1337         struct lwp *l;
 1338         void *v;
 1339         register_t *retval;
 1340 {
 1341         struct svr4_32_sys_fstatvfs_args *uap = v;
 1342         struct proc *p = l->l_proc;
 1343         struct sys_fstatvfs1_args       fs_args;
 1344         caddr_t sg = stackgap_init(p, 0);
 1345         struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
 1346         struct statvfs bfs;
 1347         struct svr4_32_statvfs sfs;
 1348         int error;
 1349 
 1350         SCARG(&fs_args, fd) = SCARG(uap, fd);
 1351         SCARG(&fs_args, buf) = fs;
 1352         SCARG(&fs_args, flags) = ST_WAIT;
 1353 
 1354         if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
 1355                 return error;
 1356 
 1357         if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
 1358                 return error;
 1359 
 1360         bsd_statvfs_to_svr4_32_statvfs(&bfs, &sfs);
 1361 
 1362         return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
 1363 }
 1364 
 1365 
 1366 int
 1367 svr4_32_sys_statvfs64(l, v, retval)
 1368         struct lwp *l;
 1369         void *v;
 1370         register_t *retval;
 1371 {
 1372         struct svr4_32_sys_statvfs64_args *uap = v;
 1373         struct sys_statvfs1_args        fs_args;
 1374         struct proc *p = l->l_proc;
 1375         caddr_t sg = stackgap_init(p, 0);
 1376         struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
 1377         struct statvfs bfs;
 1378         struct svr4_32_statvfs64 sfs;
 1379         int error;
 1380 
 1381         SCARG(&fs_args, path) = (caddr_t)(u_long)SCARG(uap, path);
 1382         CHECK_ALT_EXIST(p, &sg, SCARG(&fs_args, path));
 1383         SCARG(&fs_args, buf) = fs;
 1384         SCARG(&fs_args, flags) = ST_WAIT;
 1385 
 1386         if ((error = sys_statvfs1(l, &fs_args, retval)) != 0)
 1387                 return error;
 1388 
 1389         if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
 1390                 return error;
 1391 
 1392         bsd_statvfs_to_svr4_32_statvfs64(&bfs, &sfs);
 1393 
 1394         return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
 1395 }
 1396 
 1397 
 1398 int
 1399 svr4_32_sys_fstatvfs64(l, v, retval)
 1400         struct lwp *l;
 1401         void *v;
 1402         register_t *retval;
 1403 {
 1404         struct svr4_32_sys_fstatvfs64_args *uap = v;
 1405         struct proc *p = l->l_proc;
 1406         struct sys_fstatvfs1_args       fs_args;
 1407         caddr_t sg = stackgap_init(p, 0);
 1408         struct statvfs *fs = stackgap_alloc(p, &sg, sizeof(struct statvfs));
 1409         struct statvfs bfs;
 1410         struct svr4_32_statvfs64 sfs;
 1411         int error;
 1412 
 1413         SCARG(&fs_args, fd) = SCARG(uap, fd);
 1414         SCARG(&fs_args, buf) = fs;
 1415         SCARG(&fs_args, flags) = ST_WAIT;
 1416 
 1417         if ((error = sys_fstatvfs1(l, &fs_args, retval)) != 0)
 1418                 return error;
 1419 
 1420         if ((error = copyin(fs, &bfs, sizeof(bfs))) != 0)
 1421                 return error;
 1422 
 1423         bsd_statvfs_to_svr4_32_statvfs64(&bfs, &sfs);
 1424 
 1425         return copyout(&sfs, (caddr_t)(u_long)SCARG(uap, fs), sizeof(sfs));
 1426 }
 1427 
 1428 
 1429 int
 1430 svr4_32_sys_alarm(l, v, retval)
 1431         struct lwp *l;
 1432         void *v;
 1433         register_t *retval;
 1434 {
 1435         struct svr4_32_sys_alarm_args *uap = v;
 1436         struct proc *p = l->l_proc;
 1437         int error;
 1438         struct itimerval *ntp, *otp, tp;
 1439         struct sys_setitimer_args sa;
 1440         caddr_t sg = stackgap_init(p, 0);
 1441 
 1442         ntp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
 1443         otp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
 1444 
 1445         timerclear(&tp.it_interval);
 1446         tp.it_value.tv_sec = SCARG(uap, sec);
 1447         tp.it_value.tv_usec = 0;
 1448 
 1449         if ((error = copyout(&tp, ntp, sizeof(tp))) != 0)
 1450                 return error;
 1451 
 1452         SCARG(&sa, which) = ITIMER_REAL;
 1453         SCARG(&sa, itv) = ntp;
 1454         SCARG(&sa, oitv) = otp;
 1455 
 1456         if ((error = sys_setitimer(l, &sa, retval)) != 0)
 1457                 return error;
 1458 
 1459         if ((error = copyin(otp, &tp, sizeof(tp))) != 0)
 1460                 return error;
 1461 
 1462         if (tp.it_value.tv_usec)
 1463                 tp.it_value.tv_sec++;
 1464 
 1465         *retval = (register_t) tp.it_value.tv_sec;
 1466 
 1467         return 0;
 1468 }
 1469 
 1470 
 1471 int
 1472 svr4_32_sys_gettimeofday(l, v, retval)
 1473         struct lwp *l;
 1474         void *v;
 1475         register_t *retval;
 1476 {
 1477         struct svr4_32_sys_gettimeofday_args *uap = v;
 1478 
 1479         if (SCARG(uap, tp)) {
 1480                 struct timeval atv;
 1481 
 1482                 microtime(&atv);
 1483                 return copyout(&atv, (caddr_t)(u_long)SCARG(uap, tp), sizeof (atv));
 1484         }
 1485 
 1486         return 0;
 1487 }
 1488 
 1489 
 1490 int
 1491 svr4_32_sys_facl(l, v, retval)
 1492         struct lwp *l;
 1493         void *v;
 1494         register_t *retval;
 1495 {
 1496         struct svr4_32_sys_facl_args *uap = v;
 1497 
 1498         *retval = 0;
 1499 
 1500         switch (SCARG(uap, cmd)) {
 1501         case SVR4_SYS_SETACL:
 1502                 /* We don't support acls on any filesystem */
 1503                 return ENOSYS;
 1504 
 1505         case SVR4_SYS_GETACL:
 1506                 return copyout(retval, &SCARG(uap, num),
 1507                     sizeof(SCARG(uap, num)));
 1508 
 1509         case SVR4_SYS_GETACLCNT:
 1510                 return 0;
 1511 
 1512         default:
 1513                 return EINVAL;
 1514         }
 1515 }
 1516 
 1517 
 1518 int
 1519 svr4_32_sys_acl(l, v, retval)
 1520         struct lwp *l;
 1521         void *v;
 1522         register_t *retval;
 1523 {
 1524         return svr4_32_sys_facl(l, v, retval);  /* XXX: for now the same */
 1525 }
 1526 
 1527 
 1528 int
 1529 svr4_32_sys_auditsys(l, v, retval)
 1530         struct lwp *l;
 1531         void *v;
 1532         register_t *retval;
 1533 {
 1534         /*
 1535          * XXX: Big brother is *not* watching.
 1536          */
 1537         return 0;
 1538 }
 1539 
 1540 
 1541 int
 1542 svr4_32_sys_memcntl(l, v, retval)
 1543         struct lwp *l;
 1544         void *v;
 1545         register_t *retval;
 1546 {
 1547         struct svr4_32_sys_memcntl_args *uap = v;
 1548         switch (SCARG(uap, cmd)) {
 1549         case SVR4_MC_SYNC:
 1550                 {
 1551                         struct sys___msync13_args msa;
 1552 
 1553                         SCARG(&msa, addr) = (void *)(u_long)SCARG(uap, addr);
 1554                         SCARG(&msa, len) = SCARG(uap, len);
 1555                         SCARG(&msa, flags) = (int)(u_long)SCARG(uap, arg);
 1556 
 1557                         return sys___msync13(l, &msa, retval);
 1558                 }
 1559         case SVR4_MC_ADVISE:
 1560                 {
 1561                         struct sys_madvise_args maa;
 1562 
 1563                         SCARG(&maa, addr) = (void *)(u_long)SCARG(uap, addr);
 1564                         SCARG(&maa, len) = SCARG(uap, len);
 1565                         SCARG(&maa, behav) = (int)(u_long)SCARG(uap, arg);
 1566 
 1567                         return sys_madvise(l, &maa, retval);
 1568                 }
 1569         case SVR4_MC_LOCK:
 1570         case SVR4_MC_UNLOCK:
 1571         case SVR4_MC_LOCKAS:
 1572         case SVR4_MC_UNLOCKAS:
 1573                 return EOPNOTSUPP;
 1574         default:
 1575                 return ENOSYS;
 1576         }
 1577 }
 1578 
 1579 
 1580 int
 1581 svr4_32_sys_nice(l, v, retval)
 1582         struct lwp *l;
 1583         void *v;
 1584         register_t *retval;
 1585 {
 1586         struct svr4_32_sys_nice_args *uap = v;
 1587         struct sys_setpriority_args ap;
 1588         int error;
 1589 
 1590         SCARG(&ap, which) = PRIO_PROCESS;
 1591         SCARG(&ap, who) = 0;
 1592         SCARG(&ap, prio) = SCARG(uap, prio);
 1593 
 1594         if ((error = sys_setpriority(l, &ap, retval)) != 0)
 1595                 return error;
 1596 
 1597         if ((error = sys_getpriority(l, &ap, retval)) != 0)
 1598                 return error;
 1599 
 1600         return 0;
 1601 }
 1602 
 1603 
 1604 int
 1605 svr4_32_sys_resolvepath(l, v, retval)
 1606         struct lwp *l;
 1607         void *v;
 1608         register_t *retval;
 1609 {
 1610         struct svr4_32_sys_resolvepath_args *uap = v;
 1611         struct proc *p = l->l_proc;
 1612         struct nameidata nd;
 1613         int error;
 1614         size_t len;
 1615 
 1616         NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE,
 1617             (const char *)(u_long)SCARG(uap, path), p);
 1618 
 1619         if ((error = namei(&nd)) != 0)
 1620                 return error;
 1621 
 1622         if ((error = copyoutstr(nd.ni_cnd.cn_pnbuf,
 1623             (caddr_t)(u_long)SCARG(uap, buf),
 1624             SCARG(uap, bufsiz), &len)) != 0)
 1625                 goto bad;
 1626 
 1627         *retval = len;
 1628 bad:
 1629         vrele(nd.ni_vp);
 1630         PNBUF_PUT(nd.ni_cnd.cn_pnbuf);
 1631         return error;
 1632 }

Cache object: e6068aa6198ac9e10dd13730385adf19


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.