allow tagging a bpf .o as critical am: 4ba8c1c1ac
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/1335518
Change-Id: If7e438b861c90eff4aefcc1e737ff66eab8a340d
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index 4244eb7..9f57ce6 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -608,19 +608,26 @@
int loadProg(const char* elfPath) {
vector<char> license;
+ vector<char> critical;
vector<codeSection> cs;
vector<unique_fd> mapFds;
+ bool is_critical;
int ret;
ifstream elfFile(elfPath, ios::in | ios::binary);
if (!elfFile.is_open()) return -1;
+ ret = readSectionByName("critical", elfFile, critical);
+ is_critical = !ret;
+
ret = readSectionByName("license", elfFile, license);
if (ret) {
ALOGE("Couldn't find license in %s\n", elfPath);
return ret;
} else {
- ALOGD("Loading ELF object %s with license %s\n", elfPath, (char*)license.data());
+ ALOGD("Loading %s%s ELF object %s with license %s\n",
+ is_critical ? "critical for " : "optional", is_critical ? (char*)critical.data() : "",
+ elfPath, (char*)license.data());
}
ret = readCodeSections(elfFile, cs);
diff --git a/progs/include/bpf_helpers.h b/progs/include/bpf_helpers.h
index 8ff155f..f76b382 100644
--- a/progs/include/bpf_helpers.h
+++ b/progs/include/bpf_helpers.h
@@ -12,6 +12,12 @@
/* Example use: LICENSE("GPL"); or LICENSE("Apache 2.0"); */
#define LICENSE(NAME) char _license[] SEC("license") = (NAME)
+/* flag the resulting bpf .o file as critical to system functionality,
+ * loading all kernel version appropriate programs in it must succeed
+ * for bpfloader success
+ */
+#define CRITICAL(REASON) char _critical[] SEC("critical") = (REASON)
+
/*
* Helper functions called from eBPF programs written in C. These are
* implemented in the kernel sources.