[PATCH 4/8] libbpf: Add struct perf_event_open_args
From: Jiri Olsa
Date: Wed Nov 24 2021 - 03:43:20 EST
Adding struct perf_event_open_args to hold arguments for
perf_event_open_probe, because there's already 6 arguments
and more will come in following changes.
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/lib/bpf/libbpf.c | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b55c0fbfcc03..34219a0c39a7 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9625,11 +9625,20 @@ static int determine_uprobe_retprobe_bit(void)
#define PERF_UPROBE_REF_CTR_OFFSET_BITS 32
#define PERF_UPROBE_REF_CTR_OFFSET_SHIFT 32
-static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
- uint64_t offset, int pid, size_t ref_ctr_off)
+struct perf_event_open_args {
+ bool retprobe;
+ const char *name;
+ uint64_t offset;
+ int pid;
+ size_t ref_ctr_off;
+};
+
+static int perf_event_open_probe(bool uprobe, struct perf_event_open_args *args)
{
+ size_t ref_ctr_off = args->ref_ctr_off;
struct perf_event_attr attr = {};
char errmsg[STRERR_BUFSIZE];
+ int pid = args->pid;
int type, pfd, err;
if (ref_ctr_off >= (1ULL << PERF_UPROBE_REF_CTR_OFFSET_BITS))
@@ -9643,7 +9652,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
libbpf_strerror_r(type, errmsg, sizeof(errmsg)));
return type;
}
- if (retprobe) {
+ if (args->retprobe) {
int bit = uprobe ? determine_uprobe_retprobe_bit()
: determine_kprobe_retprobe_bit();
@@ -9658,8 +9667,8 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
attr.size = sizeof(attr);
attr.type = type;
attr.config |= (__u64)ref_ctr_off << PERF_UPROBE_REF_CTR_OFFSET_SHIFT;
- attr.config1 = ptr_to_u64(name); /* kprobe_func or uprobe_path */
- attr.config2 = offset; /* kprobe_addr or probe_offset */
+ attr.config1 = ptr_to_u64(args->name); /* kprobe_func or uprobe_path */
+ attr.config2 = args->offset; /* kprobe_addr or probe_offset */
/* pid filter is meaningful only for uprobes */
pfd = syscall(__NR_perf_event_open, &attr,
@@ -9791,9 +9800,15 @@ bpf_program__attach_kprobe_opts(const struct bpf_program *prog,
legacy = determine_kprobe_perf_type() < 0;
if (!legacy) {
- pfd = perf_event_open_probe(false /* uprobe */, retprobe,
- func_name, offset,
- -1 /* pid */, 0 /* ref_ctr_off */);
+ struct perf_event_open_args args = {
+ .retprobe = retprobe,
+ .name = func_name,
+ .offset = offset,
+ .pid = -1,
+ .ref_ctr_off = 0,
+ };
+
+ pfd = perf_event_open_probe(false /* uprobe */, &args);
} else {
char probe_name[256];
@@ -9984,8 +9999,15 @@ bpf_program__attach_uprobe_opts(const struct bpf_program *prog, pid_t pid,
legacy = determine_uprobe_perf_type() < 0;
if (!legacy) {
- pfd = perf_event_open_probe(true /* uprobe */, retprobe, binary_path,
- func_offset, pid, ref_ctr_off);
+ struct perf_event_open_args args = {
+ .retprobe = retprobe,
+ .name = binary_path,
+ .offset = func_offset,
+ .pid = pid,
+ .ref_ctr_off = ref_ctr_off,
+ };
+
+ pfd = perf_event_open_probe(true /* uprobe */, &args);
} else {
char probe_name[512];
--
2.33.1