[Teton] Exec process in rust.

This commit is contained in:
Drew Galbraith 2024-08-17 12:55:13 -07:00
parent 8206e671cd
commit 006f9f8ac5
11 changed files with 488 additions and 61 deletions

View file

@ -25,8 +25,7 @@ impl Psf {
pub fn new(path: &str) -> Result<Self, ZError> {
let file = File::open(&path)?;
let header = file
.slice(0, core::mem::size_of::<PsfHeader>())
let header = file.slice()[0..core::mem::size_of::<PsfHeader>()]
.as_ptr()
.cast();
let psf = Self {
@ -66,7 +65,7 @@ impl Psf {
let offset: usize =
(self.header.headersize + (index * self.header.bytes_per_glyph)) as usize;
let len: usize = self.header.bytes_per_glyph as usize;
&self.file.slice(offset, len)
&self.file.slice()[offset..offset + len]
}
pub fn width(&self) -> u32 {

View file

@ -112,6 +112,19 @@ impl Terminal {
}
}
}
"exec" => match args.next() {
None => self.write_line("Specify a program"),
Some(prog) => {
let file = victoriafalls::file::File::open(prog).expect("Failed to open file");
let proc_cap = mammoth::elf::spawn_process_from_elf(file.slice())
.expect("Faield to spawn process");
let exit_code = mammoth::syscall::process_wait(proc_cap)
.expect("Failed to wait on process.");
self.write_line(&format!("Process exit code: {}", exit_code));
}
},
_ => self.write_line(&format!("Unrecognized command: {}", cmd)),
}
}