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..05bbf85dd651fdc387b03dbd54d2c9f162c05209 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" |
@@ -392,15 +393,35 @@ 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 offset = FindAlignedLibraryInZipFile(zip_file_path, lib_name, error); |
+ if (offset == CRAZY_OFFSET_FAILED) { |
+ return NULL; |
+ } |
+ |
+ return LoadLibrary( |
+ zip_file_path, dlopen_flags, load_address, offset, |
+ search_path_list, error); |
+} |
+ |
+void LibraryList::AddLibrary(LibraryView* wrap) { |
+ known_libraries_.PushBack(wrap); |
+} |
+ |
+const size_t kMaxFilenameInZip = 256; |
+const size_t kPageSize = 4096; |
rmcilroy
2014/10/28 13:07:15
nit - please put these back at the top of the file
petrcermak
2014/10/28 13:48:16
Done (I put the constants in the anonymous namespa
|
+static_assert((kPageSize & (kPageSize - 1)) == 0, |
+ "kPageSize must be a power of 2"); |
rmcilroy
2014/10/28 13:07:15
Please move this to FindAlignedLibraryInZipFile so
petrcermak
2014/10/28 13:48:16
Done.
|
+ |
+int LibraryList::FindAlignedLibraryInZipFile( |
+ const char* zip_file_path, |
+ const char* lib_name, |
+ Error* error) { |
String fullname; |
fullname.Reserve(kMaxFilenameInZip); |
fullname = "lib/"; |
@@ -409,29 +430,28 @@ LibraryView* LibraryList::LoadLibraryInZipFile(const char* zip_file_path, |
fullname += lib_name; |
if (fullname.size() + 1 > kMaxFilenameInZip) { |
- error->Format("Filename too long for a file in a zip file %s\n", |
- fullname.c_str()); |
- return NULL; |
+ if (error) { |
+ error->Format("Filename too long for a file in a zip file %s\n", |
+ fullname.c_str()); |
+ } |
+ 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) { |
- error->Format("Library %s is not page aligned in zipfile %s\n", |
- lib_name, zip_file_path); |
- return NULL; |
+ if (error) { |
+ error->Format("Library %s is not page aligned in zipfile %s\n", |
+ lib_name, zip_file_path); |
+ } |
+ return CRAZY_OFFSET_FAILED; |
} |
- return LoadLibrary( |
- zip_file_path, dlopen_flags, load_address, offset, |
- search_path_list, error); |
-} |
- |
-void LibraryList::AddLibrary(LibraryView* wrap) { |
- known_libraries_.PushBack(wrap); |
+ assert(offset != CRAZY_OFFSET_FAILED); |
+ return offset; |
} |
LibraryView* LibraryList::FindKnownLibrary(const char* name) { |