1
0
Fork 0
forked from koniifer/ableos

»fixed« fuzzer

This commit is contained in:
Erin 2023-11-03 09:49:42 +01:00
parent 949dd3ba61
commit a7c4379976

View file

@ -1,7 +1,6 @@
#![no_main] #![no_main]
use { use {
hbbytecode::valider::validate,
hbvm::{ hbvm::{
mem::{ mem::{
softpaging::{ softpaging::{
@ -16,35 +15,33 @@ use {
}; };
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {
if validate(data).is_ok() { let mut vm = unsafe {
let mut vm = unsafe { Vm::<_, 16384>::new(
Vm::<_, 16384>::new( SoftPagedMem::<_, true> {
SoftPagedMem::<_, true> { pf_handler: TestTrapHandler,
pf_handler: TestTrapHandler, program: data,
program: data, root_pt: Box::into_raw(Default::default()),
root_pt: Box::into_raw(Default::default()), icache: Default::default(),
icache: Default::default(), },
}, Address::new(4),
Address::new(4), )
) };
};
// Alloc and map some memory // Alloc and map some memory
let pages = [ let pages = [
alloc_and_map(&mut vm.memory, 0), alloc_and_map(&mut vm.memory, 0),
alloc_and_map(&mut vm.memory, 4096), alloc_and_map(&mut vm.memory, 4096),
]; ];
// Run VM // Run VM
let _ = vm.run(); let _ = vm.run();
// Unmap and dealloc the memory // Unmap and dealloc the memory
for (i, page) in pages.into_iter().enumerate() { for (i, page) in pages.into_iter().enumerate() {
unmap_and_dealloc(&mut vm.memory, page, i as u64 * 4096); unmap_and_dealloc(&mut vm.memory, page, i as u64 * 4096);
}
let _ = unsafe { Box::from_raw(vm.memory.root_pt) };
} }
let _ = unsafe { Box::from_raw(vm.memory.root_pt) };
}); });
fn alloc_and_map(memory: &mut SoftPagedMem<TestTrapHandler>, at: u64) -> *mut u8 { fn alloc_and_map(memory: &mut SoftPagedMem<TestTrapHandler>, at: u64) -> *mut u8 {