Subject: Re: SA_SIGINFO notes
To: Paul Kranenburg <pk@cs.few.eur.nl>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: tech-kern
Date: 10/06/2003 11:55:06
This is a multipart MIME message.

--==_Exmh_349974670130
Content-Type: text/plain; charset=us-ascii


pk@cs.few.eur.nl said:
> 2. In kern_sig.c:kpsendsig(), the `ksi_trap' is used to decide which
>    arguments to pass to sa_upcall(). I don't what it is used for,
>    but blindly using `ksi_trap' without further inspection of the
>    siginfo context seems like a bad idea.

Yes, I had this impression too a while ago. I'm running a fixed system
(patch appended) for weeks now without problems. (I believe I've sent the
patch somewhere for review, but it got lost somehow.)
I didn't see problems with asynchronous signals initially, but also
for traps there is the possibility that the md T_XXX is zero
(eg T_PRIVINFLT on i386). I'll append a test program which tries
this. On an unpatched system, the libpthread signal delivery code gets
confused by it -- the signal gets delivered twice before the handler
is called, as one can see with ktrace.

best regards
Matthias



--==_Exmh_349974670130
Content-Type: text/plain ; name="k_s.txt"; charset=us-ascii
Content-Description: k_s.txt
Content-Disposition: attachment; filename="k_s.txt"

Index: kern_sig.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_sig.c,v
retrieving revision 1.164
diff -u -p -r1.164 kern_sig.c
--- kern_sig.c	4 Oct 2003 03:45:49 -0000	1.164
+++ kern_sig.c	6 Oct 2003 09:52:56 -0000
@@ -1305,7 +1305,7 @@ kpsendsig(struct lwp *l, const ksiginfo_
 		si = pool_get(&siginfo_pool, PR_WAITOK);
 		si->_info = *ksi;
 		le = li = NULL;
-		if (ksi->ksi_trap)
+		if (ksi->ksi_code > 0)
 			le = l;
 		else
 			li = l;

--==_Exmh_349974670130
Content-Type: text/plain ; name="pthsig.c"; charset=us-ascii
Content-Description: pthsig.c
Content-Disposition: attachment; filename="pthsig.c"

#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <err.h>

void *
th(void *dummy)
{

	return (0);
}

void
hdl(int sig, siginfo_t *si, void *vuc)
{

	fprintf(stderr, "hdl(%d) called\n", sig);
	_exit (1);
}

main()
{
	void *osig;
	pthread_t t;
	int res;

	osig = signal(SIGILL, hdl);
	if (osig == SIG_ERR)
		err(1, "signal");

	res = pthread_create(&t, 0, th, 0);
	if (res < 0)
		err(1, "pthread_create");
	
	__asm__(".byte 0x0f, 0x0b");
	exit (0);
}

--==_Exmh_349974670130--