Merge "allow tagging a bpf .o as critical" into rvc-dev

This commit is contained in:
TreeHugger Robot 2020-06-15 10:18:18 +00:00 committed by Android (Google) Code Review
commit 731e9939e6
2 changed files with 14 additions and 1 deletions

View file

@ -608,19 +608,26 @@ static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const
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);

View file

@ -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.