cantrip: cleanups for wrapping in a module
Enable including the generated code wrapped in a module; e.g.
mod generated {
include!(concat!(env!("SEL4_OUT_DIR"), "/../mailbox_driver/camkes.rs"));
}
use generated::*;
While here fix some compiler/clippy complaints (e.g. unneeded unsafe).
Bug: 283167860
Change-Id: Idb0f5fa9b8927382ef2688fa5bd79720187e06b6
diff --git a/camkes/templates/cantripIRQ.template.rs b/camkes/templates/cantripIRQ.template.rs
index ca02889..8fa6d6f 100644
--- a/camkes/templates/cantripIRQ.template.rs
+++ b/camkes/templates/cantripIRQ.template.rs
@@ -134,7 +134,7 @@
/*- set ntfn_obj = alloc_obj('ntfn', seL4_NotificationObject) -*/
/*- set root_ntfn = alloc_cap('ntfn', ntfn_obj, read=True) -*/
-const /*? ntfn_prefix ?*/_NOTIFICATION: sel4_sys::seL4_CPtr = /*? root_ntfn ?*/;
+pub const /*? ntfn_prefix ?*/_NOTIFICATION: sel4_sys::seL4_CPtr = /*? root_ntfn ?*/;
/*- for (i, end) in enumerate(me.parent.from_ends) -*/
/*- set irq_prefix = end.interface.name.upper() -*/
diff --git a/camkes/templates/cantripMMIO.template.rs b/camkes/templates/cantripMMIO.template.rs
index e06aab9..b533731 100644
--- a/camkes/templates/cantripMMIO.template.rs
+++ b/camkes/templates/cantripMMIO.template.rs
@@ -32,6 +32,7 @@
/*- set dataport_symbol_name = "%s" % me.interface.name.upper() -*/
/*- set dataport_symbol_size = "%s_SIZE" % me.interface.name.upper() -*/
const /*? dataport_symbol_size ?*/: usize = round_up(/*? macros.dataport_size(me.interface.type, language='rust') ?*/, /*? page_size ?*/);
+#[allow(clippy::upper_case_acronyms)]
#[repr(C, align(/*? page_size ?*/))]
pub struct /*? dataport_symbol_name ?*/ {
pub data: [u8; /*? dataport_symbol_size ?*/],
@@ -58,5 +59,5 @@
];
#[no_mangle]
pub fn get_/*? me.interface.name.lower() ?*/_caps() -> &'static [sel4_sys::seL4_CPtr] {
- unsafe { &/*? dataport_symbol_name ?*/_CAPS[..] }
+ &/*? dataport_symbol_name ?*/_CAPS[..]
}
diff --git a/camkes/templates/component.common.rs b/camkes/templates/component.common.rs
index e811baf..3073d85 100644
--- a/camkes/templates/component.common.rs
+++ b/camkes/templates/component.common.rs
@@ -7,13 +7,13 @@
/*#
*# CantripOS support.
#*/
-use crate::baresema::*;
use crate::camkes::*;
+use crate::camkes::baresema::*;
#[allow(unused_imports)]
-use crate::irq::*;
+use crate::camkes::irq::*;
#[allow(unused_imports)]
-use crate::semaphore::*;
-use crate::startup::*;
+use crate::camkes::semaphore::*;
+use crate::camkes::startup::*;
const fn round_up(a: usize, b: usize) -> usize { ((a + b - 1) / b) * b }
@@ -66,8 +66,8 @@
#[no_mangle]
pub static /*? bootinfo_symbol ?*/: /*? bootinfo_struct ?*/ = /*? bootinfo_struct ?*/ { data: [0u8; /*? page_size ?*/] } ;
#[no_mangle]
- pub fn get_bootinfo() -> &'static seL4_BootInfo {
- unsafe { &*(ptr::addr_of!(/*? bootinfo_symbol ?*/.data[0]) as *const seL4_BootInfo) }
+ pub fn get_bootinfo() -> &'static sel4_sys::seL4_BootInfo {
+ unsafe { &*(core::ptr::addr_of!(/*? bootinfo_symbol ?*/.data[0]) as *const sel4_sys::seL4_BootInfo) }
}
/*? register_shared_variable(bootinfo_symbol, bootinfo_symbol, page_size, frame_size=page_size, perm='R', language='rust') ?*/
/*- do register_fill_frame(bootinfo_symbol, 'CDL_FrameFill_BootInfo CDL_FrameFill_BootInfo_BootInfo', page_size) -*/
@@ -132,6 +132,7 @@
/*- endfor -*/
// Dataports
+#[allow(dead_code)]
pub type Buf = [u8; 4096];
/*- for dataport in me.type.dataports -*/
/*- set include_code = macros.include_code(composition, me, dataport) -*/
@@ -350,11 +351,11 @@
match thread_id {
/*- for t in threads -*/
/*- if loop.first -*/
- SELF_TCB_CONTROL => /*? me.name.title().replace('_', '') ?*/ControlThread::start(thread),
+ SELF_TCB_CONTROL => crate::/*? me.name.title().replace('_', '') ?*/ControlThread::start(thread),
/*- elif options.debug_fault_handlers and loop.last -*/
- SELF_TCB_FAULT_HANDLER => /*? me.name.title().replace('_', '') ?*/FaultHandlerThread::start(thread),
+ SELF_TCB_FAULT_HANDLER => crate::/*? me.name.title().replace('_', '') ?*/FaultHandlerThread::start(thread),
/*- else -*/
- SELF_TCB_/*? t.interface.name.upper() ?*/ => /*? t.interface.name.title().replace('_', '') ?*/InterfaceThread::start(thread),
+ SELF_TCB_/*? t.interface.name.upper() ?*/ => crate::/*? t.interface.name.title().replace('_', '') ?*/InterfaceThread::start(thread),
/*- endif -*/
/*- endfor -*/
_ => unreachable!(),
diff --git a/camkes/templates/macros.py b/camkes/templates/macros.py
index 72ef7d2..215e1a8 100644
--- a/camkes/templates/macros.py
+++ b/camkes/templates/macros.py
@@ -44,15 +44,16 @@
if language == 'rust':
page_size_bits = int(math.log(PAGE_SIZE, 2))
return '''
-const %(sym)s_STACK_SIZE: usize = round_up(%(size)s, %(page_size)s) + (2 * %(page_size)s);
+const %(size_sym)s: usize = round_up(%(size)s, %(page_size)s) + (2 * %(page_size)s);
+#[allow(non_upper_case_globals)]
#[repr(C, align(%(page_size)s))]
struct %(sym)s {
- pub data: [u8; %(sym)s_STACK_SIZE],
+ pub data: [u8; %(size_sym)s],
}
#[link_section = "align_%(page_size_bits)sbit"]
#[no_mangle]
-static mut %(sym)s: %(sym)s = %(sym)s { data: [0u8; %(sym)s_STACK_SIZE] };
-''' % {"sym": sym, "size": size, "page_size": PAGE_SIZE, "page_size_bits": 12}
+static mut %(sym)s: %(sym)s = %(sym)s { data: [0u8; %(size_sym)s] };
+''' % {"sym": sym, "size_sym": sym.upper() + "_STACK_SIZE", "size": size, "page_size": PAGE_SIZE, "page_size_bits": 12}
elif language == 'c':
return 'char %s[ROUND_UP_UNSAFE(%d, ' \
'PAGE_SIZE_4K) + PAGE_SIZE_4K * 2]\n' \
@@ -67,6 +68,7 @@
if language == 'rust':
page_size_bits = int(math.log(PAGE_SIZE, 2))
return '''
+#[allow(non_upper_case_globals)]
#[repr(C, align(%(page_size)s))]
struct %(sym)s {
pub data: [u8; %(page_size)s * 3],
@@ -97,6 +99,7 @@
page_size_bits = int(math.log(page_size, 2))
if language == 'rust':
return '''
+#[allow(non_upper_case_globals)]
#[repr(C, align(%(page_size)s))]
pub struct %(sym)s {
pub data: [u8; %(shmem_size)s],