dl_iterate_phdr(3): provide exclusive locking for callback when statically linked.

Apparently llvm unwinder depends on the external locking for callback.

Reviewed by:	cem, emaste
Tested by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D26109
This commit is contained in:
Konstantin Belousov 2020-08-20 15:19:09 +00:00
parent 9060f2c392
commit 22517af2c1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=364423

View File

@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <pthread.h>
#include "un-namespace.h"
#include "libc_private.h"
#include "reentrant.h"
static char sorry[] = "Service unavailable";
@ -164,6 +165,7 @@ _rtld_thread_init(void *li __unused)
#ifndef IN_LIBDL
static pthread_once_t dl_phdr_info_once = PTHREAD_ONCE_INIT;
static struct dl_phdr_info phdr_info;
static mutex_t dl_phdr_info_lock = MUTEX_INITIALIZER;
static void
dl_init_phdr_info(void)
@ -204,13 +206,17 @@ int
dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *) __unused,
void *data __unused)
{
#ifndef IN_LIBDL
int ret;
__init_elf_aux_vector();
if (__elf_aux_vector == NULL)
return (1);
_once(&dl_phdr_info_once, dl_init_phdr_info);
return (callback(&phdr_info, sizeof(phdr_info), data));
mutex_lock(&dl_phdr_info_lock);
ret = callback(&phdr_info, sizeof(phdr_info), data);
mutex_unlock(&dl_phdr_info_lock);
return (ret);
#else
return (0);
#endif