1mod fdt;
2mod node;
3
4use core::ops::Deref;
5
6pub use fdt::*;
7pub use node::*;
8
9struct Align4Vec {
10 ptr: *mut u8,
11 size: usize,
12}
13
14unsafe impl Send for Align4Vec {}
15
16impl Align4Vec {
17 const ALIGN: usize = 4;
18
19 pub fn new(data: &[u8]) -> Self {
20 let size = data.len();
21 let layout = core::alloc::Layout::from_size_align(size, Self::ALIGN).unwrap();
22 let ptr = unsafe { alloc::alloc::alloc_zeroed(layout) };
23 unsafe { core::ptr::copy_nonoverlapping(data.as_ptr(), ptr, size) };
24 Align4Vec { ptr, size }
25 }
26}
27
28impl Drop for Align4Vec {
29 fn drop(&mut self) {
30 let layout = core::alloc::Layout::from_size_align(self.size, Self::ALIGN).unwrap();
31 unsafe { alloc::alloc::dealloc(self.ptr, layout) };
32 }
33}
34
35impl Deref for Align4Vec {
36 type Target = [u8];
37
38 fn deref(&self) -> &Self::Target {
39 unsafe { alloc::slice::from_raw_parts(self.ptr, self.size) }
40 }
41}