Skip to content

Commit 7284100

Browse files
authored
Merge pull request rust-lang#4261 from CraftSpider/windows-rtl-to-dos
Implement RtlNtStatusToDosError and shim test for it
2 parents d1f901a + f243cb8 commit 7284100

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
@@ -396,6 +396,25 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
396396
let last_error = this.get_last_error()?;
397397
this.write_scalar(last_error, dest)?;
398398
}
399+
"RtlNtStatusToDosError" => {
400+
let [status] = this.check_shim(abi, sys_conv, link_name, args)?;
401+
let status = this.read_scalar(status)?.to_u32()?;
402+
let err = match status {
403+
// STATUS_MEDIA_WRITE_PROTECTED => ERROR_WRITE_PROTECT
404+
0xC00000A2 => 19,
405+
// STATUS_FILE_INVALID => ERROR_FILE_INVALID
406+
0xC0000098 => 1006,
407+
// STATUS_DISK_FULL => ERROR_DISK_FULL
408+
0xC000007F => 112,
409+
// STATUS_IO_DEVICE_ERROR => ERROR_IO_DEVICE
410+
0xC0000185 => 1117,
411+
// STATUS_ACCESS_DENIED => ERROR_ACCESS_DENIED
412+
0xC0000022 => 5,
413+
// Anything without an error code => ERROR_MR_MID_NOT_FOUND
414+
_ => 317,
415+
};
416+
this.write_scalar(Scalar::from_i32(err), dest)?;
417+
}
399418

400419
// Querying system information
401420
"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)