win-handles-sys
Memory-safe Rust over the Win32 handle and object API, the area Microsoft Learn files under System Services > Windows System Information > Handles and Objects. Thin over Win32, adding no policy.
duplicate_handle_with_accessisDuplicateHandleover any handle, in this process, with the access mask chosen. It returns anOwnedHandle, so the duplicate is closed when it is dropped and nothing else has to.get_handle_informationisGetHandleInformation: theHandleFlagsa handle carries, whether it is inheritable and whether closing it is refused. A bit Windows defines that is not named is kept, not refused.Accessis the mask, a newtype over the Win32 bits combined with|.SYNCHRONIZEandEVENT_MODIFY_STATEare named; any other right isAccess::from_bits.
Windows does not confine a duplicate to the source handle's access. A duplicate may ask for rights the source lacks and get them, so narrowing is a guard against a handle being used for what it was not handed out for, and not a boundary against code in the process that sets out to cross it.
use File;
use ;
let path = temp_dir.join;
let file = create?;
// A second handle to the same file, that can wait on it and do nothing else.
let waiter = duplicate_handle_with_access?;
drop;
# drop;
# remove_file?;
# Ok::
The crate was made by moving this code out of win-sync-sys. From that crate's release that depends on this
one, it re-exports this crate at the paths it had; a release from before then has its own copy, whose types are
distinct from these.