enforce bpf ring buffer size is a power of two am: 94a8fe633e
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/net/+/2628132
Change-Id: Idccc5feb47eaac5a74a188cb6c325ddd9f0c8490
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
index fed4002..67ac0e4 100644
--- a/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
+++ b/staticlibs/native/bpf_headers/include/bpf/bpf_helpers.h
@@ -233,14 +233,22 @@
selinux, pindir, share, KVER(5, 8, 0), KVER_INF, \
min_loader, max_loader, ignore_eng, ignore_user, \
ignore_userdebug); \
+ \
+ _Static_assert((size_bytes) >= 4096, "min 4 kiB ringbuffer size"); \
+ _Static_assert((size_bytes) <= 0x10000000, "max 256 MiB ringbuffer size"); \
+ _Static_assert(((size_bytes) & ((size_bytes) - 1)) == 0, \
+ "ring buffer size must be a power of two"); \
+ \
static inline __always_inline __unused int bpf_##the_map##_output( \
const ValueType* v) { \
return bpf_ringbuf_output_unsafe(&the_map, v, sizeof(*v), 0); \
} \
+ \
static inline __always_inline __unused \
ValueType* bpf_##the_map##_reserve() { \
return bpf_ringbuf_reserve_unsafe(&the_map, sizeof(ValueType), 0); \
} \
+ \
static inline __always_inline __unused void bpf_##the_map##_submit( \
const ValueType* v) { \
bpf_ringbuf_submit_unsafe(v, 0); \