diff options
| author | Andrii Nakryiko <[email protected]> | 2022-02-12 05:57:32 +0000 |
|---|---|---|
| committer | Alexei Starovoitov <[email protected]> | 2022-02-15 17:59:01 +0000 |
| commit | bb8ffe61ea454a565e4fb1f450ef71237c9f032c (patch) | |
| tree | 6053c062a6eb0afa2162a841e084f64a3328c114 /tools/testing/selftests/bpf/test_cpp.cpp | |
| parent | selftests/bpf: Fix GCC11 compiler warnings in -O2 mode (diff) | |
| download | kernel-bb8ffe61ea454a565e4fb1f450ef71237c9f032c.tar.gz kernel-bb8ffe61ea454a565e4fb1f450ef71237c9f032c.zip | |
bpftool: Add C++-specific open/load/etc skeleton wrappers
Add C++-specific static methods for code-generated BPF skeleton for each
skeleton operation: open, open_opts, open_and_load, load, attach,
detach, destroy, and elf_bytes. This is to facilitate easier C++
templating on top of pure C BPF skeleton.
In C, open/load/destroy/etc "methods" are of the form
<skeleton_name>__<method>() to avoid name collision with similar
"methods" of other skeletons withint the same application. This works
well, but is very inconvenient for C++ applications that would like to
write generic (templated) wrappers around BPF skeleton to fit in with
C++ code base and take advantage of destructors and other convenient C++
constructs.
This patch makes it easier to build such generic templated wrappers by
additionally defining C++ static methods for skeleton's struct with
fixed names. This allows to refer to, say, open method as `T::open()`
instead of having to somehow generate `T__open()` function call.
Next patch adds an example template to test_cpp selftest to demonstrate
how it's possible to have all the operations wrapped in a generic
Skeleton<my_skeleton> type without explicitly passing function references.
An example of generated declaration section without %1$s placeholders:
#ifdef __cplusplus
static struct test_attach_probe *open(const struct bpf_object_open_opts *opts = nullptr);
static struct test_attach_probe *open_and_load();
static int load(struct test_attach_probe *skel);
static int attach(struct test_attach_probe *skel);
static void detach(struct test_attach_probe *skel);
static void destroy(struct test_attach_probe *skel);
static const void *elf_bytes(size_t *sz);
#endif /* __cplusplus */
Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/testing/selftests/bpf/test_cpp.cpp')
0 files changed, 0 insertions, 0 deletions
