Author: kib
Date: Thu Aug 20 15:19:09 2020
New Revision: 364423
URL: https://svnweb.freebsd.org/changeset/base/364423

Log:
  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

Modified:
  head/lib/libc/gen/dlfcn.c

Modified: head/lib/libc/gen/dlfcn.c
==============================================================================
--- head/lib/libc/gen/dlfcn.c   Thu Aug 20 14:07:29 2020        (r364422)
+++ head/lib/libc/gen/dlfcn.c   Thu Aug 20 15:19:09 2020        (r364423)
@@ -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
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to