@@ -5,14 +5,19 @@ use rustc_span::Symbol;
55use rustc_target:: abi:: Size ;
66use rustc_target:: spec:: abi:: Abi ;
77
8+ use crate :: shims:: os_str:: bytes_to_os_str;
89use crate :: * ;
910use shims:: foreign_items:: EmulateForeignItemResult ;
1011use shims:: windows:: handle:: { EvalContextExt as _, Handle , PseudoHandle } ;
1112use shims:: windows:: sync:: EvalContextExt as _;
1213use shims:: windows:: thread:: EvalContextExt as _;
1314
1415fn is_dyn_sym ( name : & str ) -> bool {
15- matches ! ( name, "SetThreadDescription" | "WaitOnAddress" | "WakeByAddressSingle" )
16+ // std does dynamic detection for these symbols
17+ matches ! (
18+ name,
19+ "SetThreadDescription" | "GetThreadDescription" | "WaitOnAddress" | "WakeByAddressSingle"
20+ )
1621}
1722
1823impl < ' mir , ' tcx : ' mir > EvalContextExt < ' mir , ' tcx > for crate :: MiriInterpCx < ' mir , ' tcx > { }
@@ -172,6 +177,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
172177 let res = this. realloc ( ptr, size, MiriMemoryKind :: WinHeap ) ?;
173178 this. write_pointer ( res, dest) ?;
174179 }
180+ "LocalFree" => {
181+ let [ ptr] = this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
182+ let ptr = this. read_pointer ( ptr) ?;
183+ this. free ( ptr, MiriMemoryKind :: WinLocal ) ?;
184+ this. write_null ( dest) ?;
185+ }
175186
176187 // errno
177188 "SetLastError" => {
@@ -403,7 +414,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
403414 this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
404415
405416 let handle = this. read_scalar ( handle) ?;
406-
407417 let name = this. read_wide_str ( this. read_pointer ( name) ?) ?;
408418
409419 let thread = match Handle :: from_scalar ( handle, this) ? {
@@ -412,7 +422,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
412422 _ => this. invalid_handle ( "SetThreadDescription" ) ?,
413423 } ;
414424
415- this. set_thread_name_wide ( thread, & name) ;
425+ // FIXME: use non-lossy conversion
426+ this. set_thread_name ( thread, String :: from_utf16_lossy ( & name) . into_bytes ( ) ) ;
427+
428+ this. write_null ( dest) ?;
429+ }
430+ "GetThreadDescription" => {
431+ let [ handle, name_ptr] =
432+ this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
433+
434+ let handle = this. read_scalar ( handle) ?;
435+ let name_ptr = this. deref_pointer ( name_ptr) ?; // the pointer where we should store the ptr to the name
436+
437+ let thread = match Handle :: from_scalar ( handle, this) ? {
438+ Some ( Handle :: Thread ( thread) ) => thread,
439+ Some ( Handle :: Pseudo ( PseudoHandle :: CurrentThread ) ) => this. get_active_thread ( ) ,
440+ _ => this. invalid_handle ( "SetThreadDescription" ) ?,
441+ } ;
442+ // Looks like the default thread name is empty.
443+ let name = this. get_thread_name ( thread) . unwrap_or ( b"" ) . to_owned ( ) ;
444+ let name = this. alloc_os_str_as_wide_str (
445+ bytes_to_os_str ( & name) ?,
446+ MiriMemoryKind :: WinLocal . into ( ) ,
447+ ) ?;
448+
449+ this. write_scalar ( Scalar :: from_maybe_pointer ( name, this) , & name_ptr) ?;
416450
417451 this. write_null ( dest) ?;
418452 }
0 commit comments