Linux Audio

Check our new training course

Loading...
Note: File does not exist in v5.4.
 1/* SPDX-License-Identifier: GPL-2.0-only */
 2/* A pointer that can point to either kernel or userspace memory. */
 3#ifndef _LINUX_BPFPTR_H
 4#define _LINUX_BPFPTR_H
 5
 6#include <linux/sockptr.h>
 7
 8typedef sockptr_t bpfptr_t;
 9
10static inline bool bpfptr_is_kernel(bpfptr_t bpfptr)
11{
12	return bpfptr.is_kernel;
13}
14
15static inline bpfptr_t KERNEL_BPFPTR(void *p)
16{
17	return (bpfptr_t) { .kernel = p, .is_kernel = true };
18}
19
20static inline bpfptr_t USER_BPFPTR(void __user *p)
21{
22	return (bpfptr_t) { .user = p };
23}
24
25static inline bpfptr_t make_bpfptr(u64 addr, bool is_kernel)
26{
27	if (is_kernel)
28		return KERNEL_BPFPTR((void*) (uintptr_t) addr);
29	else
30		return USER_BPFPTR(u64_to_user_ptr(addr));
31}
32
33static inline bool bpfptr_is_null(bpfptr_t bpfptr)
34{
35	if (bpfptr_is_kernel(bpfptr))
36		return !bpfptr.kernel;
37	return !bpfptr.user;
38}
39
40static inline void bpfptr_add(bpfptr_t *bpfptr, size_t val)
41{
42	if (bpfptr_is_kernel(*bpfptr))
43		bpfptr->kernel += val;
44	else
45		bpfptr->user += val;
46}
47
48static inline int copy_from_bpfptr_offset(void *dst, bpfptr_t src,
49					  size_t offset, size_t size)
50{
51	return copy_from_sockptr_offset(dst, (sockptr_t) src, offset, size);
52}
53
54static inline int copy_from_bpfptr(void *dst, bpfptr_t src, size_t size)
55{
56	return copy_from_bpfptr_offset(dst, src, 0, size);
57}
58
59static inline int copy_to_bpfptr_offset(bpfptr_t dst, size_t offset,
60					const void *src, size_t size)
61{
62	return copy_to_sockptr_offset((sockptr_t) dst, offset, src, size);
63}
64
65static inline void *memdup_bpfptr(bpfptr_t src, size_t len)
66{
67	return memdup_sockptr((sockptr_t) src, len);
68}
69
70static inline long strncpy_from_bpfptr(char *dst, bpfptr_t src, size_t count)
71{
72	return strncpy_from_sockptr(dst, (sockptr_t) src, count);
73}
74
75#endif /* _LINUX_BPFPTR_H */