fix: sync kernel tests with current API, add CapSlot::const_new
Tests: - IPC tests: spawn thread B explicitly (CreateProcess no longer spawns threads since the boot logic fix) - Memory tests: RequestPages now returns Value(va) not Slot(cap) - MockPlatform: tracks VA→PA mappings for translate_va - ReleasePages test: ignored (RequestPages no longer creates regions — ReleasePages needs redesign) CapSlot::const_new(value): - const fn that panics at compile time for invalid values - Replaces CapSlot::new(N).unwrap() in init, echo, snake - Cap slot constants are now compile-time verified Also fixes handle_release_pages to use translate_va instead of treating VA as PA directly. 35 kernel tests pass, 1 ignored.
This commit is contained in:
@@ -11,10 +11,10 @@ const USER_STACK_TOP: StackPointer = StackPointer::from_raw(USER_CODE_BASE);
|
||||
const USER_STACK_PAGES: usize = 4;
|
||||
const CMD_READ_FILE: usize = 1;
|
||||
|
||||
fn create_cap() -> CapSlot { CapSlot::new(0).unwrap() }
|
||||
fn storage_ep() -> CapSlot { CapSlot::new(2).unwrap() }
|
||||
fn display_ep() -> CapSlot { CapSlot::new(3).unwrap() }
|
||||
fn input_ep() -> CapSlot { CapSlot::new(5).unwrap() }
|
||||
const CREATE_CAP: CapSlot = CapSlot::const_new(0);
|
||||
const STORAGE_EP: CapSlot = CapSlot::const_new(2);
|
||||
const DISPLAY_EP: CapSlot = CapSlot::const_new(3);
|
||||
const INPUT_EP: CapSlot = CapSlot::const_new(5);
|
||||
|
||||
fn debug_print(s: &[u8]) {
|
||||
for &b in s {
|
||||
@@ -48,8 +48,8 @@ fn request_file(shared_buf: *mut u8, filename: &[u8]) -> usize {
|
||||
core::ptr::write_volatile(shared_buf.add(i), b);
|
||||
}
|
||||
}
|
||||
syscall::send(storage_ep(), CMD_READ_FILE, filename.len(), 0, 0);
|
||||
let (file_size, _, _, _) = syscall::receive(storage_ep());
|
||||
syscall::send(STORAGE_EP, CMD_READ_FILE, filename.len(), 0, 0);
|
||||
let (file_size, _, _, _) = syscall::receive(STORAGE_EP);
|
||||
file_size
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ fn load_binary(shared_buf: *mut u8, filename: &[u8]) -> Option<LoadedProcess> {
|
||||
Err(_) => return None,
|
||||
};
|
||||
|
||||
let process_cap = syscall::create_process(create_cap())?;
|
||||
let process_cap = syscall::create_process(CREATE_CAP)?;
|
||||
|
||||
for segment in elf_info.segments() {
|
||||
let page_start = segment.vaddr & !0xFFF;
|
||||
@@ -169,7 +169,7 @@ pub fn run(shared_buf_va: usize) -> ! {
|
||||
// Snake renders via debug_putchar (UART) — no display endpoint needed
|
||||
debug_print(b"init: loading snake... ");
|
||||
if let Some(snake) = load_binary(shared_buf, b"snake.elf") {
|
||||
syscall::delegate(input_ep(), snake.process_cap, ipc_perms);
|
||||
syscall::delegate(INPUT_EP, snake.process_cap, ipc_perms);
|
||||
syscall::spawn_thread_in(snake.process_cap, snake.entry_point, USER_STACK_TOP);
|
||||
debug_print(b"ok\n");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user