summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/bpf_kfuncs.h
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2024-01-30 13:20:22 -0800
committerMartin KaFai Lau <martin.lau@kernel.org>2024-01-30 15:55:50 -0800
commit20d59ee55172fdf6072abf871fa62b2070d6383f (patch)
tree943d0e21220a3f83781da27546c470cbd56f71cf /tools/testing/selftests/bpf/bpf_kfuncs.h
parent4d8ebe1304e99cf6e08e432c23041638d6d1de56 (diff)
libbpf: add bpf_core_cast() macro
Add bpf_core_cast() macro that wraps bpf_rdonly_cast() kfunc. It's more ergonomic than kfunc, as it automatically extracts btf_id with bpf_core_type_id_kernel(), and works with type names. It also casts result to (T *) pointer. See the definition of the macro, it's self-explanatory. libbpf declares bpf_rdonly_cast() extern as __weak __ksym and should be safe to not conflict with other possible declarations in user code. But we do have a conflict with current BPF selftests that declare their externs with first argument as `void *obj`, while libbpf opts into more permissive `const void *obj`. This causes conflict, so we fix up BPF selftests uses in the same patch. Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20240130212023.183765-2-andrii@kernel.org Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/bpf_kfuncs.h')
-rw-r--r--tools/testing/selftests/bpf/bpf_kfuncs.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/testing/selftests/bpf/bpf_kfuncs.h b/tools/testing/selftests/bpf/bpf_kfuncs.h
index 23c24f852f4f..0cd4111f954c 100644
--- a/tools/testing/selftests/bpf/bpf_kfuncs.h
+++ b/tools/testing/selftests/bpf/bpf_kfuncs.h
@@ -63,7 +63,7 @@ extern int bpf_sk_assign_tcp_reqsk(struct __sk_buff *skb, struct sock *sk,
void *bpf_cast_to_kern_ctx(void *) __ksym;
-void *bpf_rdonly_cast(void *obj, __u32 btf_id) __ksym;
+extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
extern int bpf_get_file_xattr(struct file *file, const char *name,
struct bpf_dynptr *value_ptr) __ksym;