Skip to content

Commit

Permalink
added mmap and munmap tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhichang authored and yonghong-song committed Feb 23, 2022
1 parent b3d45a6 commit d1fe110
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ def run_command_get_pid(command):
return gen_alloc_exit(ctx);
}
int mmap_enter(struct pt_regs *ctx) {
size_t size = (size_t)PT_REGS_PARM2(ctx);
return gen_alloc_enter(ctx, size);
}
int mmap_exit(struct pt_regs *ctx) {
return gen_alloc_exit(ctx);
}
int munmap_enter(struct pt_regs *ctx, void *address) {
return gen_free_enter(ctx, address);
}
int posix_memalign_enter(struct pt_regs *ctx, void **memptr, size_t alignment,
size_t size) {
u64 memptr64 = (u64)(size_t)memptr;
Expand Down Expand Up @@ -449,13 +462,16 @@ def attach_probes(sym, fn_prefix=None, can_fail=False):
attach_probes("malloc")
attach_probes("calloc")
attach_probes("realloc")
attach_probes("mmap")
attach_probes("posix_memalign")
attach_probes("valloc", can_fail=True) # failed on Android, is deprecated in libc.so from bionic directory
attach_probes("memalign")
attach_probes("pvalloc", can_fail=True) # failed on Android, is deprecated in libc.so from bionic directory
attach_probes("aligned_alloc", can_fail=True) # added in C11
bpf.attach_uprobe(name=obj, sym="free", fn_name="free_enter",
pid=pid)
bpf.attach_uprobe(name=obj, sym="munmap", fn_name="munmap_enter",
pid=pid)

else:
print("Attaching to kernel allocators, Ctrl+C to quit.")
Expand Down

0 comments on commit d1fe110

Please sign in to comment.