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

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

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

@ -1,3 +1,5 @@
use crate::ALLOCATOR;
#[inline(always)] #[inline(always)]
fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 { 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; let id = syscall_id as usize;
@ -32,6 +34,12 @@ fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3:
ret 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) -> ! { pub fn sys_exit(code: usize) -> ! {
sys_call(SyscallId::Exit, code, 0, 0, 0, 0, 0); sys_call(SyscallId::Exit, code, 0, 0, 0, 0, 0);
unreachable!() unreachable!()

Loading…
Cancel
Save