Skip to content

Commit

Permalink
libbpf-tools/memleak: add mremap uprobe (#5151)
Browse files Browse the repository at this point in the history
Add mremap uprobe.

Signed-off-by: Xiaobo Liu <[email protected]>
  • Loading branch information
cppcoffee authored Nov 23, 2024
1 parent fb62cc3 commit 378d287
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libbpf-tools/memleak.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions libbpf-tools/memleak.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 378d287

Please sign in to comment.