hypervisor: add safety statement in set_user_memory_region

When set_user_memory_region was moved to hypervisor crate, it was turned
into a safe function that wrapped around an unsafe call. All but one
call site had the safety statements removed. But safety statement was
not moved inside the wrapper function.

Add the safety statement back to help reasoning in the future. Also
remove that one last instance where the safety statement is not needed .

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2020-06-24 15:29:49 +00:00 committed by Sebastien Boeuf
parent b27439b6ed
commit 1741af74ed
2 changed files with 1 additions and 1 deletions

View File

@ -170,6 +170,7 @@ impl vm::Vm for KvmVm {
/// Creates/modifies a guest physical memory slot. /// Creates/modifies a guest physical memory slot.
/// ///
fn set_user_memory_region(&self, user_memory_region: MemoryRegion) -> vm::Result<()> { fn set_user_memory_region(&self, user_memory_region: MemoryRegion) -> vm::Result<()> {
// Safe because guest regions are guaranteed not to overlap.
unsafe { unsafe {
self.fd self.fd
.set_user_memory_region(user_memory_region) .set_user_memory_region(user_memory_region)

View File

@ -1459,7 +1459,6 @@ pub fn test_vm() {
flags: 0, flags: 0,
}; };
// Safe because the guest regions are guaranteed not to overlap.
vm_fd.set_user_memory_region(mem_region) vm_fd.set_user_memory_region(mem_region)
}) })
.expect("Cannot configure guest memory"); .expect("Cannot configure guest memory");