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
use core::fmt::{Debug, Error, Formatter};
#[repr(C)]
#[derive(Debug)]
pub struct VdsoConstants {
pub max_num_cpus: u32,
pub features: Features,
pub dcache_line_size: u32,
pub icache_line_size: u32,
pub ticks_per_second: u64,
pub ticks_to_mono_numerator: u32,
pub ticks_to_mono_denominator: u32,
pub physmem: u64,
pub version_string_len: u64,
pub version_string: VersionString,
}
#[repr(C)]
#[derive(Debug)]
pub struct Features {
pub cpu: u32,
pub hw_breakpoint_count: u32,
pub hw_watchpoint_count: u32,
}
impl VdsoConstants {
pub fn set_version_string(&mut self, s: &str) {
let len = s.len().min(64);
self.version_string_len = len as u64;
self.version_string.0[..len].copy_from_slice(s.as_bytes());
}
}
#[repr(C)]
pub struct VersionString([u8; 64]);
impl Default for VersionString {
fn default() -> Self {
VersionString([0; 64])
}
}
impl Debug for VersionString {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
for &c in self.0.iter().take_while(|&&c| c != 0) {
write!(f, "{}", c as char)?;
}
Ok(())
}
}