-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Graham MacDonald <[email protected]>
- Loading branch information
Showing
11 changed files
with
1,103 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use core::{mem::MaybeUninit, ptr::addr_of}; | ||
|
||
use port::{ | ||
mcslock::{Lock, LockNode}, | ||
mem::VirtRange, | ||
vmem::{Arena, Boundary}, | ||
}; | ||
|
||
static VMALLOC: Lock<Option<&'static mut VmAlloc>> = Lock::new("vmalloc", None); | ||
|
||
static mut EARLY_TAGS_PAGE: [u8; 4096] = [0; 4096]; | ||
|
||
struct VmAlloc { | ||
heap_arena: Arena, | ||
} | ||
|
||
impl VmAlloc { | ||
fn new(heap_range: VirtRange) -> Self { | ||
let quantum = 4096; | ||
|
||
let early_tags_ptr = unsafe { addr_of!(EARLY_TAGS_PAGE) as usize }; | ||
let early_tags_size = unsafe { EARLY_TAGS_PAGE.len() }; | ||
let early_tags_range = VirtRange::with_len(early_tags_ptr, early_tags_size); | ||
|
||
Self { | ||
heap_arena: Arena::new_with_static_range( | ||
"heap", | ||
Some(Boundary::from(heap_range)), | ||
quantum, | ||
None, | ||
early_tags_range, | ||
), | ||
} | ||
} | ||
} | ||
|
||
pub fn init(heap_range: VirtRange) { | ||
let node = LockNode::new(); | ||
let mut vmalloc = VMALLOC.lock(&node); | ||
*vmalloc = Some({ | ||
static mut MAYBE_VMALLOC: MaybeUninit<VmAlloc> = MaybeUninit::uninit(); | ||
unsafe { | ||
MAYBE_VMALLOC.write(VmAlloc::new(heap_range)); | ||
MAYBE_VMALLOC.assume_init_mut() | ||
} | ||
}); | ||
} | ||
|
||
pub fn alloc(size: usize) -> *mut u8 { | ||
let node = LockNode::new(); | ||
let mut lock = VMALLOC.lock(&node); | ||
let vmalloc = lock.as_deref_mut().unwrap(); | ||
vmalloc.heap_arena.alloc(size) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ pub mod devcons; | |
pub mod fdt; | ||
pub mod mcslock; | ||
pub mod mem; | ||
pub mod vmem; |
Oops, something went wrong.