Make VirtioConsolesPrinter heapless

This commit is contained in:
Yuke Peng
2025-02-18 15:16:06 +08:00
committed by Tate, Hongliang Tian
parent d37e60d082
commit 96d83e43b4
2 changed files with 16 additions and 2 deletions

View File

@ -11,7 +11,11 @@ struct VirtioConsolesPrinter;
impl Write for VirtioConsolesPrinter {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
for (_, device) in aster_console::all_devices() {
// We must call `all_devices_lock` instead of `all_devices` here, as `all_devices` invokes
// the clone method of String and Arc, which may lead to a deadlock when there is low memory
// in the heap (The heap allocator will log a message when memory is low.).
let devices = aster_console::all_devices_lock();
for (_, device) in devices.iter() {
device.send(s.as_bytes());
}
Ok(())