rlimit/resource/
generated.rs

1use super::ParseResourceError;
2use super::Resource;
3use crate::bindings as C;
4
5impl Resource {
6    /// The maximum size (in bytes) of the process's virtual memory (address space).
7    pub const AS: Self = Self {
8        tag: 1,
9        value: C::RLIMIT_AS,
10    };
11
12    /// The maximum size (in bytes) of a core file that the process may dump.
13    pub const CORE: Self = Self {
14        tag: 2,
15        value: C::RLIMIT_CORE,
16    };
17
18    /// A limit (in seconds) on the amount of CPU time that the process can consume.
19    pub const CPU: Self = Self {
20        tag: 3,
21        value: C::RLIMIT_CPU,
22    };
23
24    /// The maximum size (in bytes) of the process's data segment (initialized data, uninitialized data, and heap).
25    pub const DATA: Self = Self {
26        tag: 4,
27        value: C::RLIMIT_DATA,
28    };
29
30    /// The maximum size (in bytes) of files that the process may create.
31    pub const FSIZE: Self = Self {
32        tag: 5,
33        value: C::RLIMIT_FSIZE,
34    };
35
36    /// The maximum number of kqueues this user id is allowed to create.
37    pub const KQUEUES: Self = Self {
38        tag: 6,
39        value: C::RLIMIT_KQUEUES,
40    };
41
42    /// (early Linux 2.4 only)
43    ///
44    /// A limit on the combined number of `flock(2)` locks and `fcntl(2)` leases that this process may establish.
45    pub const LOCKS: Self = Self {
46        tag: 7,
47        value: C::RLIMIT_LOCKS,
48    };
49
50    /// The maximum number (in bytes) of memory that may be locked into RAM.
51    pub const MEMLOCK: Self = Self {
52        tag: 8,
53        value: C::RLIMIT_MEMLOCK,
54    };
55
56    /// A limit on the number of bytes that can be allocated for POSIX message queues for the real user ID of the calling process.
57    pub const MSGQUEUE: Self = Self {
58        tag: 9,
59        value: C::RLIMIT_MSGQUEUE,
60    };
61
62    /// This specifies a ceiling to which the process's nice value can be raised using `setpriority(2)` or `nice(2)`.
63    pub const NICE: Self = Self {
64        tag: 10,
65        value: C::RLIMIT_NICE,
66    };
67
68    /// This specifies a value one greater than the maximum file descriptor number that can be opened by this process.
69    pub const NOFILE: Self = Self {
70        tag: 11,
71        value: C::RLIMIT_NOFILE,
72    };
73
74    /// The number of open vnode monitors.
75    pub const NOVMON: Self = Self {
76        tag: 12,
77        value: C::RLIMIT_NOVMON,
78    };
79
80    /// A limit on the number of extant process (or, more precisely on Linux, threads) for the real user ID of the calling process.
81    pub const NPROC: Self = Self {
82        tag: 13,
83        value: C::RLIMIT_NPROC,
84    };
85
86    /// The maximum number of pseudo-terminals this user id is allowed to create.
87    pub const NPTS: Self = Self {
88        tag: 14,
89        value: C::RLIMIT_NPTS,
90    };
91
92    /// The maximum number of simultaneous threads (Lightweight Processes) for this user id.
93    /// Kernel threads and the first thread of each process are not counted against this limit.
94    pub const NTHR: Self = Self {
95        tag: 15,
96        value: C::RLIMIT_NTHR,
97    };
98
99    /// The maximum number of POSIX-type advisory-mode locks available to this user.
100    pub const POSIXLOCKS: Self = Self {
101        tag: 16,
102        value: C::RLIMIT_POSIXLOCKS,
103    };
104
105    /// A limit (in bytes) on the process's resident set (the number of virtual pages resident in RAM).
106    pub const RSS: Self = Self {
107        tag: 17,
108        value: C::RLIMIT_RSS,
109    };
110
111    /// This specifies a ceiling on the real-time priority that may be set for this process using `sched_setscheduler(2)` and `sched_setparam(2)`.
112    pub const RTPRIO: Self = Self {
113        tag: 18,
114        value: C::RLIMIT_RTPRIO,
115    };
116
117    /// A limit (in microseconds) on the amount of CPU time that a process scheduled under a real-time scheduling policy may consume without making a blocking system call.
118    pub const RTTIME: Self = Self {
119        tag: 19,
120        value: C::RLIMIT_RTTIME,
121    };
122
123    /// The maximum size (in bytes) of socket buffer usage for this user. This limits the amount of network memory, and hence the amount of mbufs, that this user may hold at any time.
124    pub const SBSIZE: Self = Self {
125        tag: 20,
126        value: C::RLIMIT_SBSIZE,
127    };
128
129    /// A limit on the number of signals that may be queued for the real user ID ofthe calling process.
130    pub const SIGPENDING: Self = Self {
131        tag: 21,
132        value: C::RLIMIT_SIGPENDING,
133    };
134
135    /// The maximum size (in bytes) of the process stack.
136    pub const STACK: Self = Self {
137        tag: 22,
138        value: C::RLIMIT_STACK,
139    };
140
141    /// The maximum size (in bytes) of the swap space that may be reserved or used by all of this user id's processes.
142    pub const SWAP: Self = Self {
143        tag: 23,
144        value: C::RLIMIT_SWAP,
145    };
146
147    /// **AIX**: The maximum number of threads each process can create. This limit is enforced by the kernel and the pthread debug library.
148    pub const THREADS: Self = Self {
149        tag: 24,
150        value: C::RLIMIT_THREADS,
151    };
152
153    /// The number of shared locks a given user may create simultaneously.
154    pub const UMTXP: Self = Self {
155        tag: 25,
156        value: C::RLIMIT_UMTXP,
157    };
158
159    /// An alias for [`RLIMIT_AS`](Resource::AS). The maximum size of a process's mapped address space in bytes.
160    pub const VMEM: Self = Self {
161        tag: 26,
162        value: C::RLIMIT_VMEM,
163    };
164}
165
166impl Resource {
167    pub(super) const fn find_name_by_tag(tag: u8) -> Option<&'static str> {
168        match tag {
169            1 => Some("RLIMIT_AS"),
170            2 => Some("RLIMIT_CORE"),
171            3 => Some("RLIMIT_CPU"),
172            4 => Some("RLIMIT_DATA"),
173            5 => Some("RLIMIT_FSIZE"),
174            6 => Some("RLIMIT_KQUEUES"),
175            7 => Some("RLIMIT_LOCKS"),
176            8 => Some("RLIMIT_MEMLOCK"),
177            9 => Some("RLIMIT_MSGQUEUE"),
178            10 => Some("RLIMIT_NICE"),
179            11 => Some("RLIMIT_NOFILE"),
180            12 => Some("RLIMIT_NOVMON"),
181            13 => Some("RLIMIT_NPROC"),
182            14 => Some("RLIMIT_NPTS"),
183            15 => Some("RLIMIT_NTHR"),
184            16 => Some("RLIMIT_POSIXLOCKS"),
185            17 => Some("RLIMIT_RSS"),
186            18 => Some("RLIMIT_RTPRIO"),
187            19 => Some("RLIMIT_RTTIME"),
188            20 => Some("RLIMIT_SBSIZE"),
189            21 => Some("RLIMIT_SIGPENDING"),
190            22 => Some("RLIMIT_STACK"),
191            23 => Some("RLIMIT_SWAP"),
192            24 => Some("RLIMIT_THREADS"),
193            25 => Some("RLIMIT_UMTXP"),
194            26 => Some("RLIMIT_VMEM"),
195            _ => None,
196        }
197    }
198
199    pub(super) const fn find_ident_by_tag(tag: u8) -> Option<&'static str> {
200        match tag {
201            1 => Some("AS"),
202            2 => Some("CORE"),
203            3 => Some("CPU"),
204            4 => Some("DATA"),
205            5 => Some("FSIZE"),
206            6 => Some("KQUEUES"),
207            7 => Some("LOCKS"),
208            8 => Some("MEMLOCK"),
209            9 => Some("MSGQUEUE"),
210            10 => Some("NICE"),
211            11 => Some("NOFILE"),
212            12 => Some("NOVMON"),
213            13 => Some("NPROC"),
214            14 => Some("NPTS"),
215            15 => Some("NTHR"),
216            16 => Some("POSIXLOCKS"),
217            17 => Some("RSS"),
218            18 => Some("RTPRIO"),
219            19 => Some("RTTIME"),
220            20 => Some("SBSIZE"),
221            21 => Some("SIGPENDING"),
222            22 => Some("STACK"),
223            23 => Some("SWAP"),
224            24 => Some("THREADS"),
225            25 => Some("UMTXP"),
226            26 => Some("VMEM"),
227            _ => None,
228        }
229    }
230}
231impl std::str::FromStr for Resource {
232    type Err = ParseResourceError;
233
234    fn from_str(s: &str) -> Result<Self, Self::Err> {
235        match s {
236            "RLIMIT_AS" => Ok(Self::AS),
237            "RLIMIT_CORE" => Ok(Self::CORE),
238            "RLIMIT_CPU" => Ok(Self::CPU),
239            "RLIMIT_DATA" => Ok(Self::DATA),
240            "RLIMIT_FSIZE" => Ok(Self::FSIZE),
241            "RLIMIT_KQUEUES" => Ok(Self::KQUEUES),
242            "RLIMIT_LOCKS" => Ok(Self::LOCKS),
243            "RLIMIT_MEMLOCK" => Ok(Self::MEMLOCK),
244            "RLIMIT_MSGQUEUE" => Ok(Self::MSGQUEUE),
245            "RLIMIT_NICE" => Ok(Self::NICE),
246            "RLIMIT_NOFILE" => Ok(Self::NOFILE),
247            "RLIMIT_NOVMON" => Ok(Self::NOVMON),
248            "RLIMIT_NPROC" => Ok(Self::NPROC),
249            "RLIMIT_NPTS" => Ok(Self::NPTS),
250            "RLIMIT_NTHR" => Ok(Self::NTHR),
251            "RLIMIT_POSIXLOCKS" => Ok(Self::POSIXLOCKS),
252            "RLIMIT_RSS" => Ok(Self::RSS),
253            "RLIMIT_RTPRIO" => Ok(Self::RTPRIO),
254            "RLIMIT_RTTIME" => Ok(Self::RTTIME),
255            "RLIMIT_SBSIZE" => Ok(Self::SBSIZE),
256            "RLIMIT_SIGPENDING" => Ok(Self::SIGPENDING),
257            "RLIMIT_STACK" => Ok(Self::STACK),
258            "RLIMIT_SWAP" => Ok(Self::SWAP),
259            "RLIMIT_THREADS" => Ok(Self::THREADS),
260            "RLIMIT_UMTXP" => Ok(Self::UMTXP),
261            "RLIMIT_VMEM" => Ok(Self::VMEM),
262            _ => Err(ParseResourceError(())),
263        }
264    }
265}