From 6e6b2096e18888a6ba84416caf03304ccccf61fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 24 Jun 2024 23:57:41 +0000 Subject: [PATCH] Exempt Wear on Arm from 64-bit userspace requirement check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arm-only because the 32 bit userspace vs 64-bit kernel issues are worse on x86 because of some extra 4 vs 8 byte alignment (when included in structs) ABI issues. Wear is unlikely to ever run on comparatively high power usage x86 cpus, so this should be fine. Manually tested by adding: if (isWear()) ALOGI("Wear!"); and additionally logging 'bool watch' within isWear() on 'cf_gwear_x86-trunk_staging-userdebug'. Resulting output: I NetBpfLoad: NetBpfLoad v0.46 (/apex/com.android.tethering/bin/netbpfload) api:35/36 kver:601004b (32-on-x86-64) uid:0 rc:01 I NetBpfLoad: isWear(ro.cw_build.wear_sdk.version=6[6] ro.build.characteristics='nosdcard,watch'[1]): true I NetBpfLoad: Wear! Bug: 346252668 Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I9b2a3b88095264245935950bd1a7dfbb5293334b --- netbpfload/NetBpfLoad.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/netbpfload/NetBpfLoad.cpp b/netbpfload/NetBpfLoad.cpp index e9c6d8a2d4..0d4a5c4f7b 100644 --- a/netbpfload/NetBpfLoad.cpp +++ b/netbpfload/NetBpfLoad.cpp @@ -57,6 +57,7 @@ namespace bpf { using base::StartsWith; using base::EndsWith; using std::string; +using std::vector; static bool exists(const char* const path) { int v = access(path, F_OK); @@ -248,6 +249,22 @@ static bool isTV() { return tv; } +static bool isWear() { + static string wearSdkStr = base::GetProperty("ro.cw_build.wear_sdk.version", ""); + static int wearSdkInt = base::GetIntProperty("ro.cw_build.wear_sdk.version", 0); + static string buildChars = base::GetProperty("ro.build.characteristics", ""); + static vector v = base::Tokenize(buildChars, ","); + static bool watch = (std::find(v.begin(), v.end(), "watch") != v.end()); + static bool wear = (wearSdkInt > 0) || watch; + static bool logged = false; + if (!logged) { + logged = true; + ALOGI("isWear(ro.cw_build.wear_sdk.version=%d[%s] ro.build.characteristics='%s'): %s", + wearSdkInt, wearSdkStr.c_str(), buildChars.c_str(), wear ? "true" : "false"); + } + return wear; +} + static int doLoad(char** argv, char * const envp[]) { const bool runningAsRoot = !getuid(); // true iff U QPR3 or V+ @@ -402,7 +419,8 @@ static int doLoad(char** argv, char * const envp[]) { * and 32-bit userspace on 64-bit kernel bpf ringbuffer compatibility is broken. */ ALOGE("64-bit userspace required on 6.2+ kernels."); - if (!isTV()) return 1; + // Stuff won't work reliably, but exempt TVs & Arm Wear devices + if (!isTV() && !(isWear() && isArm())) return 1; } // Ensure we can determine the Android build type.