Skip to content

Commit b40e0d5

Browse files
authored
Unrolled build for rust-lang#127999
Rollup merge of rust-lang#127999 - ChrisDenton:arm32, r=Amanieu Inject arm32 shims into Windows metadata generation I had been keen to eventually move to using windows-sys as a normal Cargo dependency. But for linking, compile times and other reasons that's unlikely to ever happen. So if we're sticking with generated bindings then injecting any necessary missing type definitions (i.e. for the MS unsupported arm32) is simpler than defining whole functions ourselves just because we need to manually implement those types on a tier 3 platform. This also reduces the places we need to change when making changes to how we use `#[link]`. r? libs
2 parents eb10639 + c629bfc commit b40e0d5

File tree

4 files changed

+45
-41
lines changed

4 files changed

+45
-41
lines changed

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

-41
Original file line numberDiff line numberDiff line change
@@ -276,44 +276,3 @@ compat_fn_with_fallback! {
276276
Status as u32
277277
}
278278
}
279-
280-
// # Arm32 shim
281-
//
282-
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
283-
// However, Microsoft no longer supports thumbv7a so definitions for those targets
284-
// are not included in the win32 metadata. We work around that by defining them here.
285-
//
286-
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
287-
cfg_if::cfg_if! {
288-
if #[cfg(not(target_vendor = "uwp"))] {
289-
#[link(name = "kernel32")]
290-
extern "system" {
291-
pub fn AddVectoredExceptionHandler(
292-
first: u32,
293-
handler: PVECTORED_EXCEPTION_HANDLER,
294-
) -> *mut c_void;
295-
}
296-
pub type PVECTORED_EXCEPTION_HANDLER = Option<
297-
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
298-
>;
299-
#[repr(C)]
300-
pub struct EXCEPTION_POINTERS {
301-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
302-
pub ContextRecord: *mut CONTEXT,
303-
}
304-
#[cfg(target_arch = "arm")]
305-
pub enum CONTEXT {}
306-
}}
307-
// WSAStartup is only redefined here so that we can override WSADATA for Arm32
308-
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32);
309-
#[cfg(target_arch = "arm")]
310-
#[repr(C)]
311-
pub struct WSADATA {
312-
pub wVersion: u16,
313-
pub wHighVersion: u16,
314-
pub szDescription: [u8; 257],
315-
pub szSystemStatus: [u8; 129],
316-
pub iMaxSockets: u16,
317-
pub iMaxUdpDg: u16,
318-
pub lpVendorInfo: PSTR,
319-
}

