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/irix/irix_resource.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: irix_resource.c,v 1.14.10.1 2009/04/01 00:25:21 snj Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Emmanuel Dreyfus.
    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  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: irix_resource.c,v 1.14.10.1 2009/04/01 00:25:21 snj Exp $");
   34 
   35 #include <sys/types.h>
   36 #include <sys/signal.h>
   37 #include <sys/param.h>
   38 #include <sys/mount.h>
   39 #include <sys/proc.h>
   40 #include <sys/systm.h>
   41 #include <sys/resource.h>
   42 #include <sys/resourcevar.h>
   43 #include <sys/syscallargs.h>
   44 
   45 #include <compat/common/compat_util.h>
   46 
   47 #include <compat/irix/irix_types.h>
   48 #include <compat/irix/irix_signal.h>
   49 #include <compat/irix/irix_resource.h>
   50 #include <compat/irix/irix_syscallargs.h>
   51 
   52 static int irix_to_native_resource(int);
   53 
   54 static int
   55 irix_to_native_resource(int irix_res)
   56 {
   57         int bsd_res;
   58 
   59         switch(irix_res) {
   60         case IRIX_RLIMIT_CPU:
   61                 bsd_res = RLIMIT_CPU;
   62                 break;
   63         case IRIX_RLIMIT_FSIZE:
   64                 bsd_res = RLIMIT_FSIZE;
   65                 break;
   66         case IRIX_RLIMIT_DATA:
   67                 bsd_res = RLIMIT_DATA;
   68                 break;
   69         case IRIX_RLIMIT_STACK:
   70                 bsd_res = RLIMIT_STACK;
   71                 break;
   72         case IRIX_RLIMIT_CORE:
   73                 bsd_res = RLIMIT_CORE;
   74                 break;
   75         case IRIX_RLIMIT_NOFILE:
   76                 bsd_res = RLIMIT_NOFILE;
   77                 break;
   78         case IRIX_RLIMIT_VMEM:
   79                 bsd_res = RLIMIT_AS;
   80                 break;
   81         case IRIX_RLIMIT_RSS:
   82                 bsd_res = RLIMIT_RSS;
   83                 break;
   84         case IRIX_RLIMIT_PTHREAD:
   85                 printf("Warning: ignored IRIX pthread rlimit flag\n");
   86         default:
   87                 bsd_res = -1;
   88                 break;
   89         }
   90         return bsd_res;
   91 }
   92 
   93 int
   94 irix_sys_getrlimit(struct lwp *l, const struct irix_sys_getrlimit_args *uap, register_t *retval)
   95 {
   96         /* {
   97                 syscallarg(int) resource;
   98                 syscallarg(struct irix_rlimit *) rlp;
   99         } */
  100         struct rlimit *rlp;
  101         struct irix_rlimit irlp;
  102         int which;
  103 
  104         which = irix_to_native_resource(SCARG(uap, resource));
  105         if (which < 0)
  106                 return EINVAL;
  107 
  108         rlp = &l->l_proc->p_rlimit[which];
  109 
  110         if (rlp->rlim_cur == RLIM_INFINITY)
  111                 irlp.rlim_cur = IRIX_RLIM_INFINITY;
  112         else
  113                 irlp.rlim_cur = rlp->rlim_cur;
  114 
  115         if (rlp->rlim_max == RLIM_INFINITY)
  116                 irlp.rlim_max = IRIX_RLIM_INFINITY;
  117         else
  118                 irlp.rlim_max = rlp->rlim_cur;
  119 
  120         return copyout(&irlp, SCARG(uap, rlp), sizeof(irlp));
  121 }
  122 
  123 int
  124 irix_sys_getrlimit64(struct lwp *l, const struct irix_sys_getrlimit64_args *uap, register_t *retval)
  125 {
  126         /* {
  127                 syscallarg(int) resource;
  128                 syscallarg(struct irix_rlimit64 *) rlp;
  129         } */
  130         struct rlimit *rlp;
  131         struct irix_rlimit64 irlp;
  132         int which;
  133 
  134         which = irix_to_native_resource(SCARG(uap, resource));
  135         if (which < 0)
  136                 return EINVAL;
  137 
  138         rlp = &l->l_proc->p_rlimit[which];
  139 
  140         if (rlp->rlim_cur == RLIM_INFINITY)
  141                 irlp.rlim_cur = IRIX_RLIM64_INFINITY;
  142         else
  143                 irlp.rlim_cur = rlp->rlim_cur;
  144 
  145         if (rlp->rlim_max == RLIM_INFINITY)
  146                 irlp.rlim_max = IRIX_RLIM64_INFINITY;
  147         else
  148                 irlp.rlim_max = rlp->rlim_cur;
  149 
  150         return copyout(&irlp, SCARG(uap, rlp), sizeof(irlp));
  151 }
  152 
  153 int
  154 irix_sys_setrlimit(struct lwp *l, const struct irix_sys_setrlimit_args *uap, register_t *retval)
  155 {
  156         /* {
  157                 syscallarg(int) resource;
  158                 syscallarg(const struct irix_rlimit *) rlp;
  159         } */
  160         struct irix_rlimit irlp;
  161         struct rlimit rlp;
  162         int which;
  163         int error;
  164 
  165         which = irix_to_native_resource(SCARG(uap, resource));
  166         if (which < 0)
  167                 return EINVAL;
  168 
  169         if ((error = copyin(SCARG(uap, rlp), &irlp, sizeof(irlp))) != 0)
  170                 return error;
  171 
  172         if (irlp.rlim_cur == IRIX_RLIM_INFINITY)
  173                 rlp.rlim_cur = RLIM_INFINITY;
  174         else
  175                 rlp.rlim_cur = irlp.rlim_cur;
  176 
  177         if (irlp.rlim_max == IRIX_RLIM_INFINITY)
  178                 rlp.rlim_max = RLIM_INFINITY;
  179         else
  180                 rlp.rlim_max = irlp.rlim_cur;
  181 
  182         return dosetrlimit(l, l->l_proc, which, &rlp);
  183 }
  184 
  185 int
  186 irix_sys_setrlimit64(struct lwp *l, const struct irix_sys_setrlimit64_args *uap, register_t *retval)
  187 {
  188         /* {
  189                 syscallarg(int) resource;
  190                 syscallarg(const struct irix_rlimit64 *) rlp;
  191         } */
  192         struct rlimit rlp;
  193         struct irix_rlimit64 irlp;
  194         int which;
  195         int error;
  196 
  197         which = irix_to_native_resource(SCARG(uap, resource));
  198         if (which < 0)
  199                 return EINVAL;
  200 
  201         if ((error = copyin(SCARG(uap, rlp), &irlp, sizeof(irlp))) != 0)
  202                 return error;
  203 
  204         if (irlp.rlim_cur == IRIX_RLIM64_INFINITY)
  205                 rlp.rlim_cur = RLIM_INFINITY;
  206         else
  207                 rlp.rlim_cur = irlp.rlim_cur;
  208 
  209         if (irlp.rlim_max == IRIX_RLIM64_INFINITY)
  210                 rlp.rlim_max = RLIM_INFINITY;
  211         else
  212                 rlp.rlim_max = irlp.rlim_cur;
  213 
  214         return dosetrlimit(l, l->l_proc, which, &rlp);
  215 }

Cache object: fc55ac7882beb8a157c75b5c256df64a


[ 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.