diff --git a/libafl/src/executors/hooks/timer.rs b/libafl/src/executors/hooks/timer.rs index 6f1f6991e0..e6109e6470 100644 --- a/libafl/src/executors/hooks/timer.rs +++ b/libafl/src/executors/hooks/timer.rs @@ -1,21 +1,22 @@ //! The struct `TimerStruct` will absorb all the difference in timeout implementation in various system. -use core::time::Duration; #[cfg(any(windows, target_os = "linux"))] -use core::{ - ffi::c_void, - ptr::{addr_of_mut, write_volatile}, -}; +use core::ptr::addr_of_mut; +use core::time::Duration; #[cfg(target_os = "linux")] use core::{ mem::zeroed, - ptr::{self, addr_of, null_mut}, + ptr::{addr_of, null_mut}, }; #[cfg(all(unix, not(target_os = "linux")))] pub(crate) const ITIMER_REAL: core::ffi::c_int = 0; #[cfg(windows)] -use core::sync::atomic::{compiler_fence, Ordering}; +use core::{ + ffi::c_void, + ptr::write_volatile, + sync::atomic::{compiler_fence, Ordering}, +}; #[cfg(target_os = "linux")] use libafl_bolts::current_time; @@ -29,7 +30,7 @@ use windows::Win32::{ }, }; -#[cfg(any(windows, target_os = "linux"))] +#[cfg(windows)] use crate::executors::hooks::inprocess::GLOBAL_STATE; #[repr(C)] @@ -296,12 +297,6 @@ impl TimerStruct { pub fn set_timer(&mut self) { unsafe { if self.batch_mode { - let data = addr_of_mut!(GLOBAL_STATE); - write_volatile( - addr_of_mut!((*data).executor_ptr), - ptr::from_mut(self) as *mut c_void, - ); - if self.executions == 0 { libc::timer_settime(self.timerid, 0, addr_of_mut!(self.itimerspec), null_mut()); self.tmout_start_time = current_time(); diff --git a/libafl_bolts/src/os/windows_exceptions.rs b/libafl_bolts/src/os/windows_exceptions.rs index 78451d62b0..f491e98390 100644 --- a/libafl_bolts/src/os/windows_exceptions.rs +++ b/libafl_bolts/src/os/windows_exceptions.rs @@ -5,7 +5,7 @@ use alloc::vec::Vec; use core::{ cell::UnsafeCell, fmt::{self, Display, Formatter}, - ptr::{self, addr_of_mut, write_volatile}, + ptr::{self, addr_of, addr_of_mut, write_volatile}, sync::atomic::{compiler_fence, Ordering}, }; use std::os::raw::{c_long, c_void}; @@ -463,7 +463,8 @@ pub(crate) unsafe fn setup_ctrl_handler( } unsafe extern "system" fn ctrl_handler(ctrl_type: u32) -> BOOL { - match &CTRL_HANDLER { + let handler = ptr::read_volatile(addr_of!(CTRL_HANDLER)); + match handler { Some(handler_holder) => { info!("{:?}: Handling ctrl {}", std::process::id(), ctrl_type); let handler = &mut *handler_holder.handler.get();