From 8444cf7cc88fdba11ccb050f6fc7cba345af49c2 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Sun, 4 Dec 2022 23:07:30 +0900 Subject: [PATCH] Fix libafl_qemu i386 build (#924) * fix * fmt Co-authored-by: Andrea Fioraldi --- libafl_qemu/src/blocks.rs | 9 +++++++++ libafl_qemu/src/snapshot.rs | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libafl_qemu/src/blocks.rs b/libafl_qemu/src/blocks.rs index 97e4c150a9..1fae24fef6 100644 --- a/libafl_qemu/src/blocks.rs +++ b/libafl_qemu/src/blocks.rs @@ -50,6 +50,15 @@ pub fn pc2basicblock(pc: GuestAddr, emu: &Emulator) -> Result, .detail(true) .build() .unwrap(); + + #[cfg(cpu_target = "i386")] + let cs = Capstone::new() + .x86() + .mode(capstone::arch::x86::ArchMode::Mode32) + .detail(true) + .build() + .unwrap(); + #[cfg(cpu_target = "arm")] let cs = Capstone::new() .arm() diff --git a/libafl_qemu/src/snapshot.rs b/libafl_qemu/src/snapshot.rs index d79a77a113..6163055e48 100644 --- a/libafl_qemu/src/snapshot.rs +++ b/libafl_qemu/src/snapshot.rs @@ -15,9 +15,11 @@ use crate::{ GuestAddr, SYS_fstat, SYS_fstatfs, SYS_futex, SYS_getrandom, SYS_mprotect, SYS_mremap, SYS_munmap, SYS_pread64, SYS_read, SYS_readlinkat, SYS_statfs, }; +#[cfg(cpu_target = "i386")] +use crate::{SYS_fstatat64, SYS_mmap}; #[cfg(cpu_target = "arm")] use crate::{SYS_fstatat64, SYS_mmap2}; -#[cfg(not(cpu_target = "arm"))] +#[cfg(not(any(cpu_target = "arm", cpu_target = "i386")))] use crate::{SYS_mmap, SYS_newfstatat}; // TODO use the functions provided by Emulator @@ -630,14 +632,14 @@ where let h = hooks.match_helper_mut::().unwrap(); h.access(a0 as GuestAddr, a3 as usize); } - #[cfg(not(cpu_target = "arm"))] + #[cfg(not(any(cpu_target = "arm", cpu_target = "i386")))] SYS_newfstatat => { if a2 != 0 { let h = hooks.match_helper_mut::().unwrap(); h.access(a2 as GuestAddr, 4096); // stat is not greater than a page } } - #[cfg(cpu_target = "arm")] + #[cfg(any(cpu_target = "arm", cpu_target = "i386"))] SYS_fstatat64 => { if a2 != 0 { let h = hooks.match_helper_mut::().unwrap();