init/2

62 lines
1.8 KiB
Plaintext
Raw Normal View History

2022-11-01 12:41:57 -05:00
#![no_std]
#![no_main]
#![feature(int_roundings)]
#![deny(unsafe_op_in_unsafe_fn)]
use ext2::Ext2;
use std::fmt::Debug;
use std::loader::{Binary, Loader};
use std::path::Path;
use std::syscalls::{get_initrd, new_process};
use std::{ipc, prelude::*, str};
use tar_no_std::TarArchiveRef;
use ata::PRIMARY_SLAVE;
mod ata;
mod ext2;
main!({
let primary_slave = PRIMARY_SLAVE.unwrap();
let fs = Ext2::new(primary_slave).unwrap();
print_all_files("/", &fs);
println!("Hello, syscall format world!");
let initrd = TarArchiveRef::new(get_initrd());
let test_proc = Binary::new(
initrd
.entries()
.find(|entry| entry.filename() == *"bin/test_proc")
.expect("test_proc not found")
.data(),
)
.expect("test_proc not an ELF binary");
let space = Loader::load(&test_proc);
let pid = new_process(test_proc.entry_point(), space).expect("Failed to create process");
ipc::base::allow_protocol(0);
let id = ipc::rpc::send_call(pid, 0, 0, "Hello, RPC call world".as_bytes());
let ret = loop {
ipc::rpc::process_messages();
if let Some(ret) = ipc::rpc::get_return(id) {
dbg!();
break ret;
}
};
dbg!(&ret.retval);
println!("{}", str::from_utf8(&ret.retval).unwrap());
loop {}
});
fn print_all_files<P: AsRef<Path> + Debug>(path: P, fs: &Ext2) {
for entry in fs.read_dir(path).unwrap() {
let entry = entry.unwrap();
if entry.metadata().file_type().is_dir() {
print_all_files(entry.path(), fs);
} else {
let mut file = fs.open(entry.path()).unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf).unwrap();
print!("{:?}:\n{}", entry.path(), buf);
}
}
}