-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
Description
On 32-bit Windows, attempting to call Windows APIs directly will cause a crash, because the Win32 API generally uses the stdcall calling convention, in which the callee is responsible for popping its arguments off the stack (using the ret nn instruction), but Swift drops the calling convention on the floor and performs the call as if the Win32 API was using cdecl — the upshot being that both Swift and the Win32 API will pop the arguments from the stack, which leads to stack corruption and hard to debug crashes.
Reproduction
func foo() {
let hStdin = GetStdHandle(STD_INPUT_HANDLE)
print(hStdin)
}
foo()should be sufficient to cause a crash.
Expected behavior
Swift should respect calling conventions on imported C APIs.
Environment
Swift 6.2. This actually affects more than just 32-bit Windows — it's just that that platform relies most heavily on foreign calling conventions that aren't compatible with cdecl or swiftcc.
Additional information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status