summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Stjernholm <mast@google.com>2019-10-04 01:28:43 +0100
committerMartin Stjernholm <mast@google.com>2019-10-08 19:21:45 +0100
commit9062bb42691918ba4b55f780f14431c50673d154 (patch)
tree135793557fa8cdf791b4cd3ddf96bfacfc9e9562
parent4d7d903e2b3191f4a3688f3631bfb2db11ec8088 (diff)
downloadcore-9062bb42691918ba4b55f780f14431c50673d154.tar.gz
Continue without DEX support if libdexfile_external.so fails to load.
libunwindstack may be used in situations where we cannot guarantee that libdexfile_external.so is available, e.g. from libc_malloc_debug.so in the bootstrap Bionic, or in APEXes with incomplete linker configs. Test: atest libunwindstack_unit_test Test: atest --host libunwindstack_unit_test Test: rm -f out/host/linux-x86/lib*/libdexfile_external.so && \ out/host/linux-x86/nativetest64/libunwindstack_unit_test/libunwindstack_unit_test (check that DexFile(s)Test tests fail without abort) Bug; 139408016 Change-Id: I7eeee77ab363d9d39412ece2038ce786394bb34f
-rw-r--r--libunwindstack/DexFile.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libunwindstack/DexFile.cpp b/libunwindstack/DexFile.cpp
index eaf867fd0..dff7a8b3c 100644
--- a/libunwindstack/DexFile.cpp
+++ b/libunwindstack/DexFile.cpp
@@ -22,6 +22,9 @@
#include <memory>
+#define LOG_TAG "unwind"
+#include <log/log.h>
+
#include <android-base/unique_fd.h>
#include <art_api/dex_file_support.h>
@@ -32,6 +35,19 @@
namespace unwindstack {
+static bool CheckDexSupport() {
+ if (std::string err_msg; !art_api::dex::TryLoadLibdexfileExternal(&err_msg)) {
+ ALOGW("Failed to initialize DEX file support: %s", err_msg.c_str());
+ return false;
+ }
+ return true;
+}
+
+static bool HasDexSupport() {
+ static bool has_dex_support = CheckDexSupport();
+ return has_dex_support;
+}
+
std::unique_ptr<DexFile> DexFile::Create(uint64_t dex_file_offset_in_memory, Memory* memory,
MapInfo* info) {
if (!info->name.empty()) {
@@ -57,6 +73,10 @@ bool DexFile::GetMethodInformation(uint64_t dex_offset, std::string* method_name
std::unique_ptr<DexFileFromFile> DexFileFromFile::Create(uint64_t dex_file_offset_in_file,
const std::string& file) {
+ if (UNLIKELY(!HasDexSupport())) {
+ return nullptr;
+ }
+
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(file.c_str(), O_RDONLY | O_CLOEXEC)));
if (fd == -1) {
return nullptr;
@@ -75,6 +95,10 @@ std::unique_ptr<DexFileFromFile> DexFileFromFile::Create(uint64_t dex_file_offse
std::unique_ptr<DexFileFromMemory> DexFileFromMemory::Create(uint64_t dex_file_offset_in_memory,
Memory* memory,
const std::string& name) {
+ if (UNLIKELY(!HasDexSupport())) {
+ return nullptr;
+ }
+
std::vector<uint8_t> backing_memory;
for (size_t size = 0;;) {