userspace/memory/
stack.rs

1pub use crate::info;
2pub mod arguments;
3pub mod auxiliary;
4pub mod environment;
5
6// impl<A: ample::traits::Bytes<ample::Origin>> ample::traits::Bytes<crate::Origin, crate::Origin> for A {
7//     const BYTES_ALIGN: usize = A::BYTES_ALIGN;
8//     const BYTES_SIZE: usize = A::BYTES_SIZE;
9//     fn from_bytes(
10//         bytes: [u8; <Self as ample::traits::Bytes<crate::Origin, crate::Origin>>::BYTES_SIZE],
11//         endianness: bool,
12//     ) -> Self
13//     where
14//         Self: Sized,
15//         [u8; <Self as ample::traits::Bytes<crate::Origin, crate::Origin>>::BYTES_SIZE]:,
16//     {
17//         let crate_bytes = [0u8; <Self as ample::traits::Bytes<crate::Origin, crate::Origin>>::BYTES_SIZE];
18//         crate_bytes.copy_from_slice(<A as ample::traits::Bytes<ample::Origin>>::to_bytes(
19//             &self, endianness,
20//         ));
21//     }
22// }
23
24#[repr(u8)]
25#[derive(Debug, Clone, Copy)]
26pub enum Status {
27    Raw,
28    Modfied,
29}
30
31ample::r#struct!(
32    #[derive(Debug)]
33    pub struct ArgumentNode {
34        pub pointer: crate::target::arch::PointerType,
35        // pub string: ample::String,
36    }
37);
38
39ample::r#enum!(
40    u32;
41    #[derive(Debug, Clone, Copy)]
42    pub enum StackNode {
43        A(ArgumentNode) = 1,
44        B(()) = 2,
45    }
46);
47
48// pub type Stack = ample::list::LinkedList<crate::Origin,crate::memory::Origin, >
49
50#[repr(C)]
51#[derive(Debug)]
52pub struct Stack {
53    // pub meta: crate::target::arch::Pointer,
54    pub former: crate::target::arch::Pointer,
55    pub latter: crate::target::arch::Pointer,
56    // pub size: usize,
57    // pub size_modified: usize,
58    pub arguments: arguments::List,
59    pub environment: environment::List,
60    pub auxiliary: auxiliary::List,
61    pub status: Status,
62}
63
64impl Stack {
65    pub fn from_pointer(stack_pointer: crate::target::arch::Pointer) -> Self {
66        let (arguments, environment_pointer) = arguments::List::from_pointer(stack_pointer);
67        let (environment, auxiliary_pointer) = environment::List::from_pointer(environment_pointer);
68        let (auxiliary, latter_pointer) = auxiliary::List::from_pointer(auxiliary_pointer);
69        // let latter_pointer = auxiliary_pointer;
70        Self {
71            former: stack_pointer,
72            latter: latter_pointer,
73            arguments,
74            environment,
75            auxiliary,
76            status: Status::Raw,
77        }
78    }
79
80    pub fn current() -> Self {
81        Self::from_pointer(crate::target::arch::Pointer::current())
82    }
83
84    pub fn print(&self) {
85        info!("--- Stack Contents ---\n");
86        info!(
87            "pub struct Stack {{
88                pub former: crate::target::arch::Pointer = {:?},
89                pub latter: crate::target::arch::Pointer = {:?},
90                pub arguments: arguments::List = {:?},
91                pub status: Status = {:?},
92            }}\n",
93            self.former, self.latter, self.arguments, self.status,
94        );
95        self.arguments.print();
96        self.environment.print();
97        self.auxiliary.print();
98        info!("---------------------\n");
99    }
100}