From 98d536f346d68eab9f0cc83e1e98122db508688e Mon Sep 17 00:00:00 2001 From: Luca Abeni Date: Thu, 23 Sep 2021 09:16:31 +0200 Subject: [PATCH 2/3] Try to fix the dmesg logger --- dmesg_logger/src/lib.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/dmesg_logger/src/lib.rs b/dmesg_logger/src/lib.rs index dcc8a34..3833e2d 100644 --- a/dmesg_logger/src/lib.rs +++ b/dmesg_logger/src/lib.rs @@ -18,19 +18,20 @@ pub struct DMesgLogger {} struct PrintK {} -const KERN_INFO: &[u8; 2] = b"6\0"; - // https://www.kernel.org/doc/html/latest/core-api/printk-basics.html impl fmt::Write for PrintK { fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { - unsafe { - printk(KERN_INFO.as_ptr()); - } + let mut data = [0u8; 1024]; + let mut i = 0; for c in s.bytes() { - unsafe { - printk(b"c%c\0".as_ptr(), c as u32); - } + data[i] = c; + i = i + 1; + } + data[i] = 0; + + unsafe { + printk("%s".as_ptr(), data.as_ptr()); } Ok(()) } @@ -42,7 +43,7 @@ impl DMesgLogger { /// handle the locking for us. pub fn write_fmt(&self, args: core::fmt::Arguments) { let mut printk_obj = PrintK {}; - let _ = write!(printk_obj, "{}\r\n", args); + let _ = write!(printk_obj, "{}", args); } } -- 2.25.1