-
Notifications
You must be signed in to change notification settings - Fork 210
Closed
Labels
windowsIssue regarding compiling/running on WindowsIssue regarding compiling/running on Windows
Description
The following code, if compiled as an x86_64 process and run on an arm64 system, will claim that the command shell binary is not executable. This is because GetBinaryTypeW returns ERROR_BAD_EXE_FORMAT for emulated processes.
This is not necessarily a bug in Foundation, but a quirk in the Win32 APIs. It seems worth documenting this caveat, at least.
import Foundation
import WinSDK
let fm = FileManager()
let path = "C:\\Windows\\system32\\cmd.exe"
print("\(path) isExecutable = \(fm.isExecutableFile(atPath: path))") // false
var dwBinaryType: DWORD = .max
let ret = path.withCString(encodedAs: UTF16.self) { ptr in
GetBinaryTypeW(ptr, &dwBinaryType)
}
let err = GetLastError()
print("\(ret) \(dwBinaryType) \(err)")
// err == ERROR_BAD_EXE_FORMATMetadata
Metadata
Assignees
Labels
windowsIssue regarding compiling/running on WindowsIssue regarding compiling/running on Windows