Skip to main content

userspace_build/memory/stack/arguments/
entry.rs

1ample::r#struct!(
2    #[repr(C)]
3    pub struct Entry {
4        pub prev: *mut Entry,
5        pub next: *mut Entry,
6        pub pointer: crate::target::arch::Pointer, // armazenar o ponteiro cru
7    }
8);
9
10impl Entry {
11    pub fn from_pointer(pointer: crate::target::arch::Pointer) -> Entry {
12        Entry {
13            prev: core::ptr::null_mut(),
14            next: core::ptr::null_mut(),
15            pointer: pointer,
16        }
17    }
18}
19
20impl crate::memory::stack::list::LinkedEntry for Entry {
21    fn set_links(&mut self, previous: *mut Self, next: *mut Self) {
22        self.prev = previous;
23        self.next = next;
24    }
25}
26
27impl core::fmt::Debug for Entry {
28    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
29        unsafe {
30            let _cstr = self.pointer.0;
31
32            let _ = write!(f, "Entry: {{ ");
33
34            let cstr_ptr = self.pointer.0 as *mut i8;
35            if !cstr_ptr.is_null() {
36                let cstr = core::ffi::CStr::from_ptr(cstr_ptr);
37                if let Ok(str_slice) = cstr.to_str() {
38                    let _ = write!(f, "\"{}\", ", str_slice);
39                } else {
40                    let _ = write!(f, "<invalid utf8>, ");
41                }
42            }
43            let _ = write!(f, " }}");
44            return Ok(());
45        }
46    }
47}