On Tue, Oct 8, 2024 at 2:02 AM Hou Tao <houtao@xxxxxxxxxxxxxxx> wrote: > > From: Hou Tao <houtao1@xxxxxxxxxx> > > Add bpf_dynptr_user_init() to initialize a bpf_dynptr_user object, > bpf_dynptr_user_{data,size}() to get the address and length of the > dynptr object, and bpf_dynptr_user_set_size() to set the its size. > > 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 | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > I don't think we need this patch and these APIs at all, let user work with bpf_udynptr directly > diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h > index a4a7b1ad1b63..92b4afac5f5f 100644 > --- a/tools/lib/bpf/bpf.h > +++ b/tools/lib/bpf/bpf.h > @@ -700,6 +700,33 @@ struct bpf_token_create_opts { > LIBBPF_API int bpf_token_create(int bpffs_fd, > struct bpf_token_create_opts *opts); > > +/* sys_bpf() will check the validity of data and size */ > +static inline void bpf_dynptr_user_init(void *data, __u32 size, > + struct bpf_dynptr_user *dynptr) > +{ > + dynptr->data = (__u64)(unsigned long)data; > + dynptr->size = size; > + dynptr->rsvd = 0; > +} > + > +static inline void bpf_dynptr_user_set_size(struct bpf_dynptr_user *dynptr, > + __u32 new_size) > +{ > + dynptr->size = new_size; > +} > + > +static inline __u32 > +bpf_dynptr_user_size(const struct bpf_dynptr_user *dynptr) > +{ > + return dynptr->size; > +} > + > +static inline void * > +bpf_dynptr_user_data(const struct bpf_dynptr_user *dynptr) > +{ > + return (void *)(unsigned long)dynptr->data; > +} > + > #ifdef __cplusplus > } /* extern "C" */ > #endif > -- > 2.44.0 >