diff --git a/mshv-bindings/src/unmarshal.rs b/mshv-bindings/src/unmarshal.rs index a00fd331..f81f26c6 100644 --- a/mshv-bindings/src/unmarshal.rs +++ b/mshv-bindings/src/unmarshal.rs @@ -24,6 +24,7 @@ impl hv_message { pub fn to_memory_info(&self) -> Result { if self.header.message_type != hv_message_type_HVMSG_GPA_INTERCEPT && self.header.message_type != hv_message_type_HVMSG_UNMAPPED_GPA + && self.header.message_type != hv_message_type_HVMSG_UNACCEPTED_GPA { return Err(errno::Error::new(libc::EINVAL)); } @@ -35,6 +36,18 @@ impl hv_message { Ok(ret) } #[inline] + pub fn to_gpa_attribute_info(&self) -> Result { + if self.header.message_type != hv_message_type_HVMSG_GPA_ATTRIBUTE_INTERCEPT { + return Err(errno::Error::new(libc::EINVAL)); + } + // SAFETY: We know at this point the payload is of the correct type. The payload field is + // unaligned. We use addr_of! to safely create a pointer, then call read_unaligned for + // copying its content out. + let ret = + unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) }; + Ok(ret) + } + #[inline] pub fn to_ioport_info(&self) -> Result { if self.header.message_type != hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT { return Err(errno::Error::new(libc::EINVAL));