BpfRingbuf.h - use exclusively locked map

As currently implemented, it is not safe to open (and mmap) the
same kernel -> userspace ringbuffer multiple times.

Note: it's likely, that as implemented, even a single instance
is not thread safe without external locking.

Test: TreeHugger, atest bpf_existence_test bpf_module_test bpf-time-in-state-tests libbpf_android_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iea6908746a58e7412c0ce89da29a764aefeaef47
This commit is contained in:
Maciej Żenczykowski 2024-06-15 02:40:46 -07:00
commit fbaa3c9890

View file

@ -151,7 +151,7 @@ class BpfRingbuf : public BpfRingbufBase {
inline base::Result<void> BpfRingbufBase::Init(const char* path) {
mRingFd.reset(mapRetrieveRW(path));
mRingFd.reset(mapRetrieveExclusiveRW(path));
if (!mRingFd.ok()) {
return android::base::ErrnoError()
<< "failed to retrieve ringbuffer at " << path;