Merge pull request #4818 from beepster4096/psuedohandling
windows shims: throw unsupported error for DuplicateHandle on pseudo handle
This commit is contained in:
commit
a3d2e99d13
4 changed files with 40 additions and 2 deletions
|
|
@ -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")?,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
22
src/tools/miri/tests/fail-dep/win/duplicate-pseudo-handle.rs
Normal file
22
src/tools/miri/tests/fail-dep/win/duplicate-pseudo-handle.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue