diff --git a/Cargo.lock b/Cargo.lock index 19937dea8..635bf006f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1744,7 +1744,7 @@ version = "0.8.3" dependencies = [ "libc", "thiserror 1.0.69", - "winapi", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c102eb98a..de2616236 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -266,6 +266,7 @@ winapi = "0.3.9" window = {path="window"} window-funcs = { path = "lua-api-crates/window-funcs" } windows = "0.33.0" +windows-sys = { version = "0.61.2", default-features = false } winreg = "0.10" x11 = "2.21" xcb = "1.3" diff --git a/filedescriptor/Cargo.toml b/filedescriptor/Cargo.toml index 4241e97a1..50f9728ad 100644 --- a/filedescriptor/Cargo.toml +++ b/filedescriptor/Cargo.toml @@ -15,12 +15,13 @@ thiserror.workspace = true libc.workspace = true [target."cfg(windows)".dependencies] -winapi = { workspace=true, features = [ - "winuser", - "handleapi", - "fileapi", - "namedpipeapi", - "processthreadsapi", - "winsock2", - "processenv" +windows-sys = { workspace=true, features = [ + "Win32_Foundation", + "Win32_Networking_WinSock", + "Win32_Security", + "Win32_Storage_FileSystem", + "Win32_System_Console", + "Win32_System_IO", + "Win32_System_Pipes", + "Win32_System_Threading", ]} diff --git a/filedescriptor/src/windows.rs b/filedescriptor/src/windows.rs index 6b43f7f3c..aa75af90e 100644 --- a/filedescriptor/src/windows.rs +++ b/filedescriptor/src/windows.rs @@ -8,21 +8,25 @@ use std::os::windows::prelude::*; use std::ptr; use std::sync::Once; use std::time::Duration; -use winapi::shared::ws2def::{AF_INET, INADDR_LOOPBACK, SOCKADDR_IN}; -use winapi::um::fileapi::*; -use winapi::um::handleapi::*; -use winapi::um::minwinbase::SECURITY_ATTRIBUTES; -use winapi::um::namedpipeapi::{CreatePipe, GetNamedPipeInfo}; -use winapi::um::processenv::{GetStdHandle, SetStdHandle}; -use winapi::um::processthreadsapi::*; -use winapi::um::winbase::{FILE_TYPE_CHAR, FILE_TYPE_DISK, FILE_TYPE_PIPE}; -use winapi::um::winnt::HANDLE; -use winapi::um::winsock2::{ - accept, bind, closesocket, connect, getsockname, getsockopt, htonl, ioctlsocket, listen, recv, - send, WSAGetLastError, WSAPoll, WSASocketW, WSAStartup, INVALID_SOCKET, SOCKET, SOCK_STREAM, - SOL_SOCKET, SO_ERROR, WSADATA, WSAENOTSOCK, WSA_FLAG_NO_HANDLE_INHERIT, +use windows_sys::Win32::Foundation::{ + CloseHandle, DuplicateHandle, DUPLICATE_SAME_ACCESS, HANDLE, INVALID_HANDLE_VALUE, }; -pub use winapi::um::winsock2::{POLLERR, POLLHUP, POLLIN, POLLOUT, WSAPOLLFD as pollfd}; +use windows_sys::Win32::Networking::WinSock::{ + accept, bind, closesocket, connect, getsockname, getsockopt, htonl, ioctlsocket, listen, recv, + send, WSAGetLastError, WSAPoll, WSASocketW, WSAStartup, ADDRESS_FAMILY, AF_INET, FIONBIO, + INADDR_LOOPBACK, INVALID_SOCKET, SOCKADDR_IN, SOCKET, SOCK_STREAM, SOL_SOCKET, SO_ERROR, + WSADATA, WSAENOTSOCK, WSA_FLAG_NO_HANDLE_INHERIT, +}; +pub use windows_sys::Win32::Networking::WinSock::{ + POLLERR, POLLHUP, POLLIN, POLLOUT, WSAPOLLFD as pollfd, +}; +use windows_sys::Win32::Security::SECURITY_ATTRIBUTES; +use windows_sys::Win32::Storage::FileSystem::{ + GetFileType, ReadFile, WriteFile, FILE_TYPE_CHAR, FILE_TYPE_DISK, FILE_TYPE_PIPE, +}; +use windows_sys::Win32::System::Console::{GetStdHandle, SetStdHandle}; +use windows_sys::Win32::System::Pipes::{CreatePipe, GetNamedPipeInfo}; +use windows_sys::Win32::System::Threading::GetCurrentProcess; /// `RawFileDescriptor` is a platform independent type alias for the /// underlying platform file descriptor type. It is primarily useful @@ -126,7 +130,7 @@ impl OwnedHandle { handle as _, SOL_SOCKET, SO_ERROR, - &mut err as *mut _ as *mut i8, + &mut err as *mut _ as *mut _, &mut errsize, ) != 0 && WSAGetLastError() == WSAENOTSOCK @@ -196,7 +200,7 @@ impl OwnedHandle { &mut duped, 0, 0, // not inheritable - winapi::um::winnt::DUPLICATE_SAME_ACCESS, + DUPLICATE_SAME_ACCESS, ) }; if ok == 0 { @@ -254,13 +258,7 @@ impl FileDescriptor { } let mut on = if non_blocking { 1 } else { 0 }; - let res = unsafe { - ioctlsocket( - self.as_raw_socket() as SOCKET, - winapi::um::winsock2::FIONBIO, - &mut on, - ) - }; + let res = unsafe { ioctlsocket(self.as_raw_socket() as SOCKET, FIONBIO, &mut on) }; if res != 0 { Err(Error::FionBio(std::io::Error::last_os_error())) } else { @@ -327,7 +325,7 @@ impl AsRawSocket for FileDescriptor { } impl AsSocket for FileDescriptor { - fn as_socket(&self) -> BorrowedSocket { + fn as_socket(&self) -> BorrowedSocket<'_> { unsafe { BorrowedSocket::borrow_raw(self.as_raw_socket()) } } } @@ -465,10 +463,10 @@ fn init_winsock() { }); } -fn socket(af: i32, sock_type: i32, proto: i32) -> Result { +fn socket(af: ADDRESS_FAMILY, sock_type: i32, proto: i32) -> Result { let s = unsafe { WSASocketW( - af, + af as _, sock_type, proto, ptr::null_mut(), @@ -495,10 +493,8 @@ pub fn socketpair_impl() -> Result<(FileDescriptor, FileDescriptor)> { let s = socket(AF_INET, SOCK_STREAM, 0)?; let mut in_addr: SOCKADDR_IN = unsafe { std::mem::zeroed() }; - in_addr.sin_family = AF_INET as _; - unsafe { - *in_addr.sin_addr.S_un.S_addr_mut() = htonl(INADDR_LOOPBACK); - } + in_addr.sin_family = AF_INET; + in_addr.sin_addr.S_un.S_addr = unsafe { htonl(INADDR_LOOPBACK) }; unsafe { if bind( diff --git a/mux/Cargo.toml b/mux/Cargo.toml index 3aa00b582..4fa91ef0c 100644 --- a/mux/Cargo.toml +++ b/mux/Cargo.toml @@ -57,6 +57,7 @@ winapi = { workspace=true, features = [ "psapi", "processthreadsapi", "tlhelp32", + "winsock2" ]} [dev-dependencies] diff --git a/pty/Cargo.toml b/pty/Cargo.toml index fed6ae3c5..359686deb 100644 --- a/pty/Cargo.toml +++ b/pty/Cargo.toml @@ -33,6 +33,7 @@ winapi = { workspace=true, features = [ "handleapi", "fileapi", "namedpipeapi", + "processenv", "synchapi", ]} winreg.workspace = true