9832fd
This is a partial recreation of this upstream commit, restricted to
9832fd
the malloc_info function:
9832fd
9832fd
commit 6c8dbf00f536d78b1937b5af6f57be47fd376344
9832fd
Author: Ondřej Bílka <neleai@seznam.cz>
9832fd
Date:   Thu Jan 2 09:38:18 2014 +0100
9832fd
9832fd
    Reformat malloc to gnu style.
9832fd
9832fd
It is not an exact copy because glibc-rh1103856.patch backported
9832fd
commit 4d653a59ffeae0f46f76a40230e2cfa9587b7e7e ("Add mmap usage in
9832fd
malloc_info output"), which came after the reformatting upstream.
9832fd
9832fd
diff --git a/malloc/malloc.c b/malloc/malloc.c
9832fd
index c98b3f79ed38b4f0..5c7a27129d66e06a 100644
9832fd
--- a/malloc/malloc.c
9832fd
+++ b/malloc/malloc.c
9832fd
@@ -5023,7 +5023,8 @@ malloc_info (int options, FILE *fp)
9832fd
   size_t total_aspace = 0;
9832fd
   size_t total_aspace_mprotect = 0;
9832fd
 
9832fd
-  void mi_arena (mstate ar_ptr)
9832fd
+  void
9832fd
+  mi_arena (mstate ar_ptr)
9832fd
   {
9832fd
     fprintf (fp, "<heap nr=\"%d\">\n<sizes>\n", n++);
9832fd
 
9832fd
@@ -5044,28 +5045,28 @@ malloc_info (int options, FILE *fp)
9832fd
 
9832fd
     for (size_t i = 0; i < NFASTBINS; ++i)
9832fd
       {
9832fd
-	mchunkptr p = fastbin (ar_ptr, i);
9832fd
-	if (p != NULL)
9832fd
-	  {
9832fd
-	    size_t nthissize = 0;
9832fd
-	    size_t thissize = chunksize (p);
9832fd
-
9832fd
-	    while (p != NULL)
9832fd
-	      {
9832fd
-		++nthissize;
9832fd
-		p = p->fd;
9832fd
-	      }
9832fd
-
9832fd
-	    fastavail += nthissize * thissize;
9832fd
-	    nfastblocks += nthissize;
9832fd
-	    sizes[i].from = thissize - (MALLOC_ALIGNMENT - 1);
9832fd
-	    sizes[i].to = thissize;
9832fd
-	    sizes[i].count = nthissize;
9832fd
-	  }
9832fd
-	else
9832fd
-	  sizes[i].from = sizes[i].to = sizes[i].count = 0;
9832fd
-
9832fd
-	sizes[i].total = sizes[i].count * sizes[i].to;
9832fd
+        mchunkptr p = fastbin (ar_ptr, i);
9832fd
+        if (p != NULL)
9832fd
+          {
9832fd
+            size_t nthissize = 0;
9832fd
+            size_t thissize = chunksize (p);
9832fd
+
9832fd
+            while (p != NULL)
9832fd
+              {
9832fd
+                ++nthissize;
9832fd
+                p = p->fd;
9832fd
+              }
9832fd
+
9832fd
+            fastavail += nthissize * thissize;
9832fd
+            nfastblocks += nthissize;
9832fd
+            sizes[i].from = thissize - (MALLOC_ALIGNMENT - 1);
9832fd
+            sizes[i].to = thissize;
9832fd
+            sizes[i].count = nthissize;
9832fd
+          }
9832fd
+        else
9832fd
+          sizes[i].from = sizes[i].to = sizes[i].count = 0;
9832fd
+
9832fd
+        sizes[i].total = sizes[i].count * sizes[i].to;
9832fd
       }
9832fd
 
9832fd
 
9832fd
@@ -5074,29 +5075,29 @@ malloc_info (int options, FILE *fp)
9832fd
 
9832fd
     for (size_t i = 1; i < NBINS; ++i)
9832fd
       {
9832fd
-	bin = bin_at (ar_ptr, i);
9832fd
-	r = bin->fd;
9832fd
-	sizes[NFASTBINS - 1 + i].from = ~((size_t) 0);
9832fd
-	sizes[NFASTBINS - 1 + i].to = sizes[NFASTBINS - 1 + i].total
9832fd
-	  = sizes[NFASTBINS - 1 + i].count = 0;
9832fd
-
9832fd
-	if (r != NULL)
9832fd
-	  while (r != bin)
9832fd
-	    {
9832fd
-	      ++sizes[NFASTBINS - 1 + i].count;
9832fd
-	      sizes[NFASTBINS - 1 + i].total += r->size;
9832fd
-	      sizes[NFASTBINS - 1 + i].from
9832fd
-		= MIN (sizes[NFASTBINS - 1 + i].from, r->size);
9832fd
-	      sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
9832fd
-						 r->size);
9832fd
-
9832fd
-	      r = r->fd;
9832fd
-	    }
9832fd
-
9832fd
-	if (sizes[NFASTBINS - 1 + i].count == 0)
9832fd
-	  sizes[NFASTBINS - 1 + i].from = 0;
9832fd
-	nblocks += sizes[NFASTBINS - 1 + i].count;
9832fd
-	avail += sizes[NFASTBINS - 1 + i].total;
9832fd
+        bin = bin_at (ar_ptr, i);
9832fd
+        r = bin->fd;
9832fd
+        sizes[NFASTBINS - 1 + i].from = ~((size_t) 0);
9832fd
+        sizes[NFASTBINS - 1 + i].to = sizes[NFASTBINS - 1 + i].total
9832fd
+                                        = sizes[NFASTBINS - 1 + i].count = 0;
9832fd
+
9832fd
+        if (r != NULL)
9832fd
+          while (r != bin)
9832fd
+            {
9832fd
+              ++sizes[NFASTBINS - 1 + i].count;
9832fd
+              sizes[NFASTBINS - 1 + i].total += r->size;
9832fd
+              sizes[NFASTBINS - 1 + i].from
9832fd
+                = MIN (sizes[NFASTBINS - 1 + i].from, r->size);
9832fd
+              sizes[NFASTBINS - 1 + i].to = MAX (sizes[NFASTBINS - 1 + i].to,
9832fd
+                                                 r->size);
9832fd
+
9832fd
+              r = r->fd;
9832fd
+            }
9832fd
+
9832fd
+        if (sizes[NFASTBINS - 1 + i].count == 0)
9832fd
+          sizes[NFASTBINS - 1 + i].from = 0;
9832fd
+        nblocks += sizes[NFASTBINS - 1 + i].count;
9832fd
+        avail += sizes[NFASTBINS - 1 + i].total;
9832fd
       }
9832fd
 
9832fd
     mutex_unlock (&ar_ptr->mutex);
9832fd
@@ -5109,51 +5110,51 @@ malloc_info (int options, FILE *fp)
9832fd
 
9832fd
     for (size_t i = 0; i < nsizes; ++i)
9832fd
       if (sizes[i].count != 0 && i != NFASTBINS)
9832fd
-	fprintf (fp, "\
9832fd
+        fprintf (fp, "							      \
9832fd
 <size from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
9832fd
-		 sizes[i].from, sizes[i].to, sizes[i].total, sizes[i].count);
9832fd
+                 sizes[i].from, sizes[i].to, sizes[i].total, sizes[i].count);
9832fd
 
9832fd
     if (sizes[NFASTBINS].count != 0)
9832fd
       fprintf (fp, "\
9832fd
 <unsorted from=\"%zu\" to=\"%zu\" total=\"%zu\" count=\"%zu\"/>\n",
9832fd
-	       sizes[NFASTBINS].from, sizes[NFASTBINS].to,
9832fd
-	       sizes[NFASTBINS].total, sizes[NFASTBINS].count);
9832fd
+               sizes[NFASTBINS].from, sizes[NFASTBINS].to,
9832fd
+               sizes[NFASTBINS].total, sizes[NFASTBINS].count);
9832fd
 
