* malloc/malloc.c (_int_realloc): Add parameter with old block
authorUlrich Drepper <drepper@redhat.com>
Wed, 8 Apr 2009 18:00:34 +0000 (18:00 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 8 Apr 2009 18:00:34 +0000 (18:00 +0000)
size.  Remove duplicated test.  Don't handle mmap'ed blocks here.
Adjust all callers.
* malloc/hooks.c (realloc_check): Adjust _int_realloc call.

ChangeLog
malloc/hooks.c
malloc/malloc.c
resolv/res_hconf.c
sysdeps/x86_64/strchrnul.S

index 8a589aae0f48a57e7e0fed1fd7129bb3a7492ae0..b2c5b322fb496302f03e8a510a4b28023581372b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-04-08  Ulrich Drepper  <drepper@redhat.com>
+
+       * malloc/malloc.c (_int_realloc): Add parameter with old block
+       size.  Remove duplicated test.  Don't handle mmap'ed blocks here.
+       Adjust all callers.
+       * malloc/hooks.c (realloc_check): Adjust _int_realloc call.
+
 2009-04-07  Ulrich Drepper  <drepper@redhat.com>
 
        * sysdeps/x86_64/strchrnul.S: New file.
index fe89db83f48cb636bcf60be7ac49b4db9c3c20cc..72c29293d9ab8c7c47fa0bdcfe5bf89e17f1df13 100644 (file)
@@ -358,7 +358,7 @@ realloc_check(oldmem, bytes, caller)
     if (top_check() >= 0) {
       INTERNAL_SIZE_T nb;
       checked_request2size(bytes + 1, nb);
-      newmem = _int_realloc(&main_arena, oldp, nb);
+      newmem = _int_realloc(&main_arena, oldp, oldsize, nb);
     }
 #if 0 /* Erase freed memory. */
     if(newmem)
@@ -501,7 +501,7 @@ free_starter(mem, caller) Void_t* mem; const Void_t *caller;
    then the hooks are reset to 0.  */
 
 #define MALLOC_STATE_MAGIC   0x444c4541l
-#define MALLOC_STATE_VERSION (0*0x100l + 3l) /* major*0x100 + minor */
+#define MALLOC_STATE_VERSION (0*0x100l + 4l) /* major*0x100 + minor */
 
 struct malloc_save_state {
   long          magic;
@@ -521,6 +521,10 @@ struct malloc_save_state {
   unsigned long mmapped_mem;
   unsigned long max_mmapped_mem;
   int           using_malloc_checking;
+  unsigned long max_fast;
+  unsigned long arena_test;
+  unsigned long arena_max;
+  unsigned long narenas;
 };
 
 Void_t*
@@ -568,6 +572,12 @@ public_gET_STATe(void)
   ms->mmapped_mem = mp_.mmapped_mem;
   ms->max_mmapped_mem = mp_.max_mmapped_mem;
   ms->using_malloc_checking = using_malloc_checking;
+  ms->max_fast = get_max_fast();
+#ifdef PER_THREAD
+  ms->arena_test = mp_.arena_test;
+  ms->arena_max = mp_.arena_max;
+  ms->narenas = narenas;
+#endif
   (void)mutex_unlock(&main_arena.mutex);
   return (Void_t*)ms;
 }
@@ -587,7 +597,10 @@ public_sET_STATe(Void_t* msptr)
   (void)mutex_lock(&main_arena.mutex);
   /* There are no fastchunks.  */
   clear_fastchunks(&main_arena);
-  set_max_fast(DEFAULT_MXFAST);
+  if (ms->version >= 4)
+    set_max_fast(ms->max_fast);
+  else
+    set_max_fast(64);  /* 64 used to be the value we always used.  */
   for (i=0; i<NFASTBINS; ++i)
     fastbin (&main_arena, i) = 0;
   for (i=0; i<BINMAPSIZE; ++i)
@@ -663,6 +676,13 @@ public_sET_STATe(Void_t* msptr)
       using_malloc_checking = 0;
     }
   }
+  if (ms->version >= 4) {
+#ifdef PER_THREAD
+    mp_.arena_test = ms->arena_test;
+    mp_.arena_max = ms->arena_max;
+    narenas = ms->narenas;
+#endif
+  }
   check_malloc_state(&main_arena);
 
   (void)mutex_unlock(&main_arena.mutex);
