On Fri, 22 Nov 2024, Corinna Vinschen wrote: > On Nov 21 11:42, Jeremy Drake via Cygwin-patches wrote: > > Note the elif defined (__i386__) case won't compile because it references > > the no-longer-present `wow64` value. This was written and tested against > > 3.3.6, and the __i386__ case could just go away here... > > Yeah, just kill it.
That's what I thought > > @@ -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 */ > > +#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 */ > > It should actually result in > > #error unimplemented for this target No, because this is the fallback case for when IsWow64Process2 fails. This should only happen on OS versions that don't support it, which in turn don't support anything other than i386 and x86_64. However, OS versions that do support it also support ARM64. If/when Cygwin has native ARM64 support, this should not be a compilation error. If anything it may be a runtime error (assert?) > > + const USHORT current_module_machine () const; > > This is not necessary. > > > +extern const IMAGE_DOS_HEADER > > +dosheader __asm__ ("__image_base__"); > > + > > +const USHORT > > +wincapc::current_module_machine () const > > +{ > > + PIMAGE_NT_HEADERS ntheader = (PIMAGE_NT_HEADERS)((LPBYTE) &dosheader > > + + dosheader.e_lfanew); > > + return ntheader->FileHeader.Machine; > > } > > Just scratch that. First, we're using GetModuleHandle(NULL) > throughout to access the image base, but apart from that, > the info is already available in wincap via cpu_arch(). GetModuleHandle(NULL) is the exe, __image_base__ is the cygwin dll. Theoretically, with ARM64EC, you can mix-and-match x86_64 and ARM64 in the same process, so the most correct answer to the question to "are we being emulated" is whether the current module's architecture matches the host system's architecture. Yes, due to Windows already lying in Get(Native)SystemInfo, cpu_arch() will tell you this, but with *different* enums, which means you'll need a switch somewhere to translate between them, instead of just doing an == or != with the host like this function lets you do.