refactor: unsafe only in adapter + libkos; forbid(unsafe_code) everywhere else; libkos Window (volatile, bounds-checked MMIO/DMA/shared mem), entry!, thread::spawn; MapRegion returns pages; kernel const-built (with_cores/install_platform); newtype addrs

This commit is contained in:
2026-10-27 21:43:24 +01:00
parent 83809bbe94
commit 842d14987c
107 changed files with 771 additions and 647 deletions

View File

@@ -1,7 +1,7 @@
//! Pages and shared regions.
use super::{raw, slot_of, Result};
use types::address::VirtualAddress;
use types::address::{PhysicalAddress, VirtualAddress};
use types::bounded::{CapSlot, PageCount};
use types::mapping::PagePerms;
use types::syscall_abi::*;
@@ -43,9 +43,10 @@ pub fn create_region(pages: PageCount) -> Result<CapSlot> {
))
}
/// Maps the region behind `region` at `va`. The mapping lasts as long as
/// the capability: dropping or having it revoked unmaps it.
pub fn map_region(region: CapSlot, va: VirtualAddress, perms: PagePerms) -> Result<()> {
/// Maps the region behind `region` at `va`, returning how many pages that
/// is. The mapping lasts as long as the capability: dropping or having it
/// revoked unmaps it.
pub fn map_region(region: CapSlot, va: VirtualAddress, perms: PagePerms) -> Result<PageCount> {
let perms = match perms {
PagePerms::ReadOnly => PERMS_READ_ONLY,
PagePerms::ReadWrite => PERMS_READ_WRITE,
@@ -55,11 +56,14 @@ pub fn map_region(region: CapSlot, va: VirtualAddress, perms: PagePerms) -> Resu
SYS_MAP_REGION,
[region.value() as usize, va.raw(), perms, 0, 0, 0],
)
.map(|_| ())
.and_then(|r| {
let pages = u16::try_from(r[1]).ok().and_then(PageCount::new);
pages.ok_or(super::Error::InvalidArgument)
})
}
/// The physical base of the region behind `region`, for programming a
/// device's DMA. Pool regions are physically contiguous.
pub fn region_address(region: CapSlot) -> Result<usize> {
raw(SYS_REGION_ADDRESS, [region.value() as usize, 0, 0, 0, 0, 0]).map(|r| r[1])
pub fn region_address(region: CapSlot) -> Result<PhysicalAddress> {
raw(SYS_REGION_ADDRESS, [region.value() as usize, 0, 0, 0, 0, 0]).map(|r| PhysicalAddress::from_raw(r[1]))
}