sys_setrlimit  [kernel/sys.c]


Controls maximum system resource consumption.

Arguments

eax 75
ebx Resource. It must be one of the following values:
RLIMIT_AS The maximum size of the process's virtual memory (address space) in bytes. This limit affects calls to sys_brk, sys_mmap and sys_mremap, which fail with the error -ENOMEM upon exceeding this limit. Also automatic stack expansion will fail (and generate a SIGSEGV that kills the process if no alternate stack has been made available via sys_sigaltstack). Since the value is a dword this limit is at most 2 GiB.
RLIMIT_CORE Maximum size of core file. When 0 no core dump files are created. When non-zero, larger dumps are truncated to this size.
RLIMIT_CPU The maximum amount of cpu time (in seconds) to be used by each process. When the process reaches the soft limit, it is sent a SIGXCPU signal. The default action for this signal is to terminate the process. However, the signal can be caught, and the handler can return control to the main program. If the process continues to consume CPU time, it will be sent SIGXCPU once per second until the hard limit is reached, at which time it is sent SIGKILL.
RLIMIT_DATA The maximum size of the process's data segment (initialized data, uninitialized data, and heap). This limit affects calls to sys_brk, which fail with the error -ENOMEM upon encountering the soft limit of this resource.
RLIMIT_FSIZE The maximum size of files that the process may create. Attempts to extend a file beyond this limit result in delivery of a SIGXFSZ signal. By default, this signal terminates a process, but a process can catch this signal instead, in which case the relevant system call (e.g., sys_write, sys_truncate) fails with the error EFBIG.
RLIMIT_MEMLOCK The maximum number of bytes of memory that may be locked into RAM. In effect this limit is rounded down to the nearest multiple of the system page size. This limit affects sys_mlock and sys_mlockall and the sys_mmap MAP_LOCKED operation. In Linux kernels before 2.6.9, this limit controlled the amount of memory that could be locked by a privileged process. Since Linux 2.6.9, no limits are placed on the amount of memory that a privileged process may lock, and this limit instead governs the amount of memory that an unprivileged process may lock.
RLIMIT_MSGQUEUE (Since Linux 2.6.8)
Specifies the limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process. This limit is enforced for sys_mq_open. Each message queue that the user creates counts (until it is removed) against this limit according to the formula:

bytes = mq_attr.mq_maxmsg * 4 + (mq_attr.mq_maxmsg * mq_attr.mq_msgsizewhere)

mq_attr structure is the same as the one specified as the fourth argument to sys_mq_open.
The first addend in the formula, which includes "4" ensures that the user cannot create an unlimited number of zero-length messages (such messages nevertheless each consume some system memory for bookkeeping overhead).
RLIMIT_NICE (since kernel 2.6.12, but see Remarks below)
Specifies a ceiling to which the process's nice value can be raised using sys_setpriority or sys_nice. The actual ceiling for the nice value is calculated as 20-rlim_cur. (This strangeness occurs because negative numbers cannot be specified as resource limit values, since they typically have special meanings. For example, RLIM_INFINITY typically is the same as -1.)
RLIMIT_NOFILE Specifies a value one greater than the maximum file descriptor number that can be opened by this process. Attempts (sys_open, sys_pipe, sys_dup, etc.) to exceed this limit yield the error -EMFILE.
RLIMIT_NPROC The maximum number of processes that can be created for the real user ID of the calling process. Upon encountering this limit, sys_fork fails with the error -EAGAIN.
RLIMIT_RTPRIO (Since Linux 2.6.12, but see Remarks below)
Specifies a ceiling on the real-time priority that may be set for this process using sys_sched_setscheduler and sys_sched_setparam
RLIMIT_SIGPENDING Specifies the limit on the number of signals that may be queued for the real user ID of the calling process. Both standard and real-time signals are counted for the purpose of checking this limit. It is always possible to use sys_kill to queue one instance of any of the signals that are not already queued to the process.
RLIMIT_STACK The maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sys_sigaltstack).
ecx Pointer to a properly initialized rlimit structure:
struc rlimit
{
.rlim_cur rd 1 ; 'soft' limit
.rlim_max rd 1 ; 'hard' limit
}
A resource limit is specified as a soft limit and a hard limit. When a soft limit is exceeded a process may receive a signal (for example, if the cpu time or file size is exceeded), but it will be allowed to continue execution until it reaches the hard limit (or modifies its resource limit).
Only the super-user may raise the maximum limits. Other users may only alter rlim_cur within the range from 0 to rlim_max or (irreversibly) lower rlim_max. An infinite value for a limit is defined as RLIM_INFINITY.

Return values

If the system call succeeds the return value is 0.
If the system call fails the return value is one of the following errno values:

-EINVAL ebx is not valid
-EFAULT Value in ecx points outside the accessible address space.
-or-
rlimit.rlim_cur was greater than rlimit.rlim_max.
-EPERM An unprivileged process tried to use sys_setrlimit to increase a soft or hard limit above the current hard limit; the CAP_SYS_RESOURCE capability is required to do this. Or, t
-or-
The process tried to use sys_setrlimit to increase the soft or hard RLIMIT_NOFILE limit above the current kernel maximum (NR_OPEN).

Remarks

In older Linux kernels, the SIGXCPU and SIGKILL signals delivered when a process encountered the soft and hard RLIMIT_CPU limits were delivered one (CPU) second later than they should have been. This was fixed in kernel 2.6.8.

A kernel bug means that RLIMIT_RTPRIO does not work in kernel 2.6.12; the problem is fixed in kernel 2.6.13.

In kernel 2.6.12, there was an off-by-one mismatch between the priority ranges returned by sys_getpriority and RLIMIT_NICE. This had the effect that actual ceiling for the nice value was calculated as 19 - rlim_cur. This was fixed in kernel 2.6.13.

In 2.6.x kernels before 2.6.17, a RLIMIT_CPU limit of 0 is wrongly treated as "no limit" (like RLIM_INFINITY). Since kernel 2.6.17, setting a limit of 0 does have an effect, but is actually treated as a limit of 1 second.

A child process created via sys_fork inherits its parents resource limits. Resource limits are preserved across sys_execve.

Compatibility

n/a