Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Unified Diff: third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp

Issue 684453003: Add UMA for testing whether the Chromium library was page aligned in the APK file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for review feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/android_crazy_linker/src/src/crazy_linker_library_list.cpp
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 1ca932109ddcbed447c11be7dfde8ccbf0764143..444b62a4ca64328189ff6504e5fa6d5e1d5452b0 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;
}

Powered by Google App Engine
This is Rietveld 408576698