Skip to content

Commit 00b4f61

Browse files
committed
Inject win arm32 shims into metadata generation
1 parent 845a2f7 commit 00b4f61

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

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

-41
Original file line numberDiff line numberDiff line change
@@ -457,44 +457,3 @@ compat_fn_with_fallback! {
457457
Status as u32
458458
}
459459
}
460-
461-
// # Arm32 shim
462-
//
463-
// AddVectoredExceptionHandler and WSAStartup use platform-specific types.
464-
// However, Microsoft no longer supports thumbv7a so definitions for those targets
465-
// are not included in the win32 metadata. We work around that by defining them here.
466-
//
467-
// Where possible, these definitions should be kept in sync with https://docs.rs/windows-sys
468-
cfg_if::cfg_if! {
469-
if #[cfg(not(target_vendor = "uwp"))] {
470-
#[link(name = "kernel32")]
471-
extern "system" {
472-
pub fn AddVectoredExceptionHandler(
473-
first: u32,
474-
handler: PVECTORED_EXCEPTION_HANDLER,
475-
) -> *mut c_void;
476-
}
477-
pub type PVECTORED_EXCEPTION_HANDLER = Option<
478-
unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32,
479-
>;
480-
#[repr(C)]
481-
pub struct EXCEPTION_POINTERS {
482-
pub ExceptionRecord: *mut EXCEPTION_RECORD,
483-
pub ContextRecord: *mut CONTEXT,
484-
}
485-
#[cfg(target_arch = "arm")]
486-
pub enum CONTEXT {}
487-
}}
488-
// WSAStartup is only redefined here so that we can override WSADATA for Arm32
489-
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested: u16, lpwsadata: *mut WSADATA) -> i32);
490-
#[cfg(target_arch = "arm")]
491-
#[repr(C)]
492-
pub struct WSADATA {
493-
pub wVersion: u16,
494-
pub wHighVersion: u16,
495-
pub szDescription: [u8; 257],
496-
pub szSystemStatus: [u8; 129],
497-
pub iMaxSockets: u16,
498-
pub iMaxUdpDg: u16,
499-
pub lpVendorInfo: PSTR,
500-
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -2175,6 +2175,7 @@ Windows.Win32.Networking.WinSock.WSARecv
21752175
Windows.Win32.Networking.WinSock.WSASend
21762176
Windows.Win32.Networking.WinSock.WSASERVICE_NOT_FOUND
21772177
Windows.Win32.Networking.WinSock.WSASocketW
2178+
Windows.Win32.Networking.WinSock.WSAStartup
21782179
Windows.Win32.Networking.WinSock.WSASYSCALLFAILURE
21792180
Windows.Win32.Networking.WinSock.WSASYSNOTREADY
21802181
Windows.Win32.Networking.WinSock.WSATRY_AGAIN
@@ -2419,6 +2420,7 @@ Windows.Win32.System.Console.STD_HANDLE
24192420
Windows.Win32.System.Console.STD_INPUT_HANDLE
24202421
Windows.Win32.System.Console.STD_OUTPUT_HANDLE
24212422
Windows.Win32.System.Console.WriteConsoleW
2423+
Windows.Win32.System.Diagnostics.Debug.AddVectoredExceptionHandler
24222424
Windows.Win32.System.Diagnostics.Debug.ARM64_NT_NEON128
24232425
Windows.Win32.System.Diagnostics.Debug.CONTEXT
24242426
Windows.Win32.System.Diagnostics.Debug.EXCEPTION_RECORD

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);
@@ -113,6 +114,7 @@ windows_targets::link!("ws2_32.dll" "system" fn WSAGetLastError() -> WSA_ERROR);
113114
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);
114115
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);
115116
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);
117+
windows_targets::link!("ws2_32.dll" "system" fn WSAStartup(wversionrequested : u16, lpwsadata : *mut WSADATA) -> i32);
116118
windows_targets::link!("ws2_32.dll" "system" fn accept(s : SOCKET, addr : *mut SOCKADDR, addrlen : *mut i32) -> SOCKET);
117119
windows_targets::link!("ws2_32.dll" "system" fn bind(s : SOCKET, name : *const SOCKADDR, namelen : i32) -> i32);
118120
windows_targets::link!("ws2_32.dll" "system" fn closesocket(s : SOCKET) -> i32);
@@ -2283,6 +2285,12 @@ pub type EXCEPTION_DISPOSITION = i32;
22832285
pub const EXCEPTION_MAXIMUM_PARAMETERS: u32 = 15u32;
22842286
#[repr(C)]
22852287
#[derive(Clone, Copy)]
2288+
pub struct EXCEPTION_POINTERS {
2289+
pub ExceptionRecord: *mut EXCEPTION_RECORD,
2290+
pub ContextRecord: *mut CONTEXT,
2291+
}
2292+
#[repr(C)]
2293+
#[derive(Clone, Copy)]
22862294
pub struct EXCEPTION_RECORD {
22872295
pub ExceptionCode: NTSTATUS,
22882296
pub ExceptionFlags: u32,
@@ -2859,6 +2867,8 @@ pub type PTIMERAPCROUTINE = Option<
28592867
dwtimerhighvalue: u32,
28602868
),
28612869
>;
2870+
pub type PVECTORED_EXCEPTION_HANDLER =
2871+
Option<unsafe extern "system" fn(exceptioninfo: *mut EXCEPTION_POINTERS) -> i32>;
28622872
pub type PWSTR = *mut u16;
28632873
pub const READ_CONTROL: FILE_ACCESS_RIGHTS = 131072u32;
28642874
pub const REALTIME_PRIORITY_CLASS: PROCESS_CREATION_FLAGS = 256u32;
@@ -3283,5 +3293,19 @@ pub struct XSAVE_FORMAT {
32833293
pub XmmRegisters: [M128A; 8],
32843294
pub Reserved4: [u8; 224],
32853295
}
3296+
3297+
#[cfg(target_arch = "arm")]
3298+
#[repr(C)]
3299+
pub struct WSADATA {
3300+
pub wVersion: u16,
3301+
pub wHighVersion: u16,
3302+
pub szDescription: [u8; 257],
3303+
pub szSystemStatus: [u8; 129],
3304+
pub iMaxSockets: u16,
3305+
pub iMaxUdpDg: u16,
3306+
pub lpVendorInfo: PSTR,
3307+
}
3308+
#[cfg(target_arch = "arm")]
3309+
pub enum CONTEXT {}
32863310
// ignore-tidy-filelength
32873311
use super::windows_targets;

0 commit comments

Comments
 (0)