HomeFreeBSD

Fixes for very early use of the pthread_mutex_* and libthr malloc.

Description

Fixes for very early use of the pthread_mutex_* and libthr malloc.

When libthr is statically linked into the binary, order of the
constructors execution is not deterministic. It is possible for the
application constructor to use pthread_mutex_* functions before the
libthr initialization was done.

Handle it by:

  • making thr_malloc.c locking functions operational when curthread is not yet set;
  • making __thr_malloc_init() idempotent, allowing more than one call to it;
  • unconditionally calling __thr_malloc_init() before initializing a process-private mutex.

Reported and tested by: mmel
Sponsored by: The FreeBSD Foundation
MFC after: 1 week

Details

Provenance
kibAuthored on
Parents
rS343753: o As illustrated by e. g. figure 7-14 of the Intel 82599 10 GbE
Branches
Unknown
Tags
Unknown