Cygwin's spawn/exec, mintty and the "Program Compatibility Assistant"

Corinna Vinschen
Thu Feb 16 13:40:00 GMT 2012

On Feb 16 13:15, Andy Koppe wrote:
> On 16 February 2012 12:46, Corinna Vinschen wrote:
> > Hi guys, and especially
> > Hi Andy,
> >
> >
> > A couple of weeks ago we noticed this strange problem with mintty.  The
> > "Program Compatibility Assistant" (PCA) on W7 took it under its wings
> > for no apparent reason, and if the session was long enough you would
> > notice that a specific svchost process, the one running the Pcasvc
> > service, would take more and more memory and CPU time.
> >
> > The solution for this problem was either to ask the user to switch off
> > the PCA service, or a change in Cygwin's spawn/exec code.  in short, PCA
> > sets up a Job for a controlled application, but allows to breakaway from
> > the job.  That's what Cygwin now does in *every* invocation of
> > spawn/exec:
> >
> >  if (QueryInformationJobObject (NULL, JobObjectBasicLimitInformation,
> >                                 &jobinfo, sizeof jobinfo, NULL)
> >      && (jobinfo.LimitFlags & (JOB_OBJECT_LIMIT_BREAKAWAY_OK
> >                                | JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK)))
> >    {
> >      /* Add CREATE_BREAKAWAY_FROM_JOB to the CreateProcess flags. */
> >      c_flags |= CREATE_BREAKAWAY_FROM_JOB;
> >    }
> >
> > While this works, what bugs me is that this additional system call takes
> > extra time and we all know that Cygwin is slow.  Ask the users.
> >
> > I have still no idea why mintty is affected.  It doesn't show up in the
> > registry-based PCA database.  Yesterday I found this on MSDN:
> > but I don't see
> > anything there which would explain the effect for mintty.  There's a
> > section called "Detecting Program Failures Due to Deprecated Windows
> > Components", maybe that's a hint?
> I'm not aware of anything. Is there any pattern to those occurrences?

No, there's no pattern.  Mintty is always grabbed by PCA for some reason.
You can check by yourself if you build the Cygwin DLL yourself and just
change the above debug_printf to a system_printf.  When you then start
mintty with the new DLL, you can see that CYgwin has to free mintty out
of the claws of PCA's job object.

Or, if you disable the "c_flags |= CREATE_BREAKAWAY_FROM_JOB;", then
run some long running make or so, observe in Task Manager how one of
the svchost processes grab more and more memory and CPU.  This can take
some time, but it's a reliable effect.

The aforementioned MSDN articel mentions something about hooking
CoCreateInstance.  Does mintty call this functions?  Is it possible
that it tries to use some outdated COM object?

> > Apart from that, apparently there are multiple other ways to disable PCA
> > from meddling with mintty.  One of them is the (incorrectly documented)
> > registry value
> >
> >  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\ExecutablesToExclude
> >
> > which is a REG_MULTI_SZ value you can fill with full paths to the
> > exeutables to exclude.  I tried that and it actually works.  So, instead
> > of calling QueryInformationJobObject for each spawn/exec, we could just
> > add mintty.exe to that registry key.
> >
> > Or, alternatively, mintty could come with a builtin manifest.  I just
> > don't know how to include a manifest into a binary...
> Mintty already has a manifest, namely the res.mft in its sources, so
> I'd just need to know what needs to go in there.

I'm not sure.  Per the articel, it should be sufficient to include an
"asInvoker" manifest, see the section "Excluding Programs from PCA".


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

More information about the Cygwin-developers mailing list