Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r?njn draft
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 30 May 2017 15:57:28 +0900
changeset 587418 2498342205f1fa887451839424145061c9b055dd
parent 587417 7528e112c7abc897769a3e0451d4370d6af5e3a1
child 587419 f8199b5fe0a2e549e3f2d20919b6cebb044db3be
push id61698
push userbmo:mh+mozilla@glandium.org
push dateThu, 01 Jun 2017 00:41:06 +0000
reviewersnjn
bugs1368932
milestone55.0a1
Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r?njn Until now, the malloc implementation functions would call the replace-malloc functions if they exist, and fallback to the real allocator in no such function exists. Instead of doing this, we now fill the empty slots in the malloc_table_t with the real allocator functions.
memory/build/replace_malloc.c
--- a/memory/build/replace_malloc.c
+++ b/memory/build/replace_malloc.c
@@ -124,16 +124,22 @@ replace_malloc_init_funcs()
 #  define MALLOC_FUNCS (MALLOC_FUNCS_INIT | MALLOC_FUNCS_BRIDGE)
 #  include "malloc_decls.h"
 #endif
 
 #define MALLOC_DECL(name, ...) \
   replace_malloc_table.name = REPLACE_MALLOC_GET_FUNC(handle, name);
 #include "malloc_decls.h"
   }
+
+#define MALLOC_DECL(name, ...) \
+  if (!replace_malloc_table.name) { \
+    replace_malloc_table.name = je_ ## name; \
+  }
+#include "malloc_decls.h"
 }
 
 /*
  * Below is the malloc implementation overriding jemalloc and calling the
  * replacement functions if they exist.
  */
 
 static int replace_malloc_initialized = 0;
@@ -169,21 +175,17 @@ init()
 #define ARGS2(t1, t2) ARGS1(t1), arg2
 #define ARGS3(t1, t2, t3) ARGS2(t1, t2), arg3
 
 #define GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ...) \
   return_type name ## _impl(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) \
   { \
     if (MOZ_UNLIKELY(!replace_malloc_initialized)) \
       init(); \
-    if (MOZ_LIKELY(!replace_malloc_table.name)) { \
-      return je_ ## name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
-    } else { \
-      return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
-    } \
+    return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
   }
 
 #define GENERIC_MALLOC_DECL(name, return_type, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ##__VA_ARGS__)
 #define GENERIC_MALLOC_DECL_VOID(name, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, , void, ##__VA_ARGS__)
 
 #define MALLOC_DECL(...) MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__))