add support for glibc mallinfo2
parent
a71ab1a2eb
commit
a45dacc57b
17
h_malloc.c
17
h_malloc.c
|
@ -1808,12 +1808,23 @@ EXPORT int h_malloc_trim(UNUSED size_t pad) {
|
||||||
|
|
||||||
EXPORT void h_malloc_stats(void) {}
|
EXPORT void h_malloc_stats(void) {}
|
||||||
|
|
||||||
#if defined(__GLIBC__) || defined(__ANDROID__)
|
// glibc mallinfo is broken and replaced with mallinfo2
|
||||||
|
#if defined(__GLIBC__)
|
||||||
|
EXPORT struct mallinfo h_mallinfo(void) {
|
||||||
|
return (struct mallinfo){0};
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__GLIBC__) && __GLIBC_PREREQ(2, 33)) || defined(__ANDROID__)
|
||||||
|
#ifndef __GLIBC__
|
||||||
EXPORT struct mallinfo h_mallinfo(void) {
|
EXPORT struct mallinfo h_mallinfo(void) {
|
||||||
struct mallinfo info = {0};
|
struct mallinfo info = {0};
|
||||||
|
#else
|
||||||
|
EXPORT struct mallinfo2 h_mallinfo2(void) {
|
||||||
|
struct mallinfo2 info = {0};
|
||||||
|
#endif
|
||||||
|
|
||||||
// glibc mallinfo type definition and implementation are both broken
|
#if CONFIG_STATS
|
||||||
#if CONFIG_STATS && !defined(__GLIBC__)
|
|
||||||
if (!is_init()) {
|
if (!is_init()) {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ extern "C" {
|
||||||
#define h_malloc_trim malloc_trim
|
#define h_malloc_trim malloc_trim
|
||||||
#define h_malloc_stats malloc_stats
|
#define h_malloc_stats malloc_stats
|
||||||
#define h_mallinfo mallinfo
|
#define h_mallinfo mallinfo
|
||||||
|
#define h_mallinfo2 mallinfo2
|
||||||
#define h_malloc_info malloc_info
|
#define h_malloc_info malloc_info
|
||||||
|
|
||||||
#define h_memalign memalign
|
#define h_memalign memalign
|
||||||
|
|
|
@ -14,6 +14,7 @@ CPPFLAGS += \
|
||||||
EXECUTABLES := \
|
EXECUTABLES := \
|
||||||
offset \
|
offset \
|
||||||
mallinfo \
|
mallinfo \
|
||||||
|
mallinfo2 \
|
||||||
malloc_info \
|
malloc_info \
|
||||||
large_array_growth
|
large_array_growth
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
#include "test_util.h"
|
||||||
|
|
||||||
|
static void print_mallinfo2(void) {
|
||||||
|
struct mallinfo2 info = mallinfo2();
|
||||||
|
printf("mallinfo2:\n");
|
||||||
|
printf("arena: %zu\n", (size_t)info.arena);
|
||||||
|
printf("ordblks: %zu\n", (size_t)info.ordblks);
|
||||||
|
printf("smblks: %zu\n", (size_t)info.smblks);
|
||||||
|
printf("hblks: %zu\n", (size_t)info.hblks);
|
||||||
|
printf("hblkhd: %zu\n", (size_t)info.hblkhd);
|
||||||
|
printf("usmblks: %zu\n", (size_t)info.usmblks);
|
||||||
|
printf("fsmblks: %zu\n", (size_t)info.fsmblks);
|
||||||
|
printf("uordblks: %zu\n", (size_t)info.uordblks);
|
||||||
|
printf("fordblks: %zu\n", (size_t)info.fordblks);
|
||||||
|
printf("keepcost: %zu\n", (size_t)info.keepcost);
|
||||||
|
}
|
||||||
|
|
||||||
|
OPTNONE int main(void) {
|
||||||
|
void *a[4];
|
||||||
|
|
||||||
|
a[0] = malloc(1024 * 1024 * 1024);
|
||||||
|
a[1] = malloc(16);
|
||||||
|
a[2] = malloc(32);
|
||||||
|
a[3] = malloc(64);
|
||||||
|
|
||||||
|
print_mallinfo2();
|
||||||
|
|
||||||
|
free(a[0]);
|
||||||
|
free(a[1]);
|
||||||
|
free(a[2]);
|
||||||
|
free(a[3]);
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
|
print_mallinfo2();
|
||||||
|
}
|
Loading…
Reference in New Issue