Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bpf
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test
platform
system
bpf
Commits
8bcd01aa
Commit
8bcd01aa
authored
5 years ago
by
Linux Build Service Account
Browse files
Options
Downloads
Plain Diff
Merge
b0900045
on remote branch
Change-Id: I092dd007a59dbd08e5617a4476bba5ba9d1f09ce
parents
95afc946
b0900045
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libbpf_android/include/bpf/BpfUtils.h
+0
-3
0 additions, 3 deletions
libbpf_android/include/bpf/BpfUtils.h
progs/include/bpf_helpers.h
+56
-4
56 additions, 4 deletions
progs/include/bpf_helpers.h
with
56 additions
and
7 deletions
libbpf_android/include/bpf/BpfUtils.h
+
0
−
3
View file @
8bcd01aa
...
...
@@ -177,9 +177,6 @@ int synchronizeKernelRCU();
if (android::bpf::getBpfSupportLevel() != android::bpf::BpfLevel::NONE) return; \
} while (0)
constexpr
int
BPF_CONTINUE
=
0
;
constexpr
int
BPF_DELETED
=
1
;
bool
operator
==
(
const
StatsValue
&
lhs
,
const
StatsValue
&
rhs
);
bool
operator
==
(
const
UidTag
&
lhs
,
const
UidTag
&
rhs
);
bool
operator
==
(
const
StatsKey
&
lhs
,
const
StatsKey
&
rhs
);
...
...
This diff is collapsed.
Click to expand it.
progs/include/bpf_helpers.h
+
56
−
4
View file @
8bcd01aa
...
...
@@ -11,11 +11,63 @@
* Helper functions called from eBPF programs written in C. These are
* implemented in the kernel sources.
*/
/* generic functions */
static
void
*
(
*
bpf_map_lookup_elem
)(
void
*
map
,
void
*
key
)
=
(
void
*
)
BPF_FUNC_map_lookup_elem
;
static
int
(
*
bpf_map_update_elem
)(
void
*
map
,
void
*
key
,
void
*
value
,
unsigned
long
long
flags
)
=
(
void
*
)
BPF_FUNC_map_update_elem
;
static
int
(
*
bpf_map_delete_elem
)(
void
*
map
,
void
*
key
)
=
(
void
*
)
BPF_FUNC_map_delete_elem
;
/*
* Type-unsafe bpf map functions - avoid if possible.
*
* Using these it is possible to pass in keys/values of the wrong type/size,
* or, for 'unsafe_bpf_map_lookup_elem' receive into a pointer to the wrong type.
* You will not get a compile time failure, and for certain types of errors you
* might not even get a failure from the kernel's ebpf verifier during program load,
* instead stuff might just not work right at runtime.
*
* Instead please use:
* DEFINE_BPF_MAP(foo_map, TYPE, KeyType, ValueType, num_entries)
* where TYPE can be something like HASH or ARRAY, and num_entries is an integer.
*
* This defines the map (hence this should not be used in a header file included
* from multiple locations) and provides type safe accessors:
* ValueType * bpf_foo_map_lookup_elem(KeyType *)
* int bpf_foo_map_update_elem(KeyType *, ValueType *, flags)
* int bpf_foo_map_delete_elem(KeyType *)
*
* This will make sure that if you change the type of a map you'll get compile
* errors at any spots you forget to update with the new type.
*/
static
void
*
(
*
unsafe_bpf_map_lookup_elem
)(
void
*
map
,
void
*
key
)
=
(
void
*
)
BPF_FUNC_map_lookup_elem
;
static
int
(
*
unsafe_bpf_map_update_elem
)(
void
*
map
,
void
*
key
,
void
*
value
,
unsigned
long
long
flags
)
=
(
void
*
)
BPF_FUNC_map_update_elem
;
static
int
(
*
unsafe_bpf_map_delete_elem
)(
void
*
map
,
void
*
key
)
=
(
void
*
)
BPF_FUNC_map_delete_elem
;
/* type safe macro to declare a map and related accessor functions */
#define DEFINE_BPF_MAP_NO_ACCESSORS(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \
struct bpf_map_def SEC("maps") the_map = { \
.type = BPF_MAP_TYPE_##TYPE, \
.key_size = sizeof(TypeOfKey), \
.value_size = sizeof(TypeOfValue), \
.max_entries = (num_entries), \
};
#define DEFINE_BPF_MAP(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \
DEFINE_BPF_MAP_NO_ACCESSORS(the_map, TYPE, TypeOfKey, TypeOfValue, num_entries) \
\
static inline __always_inline __unused TypeOfValue* bpf_##the_map##_lookup_elem( \
TypeOfKey* k) { \
return unsafe_bpf_map_lookup_elem(&the_map, k); \
}; \
\
static inline __always_inline __unused int bpf_##the_map##_update_elem( \
TypeOfKey* k, TypeOfValue* v, unsigned long long flags) { \
return unsafe_bpf_map_update_elem(&the_map, k, v, flags); \
}; \
\
static inline __always_inline __unused int bpf_##the_map##_delete_elem(TypeOfKey* k) { \
return unsafe_bpf_map_delete_elem(&the_map, k); \
};
static
int
(
*
bpf_probe_read
)(
void
*
dst
,
int
size
,
void
*
unsafe_ptr
)
=
(
void
*
)
BPF_FUNC_probe_read
;
static
unsigned
long
long
(
*
bpf_ktime_get_ns
)(
void
)
=
(
void
*
)
BPF_FUNC_ktime_get_ns
;
static
int
(
*
bpf_trace_printk
)(
const
char
*
fmt
,
int
fmt_size
,
...)
=
(
void
*
)
BPF_FUNC_trace_printk
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment