BpfLoader: split legacy bpfloader into 3 phases, simplify arguments
Should make integration with BpfLoader written in rust easier.
While at it add simple wrappers around ALOG{V,D,I,W,E}(),
which may come in handy as bpfloader runs early enough that
logging must be to the kernel dmesg ringbuffer instead...
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia49c605bae63241b74d04e2e0f58fd089c23993d
diff --git a/loader/include/libbpf_android.h b/loader/include/libbpf_android.h
index df4e32c..fbdae6f 100644
--- a/loader/include/libbpf_android.h
+++ b/loader/include/libbpf_android.h
@@ -17,6 +17,8 @@
#pragma once
+#ifdef __cplusplus
+
#include <linux/bpf.h>
#include <fstream>
@@ -37,7 +39,26 @@
// Exposed for testing
unsigned int readSectionUint(const char* name, std::ifstream& elfFile, unsigned int defVal);
-int legacyBpfLoader(int argc, char** argv, char * const envp[]);
-
} // namespace bpf
} // namespace android
+
+extern "C" {
+#else // __cplusplus
+#define __noreturn
+#endif // __cplusplus
+
+// The C++ portion of the BpfLoader is exposed as 3 functions to be called in order.
+void initLogging();
+void legacyBpfLoader();
+__noreturn void execNetBpfLoadDone();
+
+// For logging from rust
+void logVerbose(const char* msg);
+void logDebug(const char* msg);
+void logInfo(const char* msg);
+void logWarn(const char* msg);
+void logError(const char* msg);
+
+#ifdef __cplusplus
+} // extern C
+#endif