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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![allow(unsafe_code)]
#[cfg(any(feature = "param", feature = "runtime"))]
use super::super::c;
use super::super::elf::*;
#[cfg(feature = "param")]
use crate::ffi::CStr;
#[cfg(feature = "runtime")]
use core::slice;
#[cfg(feature = "param")]
#[inline]
pub(crate) fn page_size() -> usize {
unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize }
}
#[cfg(feature = "param")]
#[inline]
pub(crate) fn clock_ticks_per_second() -> u64 {
unsafe { libc::getauxval(libc::AT_CLKTCK) as u64 }
}
#[cfg(feature = "param")]
#[inline]
pub(crate) fn linux_hwcap() -> (usize, usize) {
unsafe {
(
libc::getauxval(libc::AT_HWCAP) as usize,
libc::getauxval(libc::AT_HWCAP2) as usize,
)
}
}
#[cfg(feature = "param")]
#[inline]
pub(crate) fn linux_execfn() -> &'static CStr {
unsafe {
let execfn = libc::getauxval(libc::AT_EXECFN) as *const c::c_char;
CStr::from_ptr(execfn.cast())
}
}
#[cfg(feature = "runtime")]
#[inline]
pub(crate) fn exe_phdrs() -> (*const c::c_void, usize) {
unsafe {
(
libc::getauxval(libc::AT_PHDR) as *const c::c_void,
libc::getauxval(libc::AT_PHNUM) as usize,
)
}
}
#[cfg(feature = "runtime")]
#[inline]
pub(in super::super) fn exe_phdrs_slice() -> &'static [Elf_Phdr] {
let (phdr, phnum) = exe_phdrs();
unsafe { slice::from_raw_parts(phdr.cast(), phnum) }
}
#[inline]
pub(in super::super) fn sysinfo_ehdr() -> *const Elf_Ehdr {
unsafe { libc::getauxval(linux_raw_sys::general::AT_SYSINFO_EHDR.into()) as *const Elf_Ehdr }
}