-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgetauxval.rs
30 lines (26 loc) · 1017 Bytes
/
getauxval.rs
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
//! Define a C-compatible `getauxv`.
//!
//! This may be needed to satisfy `compiler_builtins` or other low-level code.
use core::ffi::{c_ulong, c_void};
use core::ptr::without_provenance_mut;
// `getauxval` usually returns `unsigned long`, but we make it a pointer type
// so that it preserves provenance.
#[no_mangle]
unsafe extern "C" fn getauxval(type_: c_ulong) -> *mut c_void {
_getauxval(type_)
}
#[cfg(target_arch = "aarch64")]
#[no_mangle]
unsafe extern "C" fn __getauxval(type_: c_ulong) -> *mut c_void {
_getauxval(type_)
}
fn _getauxval(type_: c_ulong) -> *mut c_void {
match type_ as _ {
linux_raw_sys::general::AT_HWCAP => without_provenance_mut(rustix::param::linux_hwcap().0),
linux_raw_sys::general::AT_HWCAP2 => without_provenance_mut(rustix::param::linux_hwcap().1),
linux_raw_sys::general::AT_MINSIGSTKSZ => {
without_provenance_mut(rustix::param::linux_minsigstksz())
}
_ => todo!("unrecognized __getauxval {}", type_),
}
}