1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2020 Facebook */
5 #include <bpf/bpf_helpers.h>
6 #include <bpf/bpf_core_read.h>
7 #include <bpf/bpf_tracing.h>
9 char _license[] SEC("license") = "GPL";
11 struct bpf_testmod_test_read_ctx {
12 /* field order is mixed up */
16 } __attribute__((preserve_access_index));
25 struct core_reloc_module_output {
33 /* we have test_progs[-flavor], so cut flavor part */
34 char comm[sizeof("test_progs")];
38 SEC("raw_tp/bpf_testmod_test_read")
39 int BPF_PROG(test_core_module_probed,
40 struct task_struct *task,
41 struct bpf_testmod_test_read_ctx *read_ctx)
43 struct core_reloc_module_output *out = (void *)&data.out;
44 __u64 pid_tgid = bpf_get_current_pid_tgid();
45 __u32 real_tgid = (__u32)(pid_tgid >> 32);
46 __u32 real_pid = (__u32)pid_tgid;
48 if (data.my_pid_tgid != pid_tgid)
51 if (BPF_CORE_READ(task, pid) != real_pid || BPF_CORE_READ(task, tgid) != real_tgid)
54 out->len = BPF_CORE_READ(read_ctx, len);
55 out->off = BPF_CORE_READ(read_ctx, off);
57 out->read_ctx_sz = bpf_core_type_size(struct bpf_testmod_test_read_ctx);
58 out->read_ctx_exists = bpf_core_type_exists(struct bpf_testmod_test_read_ctx);
59 out->buf_exists = bpf_core_field_exists(read_ctx->buf);
60 out->off_exists = bpf_core_field_exists(read_ctx->off);
61 out->len_exists = bpf_core_field_exists(read_ctx->len);
63 out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm);
68 SEC("tp_btf/bpf_testmod_test_read")
69 int BPF_PROG(test_core_module_direct,
70 struct task_struct *task,
71 struct bpf_testmod_test_read_ctx *read_ctx)
73 struct core_reloc_module_output *out = (void *)&data.out;
74 __u64 pid_tgid = bpf_get_current_pid_tgid();
75 __u32 real_tgid = (__u32)(pid_tgid >> 32);
76 __u32 real_pid = (__u32)pid_tgid;
78 if (data.my_pid_tgid != pid_tgid)
81 if (task->pid != real_pid || task->tgid != real_tgid)
84 out->len = read_ctx->len;
85 out->off = read_ctx->off;
87 out->read_ctx_sz = bpf_core_type_size(struct bpf_testmod_test_read_ctx);
88 out->read_ctx_exists = bpf_core_type_exists(struct bpf_testmod_test_read_ctx);
89 out->buf_exists = bpf_core_field_exists(read_ctx->buf);
90 out->off_exists = bpf_core_field_exists(read_ctx->off);
91 out->len_exists = bpf_core_field_exists(read_ctx->len);
93 out->comm_len = BPF_CORE_READ_STR_INTO(&out->comm, task, comm);