Skip to content

Commit c51fbb3

Browse files
committed
Auto merge of #113001 - ChrisDenton:win-arm32-shim, r=thomcc
Move windows-sys arm32 shim to c.rs This moves the arm32 shim in to c.rs instead of appending to the generated file itself. This makes it simpler to change these workarounds if/when needed. The downside is we need to exclude a couple of functions from being generated (see the comment). A metadata solution could help here but they'll be easy enough to add back if that happens.
2 parents 0d03812 + 8a7399c commit c51fbb3

File tree

5 files changed

+44
-73
lines changed

5 files changed

+44
-73
lines changed

library/std/src/sys/windows/c.rs

+44
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,47 @@ compat_fn_with_fallback! {
431431
Status as u32
432432
}
433433
}
434+
435+
// # Arm32 shim
436+
//
437+
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
438+
// However, Microsoft no longer supports thumbv7a so definitions for those targets
439+
// are not included in the win32 metadata. We work around that by defining them here.
440+
//
441+
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
442+
cfg_if::cfg_if! {
443+
if #[cfg(not(target_vendor = "uwp"))] {
444+
#[link(name = "kernel32")]
445+
extern "system" {
446+
pub fn AddVectoredExceptionHandler(
447+
first: u32,
448+
handler: PVECTORED_EXCEPTION_HANDLER,
449+
) -> *mut c_void;
450+
}
451+
pub type PVECTORED_EXCEPTION_HANDLER = Option<
452+
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
453+
>;
454+
#[repr(C)]
455+
pub struct EXCEPTION_POINTERS {
456+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
457+
pub ContextRecord: *mut CONTEXT,
458+
}
459+
#[cfg(target_arch = "arm")]
460+
pub enum CONTEXT {}
461+
}}
462+
463+
#[link(name = "ws2_32")]
464+
extern "system" {
465+
pub fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32;
466+
}
467+
#[cfg(target_arch = "arm")]
468+
#[repr(C)]
469+
pub struct WSADATA {
470+
pub wVersion: u16,
471+
pub wHighVersion: u16,
472+
pub szDescription: [u8; 257],
473+
pub szSystemStatus: [u8; 129],
474+
pub iMaxSockets: u16,
475+
pub iMaxUdpDg: u16,
476+
pub lpVendorInfo: PSTR,
477+
}

library/std/src/sys/windows/c/windows_sys.lst

-4
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,6 @@ Windows.Win32.Networking.WinSock.WSARecv
21712171
Windows.Win32.Networking.WinSock.WSASend
21722172
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
21732173
Windows.Win32.Networking.WinSock.WSASocketW
2174-
Windows.Win32.Networking.WinSock.WSAStartup
21752174
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
21762175
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
21772176
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
@@ -2419,12 +2418,10 @@ Windows.Win32.System.Console.STD_HANDLE
24192418
Windows.Win32.System.Console.STD_INPUT_HANDLE
24202419
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
24212420
Windows.Win32.System.Console.WriteConsoleW
2422-
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
24232421
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
24242422
Windows.Win32.System.Diagnostics.Debug.CONTEXT
24252423
Windows.Win32.System.Diagnostics.Debug.CONTEXT
24262424
Windows.Win32.System.Diagnostics.Debug.CONTEXT
2427-
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_POINTERS
24282425
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD
24292426
Windows.Win32.System.Diagnostics.Debug.FACILITY_CODE
24302427
Windows.Win32.System.Diagnostics.Debug.FACILITY_NT_BIT
@@ -2437,7 +2434,6 @@ Windows.Win32.System.Diagnostics.Debug.FORMAT_MESSAGE_IGNORE_INSERTS
24372434
Windows.Win32.System.Diagnostics.Debug.FORMAT_MESSAGE_OPTIONS
24382435
Windows.Win32.System.Diagnostics.Debug.FormatMessageW
24392436
Windows.Win32.System.Diagnostics.Debug.M128A
2440-
Windows.Win32.System.Diagnostics.Debug.PVECTORED_EXCEPTION_HANDLER
24412437
Windows.Win32.System.Diagnostics.Debug.XSAVE_FORMAT
24422438
Windows.Win32.System.Diagnostics.Debug.XSAVE_FORMAT
24432439
Windows.Win32.System.Environment.FreeEnvironmentStringsW

library/std/src/sys/windows/c/windows_sys.rs

