github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/abi/linux/limits.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package linux
    16  
    17  // Resources for getrlimit(2)/setrlimit(2)/prlimit(2).
    18  const (
    19  	RLIMIT_CPU        = 0
    20  	RLIMIT_FSIZE      = 1
    21  	RLIMIT_DATA       = 2
    22  	RLIMIT_STACK      = 3
    23  	RLIMIT_CORE       = 4
    24  	RLIMIT_RSS        = 5
    25  	RLIMIT_NPROC      = 6
    26  	RLIMIT_NOFILE     = 7
    27  	RLIMIT_MEMLOCK    = 8
    28  	RLIMIT_AS         = 9
    29  	RLIMIT_LOCKS      = 10
    30  	RLIMIT_SIGPENDING = 11
    31  	RLIMIT_MSGQUEUE   = 12
    32  	RLIMIT_NICE       = 13
    33  	RLIMIT_RTPRIO     = 14
    34  	RLIMIT_RTTIME     = 15
    35  )
    36  
    37  // RLimit corresponds to Linux's struct rlimit.
    38  type RLimit struct {
    39  	// Cur specifies the soft limit.
    40  	Cur uint64
    41  	// Max specifies the hard limit.
    42  	Max uint64
    43  }
    44  
    45  const (
    46  	// RLimInfinity is RLIM_INFINITY on Linux.
    47  	RLimInfinity = ^uint64(0)
    48  
    49  	// DefaultStackSoftLimit is called _STK_LIM in Linux.
    50  	DefaultStackSoftLimit = 8 * 1024 * 1024
    51  
    52  	// DefaultNprocLimit is defined in kernel/fork.c:set_max_threads, and
    53  	// called MAX_THREADS / 2 in Linux.
    54  	DefaultNprocLimit = FUTEX_TID_MASK / 2
    55  
    56  	// DefaultNofileSoftLimit is called INR_OPEN_CUR in Linux.
    57  	DefaultNofileSoftLimit = 1024
    58  
    59  	// DefaultNofileHardLimit is called INR_OPEN_MAX in Linux.
    60  	DefaultNofileHardLimit = 4096
    61  
    62  	// DefaultMemlockLimit is called MLOCK_LIMIT in Linux.
    63  	DefaultMemlockLimit = 64 * 1024
    64  
    65  	// DefaultMsgqueueLimit is called MQ_BYTES_MAX in Linux.
    66  	DefaultMsgqueueLimit = 819200
    67  )
    68  
    69  // InitRLimits is a map of initial rlimits set by Linux in
    70  // include/asm-generic/resource.h.
    71  var InitRLimits = map[int]RLimit{
    72  	RLIMIT_CPU:        {RLimInfinity, RLimInfinity},
    73  	RLIMIT_FSIZE:      {RLimInfinity, RLimInfinity},
    74  	RLIMIT_DATA:       {RLimInfinity, RLimInfinity},
    75  	RLIMIT_STACK:      {DefaultStackSoftLimit, RLimInfinity},
    76  	RLIMIT_CORE:       {0, RLimInfinity},
    77  	RLIMIT_RSS:        {RLimInfinity, RLimInfinity},
    78  	RLIMIT_NPROC:      {DefaultNprocLimit, DefaultNprocLimit},
    79  	RLIMIT_NOFILE:     {DefaultNofileSoftLimit, DefaultNofileHardLimit},
    80  	RLIMIT_MEMLOCK:    {DefaultMemlockLimit, DefaultMemlockLimit},
    81  	RLIMIT_AS:         {RLimInfinity, RLimInfinity},
    82  	RLIMIT_LOCKS:      {RLimInfinity, RLimInfinity},
    83  	RLIMIT_SIGPENDING: {0, 0},
    84  	RLIMIT_MSGQUEUE:   {DefaultMsgqueueLimit, DefaultMsgqueueLimit},
    85  	RLIMIT_NICE:       {0, 0},
    86  	RLIMIT_RTPRIO:     {0, 0},
    87  	RLIMIT_RTTIME:     {RLimInfinity, RLimInfinity},
    88  }