add test for DuplicateHandle on a pseudo handle

This commit is contained in:
Ralf Jung 2026-01-24 11:10:48 +01:00
parent 3c03d82c84
commit 7a937ae239
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,22 @@
//@only-target: windows # Uses win32 api functions
use windows_sys::Win32::Foundation::{CloseHandle, DUPLICATE_SAME_ACCESS, DuplicateHandle};
use windows_sys::Win32::System::Threading::{GetCurrentProcess, GetCurrentThread};
fn main() {
unsafe {
let cur_proc = GetCurrentProcess();
let pseudo = GetCurrentThread();
let mut out = std::mem::zeroed();
let res =
DuplicateHandle(cur_proc, pseudo, cur_proc, &mut out, 0, 0, DUPLICATE_SAME_ACCESS);
//~^ERROR: pseudo handle
assert!(res != 0);
assert!(out.addr() != 0);
// Since the original handle was a pseudo handle, we must return something different.
assert!(out != pseudo);
// And closing it should work (which it does not for a pseudo handle).
let res = CloseHandle(out);
assert!(res != 0);
}
}

View file

@ -0,0 +1,12 @@
error: unsupported operation: `DuplicateHandle` called on a pseudo handle, which is unsupported
--> tests/fail-dep/win/duplicate-pseudo-handle.rs:LL:CC
|
LL | DuplicateHandle(cur_proc, pseudo, cur_proc, &mut out, 0, 0, DUPLICATE_SAME_ACCESS);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
|
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error