BpfRingbuf: support 32 bit userspace
Both consumer and producer position are wrapped in an std::atomic and
extended to uint64_t to enforce atomic access.
See resulting assembly instructions for aosp_cf_x86_phone-userdebug:
frameworks/libs/net/common/native/bpf_headers/include/bpf/BpfRingbuf.h:212
2d: 8b 41 18 mov 0x18(%ecx),%eax
external/libcxx/include/atomic:926 (discriminator 4)
30: f3 0f 7e 00 movq (%eax),%xmm0
This will not work on a 32 bit kernel (so we might want to explicitly
check for that in the test).
Test: atest BpfRingbufTest
Change-Id: I7fec435cbe49d392363d05f7e702d82ecacb9e91
diff --git a/staticlibs/native/bpf_headers/BpfRingbufTest.cpp b/staticlibs/native/bpf_headers/BpfRingbufTest.cpp
index d23afae..f348333 100644
--- a/staticlibs/native/bpf_headers/BpfRingbufTest.cpp
+++ b/staticlibs/native/bpf_headers/BpfRingbufTest.cpp
@@ -25,6 +25,7 @@
#include "BpfSyscallWrappers.h"
#include "bpf/BpfRingbuf.h"
#include "bpf/BpfUtils.h"
+#include "bpf/KernelUtils.h"
#define TEST_RINGBUF_MAGIC_NUM 12345
@@ -49,8 +50,8 @@
GTEST_SKIP() << "BPF ring buffers not supported below 5.8";
}
- if (sizeof(unsigned long) != 8) {
- GTEST_SKIP() << "BPF ring buffers not supported on 32 bit arch";
+ if (!isKernel64Bit()) {
+ GTEST_SKIP() << "BPF ring buffers not supported on 32 bit kernel";
}
errno = 0;