refactor: apply newtypes throughout userspace API and display types
Every syscall stub now uses proper types from types/ — CapSlot,
EntryPoint, StackPointer, VirtualAddress, PageCount, ProcessId,
PermissionSet, Ticks. The compiler prevents swapping entry/stack,
passing a ProcessId where a CapSlot is expected, or using an
address as a page count.
New display types in types/display.rs:
- Color(u32) with rgb() constructor
- ScreenCoord(u16) for x/y positions
- Dimension(u16) for width/height
Updated throughout:
- userspace/syscall.rs: all params typed, returns Option instead
of sentinel usize::MAX
- server-framework: endpoint param is CapSlot
- port-framebuffer: trait uses Color, ScreenCoord, Dimension
- hw-virtio: DmaAddrs uses PhysicalAddress/VirtualAddress,
GPU commands use Dimension
- All servers, drivers, bins, apps updated for new signatures
- permission-manager: process field uses ProcessId
- PermissionSet: added bits() accessor
89 tests pass, full QEMU boot verified.
This commit is contained in:
36
crates/types/src/display.rs
Normal file
36
crates/types/src/display.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Color(u32);
|
||||
|
||||
impl Color {
|
||||
pub const fn from_raw(v: u32) -> Self { Self(v) }
|
||||
pub const fn raw(&self) -> u32 { self.0 }
|
||||
|
||||
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
|
||||
Self(((r as u32) << 16) | ((g as u32) << 8) | (b as u32) | 0xFF000000)
|
||||
}
|
||||
|
||||
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
|
||||
Self(((a as u32) << 24) | ((r as u32) << 16) | ((g as u32) << 8) | (b as u32))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct ScreenCoord(u16);
|
||||
|
||||
impl ScreenCoord {
|
||||
pub const fn new(v: u16) -> Self { Self(v) }
|
||||
pub const fn raw(&self) -> u16 { self.0 }
|
||||
}
|
||||
|
||||
impl core::ops::Add<Dimension> for ScreenCoord {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Dimension) -> Self { Self(self.0 + rhs.0) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Dimension(u16);
|
||||
|
||||
impl Dimension {
|
||||
pub const fn new(v: u16) -> Self { Self(v) }
|
||||
pub const fn raw(&self) -> u16 { self.0 }
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
pub mod address;
|
||||
pub mod bounded;
|
||||
pub mod display;
|
||||
pub mod generation;
|
||||
pub mod id;
|
||||
pub mod macros;
|
||||
|
||||
@@ -44,4 +44,8 @@ impl PermissionSet {
|
||||
pub fn from_bits(bits: u8) -> Self {
|
||||
PermissionSet(bits)
|
||||
}
|
||||
|
||||
pub fn bits(&self) -> u8 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user