You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 1, 2024. It is now read-only.
/// Constructs a `PhysicalAddress` from a given page frame number (PFN).
27
38
pubfnfrom_pfn(pfn:u64) -> Self{
28
39
Self(PAddr::from(pfn << BASE_PAGE_SHIFT))
29
40
}
30
41
31
-
/// Constructs a `PhysicalAddress` from a given virtual address.
32
-
pubfnfrom_va(va:u64) -> Self{
33
-
Self(PAddr::from(Self::pa_from_va(va)))
34
-
}
35
-
36
42
/// Retrieves the page frame number (PFN) for the physical address.
37
43
pubfnpfn(&self) -> u64{
38
44
self.0.as_u64() >> BASE_PAGE_SHIFT
@@ -43,60 +49,44 @@ impl PhysicalAddress {
43
49
self.0.as_u64()
44
50
}
45
51
46
-
/// Converts a virtual address to its corresponding physical address.
47
-
pubfnpa_from_va(va:u64) -> u64{
48
-
let guest_cr3 = PageTables::get_guest_cr3();
49
-
PageTables::translate_guest_virtual_to_physical(guest_cr3 asusize, va as_).unwrap()asu64
50
-
}
51
-
52
-
/// Reads a value of a specified type from guest memory at the provided virtual address, ensuring safety by internal validation.
52
+
/// Converts a guest virtual address to its corresponding host physical address.
53
53
///
54
-
/// # Arguments
54
+
/// This function first translates the guest virtual address to a guest physical address
55
+
/// using the guest's CR3. It then translates the guest physical address to a host physical
56
+
/// address using the EPT (Extended Page Table).
55
57
///
56
-
/// * `guest_cr3` - The base address of the guest's page table hierarchy.
57
-
/// * `guest_va` - The guest virtual address from which to read.
58
+
/// # Arguments
58
59
///
59
-
/// # Returns
60
+
/// * `va` - The guest virtual address to translate.
60
61
///
61
-
/// * Returns an `Option<T>` which is `Some(value)` if the read is successful and safe, or `None` if the address cannot be translated or if safety conditions are not met.
62
+
/// # Safety
62
63
///
63
-
/// # Type Parameters
64
+
/// This function is unsafe because it involves raw memory access and relies on the integrity
65
+
/// of the VMCS (Virtual Machine Control Structure).
64
66
///
65
-
/// * `T` - The type of the value to read. This can be any type that implements the `Copy` trait and has a size that can be read atomically.
67
+
/// # Returns
66
68
///
67
-
/// # Credits
68
-
/// Credits to Jessie (jessiep_) for the initial concept.
// The translation function ensures that the physical address is valid and maps to a real physical memory location.
72
-
// The dereference is only performed if the translation succeeds, and it's constrained to types that are Copy, implying they can be safely duplicated and do not manage resources that require manual cleanup.
73
-
// Still, the caller must ensure that reading from this specific address does not violate any safety contracts.
74
-
let pa = PageTables::translate_guest_virtual_to_physical(guest_cr3, guest_va)?;
75
-
unsafe{Some(*(pa as*constT))}
76
-
}
77
-
}
69
+
/// A `Result<u64, HypervisorError>` containing the host physical address on success, or an error if the translation fails.
0 commit comments