-45
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ extern "system" {
3939
pub fn AcquireSRWLockShared(srwlock: *mut RTL_SRWLOCK) -> ();
4040
}
4141
#[link(name = "kernel32")]
42-
extern "system" {
43-
pub fn AddVectoredExceptionHandler(
44-
first: u32,
45-
handler: PVECTORED_EXCEPTION_HANDLER,
46-
) -> *mut ::core::ffi::c_void;
47-
}
48-
#[link(name = "kernel32")]
4942
extern "system" {
5043
pub fn CancelIo(hfile: HANDLE) -> BOOL;
5144
}
@@ -711,10 +704,6 @@ extern "system" {
711704
) -> SOCKET;
712705
}
713706
#[link(name = "ws2_32")]
714-
extern "system" {
715-
pub fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32;
716-
}
717-
#[link(name = "ws2_32")]
718707
extern "system" {
719708
pub fn accept(s: SOCKET, addr: *mut SOCKADDR, addrlen: *mut i32) -> SOCKET;
720709
}
@@ -3029,17 +3018,6 @@ pub const ERROR_XML_PARSE_ERROR: WIN32_ERROR = 1465u32;
30293018
pub type EXCEPTION_DISPOSITION = i32;
30303019
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
30313020
#[repr(C)]
3032-
pub struct EXCEPTION_POINTERS {
3033-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
3034-
pub ContextRecord: *mut CONTEXT,
3035-
}
3036-
impl ::core::marker::Copy for EXCEPTION_POINTERS {}
3037-
impl ::core::clone::Clone for EXCEPTION_POINTERS {
3038-
fn clone(&self) -> Self {
3039-
*self
3040-
}
3041-
}
3042-
#[repr(C)]
30433021
pub struct EXCEPTION_RECORD {
30443022
pub ExceptionCode: NTSTATUS,
30453023
pub ExceptionFlags: u32,
@@ -3748,9 +3726,6 @@ pub const PROFILE_SERVER: PROCESS_CREATION_FLAGS = 1073741824u32;
37483726
pub const PROFILE_USER: PROCESS_CREATION_FLAGS = 268435456u32;
37493727
pub const PROGRESS_CONTINUE: u32 = 0u32;
37503728
pub type PSTR = *mut u8;
3751-
pub type PVECTORED_EXCEPTION_HANDLER = ::core::option::Option<
3752-
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
3753-
>;
37543729
pub type PWSTR = *mut u16;
37553730
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
37563731
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
@@ -4275,23 +4250,3 @@ impl ::core::clone::Clone for XSAVE_FORMAT {
42754250
*self
42764251
}
42774252
}
4278-
// Begin of ARM32 shim
4279-
// The raw content of this file should be processed by `generate-windows-sys`
4280-
// to be merged with the generated binding. It is not supposed to be used as
4281-
// a normal Rust module.
4282-
cfg_if::cfg_if! {
4283-
if #[cfg(target_arch = "arm")] {
4284-
#[repr(C)]
4285-
pub struct WSADATA {
4286-
pub wVersion: u16,
4287-
pub wHighVersion: u16,
4288-
pub szDescription: [u8; 257],
4289-
pub szSystemStatus: [u8; 129],
4290-
pub iMaxSockets: u16,
4291-
pub iMaxUdpDg: u16,
4292-
pub lpVendorInfo: PSTR,
4293-
}
4294-
pub enum CONTEXT {}
4295-
}
4296-
}
4297-
// End of ARM32 shim

src/tools/generate-windows-sys/src/arm_shim.rs

-20
This file was deleted.

src/tools/generate-windows-sys/src/main.rs

-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ const PRELUDE: &str = r#"// This file is autogenerated.
1111
// ignore-tidy-filelength
1212
"#;
1313

14-
/// This is a shim for the ARM (32-bit) architecture, which is no longer supported by windows-rs.
15-
const ARM_SHIM: &str = include_str!("arm_shim.rs");
16-
1714
fn main() -> io::Result<()> {
1815
let mut path: PathBuf =
1916
std::env::args_os().nth(1).expect("a path to the rust repository is required").into();
@@ -35,7 +32,6 @@ fn main() -> io::Result<()> {
3532
let mut f = std::fs::File::create(&path)?;
3633
f.write_all(PRELUDE.as_bytes())?;
3734
f.write_all(bindings.as_bytes())?;
38-
f.write_all(ARM_SHIM.as_bytes())?;
3935

4036
Ok(())
4137
}

0 commit comments

Comments
 (0)