9832fd
     total_system += ar_ptr->system_mem;
9832fd
     total_max_system += ar_ptr->max_system_mem;
9832fd
 
9832fd
     fprintf (fp,
9832fd
-	     "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
-	     "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
-	     "<system type=\"current\" size=\"%zu\"/>\n"
9832fd
-	     "<system type=\"max\" size=\"%zu\"/>\n",
9832fd
-	     nfastblocks, fastavail, nblocks, avail,
9832fd
-	     ar_ptr->system_mem, ar_ptr->max_system_mem);
9832fd
+             "</sizes>\n<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
+             "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
+             "<system type=\"current\" size=\"%zu\"/>\n"
9832fd
+             "<system type=\"max\" size=\"%zu\"/>\n",
9832fd
+             nfastblocks, fastavail, nblocks, avail,
9832fd
+             ar_ptr->system_mem, ar_ptr->max_system_mem);
9832fd
 
9832fd
     if (ar_ptr != &main_arena)
9832fd
       {
9832fd
-	heap_info *heap = heap_for_ptr(top(ar_ptr));
9832fd
-	fprintf (fp,
9832fd
-		 "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
-		 "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
9832fd
-		 heap->size, heap->mprotect_size);
9832fd
-	total_aspace += heap->size;
9832fd
-	total_aspace_mprotect += heap->mprotect_size;
9832fd
+        heap_info *heap = heap_for_ptr (top (ar_ptr));
9832fd
+        fprintf (fp,
9832fd
+                 "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
+                 "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
9832fd
+                 heap->size, heap->mprotect_size);
9832fd
+        total_aspace += heap->size;
9832fd
+        total_aspace_mprotect += heap->mprotect_size;
9832fd
       }
