Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API clarity and docs #207

Merged
merged 18 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {

untyped.with(&mut ipc_buffer).untyped_retype(
&blueprint,
&cnode.relative_self(),
&cnode.absolute_cptr_for_self(),
unbadged_notification_slot.index(),
1,
)?;
Expand All @@ -46,9 +46,9 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {

cnode
.with(&mut ipc_buffer)
.relative(badged_notification_slot.cptr())
.absolute_cptr(badged_notification_slot.cptr())
.mint(
&cnode.relative(unbadged_notification_slot.cptr()),
&cnode.absolute_cptr(unbadged_notification_slot.cptr()),
sel4::CapRights::write_only(),
badge,
)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/examples/root-task/example-root-task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {

untyped.untyped_retype(
&blueprint,
&cnode.relative_self(),
&cnode.absolute_cptr_for_self(),
unbadged_notification_slot.index(),
1,
)?;

let badge = 0x1337;

cnode.relative(badged_notification_slot.cptr()).mint(
&cnode.relative(unbadged_notification_slot.cptr()),
cnode.absolute_cptr(badged_notification_slot.cptr()).mint(
&cnode.absolute_cptr(unbadged_notification_slot.cptr()),
sel4::CapRights::write_only(),
badge,
)?;
Expand Down
22 changes: 14 additions & 8 deletions crates/examples/root-task/serial-device/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
SERIAL_DEVICE_IRQ.try_into().unwrap(),
&sel4::init_thread::slot::CNODE
.cap()
.relative(irq_handler_cap),
.absolute_cptr(irq_handler_cap),
)
.unwrap();

Expand All @@ -53,7 +53,9 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
kernel_ut
.untyped_retype(
&sel4::ObjectBlueprint::Notification,
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
irq_notification_slot.index(),
1,
)
Expand Down Expand Up @@ -95,7 +97,9 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
device_ut_cap
.untyped_retype(
&sel4::cap_type::Granule::object_blueprint(),
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
serial_device_frame_slot.index(),
1,
)
Expand Down Expand Up @@ -161,16 +165,18 @@ fn trim_untyped(
) {
let rel_a = sel4::init_thread::slot::CNODE
.cap()
.relative(free_slot_a.cptr());
.absolute_cptr(free_slot_a.cptr());
let rel_b = sel4::init_thread::slot::CNODE
.cap()
.relative(free_slot_b.cptr());
.absolute_cptr(free_slot_b.cptr());
let mut cur_paddr = ut_paddr;
while cur_paddr != target_paddr {
let size_bits = (target_paddr - cur_paddr).ilog2().try_into().unwrap();
ut.untyped_retype(
&sel4::ObjectBlueprint::Untyped { size_bits },
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
free_slot_b.index(),
1,
)
Expand All @@ -184,9 +190,9 @@ fn trim_untyped(
// // //

#[repr(C, align(4096))]
struct FreePagePlaceHolder(#[allow(dead_code)] [u8; GRANULE_SIZE]);
struct FreePagePlaceholder(#[allow(dead_code)] [u8; GRANULE_SIZE]);

static mut FREE_PAGE_PLACEHOLDER: FreePagePlaceHolder = FreePagePlaceHolder([0; GRANULE_SIZE]);
static mut FREE_PAGE_PLACEHOLDER: FreePagePlaceholder = FreePagePlaceholder([0; GRANULE_SIZE]);

fn init_free_page_addr(bootinfo: &sel4::BootInfo) -> usize {
let addr = ptr::addr_of!(FREE_PAGE_PLACEHOLDER) as usize;
Expand Down
14 changes: 8 additions & 6 deletions crates/examples/root-task/spawn-task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
object_allocator.allocate_variable_sized::<sel4::cap_type::CNode>(child_cnode_size_bits);

child_cnode
.relative_bits_with_depth(1, child_cnode_size_bits)
.absolute_cptr_from_bits_with_depth(1, child_cnode_size_bits)
.mint(
&sel4::init_thread::slot::CNODE
.cap()
.relative(inter_task_nfn),
.absolute_cptr(inter_task_nfn),
sel4::CapRights::write_only(),
0,
)
Expand All @@ -73,9 +73,11 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
.unwrap();

child_cnode
.relative_bits_with_depth(2, child_cnode_size_bits)
.absolute_cptr_from_bits_with_depth(2, child_cnode_size_bits)
.mint(
&sel4::init_thread::slot::CNODE.cap().relative(child_tcb),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr(child_tcb),
sel4::CapRights::all(),
0,
)
Expand All @@ -95,9 +97,9 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result<Never> {
// // //

#[repr(C, align(4096))]
struct FreePagePlaceHolder(#[allow(dead_code)] [u8; GRANULE_SIZE]);
struct FreePagePlaceholder(#[allow(dead_code)] [u8; GRANULE_SIZE]);

static mut FREE_PAGE_PLACEHOLDER: FreePagePlaceHolder = FreePagePlaceHolder([0; GRANULE_SIZE]);
static mut FREE_PAGE_PLACEHOLDER: FreePagePlaceholder = FreePagePlaceholder([0; GRANULE_SIZE]);

fn init_free_page_addr(bootinfo: &sel4::BootInfo) -> usize {
let addr = ptr::addr_of!(FREE_PAGE_PLACEHOLDER) as usize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ impl ObjectAllocator {
self.ut
.untyped_retype(
&blueprint,
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
slot_index,
1,
)
Expand Down
8 changes: 6 additions & 2 deletions crates/examples/root-task/spawn-thread/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl ObjectAllocator {
self.ut
.untyped_retype(
&T::object_blueprint(),
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
slot_index,
1,
)
Expand All @@ -108,7 +110,9 @@ impl ObjectAllocator {
self.ut
.untyped_retype(
&T::object_blueprint(size_bits),
&sel4::init_thread::slot::CNODE.cap().relative_self(),
&sel4::init_thread::slot::CNODE
.cap()
.absolute_cptr_for_self(),
slot_index,
1,
)
Expand Down
8 changes: 4 additions & 4 deletions crates/sel4-capdl-initializer/core/src/hold_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub(crate) struct HoldSlots<T> {
slots: [Slot; NUM_SLOTS],
slots_occupied: [bool; NUM_SLOTS],
which_slot: usize,
relative_cptr_of: T,
absolute_cptr_of: T,
}

impl<T> HoldSlots<T> {
pub(crate) fn new(
cslot_allocator: &mut CSlotAllocator,
relative_cptr_of: T,
absolute_cptr_of: T,
) -> Result<Self, CapDLInitializerError> {
Ok(Self {
slots: {
Expand All @@ -30,15 +30,15 @@ impl<T> HoldSlots<T> {
},
slots_occupied: [false; NUM_SLOTS],
which_slot: 0,
relative_cptr_of,
absolute_cptr_of,
})
}
}

impl<T: FnMut(Slot) -> AbsoluteCPtr> HoldSlots<T> {
pub(crate) fn get_slot(&mut self) -> Result<Slot, CapDLInitializerError> {
if self.slots_occupied[self.which_slot] {
(self.relative_cptr_of)(self.slots[self.which_slot]).delete()?;
(self.absolute_cptr_of)(self.slots[self.which_slot]).delete()?;
self.slots_occupied[self.which_slot] = false;
}
Ok(self.slots[self.which_slot])
Expand Down
Loading
Loading