From bcfaf89ed04d72084919084c4e0c5741e1989acb Mon Sep 17 00:00:00 2001 From: koniifer Date: Sun, 20 Oct 2024 12:36:34 +0100 Subject: [PATCH] fix buffer mutating message --- .../kernel_services/service_definition_service.rs | 10 ++++------ sysdata/libraries/stn/src/buffer.hb | 11 ++++------- sysdata/libraries/stn/src/string.hb | 4 +--- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/kernel/src/holeybytes/kernel_services/service_definition_service.rs b/kernel/src/holeybytes/kernel_services/service_definition_service.rs index 52f37ad6..7cf03ecc 100644 --- a/kernel/src/holeybytes/kernel_services/service_definition_service.rs +++ b/kernel/src/holeybytes/kernel_services/service_definition_service.rs @@ -22,21 +22,19 @@ pub enum ServiceError { pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), ServiceError> { let msg_vec = block_read(mem_addr, length); let sds_event_type: ServiceEventType = msg_vec[0].into(); - - // info!("Length {}", msg_vec.len()); + 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 string_vec = block_read(strptr, strlen); + let string = core::str::from_utf8(string_vec).expect("Our bytes should be valid utf8"); use ServiceEventType::*; match sds_event_type { CreateService => { - let string = - core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8"); let ret = sds_create_service(string); vm.registers[1] = hbvm::value::Value(ret as u64); } DeleteService => todo!(), SearchServices => { - let string = - core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8"); let ret = sds_search_service(string); vm.registers[1] = hbvm::value::Value(ret as u64); } diff --git a/sysdata/libraries/stn/src/buffer.hb b/sysdata/libraries/stn/src/buffer.hb index 554783b1..23d7e67e 100644 --- a/sysdata/libraries/stn/src/buffer.hb +++ b/sysdata/libraries/stn/src/buffer.hb @@ -8,15 +8,12 @@ write := fn(msg: ^u8, buffer_id: int, length: int): void { return @eca(3, buffer_id, msg, length) } +BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint} + create := fn(msg: ^u8): int { - msg_length := @inline(string.length, msg); - *msg = 0 - return @eca(3, 0, msg, msg_length) + return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } search := fn(msg: ^u8): int { - msg_length := @inline(string.length, msg); - *msg = 3 - - return @eca(3, 0, msg, msg_length) + return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg)) } \ No newline at end of file diff --git a/sysdata/libraries/stn/src/string.hb b/sysdata/libraries/stn/src/string.hb index 8e800011..679c180c 100644 --- a/sysdata/libraries/stn/src/string.hb +++ b/sysdata/libraries/stn/src/string.hb @@ -31,9 +31,7 @@ display_int := fn(num: int, p: ^u8): ^u8 { } reverse := fn(s: ^u8): void { - //reverse a string, don't remove digits - len := 0 - loop if *(s + len) == 0 break else len += 1 + len := @inline(length, s) i := 0 j := len - 1 temp := 0