From: Hou Tao <houtao1@xxxxxxxxxx> Add bpf_dynptr_user_init() to initialize a bpf_dynptr, and bpf_dynptr_user_get_{data,size} to get the buffer address and buffer length of bpf_dynptr_user. Instead of exporting these symbols, simply adding these helpers as inline functions. Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> --- tools/lib/bpf/bpf.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 9c50beabdd14..cd3e9dbaffa1 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -371,6 +371,25 @@ LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); +/* sys_bpf() will check the validity of size */ +static inline void bpf_dynptr_user_init(void *data, __u32 size, struct bpf_dynptr_user *dynptr) +{ + /* Zero padding bytes */ + memset(dynptr, 0, sizeof(*dynptr)); + dynptr->data = (__u64)(unsigned long)data; + dynptr->size = size; +} + +static inline __u32 bpf_dynptr_user_get_size(const struct bpf_dynptr_user *dynptr) +{ + return dynptr->size; +} + +static inline void *bpf_dynptr_user_get_data(const struct bpf_dynptr_user *dynptr) +{ + return (void *)(unsigned long)dynptr->data; +} + struct bpf_prog_query_opts { size_t sz; /* size of this struct for forward/backward compatibility */ __u32 query_flags; -- 2.29.2