Some third-party malloc(3) implementations use pthread_setspecific(3)
authorkib <kib@FreeBSD.org>
Fri, 15 May 2015 08:40:17 +0000 (08:40 +0000)
committerkib <kib@FreeBSD.org>
Fri, 15 May 2015 08:40:17 +0000 (08:40 +0000)
commit40d3cfa056957b9f55ee302fe8aac44ff6595924
treee2f875d85aebbfb01763aea6011021fa1d34d8db
parentc3a04ab331a24533e7a7470d0f8a347a23ea974d
Some third-party malloc(3) implementations use pthread_setspecific(3)
to handle per-thread information.  Since our pthread_setspecific()
implementation calls calloc(3) to allocate per-thread specific data
storage, things get complicated.

Switch the allocator to use bare mmap(2).  There is some loss of the
allocated page, since e.g. on amd64, PTHREAD_KEYS_MAX * sizeof(struct
pthread_specific_elem) is 3K (it actually spans whole page due to
padding), but I believe it is more acceptable than additional code for
specialized allocator().

The alternatives would either to make the specific data array be part of
the struct thread, or use internal bindings to call the libc malloc,
avoiding interposing.

Also do the style pass over the thr_spec.c, esp. simplify the
conditionals nesting by returning early when an error detected.
Remove trivial comments.

Found by: yuri@rawbw.com
PR: 200138
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
lib/libthr/thread/thr_spec.c