From 85429d850ff66e1450410ddc74f4dd9b7c34ae5f Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 11 Mar 2020 16:33:12 -0700 Subject: [PATCH 1/2] Debug.isVmapStack reads kernel configs only ... but not other runtime VINTF info. This may or may not fix the nullptr exception when accessing getRuntimeInfo(). In either case, this change should improves code health in general: - it avoids reading things it doesn't need - it avoids copying the map Bug: 151092221 Test: m libandroid_runtime -j Change-Id: I6cb9052eb56fd83ef7ee81751d9791533a36aeed (cherry picked from commit 77c1f592fa90dab4e3d25465d8e833889511a4f4) Merged-In: I6cb9052eb56fd83ef7ee81751d9791533a36aeed --- core/jni/android_os_Debug.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index cd3611546852b..265eb7cffb225 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -846,8 +846,11 @@ static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz) } cfg_state = CONFIG_UNKNOWN; if (cfg_state == CONFIG_UNKNOWN) { - const std::map configs = - vintf::VintfObject::GetInstance()->getRuntimeInfo()->kernelConfigs(); + auto runtime_info = vintf::VintfObject::GetInstance() + ->getRuntimeInfo(false /* skip cache */, + vintf::RuntimeInfo::FetchFlag::CONFIG_GZ); + CHECK(runtime_info != nullptr) << "Kernel configs cannot be fetched. b/151092221"; + const std::map& configs = runtime_info->kernelConfigs(); std::map::const_iterator it = configs.find("CONFIG_VMAP_STACK"); cfg_state = (it != configs.end() && it->second == "y") ? CONFIG_SET : CONFIG_UNSET; } From 9e55b45cdf939f06d51bfb9a5d344d1b809b705f Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 21 Jul 2020 17:12:43 -0700 Subject: [PATCH 2/2] VINTF: Remove skipCache boolean. Test: pass Change-Id: Iec1aa7f7c2ef203ff2f1fd6adb456baec24c075a --- core/jni/android_os_Debug.cpp | 5 ++--- core/jni/android_os_VintfRuntimeInfo.cpp | 18 ++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp index 265eb7cffb225..1037713c6af9f 100644 --- a/core/jni/android_os_Debug.cpp +++ b/core/jni/android_os_Debug.cpp @@ -846,9 +846,8 @@ static jboolean android_os_Debug_isVmapStack(JNIEnv *env, jobject clazz) } cfg_state = CONFIG_UNKNOWN; if (cfg_state == CONFIG_UNKNOWN) { - auto runtime_info = vintf::VintfObject::GetInstance() - ->getRuntimeInfo(false /* skip cache */, - vintf::RuntimeInfo::FetchFlag::CONFIG_GZ); + auto runtime_info = vintf::VintfObject::GetInstance()->getRuntimeInfo( + vintf::RuntimeInfo::FetchFlag::CONFIG_GZ); CHECK(runtime_info != nullptr) << "Kernel configs cannot be fetched. b/151092221"; const std::map& configs = runtime_info->kernelConfigs(); std::map::const_iterator it = configs.find("CONFIG_VMAP_STACK"); diff --git a/core/jni/android_os_VintfRuntimeInfo.cpp b/core/jni/android_os_VintfRuntimeInfo.cpp index 9379ea6dcd107..b0271b9e92aff 100644 --- a/core/jni/android_os_VintfRuntimeInfo.cpp +++ b/core/jni/android_os_VintfRuntimeInfo.cpp @@ -29,14 +29,12 @@ namespace android { using vintf::RuntimeInfo; using vintf::VintfObject; -#define MAP_STRING_METHOD(javaMethod, cppString, flags) \ - static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) \ - { \ - std::shared_ptr info = VintfObject::GetRuntimeInfo( \ - false /* skipCache */, flags); \ - if (info == nullptr) return nullptr; \ - return env->NewStringUTF((cppString).c_str()); \ - } \ +#define MAP_STRING_METHOD(javaMethod, cppString, flags) \ + static jstring android_os_VintfRuntimeInfo_##javaMethod(JNIEnv* env, jclass clazz) { \ + std::shared_ptr info = VintfObject::GetRuntimeInfo(flags); \ + if (info == nullptr) return nullptr; \ + return env->NewStringUTF((cppString).c_str()); \ + } MAP_STRING_METHOD(getCpuInfo, info->cpuInfo(), RuntimeInfo::FetchFlag::CPU_INFO); MAP_STRING_METHOD(getOsName, info->osName(), RuntimeInfo::FetchFlag::CPU_VERSION); @@ -54,8 +52,8 @@ MAP_STRING_METHOD(getBootVbmetaAvbVersion, vintf::to_string(info->bootVbmetaAvbV static jlong android_os_VintfRuntimeInfo_getKernelSepolicyVersion(JNIEnv *env, jclass clazz) { - std::shared_ptr info = VintfObject::GetRuntimeInfo( - false /* skipCache */, RuntimeInfo::FetchFlag::POLICYVERS); + std::shared_ptr info = + VintfObject::GetRuntimeInfo(RuntimeInfo::FetchFlag::POLICYVERS); if (info == nullptr) return 0; return static_cast(info->kernelSepolicyVersion()); }