Subject: link context for signal handlers
To: None <tech-kern@netbsd.org>
From: Antti Kantee <pooka@cs.hut.fi>
List: tech-kern
Date: 07/05/2007 17:42:17
I had a problem which boiled down to a process losing its ucontext link
in a signal handler.  Upon examination, turned out that the link context
is always set to NULL in the kernel when a signal is dispatched and
therefore lost when the signal handler calls setcontext() after execution.

The following patch makes everything behave the way I would expect it
to behave.  But I'm unsure about corner bases such as multiple signal
handlers etcetc.  Can anyone see a problem?

(The same patch obviously needs to be done for all archs, this is
just i386)

Index: machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/i386/i386/machdep.c,v
retrieving revision 1.604
diff -u -p -r1.604 machdep.c
--- machdep.c	26 Jun 2007 20:11:12 -0000	1.604
+++ machdep.c	5 Jul 2007 14:41:22 -0000
@@ -777,7 +777,7 @@ sendsig_siginfo(const ksiginfo_t *ksi, c
 	frame.sf_si._info = ksi->ksi_info;
 	frame.sf_uc.uc_flags = _UC_SIGMASK|_UC_VM;
 	frame.sf_uc.uc_sigmask = *mask;
-	frame.sf_uc.uc_link = NULL;
+	frame.sf_uc.uc_link = l->l_ctxlink;
 	frame.sf_uc.uc_flags |= (l->l_sigstk.ss_flags & SS_ONSTACK)
 	    ? _UC_SETSTACK : _UC_CLRSTACK;
 	memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));

-- 
Antti Kantee <pooka@iki.fi>                     Of course he runs NetBSD
http://www.iki.fi/pooka/                          http://www.NetBSD.org/
    "la qualité la plus indispensable du cuisinier est l'exactitude"