1use crate::{HEADER_SIZE, SECTION_SIZE};
3
4#[repr(C)]
6#[derive(Debug, Clone, Copy)]
7pub struct Section {
8 pub name: [u8; 16],
10
11 pub is_loadable: bool,
13
14 pub is_execable: bool,
16
17 pub base: u32,
19
20 pub length: u32,
22}
23
24impl Section {
25 #[inline]
27 pub const fn to_array(&self) -> [u8; SECTION_SIZE] {
28 unsafe { core::ptr::read(self as *const Self as *const [u8; SECTION_SIZE]) }
30 }
31
32 #[inline]
34 pub fn validate(&self) -> bool {
35 let is_aligned = (self.base & 0xfff) == 0;
37
38 let is_correct_group = if self.is_execable && !self.is_loadable {
40 false
41 } else {
42 true
43 };
44
45 is_aligned || is_correct_group
46 }
47}
48
49#[derive(Debug, Clone, Copy)]
51pub(crate) struct SectionIter {
52 pub buf: &'static [u8],
53 pub total: u16,
54 pub current: u16,
55}
56
57impl Iterator for SectionIter {
59 type Item = Section;
60
61 fn next(&mut self) -> Option<Self::Item> {
62 let base = HEADER_SIZE + self.current as usize * SECTION_SIZE;
63 let buf = &self.buf[base..base + SECTION_SIZE];
64
65 if self.current >= self.total {
67 return None;
68 }
69
70 let section = unsafe { *(buf.as_ptr() as *const Section) };
72 Some(section)
73 }
74}