Skip to content

Commit

Permalink
Pipe weakly typed slots collections into self-hosted process
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackPierce committed Jul 9, 2019
1 parent e041976 commit 60ccc39
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 31 deletions.
6 changes: 2 additions & 4 deletions qemu-test/test-project/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ extern crate selfe_sys;
#[macro_use]
extern crate typenum;

use selfe_sys::*;

mod call_and_response_loop;
mod child_process_cap_management;
mod child_process_runs;
Expand Down Expand Up @@ -75,11 +73,11 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
}

#[cfg(test_case = "uart")]
pub fn run(raw_boot_info: &'static seL4_BootInfo) {
pub fn run(raw_boot_info: &'static selfe_sys::seL4_BootInfo) {
uart::run(raw_boot_info).expect("run");
unsafe {
loop {
seL4_Yield();
selfe_sys::seL4_Yield();
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions qemu-test/test-project/src/self_hosted_mem_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn self_hosted_mem_mgmt(
let ut12: LocalCap<Untyped<U12>> = ut;

smart_alloc! {|slots_c: child_slots| {
let cap_transfer_slots = slots_c;
let cap_transfer_slots: LocalCap<CNodeSlotsData<U1024, role::Child>> = slots_c;
let (cnode_for_child, slots_for_child):(_, ChildCap<CNodeSlotsData<U2048, role::Child>>) =
child_cnode.generate_self_reference(&root_cnode, slots_c)?;
let child_ut12 = ut12.move_to_slot(&root_cnode, slots_c)?;
Expand All @@ -42,7 +42,8 @@ pub fn self_hosted_mem_mgmt(
)?;
}}

let (child_paging_slots, slots_for_child) = slots_for_child.alloc();
let (child_paging_slots, slots_for_child): (Cap<CNodeSlotsData<U1024, _>, _>, _) =
slots_for_child.alloc();
let (exact_child_slots, _) = slots_for_child.alloc();

let params = ProcParams {
Expand Down Expand Up @@ -78,8 +79,8 @@ pub fn self_hosted_mem_mgmt(
ut,
ut,
slots,
cap_transfer_slots,
child_paging_slots,
cap_transfer_slots.weaken(),
child_paging_slots.weaken(),
tpa,
Some(fault_source),
)?;
Expand Down
25 changes: 22 additions & 3 deletions src/cap/cnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ pub enum CNodeSlotsError {
NotEnoughSlots,
}

impl WCNodeSlots {
impl<Role: CNodeRole> LocalCap<WCNodeSlotsData<Role>> {
/// Split the WCNodeSlots(original_size) into (WCNodeSlots(count), WCNodeSlots(original_size - count))
/// Peel off a single cptr from these slots. Advance the state.
pub(crate) fn alloc(&mut self, count: usize) -> Result<WCNodeSlots, CNodeSlotsError> {
pub(crate) fn alloc(
&mut self,
count: usize,
) -> Result<LocalCap<WCNodeSlotsData<Role>>, CNodeSlotsError> {
if count > self.cap_data.size {
return Err(CNodeSlotsError::NotEnoughSlots);
}
Expand All @@ -230,6 +232,23 @@ impl WCNodeSlots {
})
}

pub(crate) fn alloc_single(
&mut self,
) -> Result<LocalCap<CNodeSlotsData<U1, Role>>, CNodeSlotsError> {
let single = self.alloc(1)?;
Ok(Cap {
cptr: single.cptr,
cap_data: CNodeSlotsData {
offset: single.cap_data.offset,
_size: PhantomData,
_role: PhantomData,
},
_role: PhantomData,
})
}
}

impl WCNodeSlots {
pub(crate) fn into_strong_iter(self) -> impl Iterator<Item = LocalCNodeSlot> {
(0..self.cap_data.size).map(move |n| Cap {
cptr: self.cptr,
Expand Down
4 changes: 2 additions & 2 deletions src/cap/fault_reply_endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::arch;
use crate::cap::{CNodeSlotsData, Cap, CapType, LocalCNodeSlot, LocalCap, PhantomCap};
use crate::error::{ErrorExt, KernelError, SeL4Error};
use crate::cap::{CNodeSlotsData, Cap, CapType, LocalCNodeSlot, LocalCap};
use crate::error::{ErrorExt, KernelError};
use core::marker::PhantomData;
use selfe_sys::*;
use typenum::*;
Expand Down
1 change: 0 additions & 1 deletion src/cap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ mod tcb;
mod untyped;

pub use asid_pool::*;
pub(crate) use asid_pool::*;
pub use badge::*;
pub use cnode::*;
pub use endpoint::*;
Expand Down
2 changes: 0 additions & 2 deletions src/cap/notification.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use typenum::*;

use selfe_sys::*;

use crate::cap::{Badge, CapType, CopyAliasable, DirectRetype, LocalCap, Mintable, PhantomCap};
Expand Down
2 changes: 0 additions & 2 deletions src/cap/tcb.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use typenum::*;

use selfe_sys::*;

use crate::arch::cap::{page_state, Page};
Expand Down
1 change: 1 addition & 0 deletions src/userland/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn yield_forever() -> ! {
pub enum ProcessSetupError {
ProcessParameterTooBigForStack,
ProcessParameterHandoffSizeMismatch,
NotEnoughCNodeSlots,
VSpaceError(VSpaceError),
SeL4Error(SeL4Error),
}
Expand Down
18 changes: 9 additions & 9 deletions src/userland/process/self_hosted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use selfe_sys::*;

use crate::arch::{self, PageBits};
use crate::cap::{
role, CNodeRole, CNodeSlotsData, Cap, ChildCNode, DirectRetype, LocalCNode, LocalCNodeSlots,
LocalCap, ThreadControlBlock, ThreadPriorityAuthority, Untyped,
role, CNodeRole, CNodeSlotsError, Cap, ChildCNode, DirectRetype, LocalCNode, LocalCNodeSlots,
LocalCap, ThreadControlBlock, ThreadPriorityAuthority, Untyped, WCNodeSlotsData,
};
use crate::userland::CapRights;
use crate::vspace::*;
Expand Down Expand Up @@ -42,8 +42,8 @@ impl SelfHostedProcess {
ipc_buffer_ut: LocalCap<Untyped<PageBits>>,
tcb_ut: LocalCap<Untyped<<ThreadControlBlock as DirectRetype>::SizeBits>>,
slots: LocalCNodeSlots<PrepareThreadCNodeSlots>,
cap_transfer_slots: LocalCap<CNodeSlotsData<U1024, role::Child>>,
child_paging_slots: Cap<CNodeSlotsData<U1024, role::Child>, role::Child>,
mut cap_transfer_slots: LocalCap<WCNodeSlotsData<role::Child>>,
mut child_paging_slots: Cap<WCNodeSlotsData<role::Child>, role::Child>,
priority_authority: &LocalCap<ThreadPriorityAuthority>,
fault_source: Option<crate::userland::FaultSource<role::Child>>,
) -> Result<Self, ProcessSetupError> {
Expand Down Expand Up @@ -93,14 +93,14 @@ impl SelfHostedProcess {
// Reserve a guard page after the stack.
vspace.skip_pages(1)?;

// TODO - consider whether to make the user-facing params already of the Weak-type
// and leave the sizing decisions to the caller
let (root_slot, cap_transfer_slots) = cap_transfer_slots.alloc();
let root_slot = cap_transfer_slots.alloc_single().map_err(|e| match e {
CNodeSlotsError::NotEnoughSlots => ProcessSetupError::NotEnoughCNodeSlots,
})?;
let child_vspace = vspace.for_child(
parent_cnode,
root_slot,
cap_transfer_slots.weaken(),
child_paging_slots.weaken(),
cap_transfer_slots,
child_paging_slots,
)?;

let sh_params = SelfHostedParams {
Expand Down
8 changes: 4 additions & 4 deletions src/vspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use crate::arch::cap::{page_state, AssignedASID, Page, UnassignedASID};
use crate::arch::{self, AddressSpace, PageBits, PageBytes, PagingRoot};
use crate::bootstrap::UserImage;
use crate::cap::{
role, CNodeRole, CNodeSlots, CNodeSlotsData, Cap, CapRange, CapType, ChildCNodeSlot,
DirectRetype, InternalASID, LocalCNode, LocalCNodeSlots, LocalCap, PhantomCap, RetypeError,
Untyped, WCNodeSlots, WCNodeSlotsData, WUntyped,
role, CNodeRole, CNodeSlots, Cap, CapRange, CapType, ChildCNodeSlot, DirectRetype,
InternalASID, LocalCNode, LocalCNodeSlots, LocalCap, PhantomCap, RetypeError, Untyped,
WCNodeSlots, WCNodeSlotsData, WUntyped,
};
use crate::error::SeL4Error;
use crate::pow::{Pow, _Pow};
Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl VSpace<vspace_state::Imaged> {
layers,
next_addr,
untyped,
slots,
slots: _,
#[cfg(feature = "vspace_map_region_at_addr")]
specific_regions,
..
Expand Down

0 comments on commit 60ccc39

Please sign in to comment.