diff --git a/libafl_qemu/src/modules/usermode/asan_guest.rs b/libafl_qemu/src/modules/usermode/asan_guest.rs index 2572c204df..567d98048e 100644 --- a/libafl_qemu/src/modules/usermode/asan_guest.rs +++ b/libafl_qemu/src/modules/usermode/asan_guest.rs @@ -123,7 +123,12 @@ pub struct AsanGuestModule { mappings: Vec, } -#[cfg(any(cpu_target = "aarch64", cpu_target = "x86_64", feature = "clippy"))] +#[cfg(any( + cpu_target = "aarch64", + cpu_target = "x86_64", + cpu_target = "riscv64", + feature = "clippy" +))] impl AsanGuestModule { const HIGH_SHADOW_START: GuestAddr = 0x02008fff7000; const HIGH_SHADOW_END: GuestAddr = 0x10007fff7fff; @@ -135,7 +140,8 @@ impl AsanGuestModule { cpu_target = "arm", cpu_target = "i386", cpu_target = "mips", - cpu_target = "ppc" + cpu_target = "ppc", + cpu_target = "riscv32", ))] impl AsanGuestModule { const HIGH_SHADOW_START: GuestAddr = 0x28000000; diff --git a/libafl_qemu/src/modules/usermode/snapshot.rs b/libafl_qemu/src/modules/usermode/snapshot.rs index ec4fe7db41..e20cfd466e 100644 --- a/libafl_qemu/src/modules/usermode/snapshot.rs +++ b/libafl_qemu/src/modules/usermode/snapshot.rs @@ -8,15 +8,16 @@ use thread_local::ThreadLocal; #[cfg(any(cpu_target = "arm", cpu_target = "i386", cpu_target = "mips"))] use crate::SYS_fstatat64; -#[cfg(not(cpu_target = "arm"))] +#[cfg(not(any(cpu_target = "arm", cpu_target = "riscv32")))] use crate::SYS_mmap; -#[cfg(any(cpu_target = "arm", cpu_target = "mips"))] +#[cfg(any(cpu_target = "arm", cpu_target = "mips", cpu_target = "riscv32"))] use crate::SYS_mmap2; #[cfg(not(any( cpu_target = "arm", cpu_target = "mips", cpu_target = "i386", - cpu_target = "ppc" + cpu_target = "ppc", + cpu_target = "riscv32", )))] use crate::SYS_newfstatat; use crate::{ @@ -26,9 +27,10 @@ use crate::{ NOP_ADDRESS_FILTER, }, qemu::{Hook, SyscallHookResult}, - Qemu, SYS_brk, SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_mprotect, SYS_mremap, - SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat, SYS_statfs, + Qemu, SYS_brk, SYS_mprotect, SYS_mremap, SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat, }; +#[cfg(not(cpu_target = "riscv32"))] +use crate::{SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_statfs}; // TODO use the functions provided by Qemu pub const SNAPSHOT_PAGE_SIZE: usize = 4096; @@ -804,6 +806,7 @@ where let h = emulator_modules.get_mut::().unwrap(); h.access(a2, a3 as usize); } + #[cfg(not(cpu_target = "riscv32"))] SYS_futex => { let h = emulator_modules.get_mut::().unwrap(); h.access(a0, a3 as usize); @@ -812,7 +815,8 @@ where cpu_target = "arm", cpu_target = "i386", cpu_target = "mips", - cpu_target = "ppc" + cpu_target = "ppc", + cpu_target = "riscv32" )))] SYS_newfstatat => { if a2 != 0 { @@ -827,10 +831,12 @@ where h.access(a2, 4096); // stat is not greater than a page } } - SYS_statfs | SYS_fstatfs | SYS_fstat => { + #[cfg(not(cpu_target = "riscv32"))] + SYS_statfs | SYS_fstat | SYS_fstatfs => { let h = emulator_modules.get_mut::().unwrap(); h.access(a1, 4096); // stat is not greater than a page } + #[cfg(not(cpu_target = "riscv32"))] SYS_getrandom => { let h = emulator_modules.get_mut::().unwrap(); h.access(a0, a1 as usize); @@ -855,7 +861,7 @@ where // TODO handle huge pages - #[cfg(any(cpu_target = "arm", cpu_target = "mips"))] + #[cfg(any(cpu_target = "arm", cpu_target = "mips", cpu_target = "riscv32"))] if sys_const == SYS_mmap2 { if let Ok(prot) = MmapPerms::try_from(a2 as i32) { let h = emulator_modules.get_mut::().unwrap(); @@ -863,7 +869,7 @@ where } } - #[cfg(not(cpu_target = "arm"))] + #[cfg(not(any(cpu_target = "arm", cpu_target = "riscv32")))] if sys_const == SYS_mmap { if let Ok(prot) = MmapPerms::try_from(a2 as i32) { let h = emulator_modules.get_mut::().unwrap();