1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::{Error, MemoryAddress, MemoryFlags, MemoryRange};
const PAGE_SIZE: usize = 4096;
extern crate alloc;
use alloc::alloc::{alloc, dealloc, Layout};
pub fn map_memory_pre(
_phys: &Option<MemoryAddress>,
_virt: &Option<MemoryAddress>,
_size: usize,
_flags: MemoryFlags,
) -> core::result::Result<(), Error> {
Ok(())
}
pub fn map_memory_post(
_phys: Option<MemoryAddress>,
_virt: Option<MemoryAddress>,
size: usize,
_flags: MemoryFlags,
_range: MemoryRange,
) -> core::result::Result<MemoryRange, Error> {
let layout = Layout::from_size_align(size, PAGE_SIZE)
.unwrap()
.pad_to_align();
let mem = unsafe { alloc(layout) } as usize;
unsafe { MemoryRange::new(mem, size) }
}
pub fn unmap_memory_pre(_range: &MemoryRange) -> core::result::Result<(), Error> {
Ok(())
}
pub fn unmap_memory_post(range: MemoryRange) -> core::result::Result<(), Error> {
let layout = Layout::from_size_align(range.len(), PAGE_SIZE)
.unwrap()
.pad_to_align();
let ptr = range.as_mut_ptr();
unsafe { dealloc(ptr, layout) };
Ok(())
}