linux_syscalls/env/mod.rs
1//! A collection of environment informations useful to detect features used in
2//! syscalls.
3
4pub mod aux;
5#[cfg_attr(target_arch = "x86", path = "kernel/x86.rs")]
6pub mod kernel;
7pub mod vdso;
8
9pub use self::{kernel::utsname, kernel::Version, vdso::Vdso};
10
11/// Returns values from the auxiliary vector, a mechanism that the kernel's ELF
12/// binary loader uses to pass certain information to user space when a program
13/// is executed.
14///
15/// Keys implements [crate::env::aux::VdsoKey]
16///
17/// # Safety
18///
19/// This function is marked as unsafe because it doesn't check if library is
20/// initialized.
21#[inline]
22pub unsafe fn unchecked_getauxval<T: aux::VdsoKey>() -> Option<T::Item> {
23 aux::get::<T>()
24}
25
26/// Returns values from the auxiliary vector, a mechanism that the kernel's ELF
27/// binary loader uses to pass certain information to user space when a program
28/// is executed.
29///
30/// Keys implements [crate::env::aux::VdsoKey]
31#[cfg(any(docs_rs, not(feature = "bare")))]
32#[cfg_attr(docs_rs, doc(cfg(not(feature = "bare"))))]
33pub fn getauxval<T: aux::VdsoKey>() -> Option<T::Item> {
34 crate::init();
35 unsafe { unchecked_getauxval::<T>() }
36}
37
38/// Returns a cached kernel version.
39///
40/// # Safety
41///
42/// This function is marked as unsafe because it doesn't check if library is
43/// initialized.
44#[inline]
45pub unsafe fn unchecked_kernel_version() -> &'static Version {
46 kernel::version()
47}
48
49/// Returns a cached kernel version.
50#[cfg(any(docs_rs, not(feature = "bare")))]
51#[cfg_attr(docs_rs, doc(cfg(not(feature = "bare"))))]
52pub fn kernel_version() -> &'static Version {
53 crate::init();
54 unsafe { unchecked_kernel_version() }
55}
56
57/// Returns a cached [crate::env::kernel::utsname].
58/// It do not use `uname` syscall.
59///
60/// # Safety
61///
62/// This function is marked as unsafe because it doesn't check if library is
63/// initialized.
64#[inline]
65pub unsafe fn unchecked_uname() -> &'static utsname {
66 kernel::uname()
67}
68
69/// Returns a cached [crate::env::kernel::utsname].
70/// It do not use `uname` syscall.
71#[cfg(any(docs_rs, not(feature = "bare")))]
72#[cfg_attr(docs_rs, doc(cfg(not(feature = "bare"))))]
73pub fn uname() -> &'static utsname {
74 crate::init();
75 unsafe { unchecked_uname() }
76}
77
78/// Returns the cached [crate::env::vdso::Vdso] for the current process.
79///
80/// # Safety
81///
82/// This function is marked as unsafe because it doesn't check if library is
83/// initialized.
84#[inline]
85pub unsafe fn unchecked_vdso() -> &'static Vdso {
86 vdso::get()
87}
88
89/// Returns cached [crate::env::vdso::Vdso] for the current process.
90#[cfg(any(docs_rs, not(feature = "bare")))]
91#[cfg_attr(docs_rs, doc(cfg(not(feature = "bare"))))]
92pub fn vdso() -> &'static Vdso {
93 crate::init();
94 unsafe { unchecked_vdso() }
95}