From 378d2876b25b2e8c07816493d8f9583c7f86bb10 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Sun, 24 Nov 2024 01:39:23 +0800 Subject: [PATCH] libbpf-tools/memleak: add mremap uprobe (#5151) Add mremap uprobe. Signed-off-by: Xiaobo Liu --- libbpf-tools/memleak.bpf.c | 14 ++++++++++++++ libbpf-tools/memleak.c | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/libbpf-tools/memleak.bpf.c b/libbpf-tools/memleak.bpf.c index b1f7333ebd37..2b2eda41c028 100644 --- a/libbpf-tools/memleak.bpf.c +++ b/libbpf-tools/memleak.bpf.c @@ -223,6 +223,20 @@ int BPF_UPROBE(munmap_enter, void *address) return gen_free_enter(address); } +SEC("uprobe") +int BPF_UPROBE(mremap_enter, void *old_address, size_t old_size, size_t new_size, int flags) +{ + gen_free_enter(old_address); + + return gen_alloc_enter(new_size); +} + +SEC("uretprobe") +int BPF_URETPROBE(mremap_exit) +{ + return gen_alloc_exit(ctx); +} + SEC("uprobe") int BPF_UPROBE(posix_memalign_enter, void **memptr, size_t alignment, size_t size) { diff --git a/libbpf-tools/memleak.c b/libbpf-tools/memleak.c index 953b77827c42..16db6023bee8 100644 --- a/libbpf-tools/memleak.c +++ b/libbpf-tools/memleak.c @@ -1060,9 +1060,15 @@ int attach_uprobes(struct memleak_bpf *skel) if (strlen(env.symbols_prefix)) { ATTACH_UPROBE(skel, mmap, mmap_enter); ATTACH_URETPROBE(skel, mmap, mmap_exit); + + ATTACH_UPROBE(skel, mremap, mmap_enter); + ATTACH_URETPROBE(skel, mremap, mmap_exit); } else { ATTACH_UPROBE_CHECKED(skel, mmap, mmap_enter); ATTACH_URETPROBE_CHECKED(skel, mmap, mmap_exit); + + ATTACH_UPROBE_CHECKED(skel, mremap, mremap_enter); + ATTACH_URETPROBE_CHECKED(skel, mremap, mremap_exit); } ATTACH_UPROBE_CHECKED(skel, posix_memalign, posix_memalign_enter);