@@ -291,14 +291,23 @@ mod _winapi {
291291 }
292292
293293 #[ pyfunction]
294- fn OpenProcess ( desired_access : u32 , inherit_handle : bool , process_id : u32 ) -> isize {
295- unsafe {
294+ fn OpenProcess (
295+ desired_access : u32 ,
296+ inherit_handle : bool ,
297+ process_id : u32 ,
298+ vm : & VirtualMachine ,
299+ ) -> PyResult < WinHandle > {
300+ let handle = unsafe {
296301 windows_sys:: Win32 :: System :: Threading :: OpenProcess (
297302 desired_access,
298303 i32:: from ( inherit_handle) ,
299304 process_id,
300- ) as _
305+ )
306+ } ;
307+ if handle. is_null ( ) {
308+ return Err ( errno_err ( vm) ) ;
301309 }
310+ Ok ( WinHandle ( handle) )
302311 }
303312
304313 #[ pyfunction]
@@ -432,7 +441,7 @@ mod _winapi {
432441 0 ,
433442 ( 2 & 0xffff ) | 0x20000 , // PROC_THREAD_ATTRIBUTE_HANDLE_LIST
434443 handlelist. as_mut_ptr ( ) as _ ,
435- ( handlelist. len ( ) * std:: mem:: size_of :: < isize > ( ) ) as _ ,
444+ ( handlelist. len ( ) * std:: mem:: size_of :: < usize > ( ) ) as _ ,
436445 std:: ptr:: null_mut ( ) ,
437446 std:: ptr:: null ( ) ,
438447 )
@@ -506,17 +515,23 @@ mod _winapi {
506515 }
507516
508517 #[ pyfunction]
509- fn OpenMutexW ( desired_access : u32 , inherit_handle : bool , name : u16 ) -> PyResult < isize > {
518+ fn OpenMutexW (
519+ desired_access : u32 ,
520+ inherit_handle : bool ,
521+ name : PyStrRef ,
522+ vm : & VirtualMachine ,
523+ ) -> PyResult < isize > {
524+ let name_wide = name. as_str ( ) . to_wide_with_nul ( ) ;
510525 let handle = unsafe {
511526 windows_sys:: Win32 :: System :: Threading :: OpenMutexW (
512527 desired_access,
513528 i32:: from ( inherit_handle) ,
514- windows_sys :: core :: PCWSTR :: from ( name as _ ) ,
529+ name_wide . as_ptr ( ) ,
515530 )
516531 } ;
517- // if handle.is_invalid() {
518- // return Err(errno_err(vm));
519- // }
532+ if handle == INVALID_HANDLE_VALUE {
533+ return Err ( errno_err ( vm) ) ;
534+ }
520535 Ok ( handle as _ )
521536 }
522537
0 commit comments