From 172e5cb55bea33fde7d0a2eb1c2831980c8c46f9 Mon Sep 17 00:00:00 2001 From: auronandace Date: Thu, 4 Jun 2026 10:35:47 +0100 Subject: [PATCH] verify sys_resource includes and add some documentation --- src/header/sys_resource/cbindgen.toml | 11 ++- src/header/sys_resource/mod.rs | 106 ++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 3 deletions(-) diff --git a/src/header/sys_resource/cbindgen.toml b/src/header/sys_resource/cbindgen.toml index 43b32e07c4..595be9a3ce 100644 --- a/src/header/sys_resource/cbindgen.toml +++ b/src/header/sys_resource/cbindgen.toml @@ -1,7 +1,12 @@ -# sys/time.h brings in sys/select.h which brings in bits/timeval.h -sys_includes = ["sys/time.h"] +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_resource.h.html +# +# Spec quotations relating to includes: +# - "The header shall define the timeval structure as described in ." +# - "The header shall define the id_t type through typedef, as described in ." +# - "Inclusion of the header may also make visible all symbols from ." after_includes = """ -#include // for id_t from sys/types.h +#include // for id_t from sys/types.h +#include // for timeval from sys/select.h (previously in sys/time.h) """ include_guard = "_RELIBC_SYS_RESOURCE_H" language = "C" diff --git a/src/header/sys_resource/mod.rs b/src/header/sys_resource/mod.rs index 83bbbab2e8..51574c1f89 100644 --- a/src/header/sys_resource/mod.rs +++ b/src/header/sys_resource/mod.rs @@ -12,62 +12,168 @@ use crate::{ }, }; +/// Returns information about the current process. pub const RUSAGE_SELF: c_int = 0; +/// Returns information about children of the current process. pub const RUSAGE_CHILDREN: c_int = -1; +/// Non-POSIX. +/// +/// Return resource consumption statistics for both the current process and +/// all of its terminated child processes that have been waited for. pub const RUSAGE_BOTH: c_int = -2; +// TODO should be guarded by `_GNU_SOURCE` +/// Non-POSIX, see . +/// +/// Return resource usage statistics for the calling thread. pub const RUSAGE_THREAD: c_int = 1; +/// A value of `rlim_t` indicating no limit. pub const RLIM_INFINITY: u64 = 0xFFFF_FFFF_FFFF_FFFF; +/// A value of type `rlim_t` indicating an unrepresentable saved soft limit. pub const RLIM_SAVED_CUR: u64 = RLIM_INFINITY; +/// A value of type `rlim_t` indicating an unrepresentable saved hard limit. pub const RLIM_SAVED_MAX: u64 = RLIM_INFINITY; +/// Limit on CPU time per process. pub const RLIMIT_CPU: c_int = 0; +/// Limit on file size. pub const RLIMIT_FSIZE: c_int = 1; +/// Limit on data segment size. pub const RLIMIT_DATA: c_int = 2; +/// Limit on stack size. pub const RLIMIT_STACK: c_int = 3; +/// Limit on size of core image. pub const RLIMIT_CORE: c_int = 4; +/// Non-POSIX, see . +/// +/// This is a limit (in bytes) on the process's resident set (the number of +/// virtual pages resident in RAM). +/// Only affects Linux 2.4.0 to 2.4.29. pub const RLIMIT_RSS: c_int = 5; +/// Non-POSIX, see . +/// +/// This is a limit on the number of extant processes (or, more preciselu on +/// Linux, threads) for the real user ID of the calling process. pub const RLIMIT_NPROC: c_int = 6; +/// Limit on number of open files. pub const RLIMIT_NOFILE: c_int = 7; +/// Non-POSIX, see . +/// +/// This is the maximum number of bytes of memory that may be locked into RAM. pub const RLIMIT_MEMLOCK: c_int = 8; +/// Limit on address space size. pub const RLIMIT_AS: c_int = 9; +/// Non-POSIX, see . +/// +/// This is a limit on the combined number of `flock(2)` locks and `fcntl(2)` +/// leases that this process may establish. +/// Only affects Linux 2.4.0 to 2.4.24. pub const RLIMIT_LOCKS: c_int = 10; +/// Non-POSIX, see . +/// +/// This is a limit on the number of signals that may be queued for the real +/// user ID of the calling process. pub const RLIMIT_SIGPENDING: c_int = 11; +/// Non-POSIX, see . +/// +/// This is a limit on the number of bytes that can be allocated for POSIX +/// message queues for the real user ID of the calling process. pub const RLIMIT_MSGQUEUE: c_int = 12; +/// Non-POSIX, see . +/// +/// This specifies a ceiling to which the process's nice value can be raised +/// using `setpriority(2)` or `nice(2)`. pub const RLIMIT_NICE: c_int = 13; +/// Non-POSIX, see . +/// +/// This specifies a ceiling on the real-time priority that may be set for +/// this process using `sched_setscheduler(2)` and `sched_setparam(2)`. pub const RLIMIT_RTPRIO: c_int = 14; +/// Non-POSIX, found in glibc. +/// +/// Number of limit flavors. pub const RLIMIT_NLIMITS: c_int = 15; +/// Unsigned integer type used for limit values. pub type rlim_t = c_ulonglong; #[repr(C)] pub struct rlimit { + /// The current (soft) limit. pub rlim_cur: rlim_t, + /// The hard limit. pub rlim_max: rlim_t, } #[repr(C)] pub struct rusage { + /// User time used. pub ru_utime: timeval, + /// System time used. pub ru_stime: timeval, + /// Non-POSIX, see . + /// + /// Maximum resident set size. pub ru_maxrss: c_long, + /// Non-POSIX, see . + /// + /// Integral shared memory size. pub ru_ixrss: c_long, + /// Non-POSIX, see . + /// + /// Integral unshared data size. pub ru_idrss: c_long, + /// Non-POSIX, see . + /// + /// Integral unshared stack size. pub ru_isrss: c_long, + /// Non-POSIX, see . + /// + /// Page reclaims (soft page faults). pub ru_minflt: c_long, + /// Non-POSIX, see . + /// + /// Page faults (hard page faults). pub ru_majflt: c_long, + /// Non-POSIX, see . + /// + /// Swaps. pub ru_nswap: c_long, + /// Non-POSIX, see . + /// + /// Block input operations. pub ru_inblock: c_long, + /// Non-POSIX, see . + /// + /// Block output operations. pub ru_oublock: c_long, + /// Non-POSIX, see . + /// + /// IPC messages sent. pub ru_msgsnd: c_long, + /// Non-POSIX, see . + /// + /// IPC messages received. pub ru_msgrcv: c_long, + /// Non-POSIX, see . + /// + /// Signals received. pub ru_nsignals: c_long, + /// Non-POSIX, see . + /// + /// Voluntary context switches. pub ru_nvcsw: c_long, + /// Non-POSIX, see . + /// + /// Involuntary context switches. pub ru_nivcsw: c_long, } +/// Identifies the `who` argument as a process ID. pub const PRIO_PROCESS: c_int = 0; +/// Identifies the `who` argument as a process group ID. pub const PRIO_PGRP: c_int = 1; +/// Identifies the `who` argument as a user ID. pub const PRIO_USER: c_int = 2; /// See .