This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/48854] New: signal mask is not restored when exiting signal handler via exception
- From: "cubbi at cubbi dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 3 May 2011 14:57:21 +0000
- Subject: [Bug c++/48854] New: signal mask is not restored when exiting signal handler via exception
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48854
Summary: signal mask is not restored when exiting signal
handler via exception
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: cubbi@cubbi.org
When using -fnon-call-exception to convert a SIGSEGV or SIGFPE to a C++
exception, the straightforward implementation fails to handle the same signal
more than once because it remains masked after the signal handler and the
exception handler have been executed.
While this is reasonable behavior, perhaps it should be briefly mentioned in
the documentation on -fnon-call-exceptions?
Example (compile with -fnon-call-exceptions)
#include <iostream>
#include <stdexcept>
#include <signal.h>
void handler(int signo)
{
std::cerr << "Signal handler called with " << signo << '\n';
// uncomment the following lines to fix the bug
// sigset_t x;
// sigemptyset (&x);
// sigaddset(&x, SIGSEGV);
// sigprocmask(SIG_UNBLOCK, &x, NULL);
throw std::runtime_error("sigsegv");
}
int main()
{
signal(SIGSEGV, handler);
int* invalid_p = NULL;
// first attempt: always works
try{
*invalid_p = 7;
} catch(const std::exception& e)
{
std::cerr << "main() caught " << e.what() << '\n';
}
// second attempt: fails unless uncommented sigprocmask above
try{
*invalid_p = 7;
} catch(const std::exception& e)
{
std::cerr << "main() caught " << e.what() << '\n';
}
}
reproduced using
gcc 3.4.6 (linux x86_64)
gcc 4.4.1 (linux i386)
gcc 4.5.2 (linux x86_64)
gcc 4.6.0 20110325 (linux x86_64)