Skip to content

Commit

Permalink
[WIP] Update to next windows-sys version
Browse files Browse the repository at this point in the history
TODO: remove the use of the git repo and use a published version.
  • Loading branch information
Thomasdezeeuw committed Jul 12, 2023
1 parent ec0776f commit 08b84c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ libc = "0.2.121"
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.48"
features = [
"Wdk_Foundation", # Required for AFD.
"Wdk_Storage_FileSystem", # Required for AFD.
"Wdk_System_IO", # Required for AFD.
"Win32_Foundation", # Basic types eg HANDLE
"Win32_Networking_WinSock", # winsock2 types/functions
"Win32_Storage_FileSystem", # Enables NtCreateFile
"Win32_System_IO", # IO types like OVERLAPPED etc
"Win32_System_WindowsProgramming", # General future used for various types/funcs
]

[patch.crates-io]
windows-sys = { git = 'https://github.com/microsoft/windows-rs', rev = 'a98ae0578b787e67546303186b46494f0c0a7a46' }

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = "0.11.0"
libc = "0.2.121"
Expand Down
34 changes: 11 additions & 23 deletions src/sys/windows/afd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@ use std::io;
use std::mem::size_of;
use std::os::windows::io::AsRawHandle;

use windows_sys::Wdk::Storage::FileSystem::NtCancelIoFileEx;
use windows_sys::Wdk::System::IO::NtDeviceIoControlFile;
use windows_sys::Win32::Foundation::{
RtlNtStatusToDosError, HANDLE, NTSTATUS, STATUS_NOT_FOUND, STATUS_PENDING, STATUS_SUCCESS,
};
use windows_sys::Win32::System::WindowsProgramming::{
NtDeviceIoControlFile, IO_STATUS_BLOCK, IO_STATUS_BLOCK_0,
};
use windows_sys::Win32::System::IO::{IO_STATUS_BLOCK, IO_STATUS_BLOCK_0};

const IOCTL_AFD_POLL: u32 = 0x00012024;

#[link(name = "ntdll")]
extern "system" {
/// See <https://processhacker.sourceforge.io/doc/ntioapi_8h.html#a0d4d550cad4d62d75b76961e25f6550c>
///
/// This is an undocumented API and as such not part of <https://github.com/microsoft/win32metadata>
/// from which `windows-sys` is generated, and also unlikely to be added, so
/// we manually declare it here
fn NtCancelIoFileEx(
FileHandle: HANDLE,
IoRequestToCancel: *mut IO_STATUS_BLOCK,
IoStatusBlock: *mut IO_STATUS_BLOCK,
) -> NTSTATUS;
}
/// Winsock2 AFD driver instance.
///
/// All operations are unsafe due to IO_STATUS_BLOCK parameter are being used by Afd driver during STATUS_PENDING before I/O Completion Port returns its result.
Expand Down Expand Up @@ -132,14 +119,15 @@ cfg_io_source! {
use std::ptr::null_mut;
use std::sync::atomic::{AtomicUsize, Ordering};

use super::iocp::CompletionPort;
use windows_sys::Win32::{
Foundation::{UNICODE_STRING, INVALID_HANDLE_VALUE},
System::WindowsProgramming::{
OBJECT_ATTRIBUTES, FILE_SKIP_SET_EVENT_ON_HANDLE,
},
Storage::FileSystem::{FILE_OPEN, NtCreateFile, SetFileCompletionNotificationModes, SYNCHRONIZE, FILE_SHARE_READ, FILE_SHARE_WRITE},
use windows_sys::Wdk::Foundation::OBJECT_ATTRIBUTES;
use windows_sys::Wdk::Storage::FileSystem::{NtCreateFile, FILE_OPEN};
use windows_sys::Win32::Foundation::{INVALID_HANDLE_VALUE, UNICODE_STRING};
use windows_sys::Win32::Storage::FileSystem::{
SetFileCompletionNotificationModes, FILE_SHARE_READ, FILE_SHARE_WRITE, SYNCHRONIZE,
};
use windows_sys::Win32::System::WindowsProgramming::FILE_SKIP_SET_EVENT_ON_HANDLE;

use super::iocp::CompletionPort;

const AFD_HELPER_ATTRIBUTES: OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES {
Length: size_of::<OBJECT_ATTRIBUTES>() as u32,
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/io_status_block.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt;
use std::ops::{Deref, DerefMut};

use windows_sys::Win32::System::WindowsProgramming::IO_STATUS_BLOCK;
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK;

pub struct IoStatusBlock(IO_STATUS_BLOCK);

cfg_io_source! {
use windows_sys::Win32::System::WindowsProgramming::{IO_STATUS_BLOCK_0};
use windows_sys::Win32::System::IO::IO_STATUS_BLOCK_0;

impl IoStatusBlock {
pub fn zeroed() -> Self {
Expand Down

0 comments on commit 08b84c5

Please sign in to comment.