Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: update windows-sys to 0.59.0 #1857

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ libc = "0.2.159"
libc = "0.2.159"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.52"
version = "0.59"
features = [
"Wdk_Foundation", # Required for AFD.
"Wdk_Storage_FileSystem", # Required for AFD.
Expand Down
4 changes: 2 additions & 2 deletions src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Read for TcpStream {
}
}

impl<'a> Read for &'a TcpStream {
impl Read for &TcpStream {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.inner.do_io(|mut inner| inner.read(buf))
}
Expand All @@ -308,7 +308,7 @@ impl Write for TcpStream {
}
}

impl<'a> Write for &'a TcpStream {
impl Write for &TcpStream {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.inner.do_io(|mut inner| inner.write(buf))
}
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/afd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Afd {
(*iosb).Anonymous.Status = STATUS_PENDING;
let status = NtDeviceIoControlFile(
self.fd.as_raw_handle() as HANDLE,
0,
std::ptr::null_mut(),
None,
overlapped,
iosb,
Expand Down Expand Up @@ -131,7 +131,7 @@ cfg_io_source! {

const AFD_HELPER_ATTRIBUTES: OBJECT_ATTRIBUTES = OBJECT_ATTRIBUTES {
Length: size_of::<OBJECT_ATTRIBUTES>() as u32,
RootDirectory: 0,
RootDirectory: null_mut(),
ObjectName: &AFD_OBJ_NAME as *const _ as *mut _,
Attributes: 0,
SecurityDescriptor: null_mut(),
Expand Down
21 changes: 15 additions & 6 deletions src/sys/windows/iocp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;
use std::io;
use std::mem;
use std::os::windows::io::*;
use std::ptr::null_mut;
use std::time::Duration;

use windows_sys::Win32::Foundation::{HANDLE, INVALID_HANDLE_VALUE};
Expand All @@ -20,6 +21,14 @@ pub(crate) struct CompletionPort {
handle: Handle,
}

// SAFETY: `Handles`s are, in general, not thread-safe. However, we only used `Handle`s for
// resources that are thread-safe in `CompletionPort`.
unsafe impl Send for CompletionPort {}

// SAFETY: `Handles`s are, in general, not thread-safe. However, we only used `Handle`s for
// resources that are thread-safe in `CompletionPort`.
unsafe impl Sync for CompletionPort {}

/// A status message received from an I/O completion port.
///
/// These statuses can be created via the `new` or `empty` constructors and then
Expand All @@ -45,8 +54,8 @@ impl CompletionPort {
/// allowed for threads associated with this port. Consult the Windows
/// documentation for more information about this value.
pub fn new(threads: u32) -> io::Result<CompletionPort> {
let ret = unsafe { CreateIoCompletionPort(INVALID_HANDLE_VALUE, 0, 0, threads) };
if ret == 0 {
let ret = unsafe { CreateIoCompletionPort(INVALID_HANDLE_VALUE, null_mut(), 0, threads) };
if ret.is_null() {
Err(io::Error::last_os_error())
} else {
Ok(CompletionPort {
Expand All @@ -69,7 +78,7 @@ impl CompletionPort {
let ret = unsafe {
CreateIoCompletionPort(t.as_raw_handle() as HANDLE, self.handle.raw(), token, 0)
};
if ret == 0 {
if ret.is_null() {
Err(io::Error::last_os_error())
} else {
Ok(())
Expand Down Expand Up @@ -191,7 +200,7 @@ impl CompletionStatus {
/// This function is useful when creating a stack buffer or vector of
/// completion statuses to be passed to the `get_many` function.
pub fn zero() -> Self {
Self::new(0, 0, std::ptr::null_mut())
Self::new(0, 0, null_mut())
}

/// Returns the number of bytes that were transferred for the I/O operation
Expand All @@ -206,7 +215,7 @@ impl CompletionStatus {
/// A completion key is a per-handle key that is specified when it is added
/// to an I/O completion port via `add_handle` or `add_socket`.
pub fn token(&self) -> usize {
self.0.lpCompletionKey as usize
self.0.lpCompletionKey
}

/// Returns a pointer to the `Overlapped` structure that was specified when
Expand Down Expand Up @@ -268,6 +277,6 @@ mod tests {
}
assert_eq!(s[2].bytes_transferred(), 0);
assert_eq!(s[2].token(), 0);
assert_eq!(s[2].overlapped(), 0 as *mut _);
assert_eq!(s[2].overlapped(), std::ptr::null_mut());
}
}
14 changes: 11 additions & 3 deletions src/sys/windows/named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ struct Inner {
pool: Mutex<BufferPool>,
}

// SAFETY: `Handles`s are, in general, not thread-safe. However, we only used `Handle`s for
// resources that are thread-safe in `Inner`.
unsafe impl Send for Inner {}

// SAFETY: `Handles`s are, in general, not thread-safe. However, we only used `Handle`s for
// resources that are thread-safe in `Inner`.
unsafe impl Sync for Inner {}

impl Inner {
/// Converts a pointer to `Inner.connect` to a pointer to `Inner`.
///
Expand Down Expand Up @@ -515,7 +523,7 @@ impl Write for NamedPipe {
}
}

impl<'a> Read for &'a NamedPipe {
impl Read for &NamedPipe {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut state = self.inner.io.lock().unwrap();

Expand Down Expand Up @@ -566,7 +574,7 @@ impl<'a> Read for &'a NamedPipe {
}
}

impl<'a> Write for &'a NamedPipe {
impl Write for &NamedPipe {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// Make sure there's no writes pending
let mut io = self.inner.io.lock().unwrap();
Expand Down Expand Up @@ -947,7 +955,7 @@ fn event_done(status: &OVERLAPPED_ENTRY, events: Option<&mut Vec<Event>>) {
// cleanup. In this case, `events` is `None` and we don't need to track
// the event.
if let Some(events) = events {
let mut ev = Event::from_completion_status(&status);
let mut ev = Event::from_completion_status(status);
// Reverse the `.data` alteration done in `schedule_event`. This
// alteration was done so the selector recognized the event as one from
// a named pipe.
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, i32) {
};

let sockaddr_in = SOCKADDR_IN {
sin_family: AF_INET as u16, // 1
sin_family: AF_INET, // 1
sin_port: addr.port().to_be(),
sin_addr,
sin_zero: [0; 8],
Expand All @@ -97,7 +97,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, i32) {
};

let sockaddr_in6 = SOCKADDR_IN6 {
sin6_family: AF_INET6 as u16, // 23
sin6_family: AF_INET6, // 23
sin6_port: addr.port().to_be(),
sin6_addr,
sin6_flowinfo: addr.flowinfo(),
Expand Down
4 changes: 2 additions & 2 deletions src/sys/windows/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub(crate) fn only_v6(socket: &net::UdpSocket) -> io::Result<bool> {
syscall!(
getsockopt(
socket.as_raw_socket() as usize,
IPPROTO_IPV6 as i32,
IPV6_V6ONLY as i32,
IPPROTO_IPV6,
IPV6_V6ONLY,
optval.as_mut_ptr().cast(),
&mut optlen,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ pub fn set_linger_zero(socket: &TcpStream) {
let res = unsafe {
setsockopt(
socket.as_raw_socket() as _,
SOL_SOCKET as i32,
SO_LINGER as i32,
SOL_SOCKET,
SO_LINGER,
&mut val as *mut _ as *mut _,
size_of::<LINGER>() as _,
)
Expand Down