Fix RISC-V port issues (#2642)

fix riscv{32,64} stuff
This commit is contained in:
Romain Malmain 2024-10-30 14:10:50 +01:00 committed by GitHub
parent af06d75d3e
commit 9da113e7a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 11 deletions

View File

@ -123,7 +123,12 @@ pub struct AsanGuestModule<F> {
mappings: Vec<QemuAsanGuestMapping>,
}
#[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<F> AsanGuestModule<F> {
const HIGH_SHADOW_START: GuestAddr = 0x02008fff7000;
const HIGH_SHADOW_END: GuestAddr = 0x10007fff7fff;
@ -135,7 +140,8 @@ impl<F> AsanGuestModule<F> {
cpu_target = "arm",
cpu_target = "i386",
cpu_target = "mips",
cpu_target = "ppc"
cpu_target = "ppc",
cpu_target = "riscv32",
))]
impl<F> AsanGuestModule<F> {
const HIGH_SHADOW_START: GuestAddr = 0x28000000;

View File

@ -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::<SnapshotModule>().unwrap();
h.access(a2, a3 as usize);
}
#[cfg(not(cpu_target = "riscv32"))]
SYS_futex => {
let h = emulator_modules.get_mut::<SnapshotModule>().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::<SnapshotModule>().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::<SnapshotModule>().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::<SnapshotModule>().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::<SnapshotModule>().unwrap();