Skip to main content

rustix/backend/libc/process/
types.rs

1#[cfg(not(any(
2    target_os = "espidf",
3    target_os = "fuchsia",
4    target_os = "horizon",
5    target_os = "redox",
6    target_os = "vita",
7    target_os = "wasi"
8)))]
9use crate::backend::c;
10
11/// A resource value for use with [`getrlimit`], [`setrlimit`], and
12/// [`prlimit`].
13///
14/// [`getrlimit`]: crate::process::getrlimit
15/// [`setrlimit`]: crate::process::setrlimit
16/// [`prlimit`]: crate::process::prlimit
17#[cfg(not(any(
18    target_os = "espidf",
19    target_os = "fuchsia",
20    target_os = "horizon",
21    target_os = "redox",
22    target_os = "vita",
23    target_os = "wasi"
24)))]
25#[derive(Copy, Clone, Debug, Eq, PartialEq)]
26#[cfg_attr(not(target_os = "l4re"), repr(u32))]
27#[cfg_attr(target_os = "l4re", repr(u64))]
28#[non_exhaustive]
29pub enum Resource {
30    /// `RLIMIT_CPU`
31    Cpu = bitcast!(c::RLIMIT_CPU),
32    /// `RLIMIT_FSIZE`
33    Fsize = bitcast!(c::RLIMIT_FSIZE),
34    /// `RLIMIT_DATA`
35    Data = bitcast!(c::RLIMIT_DATA),
36    /// `RLIMIT_STACK`
37    Stack = bitcast!(c::RLIMIT_STACK),
38    /// `RLIMIT_CORE`
39    #[cfg(not(target_os = "haiku"))]
40    Core = bitcast!(c::RLIMIT_CORE),
41    /// `RLIMIT_RSS`
42    // "nto" has `RLIMIT_RSS`, but it has the same value as `RLIMIT_AS`.
43    #[cfg(not(any(
44        apple,
45        solarish,
46        target_os = "cygwin",
47        target_os = "haiku",
48        target_os = "nto",
49    )))]
50    Rss = bitcast!(c::RLIMIT_RSS),
51    /// `RLIMIT_NPROC`
52    #[cfg(not(any(solarish, target_os = "cygwin", target_os = "haiku")))]
53    Nproc = bitcast!(c::RLIMIT_NPROC),
54    /// `RLIMIT_NOFILE`
55    Nofile = bitcast!(c::RLIMIT_NOFILE),
56    /// `RLIMIT_MEMLOCK`
57    #[cfg(not(any(solarish, target_os = "aix", target_os = "cygwin", target_os = "haiku")))]
58    Memlock = bitcast!(c::RLIMIT_MEMLOCK),
59    /// `RLIMIT_AS`
60    #[cfg(not(target_os = "openbsd"))]
61    As = bitcast!(c::RLIMIT_AS),
62    /// `RLIMIT_LOCKS`
63    #[cfg(not(any(
64        bsd,
65        solarish,
66        target_os = "aix",
67        target_os = "cygwin",
68        target_os = "haiku",
69        target_os = "hurd",
70        target_os = "nto",
71    )))]
72    Locks = bitcast!(c::RLIMIT_LOCKS),
73    /// `RLIMIT_SIGPENDING`
74    #[cfg(not(any(
75        bsd,
76        solarish,
77        target_os = "aix",
78        target_os = "cygwin",
79        target_os = "haiku",
80        target_os = "hurd",
81        target_os = "nto",
82    )))]
83    Sigpending = bitcast!(c::RLIMIT_SIGPENDING),
84    /// `RLIMIT_MSGQUEUE`
85    #[cfg(not(any(
86        bsd,
87        solarish,
88        target_os = "aix",
89        target_os = "cygwin",
90        target_os = "haiku",
91        target_os = "hurd",
92        target_os = "nto",
93    )))]
94    Msgqueue = bitcast!(c::RLIMIT_MSGQUEUE),
95    /// `RLIMIT_NICE`
96    #[cfg(not(any(
97        bsd,
98        solarish,
99        target_os = "aix",
100        target_os = "cygwin",
101        target_os = "haiku",
102        target_os = "hurd",
103        target_os = "nto",
104    )))]
105    Nice = bitcast!(c::RLIMIT_NICE),
106    /// `RLIMIT_RTPRIO`
107    #[cfg(not(any(
108        bsd,
109        solarish,
110        target_os = "aix",
111        target_os = "cygwin",
112        target_os = "haiku",
113        target_os = "hurd",
114        target_os = "nto",
115    )))]
116    Rtprio = bitcast!(c::RLIMIT_RTPRIO),
117    /// `RLIMIT_RTTIME`
118    #[cfg(not(any(
119        bsd,
120        solarish,
121        target_os = "aix",
122        target_os = "android",
123        target_os = "cygwin",
124        target_os = "emscripten",
125        target_os = "haiku",
126        target_os = "hurd",
127        target_os = "nto",
128    )))]
129    Rttime = bitcast!(c::RLIMIT_RTTIME),
130}
131
132#[cfg(apple)]
133#[allow(non_upper_case_globals)]
134impl Resource {
135    /// `RLIMIT_RSS`
136    pub const Rss: Self = Self::As;
137}
138
139#[cfg(freebsdlike)]
140pub type RawId = c::id_t;