index bb7ea36c802b56b3593d9b3cff5531586c012238..48a73799e2980000ac1b9081addc4e2076bb072f 100644 (file)
@@ -1586,7 +1586,8 @@ static void     _int_free(mstate, mchunkptr, int);
 #else
 static void     _int_free(mstate, mchunkptr);
 #endif
-static Void_t*  _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T);
+static Void_t*  _int_realloc(mstate, mchunkptr, INTERNAL_SIZE_T,
+                            INTERNAL_SIZE_T);
 static Void_t*  _int_memalign(mstate, size_t, size_t);
 static Void_t*  _int_valloc(mstate, size_t);
 static Void_t*  _int_pvalloc(mstate, size_t);
@@ -3778,7 +3779,7 @@ public_rEALLOc(Void_t* oldmem, size_t bytes)
   tsd_setspecific(arena_key, (Void_t *)ar_ptr);
 #endif
 
-  newp = _int_realloc(ar_ptr, oldp, nb);
+  newp = _int_realloc(ar_ptr, oldp, oldsize, nb);
 
   (void)mutex_unlock(&ar_ptr->mutex);
   assert(!newp || chunk_is_mmapped(mem2chunk(newp)) ||
@@ -5102,7 +5103,8 @@ static void malloc_consolidate(av) mstate av;
 */
 
 Void_t*
-_int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
+_int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
+            INTERNAL_SIZE_T nb)
 {
   mchunkptr        newp;            /* chunk to return */
   INTERNAL_SIZE_T  newsize;         /* its size */
@@ -5123,28 +5125,25 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
 
   const char *errstr = NULL;
 
-  /* Simple tests for old block integrity.  */
-  if (__builtin_expect (misaligned_chunk (oldp), 0))
-    {
-      errstr = "realloc(): invalid pointer";
-    errout:
-      malloc_printerr (check_action, errstr, chunk2mem(oldp));
-      return NULL;
-    }
-
   /* oldmem size */
-  const INTERNAL_SIZE_T oldsize = chunksize(oldp);
-
   if (__builtin_expect (oldp->size <= 2 * SIZE_SZ, 0)
       || __builtin_expect (oldsize >= av->system_mem, 0))
     {
       errstr = "realloc(): invalid old size";
-      goto errout;
+    errout:
+      malloc_printerr (check_action, errstr, chunk2mem(oldp));
+      return NULL;
     }
 
   check_inuse_chunk(av, oldp);
 
-  if (!chunk_is_mmapped(oldp)) {
+  /* All callers already filter out mmap'ed chunks.  */
+#if 0
+  if (!chunk_is_mmapped(oldp))
+#else
+  assert (!chunk_is_mmapped(oldp));
+#endif
+  {
 
     next = chunk_at_offset(oldp, oldsize);
     INTERNAL_SIZE_T nextsize = chunksize(next);
@@ -5271,6 +5270,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
     return chunk2mem(newp);
   }
 
+#if 0
   /*
     Handle mmap cases
   */
@@ -5339,6 +5339,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T nb)
     return 0;
 #endif
   }
+#endif
 }
 
 /*
index a98dfda88a5cc14144fd85d1205e95793249cab8..ed55bec29655079502f4519d6f940079091a1c6d 100644 (file)
@@ -518,7 +518,7 @@ _res_hconf_trim_domain (char *hostname)
 
       trim_len = strlen (trim);
       if (hostname_len > trim_len
-         && strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
+         && __strcasecmp (&hostname[hostname_len - trim_len], trim) == 0)
        {
          hostname[hostname_len - trim_len] = '\0';
          break;
index ae3aa073eb5a5a652e0a2e53deef074db1dcb86c..576027a38dcaf5597f73d93f352ae9d1f76d4778 100644 (file)
@@ -41,9 +41,8 @@ ENTRY (__strchrnul)
        shl     %cl, %esi
        pmovmskb %xmm0, %edx
        pmovmskb %xmm3, %ecx
-       andl    %esi, %edx
-       andl    %esi, %ecx
        orl     %edx, %ecx
+       andl    %esi, %ecx
        jnz     1f
 
 2:     movdqa  (%rdi), %xmm0