Make use of mspaces
This commit is contained in:
+20
-5
@@ -67,7 +67,26 @@ static INIT_ARRAY: [extern "C" fn(); 1] = [init_array];
|
||||
|
||||
static mut init_complete: bool = false;
|
||||
|
||||
fn alloc_init() {
|
||||
unsafe{
|
||||
if let Some(tcb) = ld_so::tcb::Tcb::current() {
|
||||
if tcb.mspace != 0 {
|
||||
ALLOCATOR.set_book_keeper(tcb.mspace);
|
||||
} else if ALLOCATOR.get_book_keeper() == 0 {
|
||||
ALLOCATOR.set_book_keeper(new_mspace());
|
||||
}
|
||||
} else if ALLOCATOR.get_book_keeper() == 0 {
|
||||
ALLOCATOR.set_book_keeper(new_mspace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn init_array() {
|
||||
// The thing is that we cannot guarantee if
|
||||
// init_array runs first or if relibc_start runs first
|
||||
// Still whoever gets to run first must initialize rust
|
||||
// memory allocator before doing anything else.
|
||||
alloc_init();
|
||||
io_init();
|
||||
unsafe { init_complete = true };
|
||||
}
|
||||
@@ -95,11 +114,7 @@ pub unsafe extern "C" fn relibc_start(sp: &'static Stack) -> ! {
|
||||
}
|
||||
// Step 1 setup the right allocator...
|
||||
// if any memory rust based memory allocation happen before this step .. we are doomed.
|
||||
if let Some(tcb) = ld_so::tcb::Tcb::current() {
|
||||
ALLOCATOR.set_book_keeper(tcb.mspace);
|
||||
} else {
|
||||
ALLOCATOR.set_book_keeper(new_mspace());
|
||||
}
|
||||
alloc_init();
|
||||
|
||||
// Ensure correct host system before executing more system calls
|
||||
relibc_verify_host();
|
||||
|
||||
Reference in New Issue
Block a user