Skip to content

Commit

Permalink
Prevent getting a raw reference from PhysicalMapping if T: !Unpin
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacWoods committed Oct 6, 2024
1 parent 35f9fba commit 37d4bb2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion acpi/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{fmt, ops::Deref, ptr::NonNull};
use core::{fmt, ops::Deref, pin::Pin, ptr::NonNull};

/// Describes a physical mapping created by `AcpiHandler::map_physical_region` and unmapped by
/// `AcpiHandler::unmap_physical_region`. The region mapped must be at least `size_of::<T>()`
Expand Down Expand Up @@ -65,6 +65,10 @@ where
self.virtual_start
}

pub fn get(&self) -> Pin<&T> {
unsafe { Pin::new_unchecked(self.virtual_start.as_ref()) }
}

pub fn region_length(&self) -> usize {
self.region_length
}
Expand All @@ -82,6 +86,7 @@ unsafe impl<H: AcpiHandler + Send, T: Send> Send for PhysicalMapping<H, T> {}

impl<H, T> Deref for PhysicalMapping<H, T>
where
T: Unpin,
H: AcpiHandler,
{
type Target = T;
Expand Down
2 changes: 1 addition & 1 deletion acpi/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ where

let madt = tables.find_table::<Madt>();
let (interrupt_model, processor_info) = match madt {
Ok(madt) => madt.parse_interrupt_model_in(allocator)?,
Ok(madt) => madt.get().parse_interrupt_model_in(allocator)?,
Err(_) => (InterruptModel::Unknown, None),
};
let pm_timer = PmTimer::new(&fadt)?;
Expand Down
2 changes: 1 addition & 1 deletion acpi/src/sdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl SdtHeader {

// This is usually redundant compared to simply calling `validate_checksum` but respects custom
// `AcpiTable::validate` implementations.
table_mapping.validate()?;
table_mapping.get().validate()?;

Ok(table_mapping)
}
Expand Down

0 comments on commit 37d4bb2

Please sign in to comment.