1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-16 07:21:57 +03:00

malloc: Decorate malloc maps

Add anonymous mmap annotations on loader malloc, malloc when it
allocates memory with mmap, and on malloc arena.  The /proc/self/maps
will now print:

   [anon: glibc: malloc arena]
   [anon: glibc: malloc]
   [anon: glibc: loader malloc]

On arena allocation, glibc annotates only the read/write mapping.

Checked on x86_64-linux-gnu and aarch64-linux-gnu.
Reviewed-by: DJ Delorie <dj@redhat.com>
This commit is contained in:
Adhemerval Zanella
2023-11-01 09:56:08 -03:00
parent 6afce56c19
commit fee9e40a8d
6 changed files with 55 additions and 0 deletions

View File

@ -218,6 +218,7 @@
#include <sys/sysinfo.h>
#include <ldsodefs.h>
#include <setvmaname.h>
#include <unistd.h>
#include <stdio.h> /* needed for malloc_stats */
@ -2428,6 +2429,8 @@ sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av)
madvise_thp (mm, size);
#endif
__set_vma_name (mm, size, " glibc: malloc");
/*
The offset to the start of the mmapped region is stored in the prev_size
field of the chunk. This allows us to adjust returned start address to
@ -2513,6 +2516,8 @@ sysmalloc_mmap_fallback (long int *s, INTERNAL_SIZE_T nb,
madvise_thp (mbrk, size);
#endif
__set_vma_name (mbrk, size, " glibc: malloc");
/* Record that we no longer have a contiguous sbrk region. After the first
time mmap is used as backup, we do not ever rely on contiguous space
since this could incorrectly bridge regions. */