From: Hou Tao <houtao1@xxxxxxxxxx> Add bpf_dynptr_user_init() to initialize a bpf_dynptr, bpf_dynptr_user_get_{data,size}() to get the address and length of dynptr, and bpf_dynptr_user_trim() to trim size of dynptr. Instead of exporting these symbols, simply adding these helpers as inline functions in bpf.h. Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> --- tools/lib/bpf/bpf.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 9c50beabdd14..6b91a8c2b2ae 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -371,6 +371,35 @@ 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; +} + +static inline void bpf_dynptr_user_trim(struct bpf_dynptr_user *dynptr, + __u32 new_size) +{ + if (new_size < dynptr->size) + dynptr->size = new_size; +} + struct bpf_prog_query_opts { size_t sz; /* size of this struct for forward/backward compatibility */ __u32 query_flags; -- 2.29.2