Skip to content

Commit

Permalink
Use addr_of_mut! macro to access mutable static memory pools
Browse files Browse the repository at this point in the history
Rust 1.77 warns about taking mutable references to static mutable
objects, on the basis that it might result in UB if concurrent accesses
are made.

This cannot occur in these cases, as the mutable globals are local to
the scope in question, and so there is no way for other code to take
such a reference.

Adopt the workaround proposed by the compiler, which essentially papers
over the issue, but that is also fine for the same reasons stated above.
  • Loading branch information
ardbiesheuvel committed Mar 26, 2024
1 parent 58439ad commit 4e12172
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod rng;

use core::mem::MaybeUninit;
use core::{arch::global_asm, panic::PanicInfo};
use core::ptr::addr_of_mut;
use linked_list_allocator::LockedHeap;
use log::{debug, error, info};

Expand Down Expand Up @@ -212,7 +213,7 @@ extern "C" fn efilite_main(base: *mut u8, used: isize, avail: usize) {
unsafe {
static mut BSPOOL: [MaybeUninit<u8>; BSPOOL_SIZE] = [MaybeUninit::uninit(); BSPOOL_SIZE];
memmap
.declare_pool(EfiBootServicesData, &mut BSPOOL)
.declare_pool(EfiBootServicesData, &mut *addr_of_mut!(BSPOOL))
.expect("Failed to declare memory pool");
}

Expand All @@ -233,7 +234,7 @@ extern "C" fn efilite_main(base: *mut u8, used: isize, avail: usize) {
#[link_section = ".rtdata"]
static mut RTPOOL: [MaybeUninit<u8>; RTPOOL_SIZE] = [MaybeUninit::uninit(); RTPOOL_SIZE];
memmap
.declare_pool(EfiRuntimeServicesData, &mut RTPOOL)
.declare_pool(EfiRuntimeServicesData, &mut *addr_of_mut!(RTPOOL))
.expect("Failed to declare memory pool");
}

Expand Down

0 comments on commit 4e12172

Please sign in to comment.