Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
simultaneous signal handling and setjmp/longjmp
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Chris Friesen  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 23:09
Newsgroups: comp.unix.programmer
From: Chris Friesen <cbf...@mail.usask.ca>
Date: Fri, 06 Nov 2009 17:09:48 -0600
Local: Fri 6 Nov 2009 23:09
Subject: simultaneous signal handling and setjmp/longjmp
I've got a bit of an odd hypothetical question dealing with signals and
setjmp/longjmp. I've looked at POSIX/susv3 and I can't find anything
dealing with what happens if you call longjmp with pending signals.

Suppose we have an app with multiple signals pending.  (Say, SIGALRM and
SIGSEGV.)  In the signal handler for SIGSEGV, we're going to call call
longjmp().  (Yes, I'm aware of the issues.)

At this point we're still in the kernel and both SIGSEGV and SIGALARM
are pending. What happens?

If we run the SIGSEGV handler does the SIGALARM stay pending until the
segfault handler completes?  What happens when the segfault handler
calls longjmp()?  Does the SIGALARM handler get called on the logical
return from sigsetjmp(), and if so how does that happen since the glibc
code for setjmp/longjmp doesn't seem to call any kernel syscalls?

Thanks for any information you can provide...

Chris


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Lurndal  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 23:52
Newsgroups: comp.unix.programmer
From: sc...@slp53.sl.home (Scott Lurndal)
Date: 06 Nov 2009 23:52:15 GMT
Local: Fri 6 Nov 2009 23:52
Subject: Re: simultaneous signal handling and setjmp/longjmp

It all depends whether you use signal(2) or sigaction(2), what your
current sigprocmask(2) is, and what mask you tell the system to use
when delivering the signal (see sigaction(2)).

Also, you should be using siglongjmp, not longjmp.

btw - the handler runs in the context of your application, not the
kernel.

scott


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Friesen  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 07:35
Newsgroups: comp.unix.programmer
From: Chris Friesen <cbf...@mail.usask.ca>
Date: Sat, 07 Nov 2009 01:35:06 -0600
Local: Sat 7 Nov 2009 07:35
Subject: Re: simultaneous signal handling and setjmp/longjmp
On 11/06/2009 05:52 PM, Scott Lurndal wrote:

Okay, for sake of discussion let's say that we're using sigaction for
each signal handler, and in each case the only signal masked is the
signal being handled.  Also assume that initially no signals are blocked.

For the purposes of the discussion I specifically asked about longjmp
because it doesn't reset the signal mask and thus (at least for glibc)
doesn't issue any kernel syscalls.

I'm aware that the handler runs in the context of the app.  However, for
a signal to interrupt the application the kernel must be involved.
Normally when you finish a signal handler you return back to the kernel
and if there is a pending signal it will switch back to userspace and
run the signal handlers before returning back to the main thread of
execution of the app.

If I call longjmp from the initial signal handler, rather than returning
back to the kernel the app switches context to what it was at the time
of the setjmp.  As far as I can tell at least for glibc this doesn't
involve any syscalls so nothing triggers the kernel to run any
additional pending signals.

The whole point of this line of questioning is that I'm curious if
there's anything in the posix/sus spec that I've missed that deals with
what specificially is supposed to happen if I call longjmp with pending
signals.  i.e...when are they supposed to be delivered?

Chris


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scott Lurndal  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 21:38
Newsgroups: comp.unix.programmer
From: sc...@slp53.sl.home (Scott Lurndal)
Date: 07 Nov 2009 21:38:29 GMT
Local: Sat 7 Nov 2009 21:38
Subject: Re: simultaneous signal handling and setjmp/longjmp

POSIX doesn't define when signals are delivered.  I don't recall that the
order is specified either (although most kernels will use a find-first-set-bit
instruction to find the next signal to deliver, implying that lower signal numbers
will be delivered ahead of higher signal numbers).

Synchronously generated signals (such as SIGSEGV, SIGBUS, SIGFPE) will always be
delivered immediately (on the instruction and/or system call that generated
the signal).

I think you've answered your own question;  POSIX defines sigsetjmp so that
the signal mask _will_ be restored as part of the siglongjmp;  If sigaction
was used and the kernel had masked the signal during delivery, it is expecting
the signal handler to be returned from in order to remove sa_mask.  If you
don't return from the signal handler and you use longjmp, the signal that caused
entry to the signal handler will remain masked.

As for when signals get delivered, they can be delivered upon return from
a system call or can be delivered whenever the process is context switched
(consider an interval timer interrupting a user-mode loop, where no system
call is invoked).

A portable program must expect that a pending signal can be delivered at
any time it is not masked, even during the longjmp (if, for example,
your process was pre-empted by a higher priority processor or an interrupt).
Ensuring that you don't invoke any system call won't prevent synchronous
nor asynchronous unmasked signals from being delivered.

scott


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google