Skip to content

Commit 39cf86c

Browse files
committed
Change resource to be repr u32 for linux
1 parent bc71c7a commit 39cf86c

File tree

1 file changed

+63
-59
lines changed

1 file changed

+63
-59
lines changed

src/sys/resource.rs

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,88 +21,92 @@ use crate::Result;
2121

2222
pub use libc::rlim_t;
2323

24+
#[cfg(any(target_os = "linux"))]
25+
libc_enum! {
26+
#[repr(u32)]
27+
pub enum Resource {
28+
/// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
29+
RLIMIT_AS,
30+
RLIMIT_CORE,
31+
RLIMIT_CPU,
32+
RLIMIT_DATA,
33+
RLIMIT_FSIZE,
34+
RLIMIT_LOCKS,
35+
RLIMIT_MEMLOCK,
36+
RLIMIT_MSGQUEUE,
37+
RLIMIT_NICE,
38+
RLIMIT_NOFILE,
39+
RLIMIT_NPROC,
40+
RLIMIT_RSS,
41+
RLIMIT_RTPRIO,
42+
RLIMIT_RTTIME,
43+
RLIMIT_SIGPENDING,
44+
RLIMIT_STACK,
45+
}
46+
}
47+
48+
#[cfg(any(
49+
target_os = "freebsd",
50+
target_os = "openbsd",
51+
target_os = "netbsd",
52+
target_os = "macos",
53+
target_os = "ios",
54+
target_os = "android",
55+
target_os = "dragonfly",
56+
target_os = "bitrig",
57+
))]
2458
libc_enum! {
25-
/// A resource that limits apply to
2659
#[repr(i32)]
2760
pub enum Resource {
28-
// POSIX
29-
/// This is the maximum size of the process's virtual memory (address space). The limit is
30-
/// specified in bytes, and is rounded down to the system page size.
61+
/// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
62+
/// BSD specific Resource https://www.freebsd.org/cgi/man.cgi?query=setrlimit
3163
RLIMIT_AS,
32-
/// This is the maximum size of a core file (see core(5)) in bytes that the process may
33-
/// dump.
3464
RLIMIT_CORE,
35-
/// This is a limit, in seconds, on the amount of CPU time that the process can consume.
3665
RLIMIT_CPU,
37-
/// This is the maximum size of the process's data segment (initialized data, uninitialized
38-
/// data, and heap). The limit is specified in bytes, and is rounded down to the system
39-
/// page size.
4066
RLIMIT_DATA,
41-
/// This is the maximum size in bytes of files that the process may create. Attempts to
42-
/// extend a file beyond this limit result in delivery of a SIGXFSZ signal.
4367
RLIMIT_FSIZE,
44-
/// This specifies a value one greater than the maximum file descriptor number that can be
45-
/// opened by this process.
4668
RLIMIT_NOFILE,
47-
/// This is the maximum size of the process stack, in bytes. Upon reaching this limit, a
48-
/// SIGSEGV signal is generated.
4969
RLIMIT_STACK,
5070

51-
/// Linux
52-
/// This is a limit (in microseconds) on the amount of CPU time that a process scheduled
53-
/// under a real-time scheduling policy may consume without making a blocking system call.
54-
#[cfg(any(target_os = "linux"))]
55-
RLIMIT_RTTIME,
71+
// platform specific
72+
#[cfg(target_os = "freebsd")]
73+
RLIMIT_KQUEUES,
74+
75+
#[cfg(any(target_os = "android"))]
76+
RLIMIT_LOCKS,
5677

57-
// BSDs and Linux
58-
/// This is the maximum number of bytes of memory that may be locked into RAM. This limit
59-
/// is in effect rounded down to the nearest multiple of the system page size.
60-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))]
78+
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd"))]
6179
RLIMIT_MEMLOCK,
62-
/// This is a limit on the number of extant process (or, more precisely on Linux, threads)
63-
/// for the real user ID of the calling process.
64-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))]
65-
RLIMIT_NPROC,
66-
/// This is a limit (in bytes) on the process's resident set (the number of virtual pages resident in RAM).
67-
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))]
68-
RLIMIT_RSS,
6980

70-
// Android and Linux only
71-
/// This is a limit on the combined number of flock(2) locks and fcntl(2) leases that this process may establish.
72-
#[cfg(any(target_os = "android", target_os = "linux"))]
73-
RLIMIT_LOCKS,
74-
/// This is a limit on the number of bytes that can be allocated for POSIX message queues
75-
/// for the real user ID of the calling process.
76-
#[cfg(any(target_os = "android", target_os = "linux"))]
81+
#[cfg(any(target_os = "android"))]
7782
RLIMIT_MSGQUEUE,
78-
/// This specifies a ceiling to which the process's nice value can be raised using
79-
/// setpriority(2) or nice(2). The actual ceiling for the nice value is calculated as 20 -
80-
/// rlim_cur.
81-
#[cfg(any(target_os = "android", target_os = "linux"))]
83+
84+
#[cfg(any(target_os = "android"))]
8285
RLIMIT_NICE,
83-
/// This specifies a ceiling on the real-time priority that may be set for this process
84-
/// using sched_setscheduler(2) and sched_setparam(2).
85-
#[cfg(any(target_os = "android", target_os = "linux"))]
86-
RLIMIT_RTPRIO,
87-
/// This is a limit on the number of signals that may be queued for the real user ID of the
88-
/// calling process. Both standard and real-time signals are counted for the purpose of
89-
/// checking this limit.
90-
#[cfg(any(target_os = "android", target_os = "linux"))]
91-
RLIMIT_SIGPENDING,
9286

93-
// Available on some BSD
94-
/// The maximum number of kqueues this user id is allowed to create.
95-
#[cfg(target_os = "freebsd")]
96-
RLIMIT_KQUEUES,
97-
/// The maximum number of pseudo-terminals this user id is allowed to create.
87+
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd"))]
88+
RLIMIT_NPROC,
89+
9890
#[cfg(target_os = "freebsd")]
9991
RLIMIT_NPTS,
100-
/// The maximum size (in bytes) of socket buffer usage for this user.
92+
93+
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd"))]
94+
RLIMIT_RSS,
95+
96+
#[cfg(any(target_os = "android"))]
97+
RLIMIT_RTPRIO,
98+
99+
#[cfg(any(target_os = "android"))]
100+
RLIMIT_SIGPENDING,
101+
101102
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
102103
RLIMIT_SBSIZE,
103-
/// The maximum size (in bytes) of the swap space that may be reserved or used by all of this user id's processes.
104+
104105
#[cfg(target_os = "freebsd")]
105106
RLIMIT_SWAP,
107+
108+
#[cfg(target_os = "freebsd")]
109+
RLIMIT_VMEM,
106110
}
107111
}
108112

0 commit comments

Comments
 (0)