446cf2
commit 72d36ffd7db55ae599f4c77feb0eae25a0f3714e
446cf2
Author: Florian Weimer <fweimer@redhat.com>
446cf2
Date:   Thu Oct 8 10:57:09 2020 +0200
446cf2
446cf2
    elf: Implement __rtld_malloc_is_complete
446cf2
    
446cf2
    In some cases, it is difficult to determine the kind of malloc
446cf2
    based on the execution context, so a function to determine that
446cf2
    is helpful.
446cf2
    
446cf2
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
446cf2
446cf2
diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
446cf2
index 4335f1bd24289b01..cf7df8a8d5eabe9d 100644
446cf2
--- a/elf/dl-minimal.c
446cf2
+++ b/elf/dl-minimal.c
446cf2
@@ -59,6 +59,14 @@ __rtld_malloc_init_stubs (void)
446cf2
   __rtld_realloc = &rtld_realloc;
446cf2
 }
446cf2
 
446cf2
+bool
446cf2
+__rtld_malloc_is_complete (void)
446cf2
+{
446cf2
+  /* The caller assumes that there is an active malloc.  */
446cf2
+  assert (__rtld_malloc != NULL);
446cf2
+  return __rtld_malloc != &rtld_malloc;
446cf2
+}
446cf2
+
446cf2
 /* Lookup NAME at VERSION in the scope of MATCH.  */
446cf2
 static void *
446cf2
 lookup_malloc_symbol (struct link_map *main_map, const char *name,
446cf2
diff --git a/include/rtld-malloc.h b/include/rtld-malloc.h
446cf2
index b026a3270cd24819..9266ec532f3f3376 100644
446cf2
--- a/include/rtld-malloc.h
446cf2
+++ b/include/rtld-malloc.h
446cf2
@@ -66,6 +66,10 @@ realloc (void *ptr, size_t size)
446cf2
    implementation.  */
446cf2
 void __rtld_malloc_init_stubs (void) attribute_hidden;
446cf2
 
446cf2
+/* Return false if the active malloc is the ld.so minimal malloc, true
446cf2
+   if it is the full implementation from libc.so.  */
446cf2
+_Bool __rtld_malloc_is_complete (void) attribute_hidden;
446cf2
+
446cf2
 /* Called shortly before the final self-relocation (when RELRO
446cf2
    variables are still writable) to activate the real malloc
446cf2
    implementation.  MAIN_MAP is the link map of the executable.  */