Only enlarge heap when necessary

master
Jiajie Chen 6 years ago
parent 3009626522
commit f5ec8a84c3

@ -55,6 +55,7 @@ impl provider::Provider for Provider {
// IMPORTANT: Must define main() like this
#[no_mangle]
pub fn main() {
enlarge_heap();
println!("I am going to map IXGBE driver to user space");
println!("Kernel network stack should not use it anymore");
let addr = sys_map_pci_device(0x8086, 0x10fb);

@ -142,6 +142,7 @@ enum State {
// IMPORTANT: Must define main() like this
#[no_mangle]
pub fn main() {
enlarge_heap();
println!("I am going to map IXGBE driver to user space");
println!("Kernel network stack should not use it anymore");
let addr = sys_map_pci_device(0x8086, 0x10fb);

@ -12,9 +12,9 @@ fn main() {
}
fn init_heap() {
const HEAP_SIZE: usize = 16 * 1024 * 1024;
let addr = sys_mmap(0, HEAP_SIZE, 0x3, 0x22, 0, 0) as usize;
unsafe { ALLOCATOR.lock().init(addr, HEAP_SIZE); }
const HEAP_SIZE: usize = 0x1000;
static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE];
unsafe { ALLOCATOR.lock().init(HEAP.as_ptr() as usize, HEAP_SIZE); }
}
#[no_mangle]

@ -1,3 +1,5 @@
use crate::ALLOCATOR;
#[inline(always)]
fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 {
let id = syscall_id as usize;
@ -32,6 +34,12 @@ fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3:
ret
}
pub fn enlarge_heap() {
const HEAP_SIZE: usize = 16 * 1024 * 1024;
let addr = sys_mmap(0, HEAP_SIZE, 0x3, 0x22, 0, 0) as usize;
unsafe { ALLOCATOR.lock().init(addr, HEAP_SIZE); }
}
pub fn sys_exit(code: usize) -> ! {
sys_call(SyscallId::Exit, code, 0, 0, 0, 0, 0);
unreachable!()

Loading…
Cancel
Save