1 use super::super::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(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_execfn() -> &'static CStr { 49 if let Some(libc_getauxval) = getauxval.get() { 50 unsafe { CStr::from_ptr(libc_getauxval(c::AT_EXECFN).cast()) } 51 } else { 52 cstr!("") 53 } 54 } 55