Skip to content

Commit

Permalink
Add host.test and update documents
Browse files Browse the repository at this point in the history
  • Loading branch information
hikalium committed Sep 1, 2024
1 parent 46f7904 commit 7c8edb3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ os:

.PHONY : doc
doc:
# `cargo doc -p os --open` to open os doc.
# `cargo doc -p noli --open` to open noli doc.
# `cargo doc -p os --open --document-private-items` to open os doc.
# `cargo doc -p noli --open --target x86_64-unknown-none --document-private-items` to open noli doc for WasabiOS apps.
cargo doc --all

.PHONY : clippy
Expand Down
2 changes: 0 additions & 2 deletions noli/src/sys/wasabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,10 @@ impl SystemApi for Api {
if addr == 0 {
None
} else {
println!("addr = {addr:#X}");
let addr = addr as *const u8;
let mut size = [0u8; 8];
size.copy_from_slice(unsafe { slice::from_raw_parts(addr, 8) });
let size = usize::from_le_bytes(size);
println!("size = {size:#X}");
Some(unsafe { slice::from_raw_parts(addr, size) })
}
}
Expand Down
9 changes: 7 additions & 2 deletions os/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,23 @@ fn run_tasks() -> Result<()> {
// Note: this message is used by e2e_test. Please do not remove.
info!("console_task has started");
let mut s = String::new();
print!("> ");
loop {
if let Some(c) = InputManager::take().pop_input() {
if c == '\r' || c == '\n' {
println!();
if let Err(e) = cmd::run(&s).await {
error!("{e:?}");
};
s.clear();
print!("> ");
}
match c {
'\x7f' | '\x08' => {
print!("{0} {0}", 0x08 as char);
s.pop();
if !s.is_empty() {
print!("{0} {0}", 0x08 as char);
s.pop();
}
}
'\n' => {
// Do nothing
Expand Down
2 changes: 0 additions & 2 deletions os/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate alloc;
use crate::allocator::ALLOCATOR;
use crate::error::Error;
use crate::error::Result;
use crate::info;
use crate::util::size_in_pages_from_bytes;
use crate::util::PAGE_SIZE;
use crate::x86_64::paging::with_current_page_table;
Expand Down Expand Up @@ -107,7 +106,6 @@ impl ContiguousPhysicalMemoryPages {
}
pub fn set_page_attr(&mut self, attr: PageAttr) -> Result<()> {
let range = self.range();
info!("Setting page attr for {:?} to {:?}", range, attr);
unsafe {
with_current_page_table(|table| {
table
Expand Down
7 changes: 0 additions & 7 deletions os/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate alloc;
use crate::error::Result;
use crate::memory::ContiguousPhysicalMemoryPages;
use crate::mutex::Mutex;
use crate::println;
use crate::x86_64::context::unchecked_load_context;
use crate::x86_64::context::unchecked_switch_context;
use crate::x86_64::context::ExecutionContext;
Expand Down Expand Up @@ -52,7 +51,6 @@ impl ProcessContext {
let args_region = match args {
Some(args) => {
let args = serialize_args(args);
println!("Serialized args: {args:?}");
let mut args_region = ContiguousPhysicalMemoryPages::alloc_bytes(args.len())?;
args_region.fill_with_bytes(0);
args_region.as_mut_slice()[0..args.len()].copy_from_slice(&args);
Expand Down Expand Up @@ -114,9 +112,7 @@ impl Scheduler {
}
pub fn exit_current_process(&self) -> ! {
let to = {
crate::info!("lock the queue");
let mut queue = self.queue.lock();
crate::info!("queue lock held");
if queue.len() <= 1 {
// No process to switch
panic!("No more process to schedule!");
Expand All @@ -125,7 +121,6 @@ impl Scheduler {
.pop_front()
.expect("queue should have a process to exit");
from.exited.store(true, Ordering::SeqCst);
crate::info!("getting to");
let to = unsafe {
queue
.front_mut()
Expand All @@ -134,10 +129,8 @@ impl Scheduler {
.lock()
.as_mut_ptr()
};
crate::info!("got to");
to
};
crate::info!("Loading next context");
unsafe { unchecked_load_context(to) };
unreachable!("Nothing should come back here");
}
Expand Down
10 changes: 9 additions & 1 deletion os/src/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ fn sys_get_args_region(_args: &[u64; 5]) -> u64 {
}
}

/// sys_nslookup provides DNS resolution for applications.
/// As written in [RFC2606](https://datatracker.ietf.org/doc/html/rfc2606#section-2),
/// this function handles some hard-coded hostnames for testing purpose.
fn sys_nslookup(args: &[u64; 5]) -> i64 {
info!("sys_nslookup!");
let host = {
let host = args[0] as *const u8;
let len = args[1] as usize;
Expand All @@ -98,6 +100,12 @@ fn sys_nslookup(args: &[u64; 5]) -> i64 {
if host == "wasabitest.example.com" {
result[0] = [127, 0, 0, 1];
return 1;
} else if host == "host.test" {
// Host (=default gateway) in the QEMU user network.
// The host machine's exposed ports will be accessible via this address.
// It also responds to ICMP ping request.
result[0] = [10, 0, 2, 2];
return 1;
} else if host == "wasabitest.example.invalid" {
// c.f. https://www.rfc-editor.org/rfc/rfc6761.html
// > The domain "invalid." and any names falling within ".invalid." are special in the ways listed below.
Expand Down
1 change: 0 additions & 1 deletion os/src/x86_64/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ pub unsafe fn unchecked_switch_context(from: *mut ExecutionContext, to: *mut Exe
/// # Safety
/// `to` should be a valid ExecutionContext, and both contexts should not be locked on the call.
pub unsafe fn unchecked_load_context(to: *mut ExecutionContext) {
crate::info!("unchecked_load_context");
asm_restore_context(to as *mut u8);
}

Expand Down

0 comments on commit 7c8edb3

Please sign in to comment.