KernelUtils: automatically assume 5.10 kernel on platform
We're adding a lot of 'isAtLeastKernelVersion(x,y,z)' checks, that would ideally compile time optimize out whenever possible. Note: we should be able to bump the '__ANDROID_API__ == 30' assert in NetBpfLoad to 31/S any day now, since technically tip-of-tree only goes into M-2025-11 which requires S. But none of the prep work for that is ready yet. Test: TreeHugger Flag: EXEMPT mainline Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I4d9a7916833f086cd36011e094005999fe770583
This commit is contained in:
parent
c5180c3766
commit
66d7b632b0
2 changed files with 43 additions and 1 deletions
|
|
@ -44,8 +44,47 @@ static inline unsigned __unused kernelVersion() {
|
|||
return kernelVer;
|
||||
}
|
||||
|
||||
#ifndef __ANDROID_API__
|
||||
#error "__ANDROID_API__ is not defined"
|
||||
#endif
|
||||
|
||||
static constexpr unsigned minSupportedKernelVer =
|
||||
#ifdef __ANDROID_APEX__ // Mainline code (incl. NetBpfLoad) in APEX shouldn't (yet) assume anything
|
||||
KVER(0, 0, 0);
|
||||
#elif __ANDROID_API__ >= 10000 // tip of dev tree - we'll need to bump this manually as time advances
|
||||
KVER(5, 10, 0);
|
||||
#elif __ANDROID_API__ >= 41 // Android ~21 - 30Q2: G -- note: 6.12 likely min for 29Q4-ish
|
||||
KVER(6, 12, 0);
|
||||
#elif __ANDROID_API__ >= 40 // Android ~20 - 29Q2: F -- note: 6.6 likely min for 28Q4-ish
|
||||
KVER(6, 6, 0);
|
||||
#elif __ANDROID_API__ >= 39 // Android ~19 - 28Q2: E -- note: 6.1 likely min for 27Q4-ish
|
||||
KVER(6, 1, 0);
|
||||
#elif __ANDROID_API__ >= 38 // Android ~18 - 27Q2: D -- note: 5.15 likely min for 26Q4-ish
|
||||
KVER(5, 15, 0);
|
||||
#elif __ANDROID_API__ >= 37 // Android ~17 - 26Q2: C -- note: 5.10 is min for 25Q4 (or even 25Q3)
|
||||
KVER(5, 10, 0);
|
||||
#elif __ANDROID_API__ >= 36 // Android 16 - 25Q2: Baklava
|
||||
KVER(5, 4, 0);
|
||||
#elif __ANDROID_API__ >= 35 // Android 15 - 24Q3: Vanilla Ice Cream
|
||||
KVER(4, 19, 0);
|
||||
#elif __ANDROID_API__ >= 34 // Android 14 - Upside Down Cake
|
||||
KVER(4, 14, 0);
|
||||
#elif __ANDROID_API__ >= 33 // Android 13 - Tiramisu
|
||||
KVER(4, 9, 0);
|
||||
#elif __ANDROID_API__ >= 32 // Android 12L - Sv2
|
||||
KVER(4, 9, 0);
|
||||
#elif __ANDROID_API__ >= 31 // Android 12 - Snow Cone
|
||||
KVER(4, 9, 0);
|
||||
#elif __ANDROID_API__ >= 30 // Android 11 - Red Velvet Cake
|
||||
KVER(4, 4, 0);
|
||||
#else
|
||||
#error "__ANDROID_API__ is pre-R"
|
||||
#endif
|
||||
|
||||
static inline bool isAtLeastKernelVersion(unsigned major, unsigned minor, unsigned sub) {
|
||||
return kernelVer >= KVER(major, minor, sub);
|
||||
unsigned k = KVER(major, minor, sub);
|
||||
if (k <= minSupportedKernelVer) return true;
|
||||
return kernelVer >= k;
|
||||
}
|
||||
|
||||
static inline bool isKernelVersion(unsigned major, unsigned minor) {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,9 @@ using std::vector;
|
|||
namespace android {
|
||||
namespace bpf {
|
||||
|
||||
static_assert(__ANDROID_API__ == 30, "NetBpfLoad must be compiled for 30/R");
|
||||
static_assert(!minSupportedKernelVer, "NetBpfLoad must not assume min kver");
|
||||
|
||||
// Returns the build type string (from ro.build.type).
|
||||
const std::string& getBuildType() {
|
||||
static std::string t = GetProperty("ro.build.type", "unknown");
|
||||
|
|
|
|||
Loading…
Reference in a new issue