@@ -23,6 +23,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
23
23
24
24
// Windows API stubs.
25
25
// HANDLE = isize
26
+ // NTSTATUS = LONH = i32
26
27
// DWORD = ULONG = u32
27
28
// BOOL = i32
28
29
// BOOLEAN = u8
@@ -64,49 +65,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
64
65
this. write_scalar ( Scalar :: from_i32 ( result) , dest) ?;
65
66
}
66
67
67
- // File related shims
68
- "GetStdHandle" => {
69
- let & [ ref which] =
70
- this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
71
- let which = this. read_scalar ( which) ?. to_i32 ( ) ?;
72
- // We just make this the identity function, so we know later in `WriteFile`
73
- // which one it is.
74
- this. write_scalar ( Scalar :: from_machine_isize ( which. into ( ) , this) , dest) ?;
75
- }
76
- "WriteFile" => {
77
- let & [ ref handle, ref buf, ref n, ref written_ptr, ref overlapped] =
78
- this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
79
- this. read_scalar ( overlapped) ?. to_machine_usize ( this) ?; // this is a poiner, that we ignore
80
- let handle = this. read_scalar ( handle) ?. to_machine_isize ( this) ?;
81
- let buf = this. read_pointer ( buf) ?;
82
- let n = this. read_scalar ( n) ?. to_u32 ( ) ?;
83
- let written_place = this. deref_operand ( written_ptr) ?;
84
- // Spec says to always write `0` first.
85
- this. write_null ( & written_place. into ( ) ) ?;
86
- let written = if handle == -11 || handle == -12 {
87
- // stdout/stderr
88
- use std:: io:: { self , Write } ;
89
-
90
- let buf_cont = this. read_bytes_ptr ( buf, Size :: from_bytes ( u64:: from ( n) ) ) ?;
91
- let res = if handle == -11 {
92
- io:: stdout ( ) . write ( buf_cont)
93
- } else {
94
- io:: stderr ( ) . write ( buf_cont)
95
- } ;
96
- res. ok ( ) . map ( |n| n as u32 )
97
- } else {
98
- throw_unsup_format ! (
99
- "on Windows, writing to anything except stdout/stderr is not supported"
100
- )
101
- } ;
102
- // If there was no error, write back how much was written.
103
- if let Some ( n) = written {
104
- this. write_scalar ( Scalar :: from_u32 ( n) , & written_place. into ( ) ) ?;
105
- }
106
- // Return whether this was a success.
107
- this. write_scalar ( Scalar :: from_i32 ( if written. is_some ( ) { 1 } else { 0 } ) , dest) ?;
108
- }
109
-
110
68
// Allocation
111
69
"HeapAlloc" => {
112
70
let & [ ref handle, ref flags, ref size] =
@@ -343,13 +301,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
343
301
return Ok ( EmulateByNameResult :: AlreadyJumped ) ;
344
302
}
345
303
346
- // Incomplete shims that we "stub out" just to get pre-main initialization code to work.
304
+ // Incomplete shims that we "stub out" just to get pre-main initialization code to work,
305
+ // or implement barely enough for stdout/stderr to work.
347
306
// These shims are enabled only when the caller is in the standard library.
307
+ "GetStdHandle" if this. frame_in_std ( ) => {
308
+ let & [ ref which] =
309
+ this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
310
+ let which = this. read_scalar ( which) ?. to_i32 ( ) ?;
311
+ // We just make this the identity function, so we know later in `NtWriteFile`
312
+ // which one it is.
313
+ this. write_scalar ( Scalar :: from_machine_isize ( which. into ( ) , this) , dest) ?;
314
+ }
348
315
"GetProcessHeap" if this. frame_in_std ( ) => {
349
316
let & [ ] = this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
350
317
// Just fake a HANDLE
351
318
this. write_scalar ( Scalar :: from_machine_isize ( 1 , this) , dest) ?;
352
319
}
320
+ "GetModuleHandleA" if this. frame_in_std ( ) => {
321
+ #[ allow( non_snake_case) ]
322
+ let & [ _lpModuleName] =
323
+ this. check_shim ( abi, Abi :: System { unwind : false } , link_name, args) ?;
324
+ // We need to return something non-null here to make `compat_fn!` work.
325
+ this. write_scalar ( Scalar :: from_machine_isize ( 1 , this) , dest) ?;
326
+ }
353
327
"SetConsoleTextAttribute" if this. frame_in_std ( ) => {
354
328
#[ allow( non_snake_case) ]
355
329
let & [ ref _hConsoleOutput, ref _wAttribute] =
0 commit comments