aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinwardvessel <5782523+inwardvessel@users.noreply.github.com>2023-09-21 11:13:36 -0700
committerHengqi Chen <chenhengqi@outlook.com>2023-10-04 16:57:04 +0800
commit32be0a338e9fc89f21168ac7fa3eb6557baa9ba1 (patch)
treea6b334bc63f76c410652e0729378c816b80553d5
parentec49363e2e9daec026ee6cae4c5fc316f8fab0ff (diff)
downloadbcc-32be0a338e9fc89f21168ac7fa3eb6557baa9ba1.tar.gz
use tid instead of tgid
-rw-r--r--libbpf-tools/memleak.bpf.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/libbpf-tools/memleak.bpf.c b/libbpf-tools/memleak.bpf.c
index 6556b540..3352f228 100644
--- a/libbpf-tools/memleak.bpf.c
+++ b/libbpf-tools/memleak.bpf.c
@@ -18,7 +18,7 @@ const volatile bool wa_missing_free = false;
struct {
__uint(type, BPF_MAP_TYPE_HASH);
- __type(key, pid_t);
+ __type(key, u32);
__type(value, u64);
__uint(max_entries, 10240);
} sizes SEC(".maps");
@@ -96,8 +96,8 @@ static int gen_alloc_enter(size_t size)
return 0;
}
- const pid_t pid = bpf_get_current_pid_tgid() >> 32;
- bpf_map_update_elem(&sizes, &pid, &size, BPF_ANY);
+ const u32 tid = bpf_get_current_pid_tgid();
+ bpf_map_update_elem(&sizes, &tid, &size, BPF_ANY);
if (trace_all)
bpf_printk("alloc entered, size = %lu\n", size);
@@ -107,17 +107,17 @@ static int gen_alloc_enter(size_t size)
static int gen_alloc_exit2(void *ctx, u64 address)
{
- const pid_t pid = bpf_get_current_pid_tgid() >> 32;
+ const u32 tid = bpf_get_current_pid_tgid();
struct alloc_info info;
- const u64* size = bpf_map_lookup_elem(&sizes, &pid);
+ const u64* size = bpf_map_lookup_elem(&sizes, &tid);
if (!size)
return 0; // missed alloc entry
__builtin_memset(&info, 0, sizeof(info));
info.size = *size;
- bpf_map_delete_elem(&sizes, &pid);
+ bpf_map_delete_elem(&sizes, &tid);
if (address != 0) {
info.timestamp_ns = bpf_ktime_get_ns();
@@ -227,8 +227,8 @@ SEC("uprobe")
int BPF_KPROBE(posix_memalign_enter, void **memptr, size_t alignment, size_t size)
{
const u64 memptr64 = (u64)(size_t)memptr;
- const u64 pid = bpf_get_current_pid_tgid() >> 32;
- bpf_map_update_elem(&memptrs, &pid, &memptr64, BPF_ANY);
+ const u32 tid = bpf_get_current_pid_tgid();
+ bpf_map_update_elem(&memptrs, &tid, &memptr64, BPF_ANY);
return gen_alloc_enter(size);
}
@@ -236,15 +236,15 @@ int BPF_KPROBE(posix_memalign_enter, void **memptr, size_t alignment, size_t siz
SEC("uretprobe")
int BPF_KRETPROBE(posix_memalign_exit)
{
- const u64 pid = bpf_get_current_pid_tgid() >> 32;
u64 *memptr64;
void *addr;
+ const u32 tid = bpf_get_current_pid_tgid();
- memptr64 = bpf_map_lookup_elem(&memptrs, &pid);
+ memptr64 = bpf_map_lookup_elem(&memptrs, &tid);
if (!memptr64)
return 0;
- bpf_map_delete_elem(&memptrs, &pid);
+ bpf_map_delete_elem(&memptrs, &tid);
if (bpf_probe_read_user(&addr, sizeof(void*), (void*)(size_t)*memptr64))
return 0;