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
pub struct Tlb {
tlbp: *mut sys::tlb_t
}
impl Tlb {
/// Create the TLB of current thread
///
/// # Remarks
///
/// In VMRead, each thread has its own Translation Lookaside Buffer so as to not spend
/// resources on locking mechanisms.
pub fn from_current_thread() -> Tlb {
Tlb {
tlbp: unsafe { sys::GetTlb() }
}
}
/// Flush TLB
pub fn flush_tlb(&self) -> &Self {
unsafe {
sys::FlushTlb(self.tlbp);
}
self
}
/// Verify TLB
pub fn verify_tlb(&self, c_ctx: &sys::WinCtx) -> &Self {
unsafe {
sys::VerifyTlb(&c_ctx.process, self.tlbp, 1, 0);
}
self
}
/// Set global TLB validity time in milliseconds
///
/// Defines for how long translation caches (TLB and page buffer) should be valid. Higher
/// values lead to higher performance, but could potentially lead to incorrect translation if
/// the page tables update in that period. Especially dangerous if write operations are to be
/// performed.
///
/// # Arguments
///
/// * `new_time` - new validity time
pub fn set_mem_cache_time(new_time: usize) {
unsafe {
sys::SetMemCacheTime(new_time as u64);
}
}
/// Get the default TLB validity in milliseconds
pub fn get_default_mem_cache_time() -> usize {
unsafe {
sys::GetDefaultMemCacheTime() as usize
}
}
}