Skip to content

Commit

Permalink
fix: put console in one-shot mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 3, 2024
1 parent 9273860 commit 46bbfd3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2021"
align-address = "0.1"
hermit-entry = { version = "0.9", features = ["loader"] }
log = "0.4"
one-shot-mutex = "0.1"
sptr = "0.3"
vm-fdt = { version = "0.3", default-features = false, features = ["alloc"] }

Expand Down
4 changes: 3 additions & 1 deletion src/console.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::fmt;

use one_shot_mutex::OneShotMutex;

pub struct Console(());

impl fmt::Write for Console {
Expand All @@ -11,4 +13,4 @@ impl fmt::Write for Console {
}
}

pub static mut CONSOLE: Console = Console(());
pub static CONSOLE: OneShotMutex<Console> = OneShotMutex::new(Console(()));
4 changes: 1 addition & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,5 @@ extern crate alloc;
fn _print(args: core::fmt::Arguments<'_>) {
use core::fmt::Write;

unsafe {
console::CONSOLE.write_fmt(args).unwrap();
}
console::CONSOLE.lock().write_fmt(args).unwrap();
}
2 changes: 1 addition & 1 deletion src/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) unsafe extern "C" fn loader_main() -> ! {
#[panic_handler]
fn panic(info: &core::panic::PanicInfo<'_>) -> ! {
// We can't use `println!` or related macros, because `_print` unwraps a result and might panic again
writeln!(unsafe { &mut console::CONSOLE }, "[LOADER] {info}").ok();
writeln!(console::CONSOLE.lock(), "[LOADER] {info}").ok();

loop {}
}

0 comments on commit 46bbfd3

Please sign in to comment.