Skip to content

Commit

Permalink
Switch from winapi to windows-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
ncihnegn committed Nov 14, 2023
1 parent 77f471f commit b4b086d
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 166 deletions.
109 changes: 53 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ futures = "0.3.28"
color-eyre = "0.6.2"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [
"std",
"winbase",
"winerror",
"processthreadsapi",
"fileapi",
"handleapi",
"namedpipeapi",
] }
windows = "0.51.1"
windows-sys = {version = "0.48.0", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_Pipes",
"Win32_System_Threading",
]}

[target.'cfg(unix)'.dependencies]
libc = { version = "0.2.137", features = ["extra_traits"] }
Expand Down
21 changes: 10 additions & 11 deletions src/os/windows/c_wrappers.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
use super::winprelude::*;
use crate::os::windows::get_borrowed;
use std::{
io,
mem::{size_of, zeroed},
};
use winapi::um::{
handleapi::DuplicateHandle, minwinbase::SECURITY_ATTRIBUTES, processthreadsapi::GetCurrentProcess,
winnt::DUPLICATE_SAME_ACCESS,
use windows_sys::Win32::{
Foundation::{DuplicateHandle, DUPLICATE_SAME_ACCESS},
Security::SECURITY_ATTRIBUTES,
System::Threading::GetCurrentProcess,
};

pub fn duplicate_handle(handle: BorrowedHandle<'_>) -> io::Result<OwnedHandle> {
let raw = duplicate_handle_inner(handle, None)?;
unsafe { Ok(OwnedHandle::from_raw_handle(raw)) }
unsafe { Ok(OwnedHandle::from_raw_handle(raw as RawHandle)) }
}
pub fn duplicate_handle_to_foreign(
handle: BorrowedHandle<'_>,
other_process: BorrowedHandle<'_>,
) -> io::Result<RawHandle> {
) -> io::Result<HANDLE> {
duplicate_handle_inner(handle, Some(other_process))
}

fn duplicate_handle_inner(
handle: BorrowedHandle<'_>,
other_process: Option<BorrowedHandle<'_>>,
) -> io::Result<RawHandle> {
fn duplicate_handle_inner(handle: BorrowedHandle<'_>, other_process: Option<BorrowedHandle<'_>>) -> io::Result<HANDLE> {
let mut new_handle = INVALID_HANDLE_VALUE;
let success = unsafe {
let proc = GetCurrentProcess();
DuplicateHandle(
proc,
handle.as_raw_handle(),
other_process.map(|h| h.as_raw_handle()).unwrap_or(proc),
get_borrowed(handle),
other_process.map(|h| get_borrowed(h)).unwrap_or(proc),
&mut new_handle,
0,
0,
Expand Down
Loading

0 comments on commit b4b086d

Please sign in to comment.