sigaltstack with threads

From: Doug Rabson (dfr_at_nlsystems.com)
Date: 12/27/03

  • Next message: Daniel Eischen: "Re: sigaltstack with threads"
    To: arch@freebsd.org
    Date: Sat, 27 Dec 2003 12:12:16 +0000
    
    

    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.

    _______________________________________________
    freebsd-arch@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-arch
    To unsubscribe, send any mail to "freebsd-arch-unsubscribe@freebsd.org"


  • Next message: Daniel Eischen: "Re: sigaltstack with threads"

    Relevant Pages

    • Re: sigaltstack with threads
      ... >> valgrind deals with signals, ... >> When a signal stack is installed in FreeBSD, ... This syscall thread runs with something like the debugged ...
      (freebsd-arch)
    • Re: sigaltstack with threads
      ... > error checker to FreeBSD. ... > When a signal stack is installed in FreeBSD, ... > used in sendsigfor signals handlers which asked for SA_ONSTACK. ... This syscall thread runs with something like the debugged ...
      (freebsd-arch)
    • Re: how do threads work?
      ... current stack, and store the stack pointer into the current thread ... Context switch done. ... only asynchronous events a process can receive are signals, ... saved signal stack frame, and return from the signal handler. ...
      (comp.os.linux.development.system)
    • Re: how do threads work?
      ... >> current stack, and store the stack pointer into the current thread ... Context switch done. ... >> only asynchronous events a process can receive are signals, ... You can fetch the stack pointer of the interupted thread in the ...
      (comp.os.linux.development.system)
    • Re: i386 ABI and the stack
      ... The x86-64 ABI has a 128-bytezone that is safe from signals etc, ... can use a small amount of stack below the stackpointer safely. ... should be using a compiler like that; and nobody is expected to compile ... brokenness that the kernel should work around. ...
      (Linux-Kernel)