From 05d8606a32c20d0e12ff265882cca0f0d5a2af16 Mon Sep 17 00:00:00 2001 From: Julian Schindel Date: Wed, 29 Apr 2026 20:43:25 +0200 Subject: [PATCH] vmm: replace unsafe with safe `Vec` creation for `LocalX2Apic` The `LocalX2Apic` structs implements `IntoBytes`, so we can use the safe abstraction instead having to use `unsafe`. On-behalf-of: SAP julian.schindel@sap.com Signed-off-by: Julian Schindel --- vmm/src/cpu.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 303f5de99..ae7b44076 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -2271,20 +2271,16 @@ impl Cpu { fn generate_mat(&self) -> Vec { let x2apic_id = arch::x86_64::get_x2apic_id(self.cpu_id, self.topology); - let lapic = LocalX2Apic { + LocalX2Apic { r#type: crate::acpi::ACPI_X2APIC_PROCESSOR, length: 16, processor_id: self.cpu_id, apic_id: x2apic_id, flags: 1 << MADT_CPU_ENABLE_FLAG, _reserved: 0, - }; - - let mut mat_data: Vec = vec![0; std::mem::size_of_val(&lapic)]; - // SAFETY: mat_data is large enough to hold lapic - unsafe { *(mat_data.as_mut_ptr() as *mut LocalX2Apic) = lapic }; - - mat_data + } + .as_bytes() + .to_vec() } }