Add mallinfo2 call.

Bug: 208293616

Test: New unit tests pass.
Change-Id: I619219b7322e2dd1c82b9c8a171dfbfe7eac6706
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index f7beb2c..40786fa 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -97,30 +97,31 @@
  */
 size_t malloc_usable_size(const void* __ptr) __INTRODUCED_IN(17);
 
+#define __MALLINFO_BODY \
+  /** Total number of non-mmapped bytes currently allocated from OS. */ \
+  size_t arena; \
+  /** Number of free chunks. */ \
+  size_t ordblks; \
+  /** (Unused.) */ \
+  size_t smblks; \
+  /** (Unused.) */ \
+  size_t hblks; \
+  /** Total number of bytes in mmapped regions. */ \
+  size_t hblkhd; \
+  /** Maximum total allocated space; greater than total if trimming has occurred. */ \
+  size_t usmblks; \
+  /** (Unused.) */ \
+  size_t fsmblks; \
+  /** Total allocated space (normal or mmapped.) */ \
+  size_t uordblks; \
+  /** Total free space. */ \
+  size_t fordblks; \
+  /** Upper bound on number of bytes releasable by a trim operation. */ \
+  size_t keepcost;
+
 #ifndef STRUCT_MALLINFO_DECLARED
 #define STRUCT_MALLINFO_DECLARED 1
-struct mallinfo {
-  /** Total number of non-mmapped bytes currently allocated from OS. */
-  size_t arena;
-  /** Number of free chunks. */
-  size_t ordblks;
-  /** (Unused.) */
-  size_t smblks;
-  /** (Unused.) */
-  size_t hblks;
-  /** Total number of bytes in mmapped regions. */
-  size_t hblkhd;
-  /** Maximum total allocated space; greater than total if trimming has occurred. */
-  size_t usmblks;
-  /** (Unused.) */
-  size_t fsmblks;
-  /** Total allocated space (normal or mmapped.) */
-  size_t uordblks;
-  /** Total free space. */
-  size_t fordblks;
-  /** Upper bound on number of bytes releasable by a trim operation. */
-  size_t keepcost;
-};
+struct mallinfo { __MALLINFO_BODY };
 #endif
 
 /**
@@ -131,6 +132,18 @@
 struct mallinfo mallinfo(void);
 
 /**
+ * On Android the struct mallinfo and struct mallinfo2 are the same.
+ */
+struct mallinfo2 { __MALLINFO_BODY };
+
+/**
+ * [mallinfo2(3)](http://man7.org/linux/man-pages/man3/mallinfo2.3.html) returns
+ * information about the current state of the heap. Note that mallinfo2() is
+ * inherently unreliable and consider using malloc_info() instead.
+ */
+struct mallinfo2 mallinfo2(void) __RENAME(mallinfo);
+
+/**
  * [malloc_info(3)](http://man7.org/linux/man-pages/man3/malloc_info.3.html)
  * writes information about the current state of the heap to the given stream.
  *