fix buffer mutating message
This commit is contained in:
parent
2ba2dcb464
commit
bcfaf89ed0
|
@ -22,21 +22,19 @@ pub enum ServiceError {
|
||||||
pub fn sds_msg_handler(vm: &mut Vm, mem_addr: u64, length: usize) -> Result<(), 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 msg_vec = block_read(mem_addr, length);
|
||||||
let sds_event_type: ServiceEventType = msg_vec[0].into();
|
let sds_event_type: ServiceEventType = msg_vec[0].into();
|
||||||
|
let strptr = u64::from_le_bytes(msg_vec[1..9].try_into().unwrap());
|
||||||
// info!("Length {}", msg_vec.len());
|
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::*;
|
use ServiceEventType::*;
|
||||||
match sds_event_type {
|
match sds_event_type {
|
||||||
CreateService => {
|
CreateService => {
|
||||||
let string =
|
|
||||||
core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8");
|
|
||||||
let ret = sds_create_service(string);
|
let ret = sds_create_service(string);
|
||||||
vm.registers[1] = hbvm::value::Value(ret as u64);
|
vm.registers[1] = hbvm::value::Value(ret as u64);
|
||||||
}
|
}
|
||||||
DeleteService => todo!(),
|
DeleteService => todo!(),
|
||||||
SearchServices => {
|
SearchServices => {
|
||||||
let string =
|
|
||||||
core::str::from_utf8(&msg_vec[1..]).expect("Our bytes should be valid utf8");
|
|
||||||
let ret = sds_search_service(string);
|
let ret = sds_search_service(string);
|
||||||
vm.registers[1] = hbvm::value::Value(ret as u64);
|
vm.registers[1] = hbvm::value::Value(ret as u64);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,12 @@ write := fn(msg: ^u8, buffer_id: int, length: int): void {
|
||||||
return @eca(3, buffer_id, msg, length)
|
return @eca(3, buffer_id, msg, length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferMsg := packed struct {operation: u8, msg: ^u8, msg_len: uint}
|
||||||
|
|
||||||
create := fn(msg: ^u8): int {
|
create := fn(msg: ^u8): int {
|
||||||
msg_length := @inline(string.length, msg);
|
return @eca(3, 0, BufferMsg.(0, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||||
*msg = 0
|
|
||||||
return @eca(3, 0, msg, msg_length)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
search := fn(msg: ^u8): int {
|
search := fn(msg: ^u8): int {
|
||||||
msg_length := @inline(string.length, msg);
|
return @eca(3, 0, BufferMsg.(3, msg, @inline(string.length, msg)), @sizeof(BufferMsg))
|
||||||
*msg = 3
|
|
||||||
|
|
||||||
return @eca(3, 0, msg, msg_length)
|
|
||||||
}
|
}
|
|
@ -31,9 +31,7 @@ display_int := fn(num: int, p: ^u8): ^u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse := fn(s: ^u8): void {
|
reverse := fn(s: ^u8): void {
|
||||||
//reverse a string, don't remove digits
|
len := @inline(length, s)
|
||||||
len := 0
|
|
||||||
loop if *(s + len) == 0 break else len += 1
|
|
||||||
i := 0
|
i := 0
|
||||||
j := len - 1
|
j := len - 1
|
||||||
temp := 0
|
temp := 0
|
||||||
|
|
Loading…
Reference in a new issue