vm-migration: add two safety comments

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2022-11-16 21:37:47 +00:00 committed by Liu Wei
parent 926d149881
commit 2a5c248f32

View File

@ -257,6 +257,7 @@ impl MemoryRangeTable {
length as usize / (std::mem::size_of::<MemoryRange>()),
Default::default,
);
// SAFETY: the slice is construted with the correct arguments
fd.read_exact(unsafe {
std::slice::from_raw_parts_mut(
data.as_ptr() as *mut MemoryRange as *mut u8,
@ -273,6 +274,7 @@ impl MemoryRangeTable {
}
pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> {
// SAFETY: the slice is construted with the correct arguments
fd.write_all(unsafe {
std::slice::from_raw_parts(
self.data.as_ptr() as *const MemoryRange as *const u8,