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

Cleanup some unsafe code #4114

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
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: 4 additions & 9 deletions src/vmm/src/arch/aarch64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ macro_rules! arm64_core_reg_id {
};
}
pub(crate) use arm64_core_reg_id;
use utils::vm_memory::ByteValued;

/// This macro computes the ID of a specific ARM64 system register similar to how
/// the kernel C macro does.
Expand Down Expand Up @@ -502,19 +503,13 @@ impl<'a> TryFrom<Aarch64RegisterRef<'a>> for Aarch64RegisterOld {
}
}

impl<'a> TryFrom<&Aarch64RegisterOld> for Aarch64RegisterRef<'a> {
impl<'a> TryFrom<&'a Aarch64RegisterOld> for Aarch64RegisterRef<'a> {
type Error = &'static str;

fn try_from(value: &Aarch64RegisterOld) -> Result<Self, Self::Error> {
fn try_from(value: &'a Aarch64RegisterOld) -> Result<Self, Self::Error> {
// # Safety:
// `self.data` is a valid memory and slice size is valid for this type.
let data_ref = unsafe {
std::slice::from_raw_parts(
(&value.data as *const u128).cast::<u8>(),
std::mem::size_of::<u128>(),
)
};

let data_ref = value.data.as_slice();
let reg_size = reg_size(value.id);
if RegSize::U2048_SIZE < reg_size {
return Err("Registers bigger then 2048 bits are not supported");
Expand Down
Loading