@@ -5,14 +5,19 @@ use rustc_span::Symbol;
5
5
use rustc_target:: abi:: Size ;
6
6
use rustc_target:: spec:: abi:: Abi ;
7
7
8
+ use crate :: shims:: os_str:: bytes_to_os_str;
8
9
use crate :: * ;
9
10
use shims:: foreign_items:: EmulateForeignItemResult ;
10
11
use shims:: windows:: handle:: { EvalContextExt as _, Handle , PseudoHandle } ;
11
12
use shims:: windows:: sync:: EvalContextExt as _;
12
13
use shims:: windows:: thread:: EvalContextExt as _;
13
14
14
15
fn 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
+ )
16
21
}
17
22
18
23
impl < ' 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> {
172
177
let res = this. realloc ( ptr, size, MiriMemoryKind :: WinHeap ) ?;
173
178
this. write_pointer ( res, dest) ?;
174
179
}
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
+ }
175
186
176
187
// errno
177
188
"SetLastError" => {
@@ -403,7 +414,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
403
414
this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
404
415
405
416
let handle = this. read_scalar ( handle) ?;
406
-
407
417
let name = this. read_wide_str ( this. read_pointer ( name) ?) ?;
408
418
409
419
let thread = match Handle :: from_scalar ( handle, this) ? {
@@ -412,7 +422,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
412
422
_ => this. invalid_handle ( "SetThreadDescription" ) ?,
413
423
} ;
414
424
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) ?;
416
450
417
451
this. write_null ( dest) ?;
418
452
}
0 commit comments