On Tue, 19 Nov 2024, Corinna Vinschen wrote:

> On Nov 18 10:10, Jeremy Drake via Cygwin-patches wrote:
> > On Mon, 18 Nov 2024, Corinna Vinschen wrote:
> >
> > > Neat, but if this only affects the ARM64 emulation, shouldn't this only
> > > be called under wincap.cpu_arch() == PROCESSOR_ARCHITECTURE_AMD64?
> >
> > Wouldn't this always be true though?
>
> Copy/Paste and not thinking straight is doing that for me, sorry.
>
> The above was supposed to be PROCESSOR_ARCHITECTURE_ARM64, but this is
> obviously dumb either way.  What I *meant* was checking if we're running
> in an emulation vias GetNativeSystemInfo or IsWow64Process2.  We're
> using the latter in find_fast_cwd() already.

GetNativeSystemInfo also lies, following the Microsoft compatibility
theory of: make existing APIs lie, add a new API that gives the real
answer, repeat for new versions.  That's why we need to use
IsWow64Process2: that's the API that (currently) doesn't lie.

> > (Except that I backported this to
> > 3.3.6 for i686 support, where I'd have to check for that possibility as
> > well).
>
> Have I missed something?  I thought this only occurs in an
> AMD64-on-ARM64 environment. What is it used for on i686?

This also occurs on i686-on-ARM64, but since Cygwin no longer supports
i686 I didn't get into that here.  Actually, I was only able to get a
debugger to give me any info about where this thread was stuck on the
i686-on-ARM64 case.  In retrospect, this was presumably so hard to debug
for the same reason as this workaround works:
SuspendThread/GetThreadContext tries to get out of emulation before
returning, but the emulator is waiting on a lock that will never be
released because the thread that owned it was terminated.

> > > Is this just to avoid the code when a native ARM64 Cygwin appears?
>
> No, the idea was running the code only if we know we're being emulated
> on ARM64.  I just screwed up :}
>
> > I have been sort of considering if the results from IsWow64Process2 should
> > be cached in wincap, then we could check that here if we are running on
> > ARM64 under emulation, and also used the cached value in the check around
> > FAST_CWD.  In addition, I was thining it might make sense to include this
> > info in `uname -s` like -WOW64 used to be when i686 was supported.
>
> That might be a good idea in the long run and patches are welcome.
> Right now we have this isolated usage of IsWow64Process2 in find_fast_cwd().
> Given this function is called at least once in a process tree anyway,
> wincap would be a natural place to keep the info.
>
> And yeah, maybe we can just attach "-ARM64" to the -s info or something.

I'll save that for a future patch, and for now send v3 without an
additional check for architecture.

Reply via email to