blob: dc0c3691dcc2b21b3d6b082302d08b7b32bdab5c (
plain)
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
|
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
#include "vmlinux.h"
#include "bpf_experimental.h"
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
pid_t target_pid = 0;
unsigned int vmas_seen = 0;
struct {
__u64 vm_start;
__u64 vm_end;
} vm_ranges[1000];
SEC("raw_tp/sys_enter")
int iter_task_vma_for_each(const void *ctx)
{
struct task_struct *task = bpf_get_current_task_btf();
struct vm_area_struct *vma;
unsigned int seen = 0;
if (task->pid != target_pid)
return 0;
if (vmas_seen)
return 0;
bpf_for_each(task_vma, vma, task, 0) {
if (bpf_cmp_unlikely(seen, >=, 1000))
break;
vm_ranges[seen].vm_start = vma->vm_start;
vm_ranges[seen].vm_end = vma->vm_end;
seen++;
}
vmas_seen = seen;
return 0;
}
char _license[] SEC("license") = "GPL";
|