libthread_xu - Fix rtld and refactor locks

Operating Systems / DragonFlyBSD - Matthew Dillon [apollo.backplane.com] - 2 November 2017 00:32 EDT

- 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'

fcaa7a3ab0 libthread_xu - Fix rtld and refactor locks
lib/libthread_xu/Makefile | 9 ++
lib/libthread_xu/thread/thr_cond.c | 180 ++++++++++++++++++++++++----------
lib/libthread_xu/thread/thr_fork.c | 57 ++++++++++-
lib/libthread_xu/thread/thr_init.c | 25 ++---
lib/libthread_xu/thread/thr_join.c | 2 +-
lib/libthread_xu/thread/thr_kern.c | 8 +-
lib/libthread_xu/thread/thr_mutex.c | 146 +++++++++++++++++++++------
lib/libthread_xu/thread/thr_private.h | 35 +++++--
lib/libthread_xu/thread/thr_rtld.c | 9 ++
lib/libthread_xu/thread/thr_rwlock.c | 132 +++++++++++++++++++++----
lib/libthread_xu/thread/thr_sem.c | 33 +++++--
lib/libthread_xu/thread/thr_sig.c | 93 ++++++++++++++++++
lib/libthread_xu/thread/thr_umtx.c | 53 ++++++----
lib/libthread_xu/thread/thr_umtx.h | 32 +++---
14 files changed, 641 insertions(+), 173 deletions(-)

Upstream: gitweb.dragonflybsd.org


  • Share