| 1 |
use crate::backend::c; |
| 2 |
#[cfg(any( |
| 3 |
all(target_os = "android", target_pointer_width = "64"), |
| 4 |
target_os = "linux", |
| 5 |
))] |
| 6 |
use crate::ffi::CStr; |
| 7 |
|
| 8 |
// `getauxval` wasn't supported in glibc until 2.16. |
| 9 |
#[cfg(any( |
| 10 |
all(target_os = "android", target_pointer_width = "64"), |
| 11 |
target_os = "linux", |
| 12 |
))] |
| 13 |
weak!(fn getauxval(c::c_ulong) -> *mut c::c_void); |
| 14 |
|
| 15 |
#[inline] |
| 16 |
pub(crate) fn page_size() -> usize { |
| 17 |
unsafe { c::sysconf(c::_SC_PAGESIZE) as usize } |
| 18 |
} |
| 19 |
|
| 20 |
#[cfg(not(any(target_os = "vita", target_os = "wasi")))] |
| 21 |
#[inline] |
| 22 |
pub(crate) fn clock_ticks_per_second() -> u64 { |
| 23 |
unsafe { c::sysconf(c::_SC_CLK_TCK) as u64 } |
| 24 |
} |
| 25 |
|
| 26 |
#[cfg(any( |
| 27 |
all(target_os = "android", target_pointer_width = "64"), |
| 28 |
target_os = "linux", |
| 29 |
))] |
| 30 |
#[inline] |
| 31 |
pub(crate) fn linux_hwcap() -> (usize, usize) { |
| 32 |
if let Some(libc_getauxval) = getauxval.get() { |
| 33 |
unsafe { |
| 34 |
let hwcap = libc_getauxval(c::AT_HWCAP) as usize; |
| 35 |
let hwcap2 = libc_getauxval(c::AT_HWCAP2) as usize; |
| 36 |
(hwcap, hwcap2) |
| 37 |
} |
| 38 |
} else { |
| 39 |
(0, 0) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
#[cfg(any( |
| 44 |
all(target_os = "android", target_pointer_width = "64"), |
| 45 |
target_os = "linux", |
| 46 |
))] |
| 47 |
#[inline] |
| 48 |
pub(crate) fn linux_minsigstksz() -> usize { |
| 49 |
// FIXME: reuse const from libc when available? |
| 50 |
const AT_MINSIGSTKSZ: c::c_ulong = 51; |
| 51 |
if let Some(libc_getauxval) = getauxval.get() { |
| 52 |
unsafe { libc_getauxval(AT_MINSIGSTKSZ) as usize } |
| 53 |
} else { |
| 54 |
0 |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
#[cfg(any( |
| 59 |
all(target_os = "android", target_pointer_width = "64"), |
| 60 |
target_os = "linux", |
| 61 |
))] |
| 62 |
#[inline] |
| 63 |
pub(crate) fn linux_execfn() -> &'static CStr { |
| 64 |
if let Some(libc_getauxval) = getauxval.get() { |
| 65 |
unsafe { CStr::from_ptr(libc_getauxval(c::AT_EXECFN).cast()) } |
| 66 |
} else { |
| 67 |
cstr!("") |
| 68 |
} |
| 69 |
} |