diff --git a/rust/src/bin/genpkts.rs b/rust/src/bin/genpkts.rs index e7d7366..c90f83d 100644 --- a/rust/src/bin/genpkts.rs +++ b/rust/src/bin/genpkts.rs @@ -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); diff --git a/rust/src/bin/iperf.rs b/rust/src/bin/iperf.rs index 75ff989..13681aa 100644 --- a/rust/src/bin/iperf.rs +++ b/rust/src/bin/iperf.rs @@ -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); diff --git a/rust/src/lang_items.rs b/rust/src/lang_items.rs index 573bd0f..67624ad 100644 --- a/rust/src/lang_items.rs +++ b/rust/src/lang_items.rs @@ -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] diff --git a/rust/src/syscall.rs b/rust/src/syscall.rs index 2ad2ef1..d368199 100644 --- a/rust/src/syscall.rs +++ b/rust/src/syscall.rs @@ -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!()