@@ -9,14 +9,9 @@ use rustc_target::callconv::{Conv, FnAbi};
99
1010use self :: shims:: windows:: handle:: { Handle , PseudoHandle } ;
1111use crate :: shims:: os_str:: bytes_to_os_str;
12- use crate :: shims:: windows:: handle:: HandleError ;
1312use crate :: shims:: windows:: * ;
1413use crate :: * ;
1514
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-
2015pub fn is_dyn_sym ( name : & str ) -> bool {
2116 // std does dynamic detection for these symbols
2217 matches ! (
@@ -498,52 +493,37 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
498493 "SetThreadDescription" => {
499494 let [ handle, name] = this. check_shim ( abi, sys_conv, link_name, args) ?;
500495
501- let handle = this. read_scalar ( handle) ?;
496+ let handle = this. read_handle ( handle) ?;
502497 let name = this. read_wide_str ( this. read_pointer ( name) ?) ?;
503498
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" ) ?,
518503 } ;
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) ?;
521507 }
522508 "GetThreadDescription" => {
523509 let [ handle, name_ptr] = this. check_shim ( abi, sys_conv, link_name, args) ?;
524510
525- let handle = this. read_scalar ( handle) ?;
511+ let handle = this. read_handle ( handle) ?;
526512 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
527513
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" ) ?,
546518 } ;
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 ) ;
547527
548528 this. write_scalar ( name, & name_ptr) ?;
549529 this. write_scalar ( res, dest) ?;
@@ -638,11 +618,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
638618 let [ handle, filename, size] = this. check_shim ( abi, sys_conv, link_name, args) ?;
639619 this. check_no_isolation ( "`GetModuleFileNameW`" ) ?;
640620
641- let handle = this. read_target_usize ( handle) ?;
621+ let handle = this. read_handle ( handle) ?;
642622 let filename = this. read_pointer ( filename) ?;
643623 let size = this. read_scalar ( size) ?. to_u32 ( ) ?;
644624
645- if handle != 0 {
625+ if handle != Handle :: Null {
646626 throw_unsup_format ! ( "`GetModuleFileNameW` only supports the NULL handle" ) ;
647627 }
648628
0 commit comments