rlimit.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <errno.h>
#include <strings.h>
#include <sys/resource.h>
#include <sys/sysconfig.h>
#include <sys/lx_types.h>
#define LX_RLIMIT_RSS 5
#define LX_RLIMIT_NPROC 6
#define LX_RLIMIT_MEMLOCK 8
#define LX_RLIMIT_LOCKS 10
#define LX_RLIMIT_NLIMITS 11
/*
* Linux supports many of the same resources that we do, but the numbering
* is slightly different. This table is used to translate Linux resource
* limit keys into their Solaris equivalents.
*/
static int ltos_resource[LX_RLIMIT_NLIMITS] = {
-1, /* RSS */
-1, /* NPROC */
-1, /* MEMLOCK */
-1 /* LOCKS */
};
#define NLIMITS (sizeof (ltos_resource) / sizeof (int))
/*
* Magic values Linux uses to indicate infinity
*/
#define LX_RLIM_INFINITY_O (0x7fffffffUL)
#define LX_RLIM_INFINITY_N (0xffffffffUL)
/*
* Array to store the rlimits that we track but do not enforce.
*/
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
};
static int
{
int rv;
int sresource;
return (-EINVAL);
if (sresource == -1) {
switch (resource) {
case LX_RLIMIT_MEMLOCK:
case LX_RLIMIT_RSS:
case LX_RLIMIT_LOCKS:
case LX_RLIMIT_NPROC:
return (-errno);
return (0);
default:
lx_unsupported("Unsupported resource type %d\n",
resource);
return (-ENOTSUP);
}
} else {
}
if (rv < 0)
return (-errno);
return (0);
}
/*
* This is the 'new' getrlimit, variously called getrlimit or ugetrlimit
* in Linux headers and code. The only difference between this and the old
* getrlimit (variously called getrlimit or old_getrlimit) is the value of
* RLIM_INFINITY, which is smaller for the older version. Modern code will
* use this version by default.
*/
int
{
}
/*
* This is the 'old' getrlimit, variously called getrlimit or old_getrlimit
* in Linux headers and code. The only difference between this and the new
* getrlimit (variously called getrlimit or ugetrlimit) is the value of
* RLIM_INFINITY, which is smaller for the older version.
*/
int
{
}
int
{
return (-EINVAL);
if (sresource == -1) {
return (-errno);
switch (resource) {
case LX_RLIMIT_MEMLOCK:
case LX_RLIMIT_RSS:
case LX_RLIMIT_LOCKS:
case LX_RLIMIT_NPROC:
return (-EINVAL);
else
else
return (0);
}
return (-ENOTSUP);
}
}
/*
* We lucked out here. Linux and Solaris have exactly the same
* rusage structures.
*/
int
{
if (who == LX_RUSAGE_SELF)
else if (who == LX_RUSAGE_CHILDREN)
else
return (-EINVAL);
}