Merge pull request #4818 from beepster4096/psuedohandling

windows shims: throw unsupported error for DuplicateHandle on pseudo handle
This commit is contained in:
Ralf Jung 2026-01-24 11:25:57 +00:00 committed by GitHub
commit a3d2e99d13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 2 deletions

View file

@ -314,7 +314,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"`DuplicateHandle` called on a thread handle, which is unsupported"
);
}
Handle::Pseudo(pseudo) => Handle::Pseudo(pseudo),
Handle::Pseudo(_) => {
throw_unsup_format!(
"`DuplicateHandle` called on a pseudo handle, which is unsupported"
);
}
Handle::Null | Handle::Invalid => this.invalid_handle("DuplicateHandle")?,
};

View file

@ -12,7 +12,7 @@ use windows_sys::Win32::System::Threading::{INFINITE, WaitForSingleObject};
// XXX HACK: This is how miri represents the handle for thread 0.
// This value can be "legitimately" obtained by using `GetCurrentThread` with `DuplicateHandle`
// but miri does not implement `DuplicateHandle` yet. (FIXME: it does now.)
// but miri does not implement `DuplicateHandle` for pseudo handles yet.
const MAIN_THREAD: HANDLE = (2i32 << 29) as HANDLE;
fn main() {

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