sel4_microkit_base

Macro memory_region_symbol

Source
macro_rules! memory_region_symbol {
    ($(#[$attrs:meta])* $symbol:ident: *mut [$ty:ty], n = $n:expr, bytes = $bytes:expr $(,)?) => { ... };
    ($(#[$attrs:meta])* $symbol:ident: *mut [$ty:ty], n = $n:expr $(,)?) => { ... };
    ($(#[$attrs:meta])* $symbol:ident: *mut $ty:ty, bytes = $bytes:expr $(,)?) => { ... };
    ($(#[$attrs:meta])* $symbol:ident: *mut $ty:ty $(,)?) => { ... };
}
Expand description

Declares a symbol via which the microkit tool can inject a memory region’s address, and returns the memory region’s address at runtime.

The patching mechanism used by the microkit tool requires that the symbol be allocated space in the protection domain’s ELF file, so we declare the symbol as part of the .data section.

For more detail, see this macro’s definition.

§Examples

let region_1 = unsafe {
    ExternallySharedRef::<'static, Foo>::new(
        memory_region_symbol!(region_1_addr: *mut Foo),
    )
};

let region_2 = unsafe {
    ExternallySharedRef::<'static, [u8]>::new_read_only(
        memory_region_symbol!(region_2_addr: *mut [u8], n = REGION_2_SIZE),
    )
};

§Note

The microkit tool requires memory region address symbols to be present in protection domain binaries. To prevent Rust from optimizing them out in cases where it is not used, add the unstable #[used(linker)] attribute. For example:

#![feature(used_with_arg)]

// might be optimized away if not used
memory_region_symbol!(region_addr: *mut Foo)

// won't be optimized away
memory_region_symbol! {
    #[used(linker)]
    region_addr: *mut Foo
}