File glibc-2.10-malloc-threadsafe.diff of Package glibc

Only in malloc~: .hooks.c.swp
Index: malloc/arena.c
===================================================================
--- malloc/arena.c.orig
+++ malloc/arena.c
@@ -567,8 +567,9 @@ ptmalloc_init (void)
     if (check_action != 0)
       __malloc_check_init();
   }
-  if(__malloc_initialize_hook != NULL)
-    (*__malloc_initialize_hook)();
+  void (*hook) (void) = force_reg (__malloc_initialize_hook);
+  if (hook != NULL)
+    (*hook)();
   __malloc_initialized = 1;
 }
 
Index: malloc/hooks.c
===================================================================
--- malloc/hooks.c.orig
+++ malloc/hooks.c
@@ -235,8 +235,9 @@ top_check()
       return -1;
     }
   /* Call the `morecore' hook if necessary.  */
-  if (__after_morecore_hook)
-    (*__after_morecore_hook) ();
+  void (*hook) (void) = force_reg (__after_morecore_hook);
+  if (hook)
+    (*hook) ();
   main_arena.system_mem = (new_brk - mp_.sbrk_base) + sbrk_size;
 
   top(&main_arena) = (mchunkptr)(brk + front_misalign);
Index: malloc/malloc.c
===================================================================
--- malloc/malloc.c.orig
+++ malloc/malloc.c
@@ -565,6 +565,13 @@ Void_t* memcpy();
 #endif
 #endif
 
+
+/* Force a value to be in a register and stop the compiler referring
+   to the source (mostly memory location) again.  */
+#define force_reg(val) \
+  ({ __typeof (val) _v; asm ("" : "=r" (_v) : "0" (val)); _v; })
+
+
 /*
   MALLOC_FAILURE_ACTION is the action to take before "return 0" when
   malloc fails to be able to return memory, either because memory is
@@ -3131,8 +3138,9 @@ static Void_t* sYSMALLOc(nb, av) INTERNA
 
   if (brk != (char*)(MORECORE_FAILURE)) {
     /* Call the `morecore' hook if necessary.  */
-    if (__after_morecore_hook)
-      (*__after_morecore_hook) ();
+    void (*hook) (void) = force_reg (__after_morecore_hook);
+    if (__builtin_expect (hook != NULL, 0))
+      (*hook) ();
   } else {
   /*
     If have mmap, try using it as a backup when MORECORE fails or
@@ -3268,10 +3276,12 @@ static Void_t* sYSMALLOc(nb, av) INTERNA
         if (snd_brk == (char*)(MORECORE_FAILURE)) {
           correction = 0;
           snd_brk = (char*)(MORECORE(0));
-        } else
+        } else {
 	  /* Call the `morecore' hook if necessary.  */
-	  if (__after_morecore_hook)
-	    (*__after_morecore_hook) ();
+	  void (*hook) (void) = force_reg (__after_morecore_hook);
+	  if (__builtin_expect (hook != NULL, 0))
+	    (*hook) ();
+	}
       }
 
       /* handle non-contiguous cases */
@@ -3415,8 +3425,9 @@ static int sYSTRIm(pad, av) size_t pad;
 
       MORECORE(-extra);
       /* Call the `morecore' hook if necessary.  */
-      if (__after_morecore_hook)
-	(*__after_morecore_hook) ();
+      void (*hook) (void) = force_reg (__after_morecore_hook);
+      if (__builtin_expect (hook != NULL, 0))
+	(*hook) ();
       new_brk = (char*)(MORECORE(0));
 
       if (new_brk != (char*)MORECORE_FAILURE) {
@@ -3541,7 +3552,8 @@ public_mALLOc(size_t bytes)
   mstate ar_ptr;
   Void_t *victim;
 
-  __malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t) = __malloc_hook;
+  __malloc_ptr_t (*hook) (size_t, __const __malloc_ptr_t)
+    = force_reg (__malloc_hook);
   if (hook != NULL)
     return (*hook)(bytes, RETURN_ADDRESS (0));
 
@@ -3584,7 +3596,8 @@ public_fREe(Void_t* mem)
   mstate ar_ptr;
   mchunkptr p;                          /* chunk corresponding to mem */
 
-  void (*hook) (__malloc_ptr_t, __const __malloc_ptr_t) = __free_hook;
+  void (*hook) (__malloc_ptr_t, __const __malloc_ptr_t)
+    = force_reg (__free_hook);
   if (hook != NULL) {
     (*hook)(mem, RETURN_ADDRESS (0));
     return;
@@ -3641,7 +3654,7 @@ public_rEALLOc(Void_t* oldmem, size_t by
   Void_t* newp;             /* chunk to return */
 
   __malloc_ptr_t (*hook) (__malloc_ptr_t, size_t, __const __malloc_ptr_t) =
-    __realloc_hook;
+    force_reg (__realloc_hook);
   if (hook != NULL)
     return (*hook)(oldmem, bytes, RETURN_ADDRESS (0));
 
@@ -3747,7 +3760,7 @@ public_mEMALIGn(size_t alignment, size_t
 
   __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
 					__const __malloc_ptr_t)) =
-    __memalign_hook;
+    force_reg (__memalign_hook);
   if (hook != NULL)
     return (*hook)(alignment, bytes, RETURN_ADDRESS (0));
 
@@ -3804,7 +3817,7 @@ public_vALLOc(size_t bytes)
 
   __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
 					__const __malloc_ptr_t)) =
-    __memalign_hook;
+    force_reg (__memalign_hook);
   if (hook != NULL)
     return (*hook)(pagesz, bytes, RETURN_ADDRESS (0));
 
@@ -3851,7 +3864,7 @@ public_pVALLOc(size_t bytes)
 
   __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
 					__const __malloc_ptr_t)) =
-    __memalign_hook;
+    force_reg (__memalign_hook);
   if (hook != NULL)
     return (*hook)(pagesz, rounded_bytes, RETURN_ADDRESS (0));
 
@@ -3892,8 +3905,6 @@ public_cALLOc(size_t n, size_t elem_size
   unsigned long clearsize;
   unsigned long nclears;
   INTERNAL_SIZE_T* d;
-  __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
-    __malloc_hook;
 
   /* size_t is unsigned so the behavior on overflow is defined.  */
   bytes = n * elem_size;
@@ -3906,6 +3917,8 @@ public_cALLOc(size_t n, size_t elem_size
     }
   }
 
+  __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, __const __malloc_ptr_t)) =
+    force_reg (__malloc_hook);
   if (hook != NULL) {
     sz = bytes;
     mem = (*hook)(sz, RETURN_ADDRESS (0));
@@ -6007,9 +6020,6 @@ int
 __posix_memalign (void **memptr, size_t alignment, size_t size)
 {
   void *mem;
-  __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
-					__const __malloc_ptr_t)) =
-    __memalign_hook;
 
   /* Test whether the SIZE argument is valid.  It must be a power of
      two multiple of sizeof (void *).  */
@@ -6020,6 +6030,9 @@ __posix_memalign (void **memptr, size_t
 
   /* Call the hook here, so that caller is posix_memalign's caller
      and not posix_memalign itself.  */
+  __malloc_ptr_t (*hook) __MALLOC_PMT ((size_t, size_t,
+					__const __malloc_ptr_t)) =
+    force_reg (__memalign_hook);
   if (hook != NULL)
     mem = (*hook)(alignment, size, RETURN_ADDRESS (0));
   else
openSUSE Build Service is sponsored by