fixes for win32

This commit is contained in:
Andrea Fioraldi 2021-03-18 16:30:57 +01:00
parent 147a6c53b8
commit 6f1058f8d1

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 *mut c_void as *const c_void); UnmapViewOfFile(self.map as *mut c_void);
CloseHandle(self.handle); CloseHandle(self.handle);
} }
} }
@ -509,7 +509,7 @@ pub mod shmem {
impl Win32ShMem { impl Win32ShMem {
pub fn from_str(map_str_bytes: &[u8; 20], map_size: usize) -> Result<Self, Error> { pub fn from_str(map_str_bytes: &[u8; 20], map_size: usize) -> Result<Self, Error> {
unsafe { unsafe {
let handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, map_str_bytes as *const u8 as *const i8); let handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, 0, map_str_bytes as *const u8 as *const i8);
if handle == HANDLE(0) { if handle == HANDLE(0) {
return Err(Error::Unknown(format!( return Err(Error::Unknown(format!(
"Cannot open shared memory {}", "Cannot open shared memory {}",
@ -524,12 +524,14 @@ pub mod shmem {
String::from_utf8_lossy(map_str_bytes) String::from_utf8_lossy(map_str_bytes)
))); )));
} }
Ok(Self { let mut ret = Self {
shm_str: map_str_bytes.clone(), shm_str: [0; 20],
handle: handle, handle: handle,
map: map, map: map,
map_size: map_size, map_size: map_size,
}) };
ret.shm_str.clone_from_slice(map_str_bytes);
Ok(ret)
} }
} }
@ -560,12 +562,14 @@ pub mod shmem {
String::from_utf8_lossy(map_str_bytes) String::from_utf8_lossy(map_str_bytes)
))); )));
} }
Ok(Self { let mut ret = Self {
shm_str: map_str_bytes[0..20].clone(), shm_str: [0; 20],
handle: handle, handle: handle,
map: map, map: map,
map_size: map_size, map_size: map_size,
}) };
ret.shm_str.clone_from_slice(map_str_bytes[0..20]);
Ok(ret)
} }
} }
} }