summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2021-10-12 15:51:16 -0700
committerSteven Moreland <smoreland@google.com>2021-10-12 23:02:55 +0000
commit78f989db44dffe7e0102d453088e5432bb7c1069 (patch)
treee2347a3e99f7540838a7276ae00b31defef8be60
parent6a8a843fd6cee4b1569f4f560a005d41f55e7fc6 (diff)
downloadlibhidl-78f989db44dffe7e0102d453088e5432bb7c1069.tar.gz
Remove HidlInstrumentor logic entirely.
This userdebug-only feature is used for collecting profiling information and getting coverage data. It was removed from user builds because it isn't threadsafe, but also, it is causing a leak because it repeatedly calls add_sysprop_change_callback. For coverage information, we have no existing multi-process solution, and we are focusing on in-process fuzzing. For profiling information, perfetto/heapprofd/atrace/simpleperf and others should be prefered. HIDL is on the deprecation route, and unfortunately this feature has bitrot, since the old VTS framework is deprecated, and we use a unified tradefed now. If anyone needs this functionality still, please reach out to me or file an issue. Thanks! Note - we can't remove the HidlInstrumentor class itself due to its ABI being frozen. Fixes: 202852241 Test: build only Change-Id: Ibce1f5762740570e6d9405a49c4d917ffb078152
-rw-r--r--base/HidlInternal.cpp149
1 files changed, 2 insertions, 147 deletions
diff --git a/base/HidlInternal.cpp b/base/HidlInternal.cpp
index e5c8f70..a94f235 100644
--- a/base/HidlInternal.cpp
+++ b/base/HidlInternal.cpp
@@ -25,26 +25,6 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
-#include <dirent.h>
-#include <dlfcn.h>
-#include <link.h>
-#include <utils/misc.h>
-#include <regex>
-
-extern "C" __attribute__((weak)) void __sanitizer_cov_dump();
-
-const char kGcovPrefixEnvVar[] = "GCOV_PREFIX";
-const char kGcovPrefixOverrideEnvVar[] = "GCOV_PREFIX_OVERRIDE";
-const char kGcovPrefixPath[] = "/data/misc/trace/";
-const char kSysPropHalCoverage[] = "hal.coverage.enable";
-#if defined(__LP64__)
-const char kSysPropInstrumentationPath[] = "hal.instrumentation.lib.path.64";
-#else
-const char kSysPropInstrumentationPath[] = "hal.instrumentation.lib.path.32";
-#endif
-#endif // LIBHIDL_TARGET_DEBUGGABLE
-
namespace android {
namespace hardware {
namespace details {
@@ -70,52 +50,7 @@ std::string getVndkSpHwPath(const char* lib) {
HidlInstrumentor::HidlInstrumentor(const std::string& package, const std::string& interface)
: mEnableInstrumentation(false),
mInstrumentationLibPackage(package),
- mInterfaceName(interface) {
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
- configureInstrumentation(false);
- if (__sanitizer_cov_dump != nullptr) {
- ::android::add_sysprop_change_callback(
- []() {
- bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false);
- if (enableCoverage) {
- __sanitizer_cov_dump();
- }
- },
- 0);
- }
- if (base::GetBoolProperty("ro.vts.coverage", false)) {
- const char* prefixOverride = getenv(kGcovPrefixOverrideEnvVar);
- if (prefixOverride == nullptr || strcmp(prefixOverride, "true") != 0) {
- const std::string gcovPath = kGcovPrefixPath + std::to_string(getpid());
- setenv(kGcovPrefixEnvVar, gcovPath.c_str(), true /* overwrite */);
- }
- ::android::add_sysprop_change_callback(
- []() {
- const bool enableCoverage = base::GetBoolProperty(kSysPropHalCoverage, false);
- if (enableCoverage) {
- dl_iterate_phdr(
- [](struct dl_phdr_info* info, size_t /* size */, void* /* data */) {
- if (strlen(info->dlpi_name) == 0) return 0;
-
- void* handle = dlopen(info->dlpi_name, RTLD_LAZY);
- if (handle == nullptr) {
- LOG(INFO) << "coverage dlopen failed: " << dlerror();
- return 0;
- }
- void (*flush)() = (void (*)())dlsym(handle, "__gcov_flush");
- if (flush == nullptr) {
- return 0;
- }
- flush();
- return 0;
- },
- nullptr /* data */);
- }
- },
- 0 /* priority */);
- }
-#endif
-}
+ mInterfaceName(interface) {}
HidlInstrumentor::~HidlInstrumentor() {}
@@ -137,93 +72,13 @@ void HidlInstrumentor::configureInstrumentation(bool log) {
void HidlInstrumentor::registerInstrumentationCallbacks(
std::vector<InstrumentationCallback> *instrumentationCallbacks) {
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
- std::vector<std::string> instrumentationLibPaths;
- const std::string instrumentationLibPath = base::GetProperty(kSysPropInstrumentationPath, "");
- if (instrumentationLibPath.size() > 0) {
- instrumentationLibPaths.push_back(instrumentationLibPath);
- } else {
- static std::string halLibPathVndkSp = getVndkSpHwPath();
-#ifndef __ANDROID_VNDK__
- instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_SYSTEM);
-#endif
- instrumentationLibPaths.push_back(halLibPathVndkSp);
- instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_VENDOR);
- instrumentationLibPaths.push_back(HAL_LIBRARY_PATH_ODM);
- }
-
- for (const auto& path : instrumentationLibPaths) {
- DIR *dir = opendir(path.c_str());
- if (dir == nullptr) {
- LOG(WARNING) << path << " does not exist. ";
- return;
- }
-
- struct dirent *file;
- while ((file = readdir(dir)) != nullptr) {
- if (!isInstrumentationLib(file))
- continue;
-
- void *handle = dlopen((path + file->d_name).c_str(), RTLD_NOW);
- char *error;
- if (handle == nullptr) {
- LOG(WARNING) << "couldn't load file: " << file->d_name
- << " error: " << dlerror();
- continue;
- }
-
- dlerror(); /* Clear any existing error */
-
- using cbFun = void (*)(
- const InstrumentationEvent,
- const char *,
- const char *,
- const char *,
- const char *,
- std::vector<void *> *);
- std::string package = mInstrumentationLibPackage;
- for (size_t i = 0; i < package.size(); i++) {
- if (package[i] == '.') {
- package[i] = '_';
- continue;
- }
-
- if (package[i] == '@') {
- package[i] = '_';
- package.insert(i + 1, "V");
- continue;
- }
- }
- auto cb = (cbFun)dlsym(handle, ("HIDL_INSTRUMENTATION_FUNCTION_"
- + package + "_" + mInterfaceName).c_str());
- if ((error = dlerror()) != nullptr) {
- LOG(WARNING)
- << "couldn't find symbol: HIDL_INSTRUMENTATION_FUNCTION_"
- << package << "_" << mInterfaceName << ", error: " << error;
- continue;
- }
- instrumentationCallbacks->push_back(cb);
- LOG(INFO) << "Register instrumentation callback from "
- << file->d_name;
- }
- closedir(dir);
- }
-#else
- // No-op for user builds.
+ // No-op, historical
(void) instrumentationCallbacks;
return;
-#endif
}
bool HidlInstrumentor::isInstrumentationLib(const dirent *file) {
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
- if (file->d_type != DT_REG) return false;
- std::cmatch cm;
- std::regex e("^" + mInstrumentationLibPackage + "(.*).profiler.so$");
- if (std::regex_match(file->d_name, cm, e)) return true;
-#else
(void) file;
-#endif
return false;
}