Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Dec 2003 09:56:36 -0500 (EST)
From:      Daniel Eischen <eischen@vigrid.com>
To:        Doug Rabson <dfr@nlsystems.com>
Cc:        arch@freebsd.org
Subject:   Re: sigaltstack with threads
Message-ID:  <Pine.GSO.4.10.10312270942550.26078-100000@pcnet5.pcnet.com>
In-Reply-To: <1072527136.11617.17.camel@herring.nlsystems.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 27 Dec 2003, Doug Rabson wrote:

> I've been using my festive spare time in porting the excellent valgrind
> error checker to FreeBSD. While working through the complex way that
> valgrind deals with signals, I noticed a tricky problem.
> 
> When a signal stack is installed in FreeBSD, the stack location is
> recorded in the per-process state (p_sigstk to be exact). This stack is
> used in sendsig() for signals handlers which asked for SA_ONSTACK. This
> is a problem for valgrind since it uses two threads (I use the thr_*
> syscalls for this purpose).
> 
> The main thread does most of the work and wants to take a selection of
> signals (SIGSEGV, SIGBUS etc) on a signal stack allocated for the
> purpose - all other signals are blocked.
> 
> The other thread is used for executing blocking syscalls (actually there
> can be more than one of these for pthread programs but I don't have that
> working yet). This syscall thread runs with something like the debugged
> program's normal signal mask so most of those signals get routed to the
> syscall thread. The main problem is that the syscall thread wants to
> take the signals on its normal stack but it can't use a different
> setting for sigaltstack.
> 
> It seems to me that sigaltstack needs to be per-thread state, not
> per-process state otherwise it is essentially useless for threaded
> programs. As far as I can make out, this is the behaviour for Linux
> threads created using their clone syscall.

In the '96 POSIX spec, using sigaltstack() in threaded applications
was undefined.  The new (SUSv3 200[123]?) POSIX spec allows this
but says "Use of this function by library threads that are not bound
to kernel-scheduled entities results in undefined behavior".  I think
that allows you to make it per-thread, but what behavior do we
want when there are multiple threads in a KSE/KSEG?  Should it be
per KSE or KSEG?




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10312270942550.26078-100000>