libthread_xu - Fix rtld and refactor locks
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 2 Nov 2017 00:18:56 +0000 (17:18 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 2 Nov 2017 00:32:46 +0000 (17:32 -0700)
commitfcaa7a3ab08a96245428bb23143cb389221fe1be
tree178c506ed6b75c1fa909b0db396521e1d4f4cb15
parente19be507c3558537e9f2545ba92e771755eddf5f
libthread_xu - Fix rtld and refactor locks

* Add a separate atfork facility for internal pthread atfork entities
  (sem and rtld) which must execute after all user atfork entities
  pre-fork and before all user atfork entities post-fork.

* Install an atfork handler for rtld-elf (also requires rtld-elf to
  be updated).  The handler will ensure that RTLD locks are in a sane
  state prior to fork (by acquiring them), and will then release the
  locks post-fork.  This is the primary fix for lang/rust and cargo.

  Also do not issue _thr_rtld_fini() when threading drops to 0.
  Once threading has been set, rtld's pthread locks remain installed.

* Refactor thr_cond.c.  Refactor condition variables to perform
  according to the spec.  Use a TAILQ to make pthread_cond_signal()
  work exactly as described in the manual (that is, waking up only
  one waiter at a time).

* Refactor thr_mutex.c.  Primary instrument for debugging and
  clean up.  Also deal with improper EINTR handling.

* Refactor thr_fork.c.  Implement the new atfork facility for
  internal atfork handlers.

* Refactor thr_rwlock.c.  Add debugging, cleanup.

* thr_sem.c now uses the internal atfork handler to ensure proper
  ordering.

* thr_sig.c implements debugging features.

* Refactor thr_umtx.c... the low level mutex code.  Store the id
  for additonal verification and use an atomic lock to clear the
  lock instead of an assignment.  Properly ignore EINTR.

* Cleanup init_private() a bit.

* Add PTHREADS_DEBUGGING=TRUE and PTHREADS_DEBUGGING2=TRUE make
  flags.  The first writes out a garbage file in /tmp for all
  locking operations as they occur.  The second is used for
  point debugging and writes out a file when signal 63 is sent
  to the program.

* Add cpu_ccfence() in various places that might need it (a hack
  for the moment, userland cannot currently #include
  "machine/cpufunc.h").

* Should fix lang/rust and 'cargo'
14 files changed:
lib/libthread_xu/Makefile
lib/libthread_xu/thread/thr_cond.c
lib/libthread_xu/thread/thr_fork.c
lib/libthread_xu/thread/thr_init.c
lib/libthread_xu/thread/thr_join.c
lib/libthread_xu/thread/thr_kern.c
lib/libthread_xu/thread/thr_mutex.c
lib/libthread_xu/thread/thr_private.h
lib/libthread_xu/thread/thr_rtld.c
lib/libthread_xu/thread/thr_rwlock.c
lib/libthread_xu/thread/thr_sem.c
lib/libthread_xu/thread/thr_sig.c
lib/libthread_xu/thread/thr_umtx.c
lib/libthread_xu/thread/thr_umtx.h