refactor(init): replace raw usize with CapSlot, StorageHandle, PhysicalAddress newtypes throughout supervisor and boot

This commit is contained in:
2026-10-18 03:54:07 +02:00
parent 0a2e01bec9
commit f72a434e1a
4 changed files with 63 additions and 53 deletions

View File

@@ -1,47 +1,44 @@
pub fn storage_open(storage_ep: usize, path: &[u8]) -> usize {
use types::bounded::CapSlot;
#[derive(Debug, Clone, Copy)]
pub struct StorageHandle(u16);
impl StorageHandle {
pub fn raw(&self) -> u16 { self.0 }
}
fn pack_path(path: &[u8]) -> (usize, usize) {
let mut w0 = [0u8; 8];
let mut w1 = [0u8; 8];
for (i, &b) in path.iter().enumerate() {
if i < 8 { w0[i] = b; }
else if i < 16 { w1[i - 8] = b; }
}
// StorageRequest::Open tag = 0
let (r0, _, _, _) = userspace::syscall::receive(storage_ep);
let _ = userspace::syscall::send(
storage_ep,
0, // Open tag
usize::from_le_bytes(w0),
usize::from_le_bytes(w1),
0,
);
// Response: Handle(h) has tag 0, handle in word 1
let (tag, handle, _, _) = userspace::syscall::receive(storage_ep);
if tag == 0 { handle } else { usize::MAX }
(usize::from_le_bytes(w0), usize::from_le_bytes(w1))
}
pub fn storage_close(storage_ep: usize, handle: usize) {
let _ = userspace::syscall::send(
storage_ep,
3, // Close tag
handle,
0,
0,
);
}
pub fn storage_write_binary(storage_ep: usize, path: &[u8], _binary: &[u8]) {
let mut w0 = [0u8; 8];
let mut w1 = [0u8; 8];
for (i, &b) in path.iter().enumerate() {
if i < 8 { w0[i] = b; }
else if i < 16 { w1[i - 8] = b; }
pub fn storage_open(endpoint: CapSlot, path: &[u8]) -> Option<StorageHandle> {
let (w0, w1) = pack_path(path);
let _ = userspace::syscall::send(endpoint.value() as usize, 0, w0, w1, 0);
let (tag, handle, _, _) = userspace::syscall::receive(endpoint.value() as usize);
if tag == 0 {
Some(StorageHandle(handle as u16))
} else {
None
}
// Create file
}
pub fn storage_close(endpoint: CapSlot, handle: StorageHandle) {
let _ = userspace::syscall::send(
storage_ep,
5, // Create tag
usize::from_le_bytes(w0),
usize::from_le_bytes(w1),
endpoint.value() as usize,
3,
handle.raw() as usize,
0,
0,
);
}
pub fn storage_write_binary(endpoint: CapSlot, path: &[u8], _binary: &[u8]) {
let (w0, w1) = pack_path(path);
let _ = userspace::syscall::send(endpoint.value() as usize, 5, w0, w1, 0);
}