tg_rcore_tutorial_linker/
app.rs1#[repr(C)]
6pub struct AppMeta {
7 base: u64,
8 step: u64,
9 count: u64,
10 first: u64,
11}
12
13impl AppMeta {
14 #[inline]
18 pub fn locate() -> &'static Self {
19 unsafe extern "C" {
20 static apps: AppMeta;
21 }
22 unsafe { &apps }
25 }
26
27 #[inline]
29 pub fn iter(&'static self) -> AppIterator {
30 AppIterator { meta: self, i: 0 }
32 }
33}
34
35pub struct AppIterator {
37 meta: &'static AppMeta,
38 i: u64,
39}
40
41impl Iterator for AppIterator {
42 type Item = &'static [u8];
43
44 fn next(&mut self) -> Option<Self::Item> {
45 if self.i >= self.meta.count {
46 None
47 } else {
48 let i = self.i as usize;
49 self.i += 1;
50 unsafe {
55 let slice = core::slice::from_raw_parts(
56 &self.meta.first as *const _ as *const usize,
57 (self.meta.count + 1) as _,
58 );
59 let pos = slice[i];
60 let size = slice[i + 1] - pos;
61 let base = self.meta.base as usize + i * self.meta.step as usize;
62 if base != 0 {
63 core::ptr::copy_nonoverlapping::<u8>(pos as _, base as _, size);
67 core::slice::from_raw_parts_mut(base as *mut u8, 0x20_0000)[size..].fill(0);
69 Some(core::slice::from_raw_parts(base as _, size))
70 } else {
71 Some(core::slice::from_raw_parts(pos as _, size))
72 }
73 }
74 }
75 }
76}