Skip to content

Commit

Permalink
mshv-bindings: Unmarshal GPA attribute message
Browse files Browse the repository at this point in the history
This message is usually send by Microsoft Hypervisor in case of SEV-SNP
host tries to access some encrypted guest memory.

Signed-off-by: Jinank Jain <[email protected]>
  • Loading branch information
jinankjain authored and Jinank Jain committed Jul 7, 2023
1 parent 8d63003 commit bf0a313
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mshv-bindings/src/unmarshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ impl hv_message {
Ok(ret)
}
#[inline]
pub fn to_gpa_attribute_info(&self) -> Result<hv_x64_gpa_attribute_intercept_message> {
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<hv_x64_io_port_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT {
return Err(errno::Error::new(libc::EINVAL));
Expand Down

0 comments on commit bf0a313

Please sign in to comment.