* Bug: Synchronous signals broken on Cygwin 64
@ 2018-04-26 7:58 Thomas Zimmermann
2018-04-26 10:44 ` Marco Atzeri
2018-04-26 10:45 ` Houder
0 siblings, 2 replies; 9+ messages in thread
From: Thomas Zimmermann @ 2018-04-26 7:58 UTC (permalink / raw)
To: cygwin
[-- Attachment #1.1.1: Type: text/plain, Size: 2472 bytes --]
Hello mailing list,
I noticed that synchronous signals (e.g., SIGSEGV, SIGFPE) appear to be
broken on 64-bit Cygwin systems. I could not find additional information
on the mailing list. If this is not already a known problem, you'll find
some analysis below.
I use Cygwin DLL 2.10 with all packages up-to-date. My test system runs
Windows 7.
The expected behavior is that an installed signal handler runs exactly
once for a signal and the OS terminates the program if the handler
returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
differs in the follow ways:
1) Generating a synchronous signal on the main thread, makes the signal
handler enter an endless loop. The attached test 'syncsig.c' illustrates
this.
2) Generating a synchronous signal on an additional POSIX thread ignores
the installed signal handler entirely. The handler does not run and the
program gets terminated immediately. The attached test 'syncsig_mt.c'
illustrates this.
As mentioned, both cases work correctly on 32-bit installations. I
cannot point to the exact location of the problem, but it appears that
the Cygwin exception-handler code is not set up by 64-bit code.
In case 2) I can see the Windows function KiUserExceptionDispatcher()
being executed for the synchronous signal on the affected thread. This
should lead to a call to the Cygwin exception handler. It does for
32-bit, but not for 64-bit code.
From what I've seen, the exception handler is installed in the c'tor
exception::exception(). [exception.cc:138] The only invocation I found
was in SetThreadName(). [miscfuncs.cc:951] This set-up code is 32-bit-only.
BTW, is there a bug tracker for Cygwin? I'd open a bug report there, or
add the information to an existing one.
Best regards
Thomas
[exception.cc:138]
https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/exception.h;h=ffff7464ba11b5526fcf9d13e32334912a30a3b0;hb=4c73ad6b20378e4b74355fcdb2005f2aac489c9f#l138
[miscfuncs.cc:951]
https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/miscfuncs.cc;h=3ad658739ad9e85868ca74ce2e86aa6ddbdbfb37;hb=4c73ad6b20378e4b74355fcdb2005f2aac489c9f#l951
--
Implement thread-safe and fault-tolerant software in C: visit picotm.org
--
GnuPG: http://tdz.users.sourceforge.net/tdz.asc
Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
Website: transactionblog.org
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: syncsig.c --]
[-- Type: text/x-csrc; name="syncsig.c", Size: 1111 bytes --]
/*
* This test program works on 32-bit and 64-bit Cygwin. On 32-bit
* systems, the signal handler runs *exactly* once, which is the correct
* behaviour. On 64-bit systems, the exception code enters an endless
* loop and the signal handler runs over and over.
*
* Compile with
*
* gcc -Wall -O0 -osyncsig ./syncsig.c
*
* Run with
*
* ./syncsig
*
* Expected Result
*
* Program prints "signal handler running" once
*
* Actual Result
*
* On 64-bit systems, the handler runs in an endless loop
* */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static void
signal_handler(int signum, siginfo_t* info, void* ucontext)
{
fprintf(stderr, "signal handler running\n"); // unsafe in real code!
}
int
main(int argc, char* argv[])
{
struct sigaction act = {
.sa_sigaction = signal_handler,
.sa_flags = SA_SIGINFO,
};
sigemptyset(&act.sa_mask);
sigaction(SIGFPE, &act, NULL);
/* Trigger Windows Exception for division by zero */
argc /= !argc;
fprintf(stderr, "no exception generated\n");
return EXIT_SUCCESS;
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.3: syncsig_mt.c --]
[-- Type: text/x-csrc; name="syncsig_mt.c", Size: 1239 bytes --]
/*
* This test program works on 32-bit Cygwin, but fails on 64-bit systems.
* Running a signal handler for SIGFPE on the created POSIX thread does
* not work.
*
* Compile with
*
* gcc -Wall -O0 -pthread -osyncsig_mt ./syncsig_mt.c
*
* Run with
*
* ./syncsig_mt
*
* Expected Result
*
* Program prints "signal handler running"
*
* Actual Result
*
* No output on 64-bit systems, signal handler does not run
* */
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static void
signal_handler(int signum, siginfo_t* info, void* ucontext)
{
fprintf(stderr, "signal handler running\n"); // unsafe in real code!
}
static void*
thread_start(void* arg)
{
int argc = *(int*)arg;
/* Trigger Windows Exception for division by zero */
argc /= !argc;
fprintf(stderr, "no exception generated\n");
return NULL;
}
int
main(int argc, char* argv[])
{
struct sigaction act = {
.sa_sigaction = signal_handler,
.sa_flags = SA_SIGINFO,
};
sigemptyset(&act.sa_mask);
sigaction(SIGFPE, &act, NULL);
pthread_t thread;
pthread_create(&thread, NULL, thread_start, &argc);
pthread_join(thread, NULL);
return EXIT_SUCCESS;
}
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 7:58 Bug: Synchronous signals broken on Cygwin 64 Thomas Zimmermann
@ 2018-04-26 10:44 ` Marco Atzeri
2018-04-26 10:45 ` Houder
1 sibling, 0 replies; 9+ messages in thread
From: Marco Atzeri @ 2018-04-26 10:44 UTC (permalink / raw)
To: cygwin
On 4/26/2018 9:57 AM, Thomas Zimmermann wrote:
> Hello mailing list,
>
> I noticed that synchronous signals (e.g., SIGSEGV, SIGFPE) appear to be
> broken on 64-bit Cygwin systems. I could not find additional information
> on the mailing list. If this is not already a known problem, you'll find
> some analysis below.
>
>
> I use Cygwin DLL 2.10 with all packages up-to-date. My test system runs
> Windows 7.
>
>
> The expected behavior is that an installed signal handler runs exactly
> once for a signal and the OS terminates the program if the handler
> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
> differs in the follow ways:
>
> 1) Generating a synchronous signal on the main thread, makes the signal
> handler enter an endless loop. The attached test 'syncsig.c' illustrates
> this.
>
> 2) Generating a synchronous signal on an additional POSIX thread ignores
> the installed signal handler entirely. The handler does not run and the
> program gets terminated immediately. The attached test 'syncsig_mt.c'
> illustrates this.
>
>
> As mentioned, both cases work correctly on 32-bit installations. I
> cannot point to the exact location of the problem, but it appears that
> the Cygwin exception-handler code is not set up by 64-bit code.
>
> In case 2) I can see the Windows function KiUserExceptionDispatcher()
> being executed for the synchronous signal on the affected thread. This
> should lead to a call to the Cygwin exception handler. It does for
> 32-bit, but not for 64-bit code.
just for confirmation, same results and discrepancies on my W7
> From what I've seen, the exception handler is installed in the c'tor
> exception::exception(). [exception.cc:138] The only invocation I found
> was in SetThreadName(). [miscfuncs.cc:951] This set-up code is 32-bit-only.
>
>
> BTW, is there a bug tracker for Cygwin? I'd open a bug report there, or
> add the information to an existing one.
there is no bug tracker. Bugs are managed on this mailing list.
>
> Best regards
> Thomas
>
Regards
Marco
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 7:58 Bug: Synchronous signals broken on Cygwin 64 Thomas Zimmermann
2018-04-26 10:44 ` Marco Atzeri
@ 2018-04-26 10:45 ` Houder
2018-04-26 10:53 ` Thomas Zimmermann
2018-04-26 10:55 ` Houder
1 sibling, 2 replies; 9+ messages in thread
From: Houder @ 2018-04-26 10:45 UTC (permalink / raw)
To: cygwin
On Thu, 26 Apr 2018 09:57:59, Thomas Zimmermann wrote:
> Hello mailing list,
>
> I noticed that synchronous signals (e.g., SIGSEGV, SIGFPE) appear to be
> broken on 64-bit Cygwin systems. I could not find additional information
> on the mailing list. If this is not already a known problem, you'll find
> some analysis below.
>
> I use Cygwin DLL 2.10 with all packages up-to-date. My test system runs
> Windows 7.
>
> The expected behavior is that an installed signal handler runs exactly
> once for a signal and the OS terminates the program if the handler
> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
> differs in the follow ways:
.. uhm, unless SA_RESETHAND (sa_flags) has been specified, I expect the
handler to be invoked again and again ...
And that is what I observe on Linux ...
> 1) Generating a synchronous signal on the main thread, makes the signal
> handler enter an endless loop. The attached test 'syncsig.c' illustrates
> this.
>
> 2) Generating a synchronous signal on an additional POSIX thread ignores
> the installed signal handler entirely. The handler does not run and the
> program gets terminated immediately. The attached test 'syncsig_mt.c'
> illustrates this.
Yes, this behaviour is wrong ...
Henri
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 10:45 ` Houder
@ 2018-04-26 10:53 ` Thomas Zimmermann
2018-04-26 11:02 ` Houder
2018-04-26 10:55 ` Houder
1 sibling, 1 reply; 9+ messages in thread
From: Thomas Zimmermann @ 2018-04-26 10:53 UTC (permalink / raw)
To: cygwin
[-- Attachment #1.1: Type: text/plain, Size: 894 bytes --]
Hi
Am 26.04.2018 um 12:45 schrieb Houder:
>> The expected behavior is that an installed signal handler runs exactly
>> once for a signal and the OS terminates the program if the handler
>> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
>> differs in the follow ways:
>
> .. uhm, unless SA_RESETHAND (sa_flags) has been specified, I expect the
> handler to be invoked again and again ...
What I mean is that the installed signal handler is re-called constantly
for the same HW exception (div-by-zero in this case). It is as if
there's an endless loop around the signal-handler function.
Best regards
Thomas
--
Implement thread-safe and fault-tolerant software in C: visit picotm.org
--
GnuPG: http://tdz.users.sourceforge.net/tdz.asc
Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
Website: tzimmermann.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 10:45 ` Houder
2018-04-26 10:53 ` Thomas Zimmermann
@ 2018-04-26 10:55 ` Houder
1 sibling, 0 replies; 9+ messages in thread
From: Houder @ 2018-04-26 10:55 UTC (permalink / raw)
To: cygwin
On 2018-04-26 12:45, Houder wrote:
> On Thu, 26 Apr 2018 09:57:59, Thomas Zimmermann wrote:
>
>> Hello mailing list,
>>
>> I noticed that synchronous signals (e.g., SIGSEGV, SIGFPE) appear to
>> be
>> broken on 64-bit Cygwin systems. I could not find additional
>> information
>> on the mailing list. If this is not already a known problem, you'll
>> find
>> some analysis below.
>>
>> I use Cygwin DLL 2.10 with all packages up-to-date. My test system
>> runs
>> Windows 7.
>>
>> The expected behavior is that an installed signal handler runs exactly
>> once for a signal and the OS terminates the program if the handler
>> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
>> differs in the follow ways:
>
> .. uhm, unless SA_RESETHAND (sa_flags) has been specified, I expect the
> handler to be invoked again and again ...
... and if SA_RESETHAND has been specified, the OS will terminate
the
program after the 1st invocation of the handler (yes, in case of
this
type of exception; in this case FPE)
> And that is what I observe on Linux ...
>
>> 1) Generating a synchronous signal on the main thread, makes the
>> signal
>> handler enter an endless loop. The attached test 'syncsig.c'
>> illustrates
>> this.
>>
>> 2) Generating a synchronous signal on an additional POSIX thread
>> ignores
>> the installed signal handler entirely. The handler does not run and
>> the
>> program gets terminated immediately. The attached test 'syncsig_mt.c'
>> illustrates this.
>
> Yes, this behaviour is wrong ...
>
> Henri
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 10:53 ` Thomas Zimmermann
@ 2018-04-26 11:02 ` Houder
2018-04-26 11:09 ` Thomas Zimmermann
2018-04-26 11:13 ` Thomas Zimmermann
0 siblings, 2 replies; 9+ messages in thread
From: Houder @ 2018-04-26 11:02 UTC (permalink / raw)
To: cygwin
On Thu, 26 Apr 2018 12:52:54, Thomas Zimmermann wrote:
> Hi
>
> Am 26.04.2018 um 12:45 schrieb Houder:
> >> The expected behavior is that an installed signal handler runs exactly
> >> once for a signal and the OS terminates the program if the handler
> >> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
> >> differs in the follow ways:
> >=20
> > .. uhm, unless SA_RESETHAND (sa_flags) has been specified, I expect the
> > handler to be invoked again and again ...
>
> What I mean is that the installed signal handler is re-called constantly
> for the same HW exception (div-by-zero in this case). It is as if
> there's an endless loop around the signal-handler function.
After the invocation of the handler, the program continues with the code
that attempts 'to divide by zero'.
As result of that, the handler is invoked again.
Henri
> Best regards
> Thomas
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 11:02 ` Houder
@ 2018-04-26 11:09 ` Thomas Zimmermann
2018-04-26 11:13 ` Thomas Zimmermann
1 sibling, 0 replies; 9+ messages in thread
From: Thomas Zimmermann @ 2018-04-26 11:09 UTC (permalink / raw)
To: cygwin
[-- Attachment #1.1: Type: text/plain, Size: 961 bytes --]
Hi
Am 26.04.2018 um 13:01 schrieb Houder:
>
> After the invocation of the handler, the program continues with the code
> that attempts 'to divide by zero'.
>
> As result of that, the handler is invoked again.
This means that the behavior of the test case is incorrect when running
in 32-bit mode. There, the signal-handler function runs exactly *once*
and then the program terminates.
Best regards
Thomas
> Henri
>
>> Best regards
>> Thomas
>
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Implement thread-safe and fault-tolerant software in C: visit picotm.org
--
GnuPG: http://tdz.users.sourceforge.net/tdz.asc
Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
Website: tzimmermann.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 11:02 ` Houder
2018-04-26 11:09 ` Thomas Zimmermann
@ 2018-04-26 11:13 ` Thomas Zimmermann
2018-04-26 12:58 ` Houder
1 sibling, 1 reply; 9+ messages in thread
From: Thomas Zimmermann @ 2018-04-26 11:13 UTC (permalink / raw)
To: cygwin
[-- Attachment #1.1: Type: text/plain, Size: 1706 bytes --]
I just saw that the result after returning from a synchronous signal is
undefined. So any behavior seems be OK. I'd still encourage to unify the
behavior of 32-bit and 64-bit code. (See my other mail.)
Best regards
Thomas
Am 26.04.2018 um 13:01 schrieb Houder:
> On Thu, 26 Apr 2018 12:52:54, Thomas Zimmermann wrote:
>
>> Hi
>>
>> Am 26.04.2018 um 12:45 schrieb Houder:
>>>> The expected behavior is that an installed signal handler runs exactly
>>>> once for a signal and the OS terminates the program if the handler
>>>> returns. This works on 32-bit Cygwin. From my observation, Cygwin 64
>>>> differs in the follow ways:
>>> =20
>>> .. uhm, unless SA_RESETHAND (sa_flags) has been specified, I expect the
>>> handler to be invoked again and again ...
>>
>> What I mean is that the installed signal handler is re-called constantly
>> for the same HW exception (div-by-zero in this case). It is as if
>> there's an endless loop around the signal-handler function.
>
> After the invocation of the handler, the program continues with the code
> that attempts 'to divide by zero'.
>
> As result of that, the handler is invoked again.
>
> Henri
>
>> Best regards
>> Thomas
>
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
>
--
Implement thread-safe and fault-tolerant software in C: visit picotm.org
--
GnuPG: http://tdz.users.sourceforge.net/tdz.asc
Fingerprint: 16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08
Website: tzimmermann.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Bug: Synchronous signals broken on Cygwin 64
2018-04-26 11:13 ` Thomas Zimmermann
@ 2018-04-26 12:58 ` Houder
0 siblings, 0 replies; 9+ messages in thread
From: Houder @ 2018-04-26 12:58 UTC (permalink / raw)
To: cygwin
On Thu, 26 Apr 2018 13:12:53, Thomas Zimmermann wrote:
> > > After the invocation of the handler, the program continues with the code
> > > that attempts 'to divide by zero'.
> > >=20
> > > As result of that, the handler is invoked again.
> >
> > This means that the behavior of the test case is incorrect when running
> > in 32-bit mode. There, the signal-handler function runs exactly *once*
> > and then the program terminates.
> >
> I just saw that the result after returning from a synchronous signal is
> undefined. So any behavior seems be OK. I'd still encourage to unify the
> behavior of 32-bit and 64-bit code. (See my other mail.)
You are correct.
For those who like a textbook reference, see:
Chapter 22, section 4 (Hardware-Generated Signals) of The Linux Programming
Interface by Michael Kerrisk.
Henri
> Best regards
> Thomas
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-04-26 12:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 7:58 Bug: Synchronous signals broken on Cygwin 64 Thomas Zimmermann
2018-04-26 10:44 ` Marco Atzeri
2018-04-26 10:45 ` Houder
2018-04-26 10:53 ` Thomas Zimmermann
2018-04-26 11:02 ` Houder
2018-04-26 11:09 ` Thomas Zimmermann
2018-04-26 11:13 ` Thomas Zimmermann
2018-04-26 12:58 ` Houder
2018-04-26 10:55 ` Houder
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).