glibc/hurd
Jeremie Koenig 653d74f12a hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.

This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.

This also updates all the glibc code accordingly.

This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.

During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork.  This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.

To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.

When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create).  This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal.  In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked).  Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive.  Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.

Options seem to be:

  * Move the locking of _hurd_siglock earlier in post_signal -- but that
    may generally impact performance, if this locking isn't generally
    needed anyway?

    On the other hand, would it actually make sense to wait here until we
    are not any longer in a critical section (which is meant to disable
    signal delivery anyway (but not for preempted signals?))?

  * Clear the global sigstate in the fork's child with the rationale that
    we're anyway restarting the signal thread from a clean state.  This
    has now been implemented.

Why has this problem not been observed before Jérémie's patches?  (Or has
it?  Perhaps even more rarely?)  In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*.  The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section?  (Not completely analyzed and verified.)

Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
2019-12-29 18:32:49 +01:00
..
hurd hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
alloc-fd.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
catch-exc.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
catch-signal.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
compat-20.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
ctty-input.c hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
ctty-output.c hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
Depend * Makefile (subdir-target-args): New variable. 2006-02-28 07:11:04 +00:00
dtable.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
exc2signal.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
faultexc.defs Sun May 12 11:16:58 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu> 1996-05-12 16:38:08 +00:00
fchroot.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
fcntl-internal.h Update copyright dates with scripts/update-copyrights. 2019-01-01 00:11:28 +00:00
fd-close.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
fd-read.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
fd-write.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
fopenport.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
get-host.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
getdport.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
geteuids.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
getumask.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurd-raise.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurd.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdauth.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdchdir.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdexec.c hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
hurdfault.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdfault.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdfchdir.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdhost.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdid.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdinit.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdioctl.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdkill.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdlock.c time: Introduce function to check correctness of nanoseconds value 2019-10-27 21:49:25 +01:00
hurdlock.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdlookup.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdmalloc.c hurdmalloc: Run fork handler as late as possible [BZ #19431] 2016-09-22 01:45:48 +02:00
hurdmalloc.h hurdmalloc: Run fork handler as late as possible [BZ #19431] 2016-09-22 01:45:48 +02:00
hurdmsg.c hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
hurdpid.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdports.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdprio.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdrlimit.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdselect.c hurd: Use __clock_gettime in _hurd_select 2019-11-07 09:54:33 +01:00
hurdsig.c hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
hurdsock.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdsocket.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdstartup.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
hurdstartup.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
intern-fd.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
intr-msg.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
intr-rpc.defs Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
intr-rpc.h Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
longjmp-ts.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
lookup-at.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
lookup-retry.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
Makefile Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
msgportdemux.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
new-fd.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
Notes initial import 1995-02-18 01:27:10 +00:00
openport.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
path-lookup.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
pid2task.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
port2fd.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
port-cleanup.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
ports-get.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
ports-set.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
preempt-sig.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
privports.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
report-wait.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
set-host.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
setauth.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
seteuids.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
siginfo.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
sigunwind.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
stack_chk_fail_local.c hurd: fix build with -fstack-protector-strong 2017-08-27 22:10:17 +02:00
task2pid.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
thread-cancel.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
thread-self.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
trampoline.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
Versions hurd: Global signal disposition 2019-12-29 18:32:49 +01:00
vpprintf.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00
xattr.c Prefer https to http for gnu.org and fsf.org URLs 2019-09-07 02:43:31 -07:00