From 2ba2dcb464f3af1cb0eeaae6d5c57d438b487e0f Mon Sep 17 00:00:00 2001 From: koniifer Date: Sun, 20 Oct 2024 12:11:29 +0100 Subject: [PATCH] change logger message format so it doesn't mutate the string --- kernel/src/holeybytes/kernel_services/logging_service.rs | 8 ++++++-- sysdata/libraries/stn/src/log.hb | 7 +++---- sysdata/libraries/stn/src/string.hb | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/kernel/src/holeybytes/kernel_services/logging_service.rs b/kernel/src/holeybytes/kernel_services/logging_service.rs index 48a38b9..b1fbf4a 100644 --- a/kernel/src/holeybytes/kernel_services/logging_service.rs +++ b/kernel/src/holeybytes/kernel_services/logging_service.rs @@ -9,12 +9,16 @@ use log::Record; pub fn log_msg_handler(_vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), LogError> { let msg_vec = block_read(mem_addr, length); - let log_level = msg_vec.last().unwrap(); + let log_level = msg_vec[0]; + let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap()); + let strlen = u64::from_le_bytes(msg_vec[9..17].try_into().unwrap()) as usize; + + let str = block_read(strptr, strlen); let file_name = "None"; let line_number = 0; - match core::str::from_utf8(&msg_vec[..msg_vec.len() - 1]) { + match core::str::from_utf8(&str) { Ok(strr) => { use log::Level::*; let log_level = match log_level { diff --git a/sysdata/libraries/stn/src/log.hb b/sysdata/libraries/stn/src/log.hb index 72c68eb..95d91c1 100644 --- a/sysdata/libraries/stn/src/log.hb +++ b/sysdata/libraries/stn/src/log.hb @@ -1,10 +1,9 @@ string := @use("string.hb") -log := fn($Level: u8, message: ^u8): void { - message_length := @inline(string.length, message); - *(message + message_length) = Level +LogMsg := packed struct {level: u8, string: ^u8, strlen: uint} - return @eca(3, 1, message, message_length + 1) +log := fn($Level: u8, message: ^u8): void { + return @eca(3, 1, LogMsg.(Level, message, @inline(string.length, message)), @sizeof(LogMsg)) } error := fn(message: ^u8): void return @inline(log, 0, message) diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index 042de02..8e80001 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -1,5 +1,5 @@ -length := fn(ptr: ^u8): int { - len := 0 +length := fn(ptr: ^u8): uint { + len := @as(uint, 0) loop if *(ptr + len) == 0 break else len += 1 return len }