Skip to content

Commit 9da113e

Browse files
authored
Fix RISC-V port issues (#2642)
fix riscv{32,64} stuff
1 parent af06d75 commit 9da113e

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

libafl_qemu/src/modules/usermode/asan_guest.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ pub struct AsanGuestModule<F> {
123123
mappings: Vec<QemuAsanGuestMapping>,
124124
}
125125

126-
#[cfg(any(cpu_target = "aarch64", cpu_target = "x86_64", feature = "clippy"))]
126+
#[cfg(any(
127+
cpu_target = "aarch64",
128+
cpu_target = "x86_64",
129+
cpu_target = "riscv64",
130+
feature = "clippy"
131+
))]
127132
impl<F> AsanGuestModule<F> {
128133
const HIGH_SHADOW_START: GuestAddr = 0x02008fff7000;
129134
const HIGH_SHADOW_END: GuestAddr = 0x10007fff7fff;
@@ -135,7 +140,8 @@ impl<F> AsanGuestModule<F> {
135140
cpu_target = "arm",
136141
cpu_target = "i386",
137142
cpu_target = "mips",
138-
cpu_target = "ppc"
143+
cpu_target = "ppc",
144+
cpu_target = "riscv32",
139145
))]
140146
impl<F> AsanGuestModule<F> {
141147
const HIGH_SHADOW_START: GuestAddr = 0x28000000;

libafl_qemu/src/modules/usermode/snapshot.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ use thread_local::ThreadLocal;
88

99
#[cfg(any(cpu_target = "arm", cpu_target = "i386", cpu_target = "mips"))]
1010
use crate::SYS_fstatat64;
11-
#[cfg(not(cpu_target = "arm"))]
11+
#[cfg(not(any(cpu_target = "arm", cpu_target = "riscv32")))]
1212
use crate::SYS_mmap;
13-
#[cfg(any(cpu_target = "arm", cpu_target = "mips"))]
13+
#[cfg(any(cpu_target = "arm", cpu_target = "mips", cpu_target = "riscv32"))]
1414
use crate::SYS_mmap2;
1515
#[cfg(not(any(
1616
cpu_target = "arm",
1717
cpu_target = "mips",
1818
cpu_target = "i386",
19-
cpu_target = "ppc"
19+
cpu_target = "ppc",
20+
cpu_target = "riscv32",
2021
)))]
2122
use crate::SYS_newfstatat;
2223
use crate::{
@@ -26,9 +27,10 @@ use crate::{
2627
NOP_ADDRESS_FILTER,
2728
},
2829
qemu::{Hook, SyscallHookResult},
29-
Qemu, SYS_brk, SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_mprotect, SYS_mremap,
30-
SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat, SYS_statfs,
30+
Qemu, SYS_brk, SYS_mprotect, SYS_mremap, SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat,
3131
};
32+
#[cfg(not(cpu_target = "riscv32"))]
33+
use crate::{SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_statfs};
3234

3335
// TODO use the functions provided by Qemu
3436
pub const SNAPSHOT_PAGE_SIZE: usize = 4096;
@@ -804,6 +806,7 @@ where
804806
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();
805807
h.access(a2, a3 as usize);
806808
}
809+
#[cfg(not(cpu_target = "riscv32"))]
807810
SYS_futex => {
808811
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();
809812
h.access(a0, a3 as usize);
@@ -812,7 +815,8 @@ where
812815
cpu_target = "arm",
813816
cpu_target = "i386",
814817
cpu_target = "mips",
815-
cpu_target = "ppc"
818+
cpu_target = "ppc",
819+
cpu_target = "riscv32"
816820
)))]
817821
SYS_newfstatat => {
818822
if a2 != 0 {
@@ -827,10 +831,12 @@ where
827831
h.access(a2, 4096); // stat is not greater than a page
828832
}
829833
}
830-
SYS_statfs | SYS_fstatfs | SYS_fstat => {
834+
#[cfg(not(cpu_target = "riscv32"))]
835+
SYS_statfs | SYS_fstat | SYS_fstatfs => {
831836
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();
832837
h.access(a1, 4096); // stat is not greater than a page
833838
}
839+
#[cfg(not(cpu_target = "riscv32"))]
834840
SYS_getrandom => {
835841
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();
836842
h.access(a0, a1 as usize);
@@ -855,15 +861,15 @@ where
855861

856862
// TODO handle huge pages
857863

858-
#[cfg(any(cpu_target = "arm", cpu_target = "mips"))]
864+
#[cfg(any(cpu_target = "arm", cpu_target = "mips", cpu_target = "riscv32"))]
859865
if sys_const == SYS_mmap2 {
860866
if let Ok(prot) = MmapPerms::try_from(a2 as i32) {
861867
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();
862868
h.add_mapped(result, a1 as usize, Some(prot));
863869
}
864870
}
865871

866-
#[cfg(not(cpu_target = "arm"))]
872+
#[cfg(not(any(cpu_target = "arm", cpu_target = "riscv32")))]
867873
if sys_const == SYS_mmap {
868874
if let Ok(prot) = MmapPerms::try_from(a2 as i32) {
869875
let h = emulator_modules.get_mut::<SnapshotModule>().unwrap();

0 commit comments

Comments
 (0)