Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Renamed stack memory range
Browse files Browse the repository at this point in the history
  • Loading branch information
memN0ps committed Jul 30, 2024
1 parent ccc2452 commit db2e0c5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions hypervisor/src/intel/hooks/hook_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ pub struct HookManager {
/// KiSetCacheInformation -> KiSetCacheInformationIntel -> KiSetStandardizedCacheInformation -> __cpuid(4, 0)
pub has_cpuid_cache_info_been_called: bool,

pub stack_memory: Vec<(usize, usize)>,
/// A vector to keep track of allocated memory ranges for debugging and management purposes.
/// Each element is a tuple where the first value is the start address and the second value is the size of the allocation.
pub allocated_memory_ranges: Vec<(usize, usize)>,
}

lazy_static! {
Expand All @@ -89,7 +91,7 @@ lazy_static! {
ntoskrnl_base_pa: 0,
ntoskrnl_size: 0,
has_cpuid_cache_info_been_called: false,
stack_memory: Vec::with_capacity(128),
allocated_memory_ranges: Vec::with_capacity(128),
});
}

Expand Down Expand Up @@ -119,12 +121,12 @@ impl HookManager {
/// * `start` - The start address of the memory allocation.
/// * `size` - The size of the memory allocation.
pub fn record_allocation(&mut self, start: usize, size: usize) {
self.stack_memory.push((start, size));
self.allocated_memory_ranges.push((start, size));
}

/// Prints the allocated memory ranges for debugging purposes.
pub fn print_allocated_memory(&self) {
self.stack_memory.iter().for_each(|(start, size)| {
self.allocated_memory_ranges.iter().for_each(|(start, size)| {
debug!("Memory Range: Start = {:#x}, Size = {:#x}", start, size);
});
}
Expand Down Expand Up @@ -218,7 +220,7 @@ impl HookManager {
/// Returns `Ok(())` if the hooks were successfully installed, `Err(HypervisorError)` otherwise.
pub fn hide_hypervisor_memory(&mut self, vm: &mut Vm, page_permissions: AccessType) -> Result<(), HypervisorError> {
let pages: Vec<u64> = self
.stack_memory
.allocated_memory_ranges
.iter()
.step_by(BASE_PAGE_SIZE)
.map(|(start, _size)| *start as u64)
Expand Down

0 comments on commit db2e0c5

Please sign in to comment.