Skip to content

Commit

Permalink
syscall: Pass &str to write syscall instead of single char
Browse files Browse the repository at this point in the history
  • Loading branch information
sysheap committed Jan 4, 2025
1 parent e50068b commit bdbc217
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion common/src/syscalls/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ scalar_enum! {
}

syscalls!(
sys_write_char(c: char) -> ();
sys_write<'a>(s: &'a str) -> Result<(), ValidationError>;
sys_read_input() -> Option<u8>;
sys_read_input_wait() -> u8;
sys_exit(status: isize) -> ();
Expand Down
7 changes: 5 additions & 2 deletions kernel/src/syscalls/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use common::{
ref_conversion::RefToPointer,
syscalls::{
kernel::KernelSyscalls, SysExecuteError, SysSocketError, SysWaitError, SyscallStatus,
ValidationError,
},
unwrap_or_return,
};
Expand Down Expand Up @@ -57,8 +58,10 @@ impl KernelSyscalls for SyscallHandler {
fn sys_panic(&mut self) {
panic!("Userspace triggered kernel panic");
}
fn sys_write_char(&mut self, c: UserspaceArgument<char>) {
print!("{}", *c);
fn sys_write(&mut self, s: UserspaceArgument<&str>) -> Result<(), ValidationError> {
let s = s.validate(self)?;
print!("{s}");
Ok(())
}

fn sys_read_input(&mut self) -> Option<u8> {
Expand Down
1 change: 0 additions & 1 deletion todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

- Multiple terminals with Ctrl+{1..10}
- Sleep for processes
- Better syscall return type
6 changes: 2 additions & 4 deletions userspace/src/print.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::fmt::{self, Write};

use common::{mutex::Mutex, syscalls::sys_write_char};
use common::{mutex::Mutex, syscalls::sys_write};

#[macro_export]
macro_rules! print {
Expand All @@ -22,9 +22,7 @@ struct Writer;

impl Write for Writer {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() {
sys_write_char(c);
}
sys_write(s).unwrap();
Ok(())
}
}
Expand Down

0 comments on commit bdbc217

Please sign in to comment.