Skip to content

Commit

Permalink
selftests/bpf: Add bpf_dynptr_user_init() helper
Browse files Browse the repository at this point in the history
Add bpf_dynptr_user_init() to initialize a bpf_dynptr_user object. It
will be used test_progs and bench. User can dereference the {data|size}
fields directly to get the address and length of the dynptr object.

Signed-off-by: Hou Tao <[email protected]>
  • Loading branch information
Hou Tao authored and Kernel Patches Daemon committed Jan 25, 2025
1 parent 2490d71 commit 664d6b0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/testing/selftests/bpf/bpf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ static inline void bpf_strlcpy(char *dst, const char *src, size_t sz)
#define ENOTSUPP 524
#endif

/* 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 = data;
dynptr->size = size;
dynptr->reserved = 0;
}

#endif /* __BPF_UTIL__ */

0 comments on commit 664d6b0

Please sign in to comment.