From 5efcecc2f2cd358e3f2dba5bf8c64716a373c869 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 25 Jan 2019 14:14:26 +0100 Subject: [PATCH] Avoid deadlock by disabling interrupts in print! and serial_print! macros --- src/serial.rs | 12 ++++++++---- src/vga_buffer.rs | 8 +++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/serial.rs b/src/serial.rs index c6990d4f..c742b09c 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -13,10 +13,14 @@ lazy_static! { #[doc(hidden)] pub fn _print(args: ::core::fmt::Arguments) { use core::fmt::Write; - SERIAL1 - .lock() - .write_fmt(args) - .expect("Printing to serial failed"); + use x86_64::instructions::interrupts; + + interrupts::without_interrupts(|| { + SERIAL1 + .lock() + .write_fmt(args) + .expect("Printing to serial failed"); + }); } /// Prints to the host through the serial interface. diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 9f0a1996..50336679 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -135,10 +135,16 @@ macro_rules! println { ($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*))); } +/// Prints the given formatted string to the VGA text buffer +/// through the global `WRITER` instance. #[doc(hidden)] pub fn _print(args: fmt::Arguments) { use core::fmt::Write; - WRITER.lock().write_fmt(args).unwrap(); + use x86_64::instructions::interrupts; + + interrupts::without_interrupts(|| { + WRITER.lock().write_fmt(args).unwrap(); + }); } #[cfg(test)]