Skip to content

Commit f243cb8

Browse files
committed
Implement RtlNtStatusToDosError and shim test for it
1 parent d0ea07e commit f243cb8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Diff for: src/tools/miri/src/shims/windows/foreign_items.rs

+19
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,25 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
346346
let last_error = this.get_last_error()?;
347347
this.write_scalar(last_error, dest)?;
348348
}
349+
"RtlNtStatusToDosError" => {
350+
let [status] = this.check_shim(abi, sys_conv, link_name, args)?;
351+
let status = this.read_scalar(status)?.to_u32()?;
352+
let err = match status {
353+
// STATUS_MEDIA_WRITE_PROTECTED => ERROR_WRITE_PROTECT
354+
0xC00000A2 => 19,
355+
// STATUS_FILE_INVALID => ERROR_FILE_INVALID
356+
0xC0000098 => 1006,
357+
// STATUS_DISK_FULL => ERROR_DISK_FULL
358+
0xC000007F => 112,
359+
// STATUS_IO_DEVICE_ERROR => ERROR_IO_DEVICE
360+
0xC0000185 => 1117,
361+
// STATUS_ACCESS_DENIED => ERROR_ACCESS_DENIED
362+
0xC0000022 => 5,
363+
// Anything without an error code => ERROR_MR_MID_NOT_FOUND
364+
_ => 317,
365+
};
366+
this.write_scalar(Scalar::from_i32(err), dest)?;
367+
}
349368

350369
// Querying system information
351370
"GetSystemInfo" => {

Diff for: src/tools/miri/tests/pass-dep/shims/windows-fs.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use std::ptr;
1010
mod utils;
1111

1212
use windows_sys::Win32::Foundation::{
13-
CloseHandle, ERROR_ALREADY_EXISTS, GENERIC_READ, GENERIC_WRITE, GetLastError,
13+
CloseHandle, ERROR_ACCESS_DENIED, ERROR_ALREADY_EXISTS, ERROR_IO_DEVICE, GENERIC_READ,
14+
GENERIC_WRITE, GetLastError, RtlNtStatusToDosError, STATUS_ACCESS_DENIED,
15+
STATUS_IO_DEVICE_ERROR,
1416
};
1517
use windows_sys::Win32::Storage::FileSystem::{
1618
BY_HANDLE_FILE_INFORMATION, CREATE_ALWAYS, CREATE_NEW, CreateFileW, FILE_ATTRIBUTE_DIRECTORY,
@@ -26,6 +28,7 @@ fn main() {
2628
test_create_always_twice();
2729
test_open_always_twice();
2830
test_open_dir_reparse();
31+
test_ntstatus_to_dos();
2932
}
3033
}
3134

@@ -191,6 +194,12 @@ unsafe fn test_open_dir_reparse() {
191194
};
192195
}
193196

197+
unsafe fn test_ntstatus_to_dos() {
198+
// We won't test all combinations, just a couple common ones
199+
assert_eq!(RtlNtStatusToDosError(STATUS_IO_DEVICE_ERROR), ERROR_IO_DEVICE);
200+
assert_eq!(RtlNtStatusToDosError(STATUS_ACCESS_DENIED), ERROR_ACCESS_DENIED);
201+
}
202+
194203
fn to_wide_cstr(path: &Path) -> Vec<u16> {
195204
let mut raw_path = path.as_os_str().encode_wide().collect::<Vec<_>>();
196205
raw_path.extend([0, 0]);

0 commit comments

Comments
 (0)