public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* stdin, stdout, stderr when GUI app is launched from command line
@ 2023-05-04 15:10 Kacvinsky, Tom
  2023-05-04 20:27 ` Jeremy Drake
  2023-05-04 21:59 ` Takashi Yano
  0 siblings, 2 replies; 5+ messages in thread
From: Kacvinsky, Tom @ 2023-05-04 15:10 UTC (permalink / raw)
  To: cygwin-developers

[-- Attachment #1: Type: text/plain, Size: 1192 bytes --]

I have a Windows GUI app that I have set to run with Windows Application Verifier.
In particular, I have App verifier set to trigger on invalid handle exceptions (code is
0xC0000008).  When the application is run from the Cygwin console, it faults with
an invalid handle three times.  I can continue past them in windbg (or gdb for that
matter) and the application launches.  I think it is curious the invalid handle exception
occurs three times - is it stdin, stdout and stderr that App Verifier thinks are invalid
handles?  My hunch is yes, they are.

I did notice that if I run the GUI use run.exe, as in "run guiapp.exe", the application
launches with no invalid handle exceptions.

I am using this version of Cygwin 64

vapkay@US05117NB ~ $ cygcheck -V
cygcheck (cygwin) 3.1.7

But it also happens with 3.4.6

Is this to be expected with a GUI app when run under a Cygwin console?  I've never
seen it until I ran with App Verifier.  The GUI application is a Qt app.  I check the Qt
version we're using for use of and I don't see anything in the WinMain what would
have to do with reading/writing to the standard IO file descriptors.

Any ideas?

Thanks,

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stdin, stdout, stderr when GUI app is launched from command line
  2023-05-04 15:10 stdin, stdout, stderr when GUI app is launched from command line Kacvinsky, Tom
@ 2023-05-04 20:27 ` Jeremy Drake
  2023-05-05  1:31   ` Kacvinsky, Tom
  2023-05-04 21:59 ` Takashi Yano
  1 sibling, 1 reply; 5+ messages in thread
From: Jeremy Drake @ 2023-05-04 20:27 UTC (permalink / raw)
  To: Kacvinsky, Tom; +Cc: cygwin-developers

I remember that a python launcher (which is included in distlib, which is
included in pip) experienced a similar situation.  There was a detailed
discussion of debugging what was happening on one of those projects, maybe
that can give you an idea where to start searching.

If you trust my memory, what was happening is that, for a GUI subsystem
app, the OS code during process startup would iterate through the standard
handles in order (in, out, err), check if the handle was attached to a
console, and if so close the handle and NULL it out.  The issue came due
to the fact that when Cygwin launched a process, stdout and stderr pointed
to the SAME handle.  When it evaluated stdout, it saw it was attached to a
console so closed the handle and NULLed the stdout handle.  Then when it
checked stderr, it was no longer a handle that was attached to a console,
it was an invalid (closed) handle, so it didn't close OR NULL out stderr.
This resulted in an invalid-but-non-null handle being present for stderr.
What was even worse is that at some later point, that handle was actually
recycled for some entirely different kind of object.

I believe what you'd see if you called GetStdHandle for each of
STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE, is that the first
two would be NULL and the third would be some handle, possibly invalid and
possibly a handle to some random object.

On Thu, 4 May 2023, Kacvinsky, Tom wrote:

> I have a Windows GUI app that I have set to run with Windows Application Verifier.
> In particular, I have App verifier set to trigger on invalid handle exceptions (code is
> 0xC0000008).  When the application is run from the Cygwin console, it faults with
> an invalid handle three times.  I can continue past them in windbg (or gdb for that
> matter) and the application launches.  I think it is curious the invalid handle exception
> occurs three times - is it stdin, stdout and stderr that App Verifier thinks are invalid
> handles?  My hunch is yes, they are.
>
> I did notice that if I run the GUI use run.exe, as in "run guiapp.exe", the application
> launches with no invalid handle exceptions.
>
> I am using this version of Cygwin 64
>
> vapkay@US05117NB ~ $ cygcheck -V
> cygcheck (cygwin) 3.1.7
>
> But it also happens with 3.4.6
>
> Is this to be expected with a GUI app when run under a Cygwin console?  I've never
> seen it until I ran with App Verifier.  The GUI application is a Qt app.  I check the Qt
> version we're using for use of and I don't see anything in the WinMain what would
> have to do with reading/writing to the standard IO file descriptors.
>
> Any ideas?
>
> Thanks,
>
> Tom

-- 
If you live to the age of a hundred you have it made because very few
people die past the age of a hundred.
		-- George Burns

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: stdin, stdout, stderr when GUI app is launched from command line
  2023-05-04 15:10 stdin, stdout, stderr when GUI app is launched from command line Kacvinsky, Tom
  2023-05-04 20:27 ` Jeremy Drake
@ 2023-05-04 21:59 ` Takashi Yano
  1 sibling, 0 replies; 5+ messages in thread
From: Takashi Yano @ 2023-05-04 21:59 UTC (permalink / raw)
  To: cygwin-developers

On Thu, 4 May 2023 15:10:03 +0000
"Kacvinsky, Tom" wrote:
> I have a Windows GUI app that I have set to run with Windows Application Verifier.
> In particular, I have App verifier set to trigger on invalid handle exceptions (code is
> 0xC0000008).  When the application is run from the Cygwin console, it faults with
> an invalid handle three times.  I can continue past them in windbg (or gdb for that
> matter) and the application launches.  I think it is curious the invalid handle exception
> occurs three times - is it stdin, stdout and stderr that App Verifier thinks are invalid
> handles?  My hunch is yes, they are.
> 
> I did notice that if I run the GUI use run.exe, as in "run guiapp.exe", the application
> launches with no invalid handle exceptions.
> 
> I am using this version of Cygwin 64
> 
> vapkay@US05117NB ~ $ cygcheck -V
> cygcheck (cygwin) 3.1.7
> 
> But it also happens with 3.4.6
> 
> Is this to be expected with a GUI app when run under a Cygwin console?  I've never
> seen it until I ran with App Verifier.  The GUI application is a Qt app.  I check the Qt
> version we're using for use of and I don't see anything in the WinMain what would
> have to do with reading/writing to the standard IO file descriptors.
> 
> Any ideas?

I cannot reproduce your problem with cygwin 3.4.6.
Could you please provide detailed steps?

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: stdin, stdout, stderr when GUI app is launched from command line
  2023-05-04 20:27 ` Jeremy Drake
@ 2023-05-05  1:31   ` Kacvinsky, Tom
  2023-05-05  4:46     ` Jeremy Drake
  0 siblings, 1 reply; 5+ messages in thread
From: Kacvinsky, Tom @ 2023-05-05  1:31 UTC (permalink / raw)
  To: cygwin-developers



> -----Original Message-----
> From: Jeremy Drake <cygwin@jdrake.com>
> Sent: Thursday, May 4, 2023 4:27 PM
> To: Kacvinsky, Tom <Tom.Kacvinsky@vector.com>
> Cc: cygwin-developers@cygwin.com
> Subject: Re: stdin, stdout, stderr when GUI app is launched from command
> line
> 
> [You don't often get email from cygwin@jdrake.com. Learn why this is
> important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> I remember that a python launcher (which is included in distlib, which is
> included in pip) experienced a similar situation.  There was a detailed
> discussion of debugging what was happening on one of those projects,
> maybe that can give you an idea where to start searching.

I think you're referring to this issue

https://github.com/pypa/distlib/issues/168

We embed Python in our product, so maybe the issue is with that.  I'm
nor certain of that, though.  But thanks for the pointer.

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: stdin, stdout, stderr when GUI app is launched from command line
  2023-05-05  1:31   ` Kacvinsky, Tom
@ 2023-05-05  4:46     ` Jeremy Drake
  0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Drake @ 2023-05-05  4:46 UTC (permalink / raw)
  To: Kacvinsky, Tom; +Cc: cygwin-developers

On Fri, 5 May 2023, Kacvinsky, Tom wrote:

> We embed Python in our product, so maybe the issue is with that.  I'm
> nor certain of that, though.  But thanks for the pointer.


To be clear, I wasn't suggesting that Python has anything to do with this.
That is just another case where I remember invalid standard handles
showing up when running a GUI (-mwindows) executable from Cygwin, that
resulted in some in-depth investigation that might shed light on how
you could end up with invalid handle traps in App Verifier.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-05  4:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04 15:10 stdin, stdout, stderr when GUI app is launched from command line Kacvinsky, Tom
2023-05-04 20:27 ` Jeremy Drake
2023-05-05  1:31   ` Kacvinsky, Tom
2023-05-05  4:46     ` Jeremy Drake
2023-05-04 21:59 ` Takashi Yano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).