fixes for win32

This commit is contained in:
Andrea Fioraldi 2021-03-18 16:26:03 +01:00
parent 5604f3d826
commit 147a6c53b8
2 changed files with 16 additions and 16 deletions

View File

@ -217,7 +217,7 @@ pub unsafe fn setup_exception_handler<T: 'static + Handler>(handler: &mut T) ->
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
unsafe { 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)); PREVIOUS_HANDLER = Some(core::mem::transmute(prev as *const c_void));
} }
} }

View File

@ -500,7 +500,7 @@ pub mod shmem {
impl Drop for Win32ShMem { impl Drop for Win32ShMem {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
UnmapViewOfFile(self.map as *const c_void); UnmapViewOfFile(self.map as *mut c_void as *const c_void);
CloseHandle(self.handle); CloseHandle(self.handle);
} }
} }
@ -524,7 +524,6 @@ pub mod shmem {
String::from_utf8_lossy(map_str_bytes) String::from_utf8_lossy(map_str_bytes)
))); )));
} }
}
Ok(Self { Ok(Self {
shm_str: map_str_bytes.clone(), shm_str: map_str_bytes.clone(),
handle: handle, handle: handle,
@ -532,10 +531,11 @@ pub mod shmem {
map_size: map_size, map_size: map_size,
}) })
} }
}
pub fn new(map_size: usize) -> Result<Self, Error> { pub fn new(map_size: usize) -> Result<Self, Error> {
let uuid = Uuid::new_v4(); 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 map_str_bytes[19] = 0; // Trucate to size 20
unsafe { unsafe {
let handle = CreateFileMappingA( let handle = CreateFileMappingA(
@ -544,7 +544,7 @@ pub mod shmem {
PAGE_READWRITE, PAGE_READWRITE,
0, 0,
map_size as u32, 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) { if handle == HANDLE(0) {
return Err(Error::Unknown(format!( return Err(Error::Unknown(format!(
@ -560,7 +560,6 @@ pub mod shmem {
String::from_utf8_lossy(map_str_bytes) String::from_utf8_lossy(map_str_bytes)
))); )));
} }
}
Ok(Self { Ok(Self {
shm_str: map_str_bytes[0..20].clone(), shm_str: map_str_bytes[0..20].clone(),
handle: handle, handle: handle,
@ -570,6 +569,7 @@ pub mod shmem {
} }
} }
} }
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {