@@ -9,14 +9,9 @@ use rustc_target::callconv::{Conv, FnAbi};
9
9
10
10
use self :: shims:: windows:: handle:: { Handle , PseudoHandle } ;
11
11
use crate :: shims:: os_str:: bytes_to_os_str;
12
- use crate :: shims:: windows:: handle:: HandleError ;
13
12
use crate :: shims:: windows:: * ;
14
13
use crate :: * ;
15
14
16
- // The NTSTATUS STATUS_INVALID_HANDLE (0xC0000008) encoded as a HRESULT by setting the N bit.
17
- // (https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a)
18
- const STATUS_INVALID_HANDLE : u32 = 0xD0000008 ;
19
-
20
15
pub fn is_dyn_sym ( name : & str ) -> bool {
21
16
// std does dynamic detection for these symbols
22
17
matches ! (
@@ -498,52 +493,37 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
498
493
"SetThreadDescription" => {
499
494
let [ handle, name] = this. check_shim ( abi, sys_conv, link_name, args) ?;
500
495
501
- let handle = this. read_scalar ( handle) ?;
496
+ let handle = this. read_handle ( handle) ?;
502
497
let name = this. read_wide_str ( this. read_pointer ( name) ?) ?;
503
498
504
- let thread = match Handle :: try_from_scalar ( handle, this) ? {
505
- Ok ( Handle :: Thread ( thread) ) => Ok ( thread) ,
506
- Ok ( Handle :: Pseudo ( PseudoHandle :: CurrentThread ) ) => Ok ( this. active_thread ( ) ) ,
507
- Ok ( _) | Err ( HandleError :: InvalidHandle ) =>
508
- this. invalid_handle ( "SetThreadDescription" ) ?,
509
- Err ( HandleError :: ThreadNotFound ( e) ) => Err ( e) ,
510
- } ;
511
- let res = match thread {
512
- Ok ( thread) => {
513
- // FIXME: use non-lossy conversion
514
- this. set_thread_name ( thread, String :: from_utf16_lossy ( & name) . into_bytes ( ) ) ;
515
- Scalar :: from_u32 ( 0 )
516
- }
517
- Err ( _) => Scalar :: from_u32 ( STATUS_INVALID_HANDLE ) ,
499
+ let thread = match handle {
500
+ Handle :: Thread ( thread) => thread,
501
+ Handle :: Pseudo ( PseudoHandle :: CurrentThread ) => this. active_thread ( ) ,
502
+ _ => this. invalid_handle ( "SetThreadDescription" ) ?,
518
503
} ;
519
-
520
- this. write_scalar ( res, dest) ?;
504
+ // FIXME: use non-lossy conversion
505
+ this. set_thread_name ( thread, String :: from_utf16_lossy ( & name) . into_bytes ( ) ) ;
506
+ this. write_scalar ( Scalar :: from_u32 ( 0 ) , dest) ?;
521
507
}
522
508
"GetThreadDescription" => {
523
509
let [ handle, name_ptr] = this. check_shim ( abi, sys_conv, link_name, args) ?;
524
510
525
- let handle = this. read_scalar ( handle) ?;
511
+ let handle = this. read_handle ( handle) ?;
526
512
let name_ptr = this. deref_pointer_as ( name_ptr, this. machine . layouts . mut_raw_ptr ) ?; // the pointer where we should store the ptr to the name
527
513
528
- let thread = match Handle :: try_from_scalar ( handle, this) ? {
529
- Ok ( Handle :: Thread ( thread) ) => Ok ( thread) ,
530
- Ok ( Handle :: Pseudo ( PseudoHandle :: CurrentThread ) ) => Ok ( this. active_thread ( ) ) ,
531
- Ok ( _) | Err ( HandleError :: InvalidHandle ) =>
532
- this. invalid_handle ( "GetThreadDescription" ) ?,
533
- Err ( HandleError :: ThreadNotFound ( e) ) => Err ( e) ,
534
- } ;
535
- let ( name, res) = match thread {
536
- Ok ( thread) => {
537
- // Looks like the default thread name is empty.
538
- let name = this. get_thread_name ( thread) . unwrap_or ( b"" ) . to_owned ( ) ;
539
- let name = this. alloc_os_str_as_wide_str (
540
- bytes_to_os_str ( & name) ?,
541
- MiriMemoryKind :: WinLocal . into ( ) ,
542
- ) ?;
543
- ( Scalar :: from_maybe_pointer ( name, this) , Scalar :: from_u32 ( 0 ) )
544
- }
545
- Err ( _) => ( Scalar :: null_ptr ( this) , Scalar :: from_u32 ( STATUS_INVALID_HANDLE ) ) ,
514
+ let thread = match handle {
515
+ Handle :: Thread ( thread) => thread,
516
+ Handle :: Pseudo ( PseudoHandle :: CurrentThread ) => this. active_thread ( ) ,
517
+ _ => this. invalid_handle ( "GetThreadDescription" ) ?,
546
518
} ;
519
+ // Looks like the default thread name is empty.
520
+ let name = this. get_thread_name ( thread) . unwrap_or ( b"" ) . to_owned ( ) ;
521
+ let name = this. alloc_os_str_as_wide_str (
522
+ bytes_to_os_str ( & name) ?,
523
+ MiriMemoryKind :: WinLocal . into ( ) ,
524
+ ) ?;
525
+ let name = Scalar :: from_maybe_pointer ( name, this) ;
526
+ let res = Scalar :: from_u32 ( 0 ) ;
547
527
548
528
this. write_scalar ( name, & name_ptr) ?;
549
529
this. write_scalar ( res, dest) ?;
@@ -638,11 +618,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
638
618
let [ handle, filename, size] = this. check_shim ( abi, sys_conv, link_name, args) ?;
639
619
this. check_no_isolation ( "`GetModuleFileNameW`" ) ?;
640
620
641
- let handle = this. read_target_usize ( handle) ?;
621
+ let handle = this. read_handle ( handle) ?;
642
622
let filename = this. read_pointer ( filename) ?;
643
623
let size = this. read_scalar ( size) ?. to_u32 ( ) ?;
644
624
645
- if handle != 0 {
625
+ if handle != Handle :: Null {
646
626
throw_unsup_format ! ( "`GetModuleFileNameW` only supports the NULL handle" ) ;
647
627
}
648
628
0 commit comments