fixes
This commit is contained in:
parent
87fea0971b
commit
59604a03ae
@ -1,7 +1,7 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
windows::build!(
|
windows::build!(
|
||||||
windows::win32::system_services::{HANDLE, PAGE_TYPE, PSTR},
|
windows::win32::system_services::{HANDLE, PSTR},
|
||||||
windows::win32::windows_programming::CloseHandle,
|
windows::win32::windows_programming::CloseHandle,
|
||||||
// API needed for the shared memory
|
// API needed for the shared memory
|
||||||
windows::win32::system_services::{CreateFileMappingA, OpenFileMappingA, MapViewOfFile, UnmapViewOfFile},
|
windows::win32::system_services::{CreateFileMappingA, OpenFileMappingA, MapViewOfFile, UnmapViewOfFile},
|
||||||
|
@ -191,12 +191,12 @@ unsafe extern "system" fn handle_exception(exception_pointers: *mut EXCEPTION_PO
|
|||||||
let ret = match &EXCEPTION_HANDLERS[code as usize] {
|
let ret = match &EXCEPTION_HANDLERS[code as usize] {
|
||||||
Some(handler_holder) => {
|
Some(handler_holder) => {
|
||||||
let handler = &mut **handler_holder.handler.get();
|
let handler = &mut **handler_holder.handler.get();
|
||||||
handler.handle(code, exception_pointers);
|
handler.handle(ExceptionCode::try_from(code).unwrap(), exception_pointers);
|
||||||
EXCEPTION_EXECUTE_HANDLER
|
EXCEPTION_EXECUTE_HANDLER
|
||||||
}
|
}
|
||||||
None => EXCEPTION_CONTINUE_EXECUTION,
|
None => EXCEPTION_CONTINUE_EXECUTION,
|
||||||
};
|
};
|
||||||
if Some(prev_handler) = unsafe { PREVIOUS_HANDLER } {
|
if let Some(prev_handler) = unsafe { PREVIOUS_HANDLER } {
|
||||||
prev_handler(exception_pointers)
|
prev_handler(exception_pointers)
|
||||||
} else {
|
} else {
|
||||||
ret
|
ret
|
||||||
@ -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 Some(prev) = SetUnhandledExceptionFilter(Some(handle_exception)) {
|
if let Some(prev) = SetUnhandledExceptionFilter(Some(handle_exception)) {
|
||||||
PREVIOUS_HANDLER = Some(core::mem::transmute(prev as *const c_void));
|
PREVIOUS_HANDLER = Some(core::mem::transmute(prev as *const c_void));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -449,16 +449,18 @@ pub mod shmem {
|
|||||||
windows::win32::system_services::{
|
windows::win32::system_services::{
|
||||||
CreateFileMappingA, MapViewOfFile, OpenFileMappingA, UnmapViewOfFile,
|
CreateFileMappingA, MapViewOfFile, OpenFileMappingA, UnmapViewOfFile,
|
||||||
},
|
},
|
||||||
windows::win32::system_services::{HANDLE, PAGE_TYPE},
|
windows::win32::system_services::{HANDLE},
|
||||||
windows::win32::windows_programming::CloseHandle,
|
windows::win32::windows_programming::CloseHandle,
|
||||||
},
|
},
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use core::{ptr, slice};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
const INVALID_HANDLE_VALUE: i32 = -1;
|
const INVALID_HANDLE_VALUE: i32 = -1;
|
||||||
const FILE_MAP_ALL_ACCESS: u32 = 0xf001f;
|
const FILE_MAP_ALL_ACCESS: u32 = 0xf001f;
|
||||||
|
const PAGE_READWRITE: u32 = 0x04;
|
||||||
|
|
||||||
/// The default Sharedmap impl for windows using shmctl & shmget
|
/// The default Sharedmap impl for windows using shmctl & shmget
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -499,7 +501,7 @@ pub mod shmem {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
UnmapViewOfFile(self.map);
|
UnmapViewOfFile(self.map);
|
||||||
CloseHandle(self.hanlde);
|
CloseHandle(self.handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -509,22 +511,22 @@ pub mod shmem {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, map_str_bytes);
|
let handle = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, map_str_bytes);
|
||||||
if handle == ptr::null() {
|
if handle == ptr::null() {
|
||||||
return Error::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Cannot open shared memory {}",
|
"Cannot open shared memory {}",
|
||||||
String::from_utf8_lossy(map_str_bytes)
|
String::from_utf8_lossy(map_str_bytes)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
let map =
|
let map =
|
||||||
MapViewOfFile(handle.clone(), FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8;
|
MapViewOfFile(handle.clone(), FILE_MAP_ALL_ACCESS, 0, 0, map_size as u32) as *mut u8;
|
||||||
if map == ptr::null_mut() {
|
if map == ptr::null_mut() {
|
||||||
return Error::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Cannot map shared memory {}",
|
"Cannot map shared memory {}",
|
||||||
String::from_utf8_lossy(map_str_bytes)
|
String::from_utf8_lossy(map_str_bytes)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
shm_str: name[0..20].clone(),
|
shm_str: map_str_bytes.clone(),
|
||||||
handle,
|
handle,
|
||||||
map,
|
map,
|
||||||
map_size,
|
map_size,
|
||||||
@ -539,24 +541,24 @@ pub mod shmem {
|
|||||||
let handle = CreateFileMappingA(
|
let handle = CreateFileMappingA(
|
||||||
INVALID_HANDLE_VALUE,
|
INVALID_HANDLE_VALUE,
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
PAGE_TYPE::PAGE_READWRITE,
|
PAGE_READWRITE,
|
||||||
0,
|
0,
|
||||||
map_size,
|
map_size,
|
||||||
map_str_bytes,
|
map_str_bytes,
|
||||||
);
|
);
|
||||||
if handle == ptr::null() {
|
if handle == ptr::null() {
|
||||||
return Error::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Cannot create shared memory {}",
|
"Cannot create shared memory {}",
|
||||||
String::from_utf8_lossy(map_str_bytes)
|
String::from_utf8_lossy(map_str_bytes)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
let map =
|
let map =
|
||||||
MapViewOfFile(handle.clone(), FILE_MAP_ALL_ACCESS, 0, 0, map_size) as *mut u8;
|
MapViewOfFile(handle.clone(), FILE_MAP_ALL_ACCESS, 0, 0, map_size as u32) as *mut u8;
|
||||||
if map == ptr::null_mut() {
|
if map == ptr::null_mut() {
|
||||||
return Error::Unknown(format!(
|
return Err(Error::Unknown(format!(
|
||||||
"Cannot map shared memory {}",
|
"Cannot map shared memory {}",
|
||||||
String::from_utf8_lossy(map_str_bytes)
|
String::from_utf8_lossy(map_str_bytes)
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user