Skip to content

Commit

Permalink
svsm: do not depend on nightly const_mut_refs feature
Browse files Browse the repository at this point in the history
Luckily, mutable references depending on this feature can be converted
to immutable references or be removed alltogether.

The mutable pointer to a ConsoleWriter in Console can be const because
ConsoleWriter::put_byte() takes &self. On the other hand,
ImmutAfterInitRef::new_from_cell() requires using a raw pointer in a
const context, which will not work without the feature. Since it is
not in use, remove the method.

Signed-off-by: Carlos López <carlos.lopez@suse.com>
  • Loading branch information
00xc committed May 12, 2023
1 parent 7c9bec5 commit 0b9c951
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pub trait ConsoleWriter {
}

pub struct Console {
writer: *mut dyn ConsoleWriter,
writer: *const dyn ConsoleWriter,
}

impl Console {
pub fn set(&mut self, w: *mut dyn ConsoleWriter) {
pub fn set(&mut self, w: *const dyn ConsoleWriter) {
self.writer = w;
}
}
Expand All @@ -42,7 +42,7 @@ impl fmt::Write for Console {

pub static WRITER: SpinLock<Console> = SpinLock::new(unsafe {
Console {
writer: &mut DEFAULT_SERIAL_PORT,
writer: &DEFAULT_SERIAL_PORT,
}
});
static CONSOLE_INITIALIZED: ImmutAfterInitCell<bool> = ImmutAfterInitCell::new(false);
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Author: Nicolai Stange <nstange@suse.de>

#![no_std]
#![feature(const_mut_refs)]

pub mod acpi;
pub mod address;
Expand Down
4 changes: 2 additions & 2 deletions src/stage2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![no_std]
#![no_main]
#![feature(const_mut_refs, rustc_private)]
#![feature(rustc_private)]

pub mod boot_stage2;

Expand Down Expand Up @@ -102,7 +102,7 @@ fn setup_env() {
init_percpu();

unsafe {
WRITER.lock().set(&mut CONSOLE_SERIAL);
WRITER.lock().set(&CONSOLE_SERIAL);
}
init_console();

Expand Down
1 change: 0 additions & 1 deletion src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#![no_std]
#![no_main]
#![feature(const_mut_refs)]
pub mod svsm_paging;

extern crate alloc;
Expand Down
15 changes: 1 addition & 14 deletions src/utils/immut_after_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub struct ImmutAfterInitRef<'a, T: 'a> {
#[doc(hidden)]
ptr: ImmutAfterInitCell<*const T>,
#[doc(hidden)]
_phantom: PhantomData<&'a mut &'a T>,
_phantom: PhantomData<&'a &'a T>,
}

impl<'a, T> ImmutAfterInitRef<'a, T> {
Expand Down Expand Up @@ -249,19 +249,6 @@ impl<'a, T: Copy> ImmutAfterInitRef<'a, T> {
{
self.ptr.init(&(*cell.data.get()).as_ptr());
}

/// Create an initialized `ImmutAfterInitRef` instance pointing to a value
/// wrapped in a [`ImmutAfterInitCell`].
///
/// * `cell` - The value to make the `ImmutAfterInitRef` to refer to. By
/// convention, the referenced value must have been initialized
/// already.
pub const fn new_from_cell(cell: &'a ImmutAfterInitCell<T>) -> Self {
Self {
ptr: ImmutAfterInitCell::new(unsafe { &*cell.data.get() }.as_ptr()),
_phantom: PhantomData,
}
}
}

impl<'a, T> Deref for ImmutAfterInitRef<'a, T> {
Expand Down

0 comments on commit 0b9c951

Please sign in to comment.