Skip to content

Add Send impl for BootInformation #114

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

Merged
merged 2 commits into from
Jun 19, 2022
Merged
Changes from 1 commit
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
26 changes: 18 additions & 8 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;

/// Load the multiboot boot information struct from an address.
///
/// This is the same as `load_with_offset` but the offset is omitted and set
/// to zero.
/// This is the same as `load_with_offset` but the offset is omitted and set to
/// zero.
///
/// ## Example
///
Expand All @@ -103,9 +103,12 @@ pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
/// ```
///
/// ## Safety
/// This function might terminate the program, if the address is invalid. This can be the case in
/// environments with standard environment (segfault) but also in UEFI-applications,
/// where the referenced memory is not (identity) mapped (UEFI does only identity mapping).
/// * `address` must be valid for reading. Otherwise this function might
/// terminate the program. This can be the case in environments with standard
/// environment (segfault) but also in UEFI-applications, where the referenced
/// memory is not (identity) mapped (UEFI does only identity mapping).
/// * The memory at `address` must not be modified after calling `load` or the
/// program may observe unsychronized mutation.
pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
load_with_offset(address, 0)
}
Expand All @@ -123,9 +126,12 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
/// ```
///
/// ## Safety
/// This function might terminate the program, if the address is invalid. This can be the case in
/// environments with standard environment (segfault) but also in UEFI-applications,
/// where the referenced memory is not (identity) mapped (UEFI does only identity mapping).
/// * `address` must be valid for reading. Otherwise this function might
/// terminate the program. This can be the case in environments with standard
/// environment (segfault) but also in UEFI-applications, where the referenced
/// memory is not (identity) mapped (UEFI does only identity mapping).
/// * The memory at `address` must not be modified after calling `load` or the
/// program may observe unsychronized mutation.
pub unsafe fn load_with_offset(
address: usize,
offset: usize,
Expand Down Expand Up @@ -326,6 +332,10 @@ impl BootInformationInner {
}
}

// SAFETY: BootInformation contains a const ptr to memory that is never mutated.
// Sending this pointer to other threads is sound.
unsafe impl Send for BootInformation {}

impl fmt::Debug for BootInformation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
/// Limit how many Elf-Sections should be debug-formatted.
Expand Down