On 21/11/2024 19:42, Jeremy Drake via Cygwin-patches wrote:
@@ -282,4 +284,30 @@ wincapc::init () __small_sprintf (osnam, "NT-%d.%d", version.dwMajorVersion, version.dwMinorVersion); + + if (!IsWow64Process2 (GetCurrentProcess (), &emul_mach, &host_mach)) + { + /* assume the only way IsWow64Process2 fails for the current process is + that we're running on an OS version where it's not implemented yet. + As such, the only two realistic options are AMD64 or I386 */
As an aid to comprehension for stupid, half-awake people, this comment might make it clearer that the normal case is that host_mach is filled in by IsWow64Process2(), and the complexity is just trying to guess a fallback if it fails...
+#if defined (__x86_64__) + host_mach = IMAGE_FILE_MACHINE_AMD64; +#elif defined (__i386__) + host_mach = wow64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_MACHINE_I386; +#else + /* this should not happen */ + host_mach = IMAGE_FILE_MACHINE_UNKNOWN; +#endif + }