9832fd
     else
9832fd
       {
9832fd
-	fprintf (fp,
9832fd
-		 "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
-		 "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
9832fd
-		 ar_ptr->system_mem, ar_ptr->system_mem);
9832fd
-	total_aspace += ar_ptr->system_mem;
9832fd
-	total_aspace_mprotect += ar_ptr->system_mem;
9832fd
+        fprintf (fp,
9832fd
+                 "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
+                 "<aspace type=\"mprotect\" size=\"%zu\"/>\n",
9832fd
+                 ar_ptr->system_mem, ar_ptr->system_mem);
9832fd
+        total_aspace += ar_ptr->system_mem;
9832fd
+        total_aspace_mprotect += ar_ptr->system_mem;
9832fd
       }
9832fd
 
9832fd
     fputs ("</heap>\n", fp);
9832fd
   }
9832fd
 
9832fd
-  if(__malloc_initialized < 0)
9832fd
+  if (__malloc_initialized < 0)
9832fd
     ptmalloc_init ();
9832fd
 
9832fd
   fputs ("<malloc version=\"1\">\n", fp);
9832fd
@@ -5168,18 +5169,18 @@ malloc_info (int options, FILE *fp)
9832fd
   while (ar_ptr != &main_arena);
9832fd
 
9832fd
   fprintf (fp,
9832fd
-	   "<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
-	   "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
+           "<total type=\"fast\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
+           "<total type=\"rest\" count=\"%zu\" size=\"%zu\"/>\n"
9832fd
 	   "<total type=\"mmap\" count=\"%d\" size=\"%zu\"/>\n"
9832fd
-	   "<system type=\"current\" size=\"%zu\"/>\n"
9832fd
-	   "<system type=\"max\" size=\"%zu\"/>\n"
9832fd
-	   "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
-	   "<aspace type=\"mprotect\" size=\"%zu\"/>\n"
9832fd
-	   "</malloc>\n",
9832fd
-	   total_nfastblocks, total_fastavail, total_nblocks, total_avail,
9832fd
+           "<system type=\"current\" size=\"%zu\"/>\n"
9832fd
+           "<system type=\"max\" size=\"%zu\"/>\n"
9832fd
+           "<aspace type=\"total\" size=\"%zu\"/>\n"
9832fd
+           "<aspace type=\"mprotect\" size=\"%zu\"/>\n"
9832fd
+           "</malloc>\n",
9832fd
+           total_nfastblocks, total_fastavail, total_nblocks, total_avail,
9832fd
 	   mp_.n_mmaps, mp_.mmapped_mem,
9832fd
-	   total_system, total_max_system,
9832fd
-	   total_aspace, total_aspace_mprotect);
9832fd
+           total_system, total_max_system,
9832fd
+           total_aspace, total_aspace_mprotect);
9832fd
 
9832fd
   return 0;
9832fd
 }