Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Playing with sendsig() and sigreturn() in DEC OSF/1
@ 1994-11-17  9:38 Raphael Manfredi
  0 siblings, 0 replies; only message in thread
From: Raphael Manfredi @ 1994-11-17  9:38 UTC (permalink / raw)


I have stumbled over what I believe is an interesting challenge,
related to signal handling in the DEC OSF/1 kernel.

We, at ACRI in the OS team, are porting DEC OSF/1 on our hardware.
The kernel runs on what we call the CU (the Control Unit) but may
receive errors (via interrupts) from other processors, the Stream
Units (SU), which are really co-processors with a separate context.

Whenever an SU detects something "bad" is happening (invalid opcode),
it sends an interrupt to the CU for the kernel to handle and signal
the user process by sending it an illegal instruction signal (SIGILL).

This is where things are hotting up: the user process is free to
catch the SIGILL, in which case three things may happen in the signal
handler:

	+ it issues a longjmp() to somewhere else.
	+ it just returns to sigtramp(), the signal trampoline code in
	  the libc that sensig() dispatched, where a sigreturn() is
	  issued.

(Those two cases are mostly identical since longjmp() issues a
sigreturn() anyway.)

	+ it prints an error message and exits(). End of the story.

The problem arises only in the second case: the signal handler may
issue some code on the CU itself, or on the SU, whose context has
been fully saved anyway before calling sendsig(). However, when
returning in sigreturn(), we need to re-instantiate the previous
SU context before resuming, at which time the SIGILL will be sent
again of course.

When I have two simultaneous error conditions sent by two distinct
co-processors (say a SIGILL and a SIGFPE), what will happen?

As far as I understand it, the trap() handler will do something like

	if (issig())
		psig()
	
And in turn psig() performs something like:

	do {
		...
		sendsig();
		...
	} while ISSIG(p);	/* p is the proc */

Correct me if I am wrong, but sendsig() merely plays with the process's
user stack by faking an exception frame as-if we were coming from sigtramp(),
hence effectively resuming there when leaving the kernel and returning to
user mode (sigtramp() being responsible for calling the user handler and
performing a sigreturn() to trap again into the kernel at the end).

So if two or more signals are pending simultaneously, I am stacking two
"handlers", returning to user mode, jumping into the first handler, returning
to kernel via sigreturn(), returning to user where the second handler is
called and back to the kernel via a second sigreturn().

At which point I need to perform the restore of the previous SU context
and resume.

The question is: How do I know all the signals have been processed when I
am in sigreturn() with little information about what's going on, so that
I may (and only now) restore the SU context.

Bonus question: what happens to my second handler on the stack if the first
handler issues a longjmp() to transfer control elsewhere? That second stack
frame should be ignored? In which case the second signal is lost?

Or what?
-- 
Raphael Manfredi <ram@acri.fr>
Advanced Computer Research Institute
1, boulevard Marius Vivier-Merle              / Tel +33 72-35-80-55 \
69443 Lyon Cedex 03, FRANCE                   \ Fax +33 72-35-84-10 /


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1994-11-17  9:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1994-11-17  9:38 Playing with sendsig() and sigreturn() in DEC OSF/1 Raphael Manfredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox