Fix batched timeout (#1920)

* fix ptr

* fix ptr

* fix

* One less windows warning

* One less windows warning
This commit is contained in:
Dongjia "toka" Zhang 2024-03-07 23:52:56 +01:00 committed by GitHub
parent 781e830923
commit 1b9f4ea29c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 16 deletions

View File

@ -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();

View File

@ -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<T: 'static + CtrlHandler>(
}
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();