Skip to content

Move windows-sys arm32 shim to c.rs #113001

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

Merged
merged 1 commit into from
Jun 25, 2023
Merged
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
44 changes: 44 additions & 0 deletions library/std/src/sys/windows/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,47 @@ compat_fn_with_fallback! {
Status as u32
}
}

// # Arm32 shim
//
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
// However, Microsoft no longer supports thumbv7a so definitions for those targets
// are not included in the win32 metadata. We work around that by defining them here.
//
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
cfg_if::cfg_if! {
if #[cfg(not(target_vendor = "uwp"))] {
#[link(name = "kernel32")]
extern "system" {
pub fn AddVectoredExceptionHandler(
first: u32,
handler: PVECTORED_EXCEPTION_HANDLER,
) -> *mut c_void;
}
pub type PVECTORED_EXCEPTION_HANDLER = Option<
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
>;
#[repr(C)]
pub struct EXCEPTION_POINTERS {
pub ExceptionRecord: *mut EXCEPTION_RECORD,
pub ContextRecord: *mut CONTEXT,
}
#[cfg(target_arch = "arm")]
pub enum CONTEXT {}
}}

#[link(name = "ws2_32")]
extern "system" {
pub fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32;
}
#[cfg(target_arch = "arm")]
#[repr(C)]
pub struct WSADATA {
pub wVersion: u16,
pub wHighVersion: u16,
pub szDescription: [u8; 257],
pub szSystemStatus: [u8; 129],
pub iMaxSockets: u16,
pub iMaxUdpDg: u16,
pub lpVendorInfo: PSTR,
}
4 changes: 0 additions & 4 deletions library/std/src/sys/windows/c/windows_sys.lst
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,6 @@ Windows.Win32.Networking.WinSock.WSARecv
Windows.Win32.Networking.WinSock.WSASend
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
Windows.Win32.Networking.WinSock.WSASocketW
Windows.Win32.Networking.WinSock.WSAStartup
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
Expand Down Expand Up @@ -2419,12 +2418,10 @@ Windows.Win32.System.Console.STD_HANDLE
Windows.Win32.System.Console.STD_INPUT_HANDLE
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
Windows.Win32.System.Console.WriteConsoleW
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
Windows.Win32.System.Diagnostics.Debug.CONTEXT
Windows.Win32.System.Diagnostics.Debug.CONTEXT
Windows.Win32.System.Diagnostics.Debug.CONTEXT
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_POINTERS
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD
Windows.Win32.System.Diagnostics.Debug.FACILITY_CODE
Windows.Win32.System.Diagnostics.Debug.FACILITY_NT_BIT
Expand All @@ -2437,7 +2434,6 @@ Windows.Win32.System.Diagnostics.Debug.FORMAT_MESSAGE_IGNORE_INSERTS
Windows.Win32.System.Diagnostics.Debug.FORMAT_MESSAGE_OPTIONS
Windows.Win32.System.Diagnostics.Debug.FormatMessageW
Windows.Win32.System.Diagnostics.Debug.M128A
Windows.Win32.System.Diagnostics.Debug.PVECTORED_EXCEPTION_HANDLER
Windows.Win32.System.Diagnostics.Debug.XSAVE_FORMAT
Windows.Win32.System.Diagnostics.Debug.XSAVE_FORMAT
Windows.Win32.System.Environment.FreeEnvironmentStringsW
Expand Down
45 changes: 0 additions & 45 deletions library/std/src/sys/windows/c/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ extern "system" {
pub fn AcquireSRWLockShared(srwlock: *mut RTL_SRWLOCK) -> ();
}
#[link(name = "kernel32")]
extern "system" {
pub fn AddVectoredExceptionHandler(
first: u32,
handler: PVECTORED_EXCEPTION_HANDLER,
) -> *mut ::core::ffi::c_void;
}
#[link(name = "kernel32")]
extern "system" {
pub fn CancelIo(hfile: HANDLE) -> BOOL;
}
Expand Down Expand Up @@ -711,10 +704,6 @@ extern "system" {
) -> SOCKET;
}
#[link(name = "ws2_32")]
extern "system" {
pub fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32;
}
#[link(name = "ws2_32")]
extern "system" {
pub fn accept(s: SOCKET, addr: *mut SOCKADDR, addrlen: *mut i32) -> SOCKET;
}
Expand Down Expand Up @@ -3029,17 +3018,6 @@ pub const ERROR_XML_PARSE_ERROR: WIN32_ERROR = 1465u32;
pub type EXCEPTION_DISPOSITION = i32;
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
#[repr(C)]
pub struct EXCEPTION_POINTERS {
pub ExceptionRecord: *mut EXCEPTION_RECORD,
pub ContextRecord: *mut CONTEXT,
}
impl ::core::marker::Copy for EXCEPTION_POINTERS {}
impl ::core::clone::Clone for EXCEPTION_POINTERS {
fn clone(&self) -> Self {
*self
}
}
#[repr(C)]
pub struct EXCEPTION_RECORD {
pub ExceptionCode: NTSTATUS,
pub ExceptionFlags: u32,
Expand Down Expand Up @@ -3748,9 +3726,6 @@ pub const PROFILE_SERVER: PROCESS_CREATION_FLAGS = 1073741824u32;
pub const PROFILE_USER: PROCESS_CREATION_FLAGS = 268435456u32;
pub const PROGRESS_CONTINUE: u32 = 0u32;
pub type PSTR = *mut u8;
pub type PVECTORED_EXCEPTION_HANDLER = ::core::option::Option<
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
>;
pub type PWSTR = *mut u16;
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
Expand Down Expand Up @@ -4275,23 +4250,3 @@ impl ::core::clone::Clone for XSAVE_FORMAT {
*self
}
}
// Begin of ARM32 shim
// The raw content of this file should be processed by `generate-windows-sys`
// to be merged with the generated binding. It is not supposed to be used as
// a normal Rust module.
cfg_if::cfg_if! {
if #[cfg(target_arch = "arm")] {
#[repr(C)]
pub struct WSADATA {
pub wVersion: u16,
pub wHighVersion: u16,
pub szDescription: [u8; 257],
pub szSystemStatus: [u8; 129],
pub iMaxSockets: u16,
pub iMaxUdpDg: u16,
pub lpVendorInfo: PSTR,
}
pub enum CONTEXT {}
}
}
// End of ARM32 shim
20 changes: 0 additions & 20 deletions src/tools/generate-windows-sys/src/arm_shim.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/tools/generate-windows-sys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const PRELUDE: &str = r#"// This file is autogenerated.
// ignore-tidy-filelength
"#;

/// This is a shim for the ARM (32-bit) architecture, which is no longer supported by windows-rs.
const ARM_SHIM: &str = include_str!("arm_shim.rs");

fn main() -> io::Result<()> {
let mut path: PathBuf =
std::env::args_os().nth(1).expect("a path to the rust repository is required").into();
Expand All @@ -35,7 +32,6 @@ fn main() -> io::Result<()> {
let mut f = std::fs::File::create(&path)?;
f.write_all(PRELUDE.as_bytes())?;
f.write_all(bindings.as_bytes())?;
f.write_all(ARM_SHIM.as_bytes())?;

Ok(())
}