mirror of
https://gitee.com/openharmony/third_party_libbpf
synced 2024-10-07 22:43:33 +00:00
libbpf: Export bpf_program__attach_kprobe_opts function
Export bpf_program__attach_kprobe_opts as a public API. Rename bpf_program_attach_kprobe_opts to bpf_kprobe_opts and turn it into OPTS struct. Suggested-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Alan Maguire <alan.maguire@oracle.com> Tested-by: Alan Maguire <alan.maguire@oracle.com> Link: https://lore.kernel.org/bpf/20210721215810.889975-4-jolsa@kernel.org
This commit is contained in:
parent
d7a2de020b
commit
14f5433b2e
31
src/libbpf.c
31
src/libbpf.c
@ -10366,25 +10366,28 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
|
|||||||
return pfd;
|
return pfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bpf_program_attach_kprobe_opts {
|
struct bpf_link *
|
||||||
bool retprobe;
|
|
||||||
unsigned long offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct bpf_link*
|
|
||||||
bpf_program__attach_kprobe_opts(struct bpf_program *prog,
|
bpf_program__attach_kprobe_opts(struct bpf_program *prog,
|
||||||
const char *func_name,
|
const char *func_name,
|
||||||
struct bpf_program_attach_kprobe_opts *opts)
|
struct bpf_kprobe_opts *opts)
|
||||||
{
|
{
|
||||||
char errmsg[STRERR_BUFSIZE];
|
char errmsg[STRERR_BUFSIZE];
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
|
unsigned long offset;
|
||||||
|
bool retprobe;
|
||||||
int pfd, err;
|
int pfd, err;
|
||||||
|
|
||||||
pfd = perf_event_open_probe(false /* uprobe */, opts->retprobe, func_name,
|
if (!OPTS_VALID(opts, bpf_kprobe_opts))
|
||||||
opts->offset, -1 /* pid */);
|
return libbpf_err_ptr(-EINVAL);
|
||||||
|
|
||||||
|
retprobe = OPTS_GET(opts, retprobe, false);
|
||||||
|
offset = OPTS_GET(opts, offset, 0);
|
||||||
|
|
||||||
|
pfd = perf_event_open_probe(false /* uprobe */, retprobe, func_name,
|
||||||
|
offset, -1 /* pid */);
|
||||||
if (pfd < 0) {
|
if (pfd < 0) {
|
||||||
pr_warn("prog '%s': failed to create %s '%s' perf event: %s\n",
|
pr_warn("prog '%s': failed to create %s '%s' perf event: %s\n",
|
||||||
prog->name, opts->retprobe ? "kretprobe" : "kprobe", func_name,
|
prog->name, retprobe ? "kretprobe" : "kprobe", func_name,
|
||||||
libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
|
libbpf_strerror_r(pfd, errmsg, sizeof(errmsg)));
|
||||||
return libbpf_err_ptr(pfd);
|
return libbpf_err_ptr(pfd);
|
||||||
}
|
}
|
||||||
@ -10393,7 +10396,7 @@ bpf_program__attach_kprobe_opts(struct bpf_program *prog,
|
|||||||
if (err) {
|
if (err) {
|
||||||
close(pfd);
|
close(pfd);
|
||||||
pr_warn("prog '%s': failed to attach to %s '%s': %s\n",
|
pr_warn("prog '%s': failed to attach to %s '%s': %s\n",
|
||||||
prog->name, opts->retprobe ? "kretprobe" : "kprobe", func_name,
|
prog->name, retprobe ? "kretprobe" : "kprobe", func_name,
|
||||||
libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
|
libbpf_strerror_r(err, errmsg, sizeof(errmsg)));
|
||||||
return libbpf_err_ptr(err);
|
return libbpf_err_ptr(err);
|
||||||
}
|
}
|
||||||
@ -10404,9 +10407,9 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
|
|||||||
bool retprobe,
|
bool retprobe,
|
||||||
const char *func_name)
|
const char *func_name)
|
||||||
{
|
{
|
||||||
struct bpf_program_attach_kprobe_opts opts = {
|
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts,
|
||||||
.retprobe = retprobe,
|
.retprobe = retprobe,
|
||||||
};
|
);
|
||||||
|
|
||||||
return bpf_program__attach_kprobe_opts(prog, func_name, &opts);
|
return bpf_program__attach_kprobe_opts(prog, func_name, &opts);
|
||||||
}
|
}
|
||||||
@ -10414,7 +10417,7 @@ struct bpf_link *bpf_program__attach_kprobe(struct bpf_program *prog,
|
|||||||
static struct bpf_link *attach_kprobe(const struct bpf_sec_def *sec,
|
static struct bpf_link *attach_kprobe(const struct bpf_sec_def *sec,
|
||||||
struct bpf_program *prog)
|
struct bpf_program *prog)
|
||||||
{
|
{
|
||||||
struct bpf_program_attach_kprobe_opts opts;
|
DECLARE_LIBBPF_OPTS(bpf_kprobe_opts, opts);
|
||||||
unsigned long offset = 0;
|
unsigned long offset = 0;
|
||||||
struct bpf_link *link;
|
struct bpf_link *link;
|
||||||
const char *func_name;
|
const char *func_name;
|
||||||
|
15
src/libbpf.h
15
src/libbpf.h
@ -104,6 +104,17 @@ struct bpf_object_open_opts {
|
|||||||
};
|
};
|
||||||
#define bpf_object_open_opts__last_field btf_custom_path
|
#define bpf_object_open_opts__last_field btf_custom_path
|
||||||
|
|
||||||
|
struct bpf_kprobe_opts {
|
||||||
|
/* size of this struct, for forward/backward compatiblity */
|
||||||
|
size_t sz;
|
||||||
|
/* function's offset to install kprobe to */
|
||||||
|
unsigned long offset;
|
||||||
|
/* kprobe is return probe */
|
||||||
|
bool retprobe;
|
||||||
|
size_t :0;
|
||||||
|
};
|
||||||
|
#define bpf_kprobe_opts__last_field retprobe
|
||||||
|
|
||||||
LIBBPF_API struct bpf_object *bpf_object__open(const char *path);
|
LIBBPF_API struct bpf_object *bpf_object__open(const char *path);
|
||||||
LIBBPF_API struct bpf_object *
|
LIBBPF_API struct bpf_object *
|
||||||
bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts);
|
bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts);
|
||||||
@ -250,6 +261,10 @@ LIBBPF_API struct bpf_link *
|
|||||||
bpf_program__attach_kprobe(struct bpf_program *prog, bool retprobe,
|
bpf_program__attach_kprobe(struct bpf_program *prog, bool retprobe,
|
||||||
const char *func_name);
|
const char *func_name);
|
||||||
LIBBPF_API struct bpf_link *
|
LIBBPF_API struct bpf_link *
|
||||||
|
bpf_program__attach_kprobe_opts(struct bpf_program *prog,
|
||||||
|
const char *func_name,
|
||||||
|
struct bpf_kprobe_opts *opts);
|
||||||
|
LIBBPF_API struct bpf_link *
|
||||||
bpf_program__attach_uprobe(struct bpf_program *prog, bool retprobe,
|
bpf_program__attach_uprobe(struct bpf_program *prog, bool retprobe,
|
||||||
pid_t pid, const char *binary_path,
|
pid_t pid, const char *binary_path,
|
||||||
size_t func_offset);
|
size_t func_offset);
|
||||||
|
@ -372,6 +372,7 @@ LIBBPF_0.5.0 {
|
|||||||
global:
|
global:
|
||||||
bpf_map__initial_value;
|
bpf_map__initial_value;
|
||||||
bpf_map_lookup_and_delete_elem_flags;
|
bpf_map_lookup_and_delete_elem_flags;
|
||||||
|
bpf_program__attach_kprobe_opts;
|
||||||
bpf_object__gen_loader;
|
bpf_object__gen_loader;
|
||||||
btf_dump__dump_type_data;
|
btf_dump__dump_type_data;
|
||||||
libbpf_set_strict_mode;
|
libbpf_set_strict_mode;
|
||||||
|
Loading…
Reference in New Issue
Block a user