Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unmarshalling new SEV-SNP message #105

Merged
merged 2 commits into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mshv-bindings/src/unmarshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl hv_message {
pub fn to_memory_info(&self) -> Result<hv_x64_memory_intercept_message> {
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));
}
Expand All @@ -35,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
Loading