-
Notifications
You must be signed in to change notification settings - Fork 1
/
memleak.h
72 lines (65 loc) · 4.92 KB
/
memleak.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
#ifndef __MEMLEAK_H__
#define __MEMLEAK_H__
#define INIT_UPROBE(name, pid, path, sym) \
{ \
off_t addr = get_elf_func_offset(path, sym); \
if (addr < 0) { \
fprintf(stderr, "cannot get offset of %s (libc: %s)\n", sym, path); \
goto cleanup; \
} \
skel->links.uprobe_##name = bpf_program__attach_uprobe(skel->progs.uprobe_##name, \
false, pid, path, addr); \
err = libbpf_get_error(skel->links.uprobe_##name); \
if (err) { \
fprintf(stderr, "Failed to attach uprobe_"#name": %d\n", err); \
goto cleanup; \
} \
}
#define INIT_URETPROBE(name, pid, path, sym) \
{ \
off_t addr = get_elf_func_offset(path, sym); \
if (addr < 0) { \
fprintf(stderr, "cannot get offset of %s (libc: %s)\n", sym, path); \
goto cleanup; \
} \
skel->links.uretprobe_##name = bpf_program__attach_uprobe(skel->progs.uretprobe_##name, \
true, pid, path, addr); \
err = libbpf_get_error(skel->links.uretprobe_##name); \
if (err) { \
fprintf(stderr, "Failed to attach uretprobe_"#name": %d\n", err); \
goto cleanup; \
} \
}
#define INIT_UPROBE_URETPROBE(name, pid, path, sym) \
{ \
off_t addr = get_elf_func_offset(path, sym); \
if (addr < 0) { \
fprintf(stderr, "cannot get offset of %s (libc: %s)\n", sym, path); \
goto cleanup; \
} \
skel->links.uprobe_##name = bpf_program__attach_uprobe(skel->progs.uprobe_##name, \
false, pid, path, addr); \
err = libbpf_get_error(skel->links.uprobe_##name); \
if (err) { \
fprintf(stderr, "Failed to attach uprobe_"#name": %d\n", err); \
goto cleanup; \
} \
skel->links.uretprobe_##name = bpf_program__attach_uprobe(skel->progs.uretprobe_##name, \
true, pid, path, addr); \
err = libbpf_get_error(skel->links.uretprobe_##name); \
if (err) { \
fprintf(stderr, "Failed to attach uretprobe_"#name": %d\n", err); \
goto cleanup; \
} \
}
struct alloc_info_t {
__u64 size;
__u64 timestamp_ns;
__u32 stack_id;
};
struct combined_alloc_info_t {
__u64 total_size;
__u64 number_of_allocs;
};
#endif /* __MEMLEAK_H__ */