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:
@@ -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]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user