islet-project/islet

Insert autopadding

Closed this issue · 1 comments

Automatically insert padding fields in a structure that is made up of fields that must be placed at specific locations.
Where those are used in RMM: mostly to communicate with the host hypervisor in normal world and the RMM in realm world.
for example,

    pub struct Params {
    0x0    pub features_0: u64,
    0x100  pub hash_algo: u8,
    0x400  pub rpv: [u8; 64],
    0x800  pub vmid: u16,
    0x808  pub rtt_base: u64,
    0x810  pub rtt_level_start: i64,
    0x818  pub rtt_num_start: u32,

Defined pad_struct macro.

Struct definition:

pad_struct!(
pub struct Params {
    0x0    pub features_0: u64,    // [offset]  [visibility] [identifier]: [type],
    0x100  pub hash_algo: u8,
    0x400  pub rpv: [u8; 64],
    0x800  pub vmid: u16,
    0x808  pub rtt_base: u64,
    0x810  pub rtt_level_start: i64,
    0x818  pub rtt_num_start: u32,
    0x1000 => @END,   // to sepecify the end of the struct
}
);

Drawback of Struct intialization:

  1. we still need to know the size of the padding.
  2. Unnecessary zero-sized paddings are inserted.
impl Default for Params {
    fn default() -> Self {
        Self {
            features_0: 0,
            _padfeatures_0: [0; 248],
            hash_algo: 0,
            _padhash_algo: [0; 767],
            rpv: [0; 64],
            _padrpv: [0; 960],
            vmid: 0,
            _padvmid: [0; 6],
            rtt_base: 0,
            _padrtt_base: [0; 0],
            rtt_level_start: 0,
            _padrtt_level_start: [0; 0],
            rtt_num_start: 0,
            _padrtt_num_start: [0; 2020],
        }
    }
}

Please feel free to directly modify the code in dev/autopadding.