From 147a6c53b890aae06428350d23b00b0c336ce77f Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Thu, 18 Mar 2021 16:26:03 +0100 Subject: [PATCH] fixes for win32 --- libafl/src/bolts/os/windows_exceptions.rs | 2 +- libafl/src/bolts/shmem.rs | 30 +++++++++++------------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libafl/src/bolts/os/windows_exceptions.rs b/libafl/src/bolts/os/windows_exceptions.rs index 5eb41413f8..f5c7a91b8f 100644 --- a/libafl/src/bolts/os/windows_exceptions.rs +++ b/libafl/src/bolts/os/windows_exceptions.rs @@ -217,7 +217,7 @@ pub unsafe fn setup_exception_handler(handler: &mut T) -> compiler_fence(Ordering::SeqCst); unsafe { - if let Some(prev) = SetUnhandledExceptionFilter(Some(core::mem::transmute(handle_exception as as *const c_void))) { + if let Some(prev) = SetUnhandledExceptionFilter(Some(core::mem::transmute(handle_exception as *const c_void))) { PREVIOUS_HANDLER = Some(core::mem::transmute(prev as *const c_void)); } } diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index eb79ff8777..9c158283f5 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -500,7 +500,7 @@ pub mod shmem { impl Drop for Win32ShMem { fn drop(&mut self) { unsafe { - UnmapViewOfFile(self.map as *const c_void); + UnmapViewOfFile(self.map as *mut c_void as *const c_void); CloseHandle(self.handle); } } @@ -524,18 +524,18 @@ pub mod shmem { String::from_utf8_lossy(map_str_bytes) ))); } + Ok(Self { + shm_str: map_str_bytes.clone(), + handle: handle, + map: map, + map_size: map_size, + }) } - Ok(Self { - shm_str: map_str_bytes.clone(), - handle: handle, - map: map, - map_size: map_size, - }) } pub fn new(map_size: usize) -> Result { let uuid = Uuid::new_v4(); - let mut map_str_bytes = format!("libafl_{}", uuid.to_simple()).as_mut_bytes(); + let mut map_str_bytes = format!("libafl_{}", uuid.to_simple()).as_mut_vec(); map_str_bytes[19] = 0; // Trucate to size 20 unsafe { let handle = CreateFileMappingA( @@ -544,7 +544,7 @@ pub mod shmem { PAGE_READWRITE, 0, map_size as u32, - map_str_bytes as *const u8 as *const i8, + map_str_bytes.as_ptr() as *const i8, ); if handle == HANDLE(0) { return Err(Error::Unknown(format!( @@ -560,13 +560,13 @@ pub mod shmem { String::from_utf8_lossy(map_str_bytes) ))); } + Ok(Self { + shm_str: map_str_bytes[0..20].clone(), + handle: handle, + map: map, + map_size: map_size, + }) } - Ok(Self { - shm_str: map_str_bytes[0..20].clone(), - handle: handle, - map: map, - map_size: map_size, - }) } } }