Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Kill all bpf_get_obj_by_fd syscall usage [3/3]
Browse files Browse the repository at this point in the history
* Seems our kernel doesn't like this

Change-Id: I8034febd634f52cf54376a8c78dc13eaf9e82210
  • Loading branch information
asuka-mio committed Aug 17, 2022
1 parent 6fcad94 commit 08de55e
Showing 1 changed file with 0 additions and 17 deletions.
17 changes: 0 additions & 17 deletions common/native/bpf_headers/include/bpf/BpfMap.h
Expand Up @@ -51,10 +51,6 @@ class BpfMap {
BpfMap<Key, Value>(const char* pathname, uint32_t flags) {
mMapFd.reset(mapRetrieve(pathname, flags));
if (mMapFd < 0) abort();
if (isAtLeastKernelVersion(4, 14, 0)) {
if (bpfGetFdKeySize(mMapFd) != sizeof(Key)) abort();
if (bpfGetFdValueSize(mMapFd) != sizeof(Value)) abort();
}
}

public:
Expand Down Expand Up @@ -109,14 +105,6 @@ class BpfMap {
if (mMapFd == -1) {
return ErrnoErrorf("Pinned map not accessible or does not exist: ({})", path);
}
if (isAtLeastKernelVersion(4, 14, 0)) {
// Normally we should return an error here instead of calling abort,
// but this cannot happen at runtime without a massive code bug (K/V type mismatch)
// and as such it's better to just blow the system up and let the developer fix it.
// Crashes are much more likely to be noticed than logs and missing functionality.
if (bpfGetFdKeySize(mMapFd) != sizeof(Key)) abort();
if (bpfGetFdValueSize(mMapFd) != sizeof(Value)) abort();
}
return {};
}

Expand Down Expand Up @@ -190,11 +178,6 @@ class BpfMap {

[[clang::reinitializes]] void reset(int fd = -1) {
mMapFd.reset(fd);
if ((fd >= 0) && isAtLeastKernelVersion(4, 14, 0)) {
if (bpfGetFdKeySize(mMapFd) != sizeof(Key)) abort();
if (bpfGetFdValueSize(mMapFd) != sizeof(Value)) abort();
if (bpfGetFdMapFlags(mMapFd) != 0) abort(); // TODO: fix for BpfMapRO
}
}

bool isValid() const { return mMapFd != -1; }
Expand Down

0 comments on commit 08de55e

Please sign in to comment.