1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::error::SysErr;
use crate::internals::rlimit as internals;
pub use internals::Rlimit;
#[cfg_attr(target_env = "gnu", repr(u32))]
#[cfg_attr(not(target_env = "gnu"), repr(i32))]
#[non_exhaustive]
pub enum Resource {
#[cfg(not(target_os = "macos"))]
AddrSpace = libc::RLIMIT_AS,
Core = libc::RLIMIT_CORE,
Cpu = libc::RLIMIT_CPU,
Data = libc::RLIMIT_DATA,
FileSize = libc::RLIMIT_FSIZE,
#[cfg(target_os = "linux")]
Locks = libc::RLIMIT_LOCKS,
MemLock = libc::RLIMIT_MEMLOCK,
#[cfg(target_os = "linux")]
MsgQueue = libc::RLIMIT_MSGQUEUE,
#[cfg(target_os = "linux")]
Nice = libc::RLIMIT_NICE,
NFiles = libc::RLIMIT_NOFILE,
NProcs = libc::RLIMIT_NPROC,
Rss = libc::RLIMIT_RSS,
#[cfg(target_os = "linux")]
RTPrio = libc::RLIMIT_RTPRIO,
#[cfg(target_os = "linux")]
RTTime = libc::RLIMIT_RTTIME,
#[cfg(target_os = "linux")]
SigPending = libc::RLIMIT_SIGPENDING,
Stack = libc::RLIMIT_STACK,
#[cfg(target_os = "freebsd")]
Swap = libc::RLIMIT_SWAP,
}
impl Resource {
fn code(self) -> internals::RlimitResource {
self as internals::RlimitResource
}
}
pub fn get_rlimit<E: SysErr>(resource: Resource) -> Result<Rlimit, E> {
let mut rlim = Rlimit::new(0, 0);
unsafe { internals::get_rlimit(resource.code(), &mut rlim) }?;
Ok(rlim)
}
pub fn set_rlimit<E: SysErr>(resource: Resource, rlim: &Rlimit) -> Result<(), E> {
unsafe { internals::set_rlimit(resource.code(), rlim) }
}