library/std/src/sys/pal/windows/c/bindings.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ Windows.Win32.Networking.WinSock.WSARecv
21762176
Windows.Win32.Networking.WinSock.WSASend
21772177
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
21782178
Windows.Win32.Networking.WinSock.WSASocketW
2179+
Windows.Win32.Networking.WinSock.WSAStartup
21792180
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
21802181
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
21812182
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
@@ -2420,6 +2421,7 @@ Windows.Win32.System.Console.STD_HANDLE
24202421
Windows.Win32.System.Console.STD_INPUT_HANDLE
24212422
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
24222423
Windows.Win32.System.Console.WriteConsoleW
2424+
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
24232425
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
24242426
Windows.Win32.System.Diagnostics.Debug.CONTEXT
24252427
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD

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

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ windows_targets::link!("advapi32.dll" "system" fn OpenProcessToken(processhandle
55
windows_targets::link!("advapi32.dll" "system" "SystemFunction036" fn RtlGenRandom(randombuffer : *mut core::ffi::c_void, randombufferlength : u32) -> BOOLEAN);
66
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockExclusive(srwlock : *mut SRWLOCK));
77
windows_targets::link!("kernel32.dll" "system" fn AcquireSRWLockShared(srwlock : *mut SRWLOCK));
8+
windows_targets::link!("kernel32.dll" "system" fn AddVectoredExceptionHandler(first : u32, handler : PVECTORED_EXCEPTION_HANDLER) -> *mut core::ffi::c_void);
89
windows_targets::link!("kernel32.dll" "system" fn CancelIo(hfile : HANDLE) -> BOOL);
910
windows_targets::link!("kernel32.dll" "system" fn CloseHandle(hobject : HANDLE) -> BOOL);
1011
windows_targets::link!("kernel32.dll" "system" fn CompareStringOrdinal(lpstring1 : PCWSTR, cchcount1 : i32, lpstring2 : PCWSTR, cchcount2 : i32, bignorecase : BOOL) -> COMPARESTRING_RESULT);
@@ -114,6 +115,7 @@ windows_targets::link!("ws2_32.dll" "system" fn WSAGetLastError() -> WSA_ERROR);
114115
windows_targets::link!("ws2_32.dll" "system" fn WSARecv(s : SOCKET, lpbuffers : *const WSABUF, dwbuffercount : u32, lpnumberofbytesrecvd : *mut u32, lpflags : *mut u32, lpoverlapped : *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> i32);
115116
windows_targets::link!("ws2_32.dll" "system" fn WSASend(s : SOCKET, lpbuffers : *const WSABUF, dwbuffercount : u32, lpnumberofbytessent : *mut u32, dwflags : u32, lpoverlapped : *mut OVERLAPPED, lpcompletionroutine : LPWSAOVERLAPPED_COMPLETION_ROUTINE) -> i32);
116117
windows_targets::link!("ws2_32.dll" "system" fn WSASocketW(af : i32, r#type : i32, protocol : i32, lpprotocolinfo : *const WSAPROTOCOL_INFOW, g : u32, dwflags : u32) -> SOCKET);
118+
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested : u16, lpwsadata : *mut WSADATA) -> i32);
117119
windows_targets::link!("ws2_32.dll" "system" fn accept(s : SOCKET, addr : *mut SOCKADDR, addrlen : *mut i32) -> SOCKET);
118120
windows_targets::link!("ws2_32.dll" "system" fn bind(s : SOCKET, name : *const SOCKADDR, namelen : i32) -> i32);
119121
windows_targets::link!("ws2_32.dll" "system" fn closesocket(s : SOCKET) -> i32);
@@ -2284,6 +2286,12 @@ pub type EXCEPTION_DISPOSITION = i32;
22842286
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
22852287
#[repr(C)]
22862288
#[derive(Clone, Copy)]
2289+
pub struct EXCEPTION_POINTERS {
2290+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
2291+
pub ContextRecord: *mut CONTEXT,
2292+
}
2293+
#[repr(C)]
2294+
#[derive(Clone, Copy)]
22872295
pub struct EXCEPTION_RECORD {
22882296
pub ExceptionCode: NTSTATUS,
22892297
pub ExceptionFlags: u32,
@@ -2860,6 +2868,8 @@ pub type PTIMERAPCROUTINE = Option<
28602868
dwtimerhighvalue: u32,
28612869
),
28622870
>;
2871+
pub type PVECTORED_EXCEPTION_HANDLER =
2872+
Option<unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32>;
28632873
pub type PWSTR = *mut u16;
28642874
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
28652875
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
@@ -3292,5 +3302,19 @@ pub struct XSAVE_FORMAT {
32923302
pub XmmRegisters: [M128A; 8],
32933303
pub Reserved4: [u8; 224],
32943304
}
3305+
3306+
#[cfg(target_arch = "arm")]
3307+
#[repr(C)]
3308+
pub struct WSADATA {
3309+
pub wVersion: u16,
3310+
pub wHighVersion: u16,
3311+
pub szDescription: [u8; 257],
3312+
pub szSystemStatus: [u8; 129],
3313+
pub iMaxSockets: u16,
3314+
pub iMaxUdpDg: u16,
3315+
pub lpVendorInfo: PSTR,
3316+
}
3317+
#[cfg(target_arch = "arm")]
3318+
pub enum CONTEXT {}
32953319
// ignore-tidy-filelength
32963320
use super::windows_targets;

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

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ use std::fs;
44
use std::io::{Read, Seek, SeekFrom, Write};
55
use std::path::PathBuf;
66

7+
/// 32-bit ARM is not supported by Microsoft so ARM types are not generated.
8+
/// Therefore we need to inject a few types to make the bindings work.
9+
const ARM32_SHIM: &str = r#"
10+
#[cfg(target_arch = "arm")]
11+
#[repr(C)]
12+
pub struct WSADATA {
13+
pub wVersion: u16,
14+
pub wHighVersion: u16,
15+
pub szDescription: [u8; 257],
16+
pub szSystemStatus: [u8; 129],
17+
pub iMaxSockets: u16,
18+
pub iMaxUdpDg: u16,
19+
pub lpVendorInfo: PSTR,
20+
}
21+
#[cfg(target_arch = "arm")]
22+
pub enum CONTEXT {}
23+
"#;
24+
725
fn main() -> Result<(), Box<dyn Error>> {
826
let mut path: PathBuf =
927
env::args_os().nth(1).expect("a path to the rust repository is required").into();
@@ -16,6 +34,7 @@ fn main() -> Result<(), Box<dyn Error>> {
1634
println!("{info}");
1735

1836
let mut f = std::fs::File::options().append(true).open("windows_sys.rs")?;
37+
f.write_all(ARM32_SHIM.as_bytes())?;
1938
writeln!(&mut f, "// ignore-tidy-filelength")?;
2039
writeln!(&mut f, "use super::windows_targets;")?;
2140

0 commit comments

Comments
 (0)