mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
log-server: fix implementation of stdout/stderr
The buffer was incorrectly sized. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
6e57fbe29b
commit
ca1b9aa35c
1 changed files with 21 additions and 2 deletions
|
|
@ -307,8 +307,27 @@ fn handle_opcode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
api::Opcode::StandardOutput | api::Opcode::StandardError => {
|
api::Opcode::StandardOutput | api::Opcode::StandardError => {
|
||||||
let buffer =
|
// let mut buffer_start_offset = mem.offset.map(|o| o.get()).unwrap_or(0);
|
||||||
unsafe { core::slice::from_raw_parts(mem.buf.as_ptr(), mem.buf.len()) };
|
let mut buffer_start_offset = 0;
|
||||||
|
let mut buffer_length = mem.valid.map(|v| v.get()).unwrap_or(mem.buf.len());
|
||||||
|
|
||||||
|
// Ensure that `buffer_start_offset` is within the range of `buffer`.
|
||||||
|
if buffer_start_offset >= mem.buf.len() {
|
||||||
|
buffer_start_offset = mem.buf.len() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clamp the buffer length so that it fits within the buffer
|
||||||
|
if buffer_start_offset + buffer_length >= mem.buf.len() {
|
||||||
|
buffer_length = mem.buf.len() - buffer_start_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safe because we validated the offsets above
|
||||||
|
let buffer = unsafe {
|
||||||
|
core::slice::from_raw_parts(
|
||||||
|
mem.buf.as_ptr().add(buffer_start_offset),
|
||||||
|
buffer_length,
|
||||||
|
)
|
||||||
|
};
|
||||||
output.write_all(buffer).unwrap();
|
output.write_all(buffer).unwrap();
|
||||||
// TODO: If the buffer is mutable, set `length` to 0.
|
// TODO: If the buffer is mutable, set `length` to 0.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue