| Index: third_party/android_crazy_linker/src/src/crazy_linker_api.cpp
|
| 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 8ea4a1258de953d22f170e58e5530dc4887c2d57..e752f4503f7ecf023423aefa9434bf1c648a17d8 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
|
| @@ -6,7 +6,10 @@
|
|
|
| #include <crazy_linker.h>
|
|
|
| +#include <unistd.h>
|
| #include <string.h>
|
| +#include <sys/types.h>
|
| +#include <sys/stat.h>
|
|
|
| #include "crazy_linker_error.h"
|
| #include "crazy_linker_ashmem.h"
|
| @@ -17,7 +20,9 @@
|
| #include "crazy_linker_thread.h"
|
| #include "crazy_linker_util.h"
|
| #include "crazy_linker_library_view.h"
|
| +#include "crazy_linker_memory_mapping.h"
|
| #include "crazy_linker_system.h"
|
| +#include "crazy_linker_zip.h"
|
|
|
| using crazy::Globals;
|
| using crazy::Error;
|
| @@ -396,6 +401,55 @@ crazy_status_t crazy_library_file_path_in_zip_file(const char* lib_name,
|
| return CRAZY_STATUS_SUCCESS;
|
| }
|
|
|
| +crazy_status_t crazy_library_offset_size_in_zip_file(const char* zip_filename,
|
| + const char* lib_name,
|
| + int* offset, int* size) {
|
| + char path_in_zip[kMaxFilePathLengthInZip] = "lib/armeabi-v7/libchrome.so";
|
| + crazy_status_t status;
|
| + status = crazy_library_file_path_in_zip_file(lib_name, path_in_zip,
|
| + kMaxFilePathLengthInZip);
|
| + if (status == CRAZY_STATUS_FAILURE) return CRAZY_STATUS_FAILURE;
|
| + crazy::OffsetSize offset_size =
|
| + crazy::FindStartOffsetAndLengthOfFileInZipFile(zip_filename, path_in_zip);
|
| + *offset = offset_size.offset;
|
| + *size = offset_size.size;
|
| + if (offset_size.offset == -1) return CRAZY_STATUS_FAILURE;
|
| + return CRAZY_STATUS_SUCCESS;
|
| +}
|
| +
|
| +crazy_status_t crazy_prefault_library(const char* filename, int offset,
|
| + int size) {
|
| + struct stat stat_buf;
|
| + int fd;
|
| +
|
| + if (stat(filename, &stat_buf) == -1) return CRAZY_STATUS_FAILURE;
|
| + if ((fd = open(filename, 0, O_RDONLY)) == -1) return CRAZY_STATUS_FAILURE;
|
| +
|
| + if (size == -1)
|
| + size = (int) stat_buf.st_size;
|
| +
|
| + crazy::MemoryMapping mapping;
|
| + bool ok =
|
| + mapping.AllocateWithOffset(NULL, size, crazy::MemoryMapping::CAN_READ, fd,
|
| + offset);
|
| + if (!ok) {
|
| + mapping.Deallocate();
|
| + close(fd);
|
| + return CRAZY_STATUS_FAILURE;
|
| + }
|
| +
|
| + unsigned char* mapped = (unsigned char*) mapping.Get();
|
| + unsigned char dummy = 0;
|
| + for (int i = 0; i < size - sizeof(long); i += 4096) {
|
| + // volatile is required to prevent the compiler from removing this loop.
|
| + dummy ^= *((volatile unsigned char*) mapped + i);
|
| + }
|
| +
|
| + mapping.Deallocate();
|
| + close(fd);
|
| + return CRAZY_STATUS_SUCCESS;
|
| +}
|
| +
|
| crazy_status_t crazy_linker_check_library_is_mappable_in_zip_file(
|
| const char* zipfile_name,
|
| const char* lib_name) {
|
|
|