summary refs log tree commit diff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-07-07 13:58:24 +0200
committerMartin Liska <mliska@suse.cz>2020-08-31 08:58:20 +0200
commite3960d1c57e57f33e0e846d615788f4ede73b945 (patch)
tree460d4f54f4d15484cf6bf639e38d6d2ab01fa438 /malloc/malloc.c
parent85f184893729e2fb8cf8b873d5371628c3ad9e92 (diff)
downloadglibc-e3960d1c57e57f33e0e846d615788f4ede73b945.tar.gz
glibc-e3960d1c57e57f33e0e846d615788f4ede73b945.tar.xz
glibc-e3960d1c57e57f33e0e846d615788f4ede73b945.zip
Add mallinfo2 function that support sizes >= 4GB.
The current int type can easily overflow for allocation of more
than 4GB.
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r--malloc/malloc.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index ee87ddbbf9..560fee2c31 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -638,6 +638,8 @@ libc_hidden_proto (__libc_mallopt)
   be kept as longs, the reported values may wrap around zero and
   thus be inaccurate.
 */
+struct mallinfo2 __libc_mallinfo2(void);
+
 struct mallinfo __libc_mallinfo(void);
 
 
@@ -4911,7 +4913,7 @@ __malloc_usable_size (void *m)
  */
 
 static void
-int_mallinfo (mstate av, struct mallinfo *m)
+int_mallinfo (mstate av, struct mallinfo2 *m)
 {
   size_t i;
   mbinptr b;
@@ -4974,10 +4976,10 @@ int_mallinfo (mstate av, struct mallinfo *m)
 }
 
 
-struct mallinfo
-__libc_mallinfo (void)
+struct mallinfo2
+__libc_mallinfo2 (void)
 {
-  struct mallinfo m;
+  struct mallinfo2 m;
   mstate ar_ptr;
 
   if (__malloc_initialized < 0)
@@ -4998,6 +5000,27 @@ __libc_mallinfo (void)
   return m;
 }
 
+struct mallinfo
+__libc_mallinfo (void)
+{
+  struct mallinfo m;
+  struct mallinfo2 m2 = __libc_mallinfo2 ();
+
+  m.arena = m2.arena;
+  m.ordblks = m2.ordblks;
+  m.smblks = m2.smblks;
+  m.hblks = m2.hblks;
+  m.hblkhd = m2.hblkhd;
+  m.usmblks = m2.usmblks;
+  m.fsmblks = m2.fsmblks;
+  m.uordblks = m2.uordblks;
+  m.fordblks = m2.fordblks;
+  m.keepcost = m2.keepcost;
+
+  return m;
+}
+
+
 /*
    ------------------------------ malloc_stats ------------------------------
  */
@@ -5016,7 +5039,7 @@ __malloc_stats (void)
   stderr->_flags2 |= _IO_FLAGS2_NOTCANCEL;
   for (i = 0, ar_ptr = &main_arena;; i++)
     {
-      struct mallinfo mi;
+      struct mallinfo2 mi;
 
       memset (&mi, 0, sizeof (mi));
       __libc_lock_lock (ar_ptr->mutex);
@@ -5632,6 +5655,8 @@ strong_alias (__libc_valloc, __valloc) weak_alias (__libc_valloc, valloc)
 strong_alias (__libc_pvalloc, __pvalloc) weak_alias (__libc_pvalloc, pvalloc)
 strong_alias (__libc_mallinfo, __mallinfo)
 weak_alias (__libc_mallinfo, mallinfo)
+strong_alias (__libc_mallinfo2, __mallinfo2)
+weak_alias (__libc_mallinfo2, mallinfo2)
 strong_alias (__libc_mallopt, __mallopt) weak_alias (__libc_mallopt, mallopt)
 
 weak_alias (__malloc_stats, malloc_stats)