diff options
| author | David Lönnhager <david.l@mullvad.net> | 2023-11-20 19:35:52 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-04-16 14:38:02 +0200 |
| commit | 99ae0b436f173b576343111cac38d6bec4ce2487 (patch) | |
| tree | c17063ac40285f7540dc28d7f161b05ca51c5c4e | |
| parent | b9a59074141024a9d40723dca5c58cfe15fccbbc (diff) | |
| download | mullvadvpn-99ae0b436f173b576343111cac38d6bec4ce2487.tar.xz mullvadvpn-99ae0b436f173b576343111cac38d6bec4ce2487.zip | |
Add Event::duplicate
| -rw-r--r-- | talpid-windows/src/sync.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/talpid-windows/src/sync.rs b/talpid-windows/src/sync.rs index 202c96524d..7b4ed59be3 100644 --- a/talpid-windows/src/sync.rs +++ b/talpid-windows/src/sync.rs @@ -1,7 +1,7 @@ use std::{io, ptr}; use windows_sys::Win32::{ - Foundation::{CloseHandle, BOOL, HANDLE}, - System::Threading::{CreateEventW, SetEvent}, + Foundation::{CloseHandle, DuplicateHandle, BOOL, DUPLICATE_SAME_ACCESS, HANDLE}, + System::Threading::{CreateEventW, GetCurrentProcess, SetEvent}, }; /// Windows event object @@ -39,6 +39,26 @@ impl Event { pub fn as_raw(&self) -> HANDLE { self.0 } + + /// Duplicate the event object with `DuplicateHandle()` + pub fn duplicate(&self) -> io::Result<Event> { + let mut new_event = 0; + let status = unsafe { + DuplicateHandle( + GetCurrentProcess(), + self.0, + GetCurrentProcess(), + &mut new_event, + 0, + 0, + DUPLICATE_SAME_ACCESS, + ) + }; + if status == 0 { + return Err(io::Error::last_os_error()); + } + Ok(Event(new_event)) + } } impl Drop for Event { |
