Bug 1309708 - [1.2] Delete reported library mapping on close. r=glandium
authorEugen Sawin <esawin@mozilla.com>
Thu, 10 Nov 2016 01:32:16 +0100
changeset 348730 459230d2ab75b5712f9c15e7640f6fe99d82a7f3
parent 348729 3930bf2158788bc3681992d61cc0d26614c8b388
child 348731 2716f83ffcc0d9adbe37cc7bd4b06a54e4a81abd
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1309708
milestone52.0a1
Bug 1309708 - [1.2] Delete reported library mapping on close. r=glandium
mozglue/android/APKOpen.cpp
mozglue/linker/CustomElf.cpp
mozglue/linker/tests/TestZip.cpp
--- a/mozglue/android/APKOpen.cpp
+++ b/mozglue/android/APKOpen.cpp
@@ -194,16 +194,31 @@ report_mapping(char *name, void *base, u
 
   struct mapping_info *info = &lib_mapping[mapping_count++];
   info->name = strdup(name);
   info->base = (uintptr_t)base;
   info->len = len;
   info->offset = offset;
 }
 
+extern "C" void
+delete_mapping(const char *name)
+{
+  for (int pos = 0; pos < mapping_count; ++pos) {
+    struct mapping_info *info = &lib_mapping[pos];
+    if (!strcmp(info->name, name)) {
+      struct mapping_info *last = &lib_mapping[mapping_count - 1];
+      free(info->name);
+      *info = *last;
+      --mapping_count;
+      break;
+    }
+  }
+}
+
 static void*
 dlopenAPKLibrary(const char* apkName, const char* libraryName)
 {
 #define APK_ASSETS_PATH "!/assets/" ANDROID_CPU_ARCH "/"
   size_t filenameLength = strlen(apkName) +
     sizeof(APK_ASSETS_PATH) + 	// includes \0 terminator
     strlen(libraryName);
   auto file = MakeUnique<char[]>(filenameLength);
--- a/mozglue/linker/CustomElf.cpp
+++ b/mozglue/linker/CustomElf.cpp
@@ -18,19 +18,21 @@ using namespace mozilla;
 
 /* TODO: Fill ElfLoader::Singleton.lastError on errors. */
 
 /* Function used to report library mappings from the custom linker to Gecko
  * crash reporter */
 #ifdef ANDROID
 extern "C" {
   void report_mapping(char *name, void *base, uint32_t len, uint32_t offset);
+  void delete_mapping(const char *name);
 }
 #else
 #define report_mapping(...)
+#define delete_mapping(...)
 #endif
 
 const Ehdr *Ehdr::validate(const void *buf)
 {
   if (!buf || buf == MAP_FAILED)
     return nullptr;
 
   const Ehdr *ehdr = reinterpret_cast<const Ehdr *>(buf);
@@ -271,16 +273,17 @@ CustomElf::~CustomElf()
   DEBUG_LOG("CustomElf::~CustomElf(%p [\"%s\"])",
             reinterpret_cast<void *>(this), GetPath());
   CallFini();
   /* Normally, __cxa_finalize is called by the .fini function. However,
    * Android NDK before r6b doesn't do that. Our wrapped cxa_finalize only
    * calls destructors once, so call it in all cases. */
   ElfLoader::__wrap_cxa_finalize(this);
   ElfLoader::Singleton.Forget(this);
+  delete_mapping(GetName());
 }
 
 void *
 CustomElf::GetSymbolPtrInDeps(const char *symbol) const
 {
   /* Resolve dlopen and related functions to point to ours */
   if (symbol[0] == 'd' && symbol[1] == 'l') {
     if (strcmp(symbol + 2, "open") == 0)
--- a/mozglue/linker/tests/TestZip.cpp
+++ b/mozglue/linker/tests/TestZip.cpp
@@ -3,16 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <cstdio>
 #include <unistd.h>
 #include "Zip.h"
 #include "mozilla/RefPtr.h"
 
 extern "C" void report_mapping() { }
+extern "C" void delete_mapping() { }
 
 /**
  * test.zip is a basic test zip file with a central directory. It contains
  * four entries, in the following order:
  * "foo", "bar", "baz", "qux".
  * The entries are going to be read out of order.
  */
 const char *test_entries[] = {