summaryrefslogtreecommitdiffstats
path: root/third_party
diff options
context:
space:
mode:
authorpetrcermak <petrcermak@chromium.org>2014-10-29 04:06:56 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-29 11:07:11 +0000
commit2a112d50b0a28f82a519e194230b7de91ee21023 (patch)
treeafde719e7d447a973c10b5027cde26e2ba14c9eb /third_party
parent9b26716f12e1c458e9b5cc10ea53c560220e3311 (diff)
downloadchromium_src-2a112d50b0a28f82a519e194230b7de91ee21023.zip
chromium_src-2a112d50b0a28f82a519e194230b7de91ee21023.tar.gz
chromium_src-2a112d50b0a28f82a519e194230b7de91ee21023.tar.bz2
Add UMA for testing whether the Chromium library was page aligned in the APK file.
The following histogram is added: ChromiumAndroidLinker.LibraryAlignedInApk Whether the Chromium library is page aligned in the APK file. The functionality is checked and reported during every Chromium browser process start up if direct library loading from the APK file is enabled. BUG= Review URL: https://codereview.chromium.org/684453003 Cr-Commit-Position: refs/heads/master@{#301813}
Diffstat (limited to 'third_party')
-rw-r--r--third_party/android_crazy_linker/src/include/crazy_linker.h5
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_api.cpp11
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp47
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_library_list.h8
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_util.h3
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp21
-rw-r--r--third_party/android_crazy_linker/src/src/crazy_linker_zip.h7
7 files changed, 76 insertions, 26 deletions
diff --git a/third_party/android_crazy_linker/src/include/crazy_linker.h b/third_party/android_crazy_linker/src/include/crazy_linker.h
index 04fc8ce..b09f8c5 100644
--- a/third_party/android_crazy_linker/src/include/crazy_linker.h
+++ b/third_party/android_crazy_linker/src/include/crazy_linker.h
@@ -335,6 +335,11 @@ crazy_status_t crazy_library_find_from_address(
void* address,
crazy_library_t** library) _CRAZY_PUBLIC;
+// Check whether |lib_name| is page aligned in |zipfile_name|.
+crazy_status_t crazy_linker_check_library_aligned_in_zip_file(
+ const char* zipfile_name,
+ const char* lib_name) _CRAZY_PUBLIC;
+
// Close a library. This decrements its reference count. If it reaches
// zero, the library be unloaded from the process.
void crazy_library_close(crazy_library_t* library) _CRAZY_PUBLIC;
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_api.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_api.cpp
index 10a64bf..80d29fd 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_api.cpp
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_api.cpp
@@ -372,6 +372,17 @@ crazy_status_t crazy_library_find_from_address(void* address,
}
}
+crazy_status_t crazy_linker_check_library_aligned_in_zip_file(
+ const char* zipfile_name,
+ const char* lib_name) {
+ Error error;
+ if (crazy::LibraryList::FindAlignedLibraryInZipFile(
+ zipfile_name, lib_name, &error) == CRAZY_OFFSET_FAILED)
+ return CRAZY_STATUS_FAILURE;
+
+ return CRAZY_STATUS_SUCCESS;
+}
+
void crazy_library_close(crazy_library_t* library) {
crazy_library_close_with_context(library, NULL);
}
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp
index 1ca9321..444b62a 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp
@@ -4,6 +4,7 @@
#include "crazy_linker_library_list.h"
+#include <assert.h>
#include <dlfcn.h>
#include "crazy_linker_debug.h"
@@ -19,6 +20,14 @@ namespace crazy {
namespace {
+// Maximum filename length of a file in a zip file.
+const size_t kMaxFilenameInZip = 256;
+
+// Page size for alignment in a zip file.
+const size_t kZipAlignmentPageSize = 4096;
+static_assert(kZipAlignmentPageSize % PAGE_SIZE == 0,
+ "kZipAlignmentPageSize must be a multiple of PAGE_SIZE");
+
// A helper struct used when looking up symbols in libraries.
struct SymbolLookupState {
void* found_addr;
@@ -392,15 +401,10 @@ LibraryView* LibraryList::LoadLibrary(const char* lib_name,
#error "Unsupported target abi"
#endif
-const size_t kMaxFilenameInZip = 256;
-const size_t kPageSize = 4096;
-
-LibraryView* LibraryList::LoadLibraryInZipFile(const char* zip_file_path,
- const char* lib_name,
- int dlopen_flags,
- uintptr_t load_address,
- SearchPathList* search_path_list,
- Error* error) {
+int LibraryList::FindAlignedLibraryInZipFile(
+ const char* zip_file_path,
+ const char* lib_name,
+ Error* error) {
String fullname;
fullname.Reserve(kMaxFilenameInZip);
fullname = "lib/";
@@ -411,17 +415,34 @@ LibraryView* LibraryList::LoadLibraryInZipFile(const char* zip_file_path,
if (fullname.size() + 1 > kMaxFilenameInZip) {
error->Format("Filename too long for a file in a zip file %s\n",
fullname.c_str());
- return NULL;
+ return CRAZY_OFFSET_FAILED;
}
int offset = FindStartOffsetOfFileInZipFile(zip_file_path, fullname.c_str());
- if (offset == -1) {
- return NULL;
+ if (offset == CRAZY_OFFSET_FAILED) {
+ return CRAZY_OFFSET_FAILED;
}
- if ((offset & (kPageSize - 1)) != 0) {
+ static_assert((kZipAlignmentPageSize & (kZipAlignmentPageSize - 1)) == 0,
+ "kZipAlignmentPageSize must be a power of 2");
+ if ((offset & (kZipAlignmentPageSize - 1)) != 0) {
error->Format("Library %s is not page aligned in zipfile %s\n",
lib_name, zip_file_path);
+ return CRAZY_OFFSET_FAILED;
+ }
+
+ assert(offset != CRAZY_OFFSET_FAILED);
+ return offset;
+}
+
+LibraryView* LibraryList::LoadLibraryInZipFile(const char* zip_file_path,
+ const char* lib_name,
+ int dlopen_flags,
+ uintptr_t load_address,
+ SearchPathList* search_path_list,
+ Error* error) {
+ int offset = FindAlignedLibraryInZipFile(zip_file_path, lib_name, error);
+ if (offset == CRAZY_OFFSET_FAILED) {
return NULL;
}
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_library_list.h b/third_party/android_crazy_linker/src/src/crazy_linker_library_list.h
index 9759a77..6539b80 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_library_list.h
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_library_list.h
@@ -71,6 +71,14 @@ class LibraryList {
SearchPathList* search_path_list,
Error* error);
+ // Find the location of a library in the zip file. If the name of the library
+ // is too long, an error occurs during the search or the library is not
+ // page aligned in the zip file, CRAZY_OFFSET_FAILED is returned. Otherwise,
+ // the offset of the library in the zip file is returned.
+ static int FindAlignedLibraryInZipFile(const char* zip_file_path,
+ const char* lib_name,
+ Error* error);
+
// Try to load a library from its location in the zip file.
// On failure, returns NULL and sets the |error| message.
LibraryView* LoadLibraryInZipFile(const char* zip_file_path,
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_util.h b/third_party/android_crazy_linker/src/src/crazy_linker_util.h
index ee67076..5cf2006 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_util.h
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_util.h
@@ -20,6 +20,9 @@ namespace crazy {
// int CRAZY_UNUSED my_var = 0;
#define CRAZY_UNUSED __attribute__((unused))
+// Offset in a file indicating a failure.
+#define CRAZY_OFFSET_FAILED (-1)
+
// Helper scoped pointer class.
template <class T>
class ScopedPtr {
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp b/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp
index 6b3d41c..deb17be 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_zip.cpp
@@ -11,6 +11,7 @@
#include "crazy_linker_debug.h"
#include "crazy_linker_system.h"
+#include "crazy_linker_util.h"
namespace {
@@ -97,7 +98,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
if (!fd.OpenReadOnly(zip_file)) {
LOG_ERRNO("%s: open failed trying to open zip file %s\n",
__FUNCTION__, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
// Find the length of the file.
@@ -105,13 +106,13 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
if (stat(zip_file, &stat_buf) == -1) {
LOG_ERRNO("%s: stat failed trying to stat zip file %s\n",
__FUNCTION__, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
if (stat_buf.st_size > kMaxZipFileLength) {
LOG("%s: The size %ld of %s is too large to map\n",
__FUNCTION__, stat_buf.st_size, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
// Map the file into memory.
@@ -119,7 +120,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
if (mem == MAP_FAILED) {
LOG_ERRNO("%s: mmap failed trying to mmap zip file %s\n",
__FUNCTION__, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
ScopedMMap scoped_mmap(mem, stat_buf.st_size);
@@ -136,7 +137,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
if (off == -1) {
LOG("%s: Failed to find end of central directory in %s\n",
__FUNCTION__, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
// We have located the end of central directory record, now locate
@@ -150,14 +151,14 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
if (start_of_central_dir > off) {
LOG("%s: Found out of range offset %u for start of directory in %s\n",
__FUNCTION__, start_of_central_dir, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
uint32_t end_of_central_dir = start_of_central_dir + length_of_central_dir;
if (end_of_central_dir > off) {
LOG("%s: Found out of range offset %u for end of directory in %s\n",
__FUNCTION__, end_of_central_dir, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
uint32_t num_entries = ReadUInt16(
@@ -173,7 +174,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
LOG("%s: Failed to find central directory header marker in %s. "
"Found 0x%x but expected 0x%x\n", __FUNCTION__,
zip_file, marker, kCentralDirHeaderMarker);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
uint32_t file_name_length =
ReadUInt16(mem_bytes, off + kOffsetFilenameLengthInCentralDirectory);
@@ -198,7 +199,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
LOG("%s: Failed to find local file header marker in %s. "
"Found 0x%x but expected 0x%x\n", __FUNCTION__,
zip_file, marker, kLocalHeaderMarker);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
uint32_t file_name_length =
@@ -229,7 +230,7 @@ int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename) {
}
LOG("%s: Did not find %s in %s\n", __FUNCTION__, filename, zip_file);
- return -1;
+ return CRAZY_OFFSET_FAILED;
}
} // crazy namespace
diff --git a/third_party/android_crazy_linker/src/src/crazy_linker_zip.h b/third_party/android_crazy_linker/src/src/crazy_linker_zip.h
index 6e289c0..3865493 100644
--- a/third_party/android_crazy_linker/src/src/crazy_linker_zip.h
+++ b/third_party/android_crazy_linker/src/src/crazy_linker_zip.h
@@ -10,9 +10,10 @@
namespace crazy {
// Find "filename" in the specified "zip_file" and return the offset
-// in the file of the start of the data for the file. Return -1 on error.
-// This routine replaces code which used the minizip library, but is about
-// 150 times faster, locating the offset in less than 0.5ms on a Nexus 4.
+// in the file of the start of the data for the file. Return
+// CRAZY_OFFSET_FAILED on error. This routine replaces code which used the
+// minizip library, but is about 150 times faster, locating the offset in less
+// than 0.5ms on a Nexus 4.
int FindStartOffsetOfFileInZipFile(const char* zip_file, const char* filename);
}