Skip to content

Commit 0cd2eda

Browse files
committed
windows: Wrap HANDLE to
windows 0.58 changed HANDLE from int to void pointer, now it wouldn't compile anymore because we need it to implement Send. So just implement a wrapper around it. Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 0287355 commit 0cd2eda

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

framework_lib/src/chromium_ec/windows.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ use windows::{
1414
use crate::chromium_ec::EC_MEMMAP_SIZE;
1515
use crate::chromium_ec::{EcError, EcResponseStatus, EcResult};
1616

17+
// Create a wrapper around HANDLE to mark it as Send.
18+
// I'm not sure, but I think it's safe to do that for this type of HANDL.
19+
#[derive(Copy, Clone)]
20+
struct DevHandle(HANDLE);
21+
unsafe impl Send for DevHandle {}
22+
1723
lazy_static! {
18-
static ref DEVICE: Arc<Mutex<Option<HANDLE>>> = Arc::new(Mutex::new(None));
24+
static ref DEVICE: Arc<Mutex<Option<DevHandle>>> = Arc::new(Mutex::new(None));
1925
}
2026

2127
fn init() {
@@ -26,7 +32,7 @@ fn init() {
2632

2733
let path = w!(r"\\.\GLOBALROOT\Device\CrosEC");
2834
unsafe {
29-
*device = Some(
35+
*device = Some(DevHandle(
3036
CreateFileW(
3137
path,
3238
FILE_GENERIC_READ.0 | FILE_GENERIC_WRITE.0,
@@ -37,7 +43,7 @@ fn init() {
3743
None,
3844
)
3945
.unwrap(),
40-
);
46+
));
4147
}
4248
}
4349

@@ -61,7 +67,7 @@ pub fn read_memory(offset: u16, length: u16) -> EcResult<Vec<u8>> {
6167
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
6268
};
6369
DeviceIoControl(
64-
device,
70+
device.0,
6571
IOCTL_CROSEC_RDMEM,
6672
Some(const_ptr),
6773
ptr_size,
@@ -104,15 +110,16 @@ pub fn send_command(command: u16, command_version: u8, data: &[u8]) -> EcResult<
104110
return EcResult::Err(EcError::DeviceError("No EC device".to_string()));
105111
};
106112
DeviceIoControl(
107-
device,
113+
device.0,
108114
IOCTL_CROSEC_XCMD,
109115
Some(const_ptr),
110116
size.try_into().unwrap(),
111117
Some(mut_ptr),
112118
size.try_into().unwrap(),
113119
Some(&mut returned as *mut u32),
114120
None,
115-
);
121+
)
122+
.unwrap();
116123
}
117124

118125
match FromPrimitive::from_u32(cmd.result) {

0 commit comments

Comments
 (0)