| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This is the Android-specific Chromium linker, a tiny shared library | 5 // This is the Android-specific Chromium linker, a tiny shared library |
| 6 // implementing a custom dynamic linker that can be used to load the | 6 // implementing a custom dynamic linker that can be used to load the |
| 7 // real Chromium libraries (e.g. libcontentshell.so). | 7 // real Chromium libraries (e.g. libcontentshell.so). |
| 8 | 8 |
| 9 // The main point of this linker is to be able to share the RELRO | 9 // The main point of this linker is to be able to share the RELRO |
| 10 // section of libcontentshell.so (or equivalent) between the browser and | 10 // section of libcontentshell.so (or equivalent) between the browser and |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 jstring library_name, | 343 jstring library_name, |
| 344 jlong load_address, | 344 jlong load_address, |
| 345 jobject lib_info_obj) { | 345 jobject lib_info_obj) { |
| 346 String lib_name(env, library_name); | 346 String lib_name(env, library_name); |
| 347 FileLibraryOpener opener; | 347 FileLibraryOpener opener; |
| 348 return GenericLoadLibrary( | 348 return GenericLoadLibrary( |
| 349 env, lib_name.c_str(), | 349 env, lib_name.c_str(), |
| 350 static_cast<size_t>(load_address), lib_info_obj, opener); | 350 static_cast<size_t>(load_address), lib_info_obj, opener); |
| 351 } | 351 } |
| 352 | 352 |
| 353 const size_t kMaxFilenameInZip = 256; |
| 354 jstring LibraryFilenameInZipFile(JNIEnv* env, jclass clazz, jstring lib_name) { |
| 355 String lib_name_str(env, lib_name); |
| 356 char buffer[kMaxFilenameInZip + 1]; |
| 357 if (CRAZY_STATUS_SUCCESS != crazy_library_filename_in_zip_file( |
| 358 lib_name_str.c_str(), buffer, sizeof(buffer))) { |
| 359 LOG_ERROR("Failure to get library filename from zipfile"); |
| 360 buffer[0] = '\0'; |
| 361 } |
| 362 return env->NewStringUTF(buffer); |
| 363 } |
| 364 |
| 353 // Load a library from a zipfile with the chromium linker. The | 365 // Load a library from a zipfile with the chromium linker. The |
| 354 // library in the zipfile must be uncompressed and page aligned. | 366 // library in the zipfile must be uncompressed and page aligned. |
| 355 // The basename of the library is given. The library is expected | 367 // The basename of the library is given. The library is expected |
| 356 // to be lib/<abi_tag>/crazy.<basename>. The <abi_tag> used will be the | 368 // to be lib/<abi_tag>/crazy.<basename>. The <abi_tag> used will be the |
| 357 // same as the abi for this linker. The "crazy." prefix is included | 369 // same as the abi for this linker. The "crazy." prefix is included |
| 358 // so that the Android Package Manager doesn't extract the library into | 370 // so that the Android Package Manager doesn't extract the library into |
| 359 // /data/app-lib. | 371 // /data/app-lib. |
| 360 // | 372 // |
| 361 // Loading the library will also call its JNI_OnLoad() method, which | 373 // Loading the library will also call its JNI_OnLoad() method, which |
| 362 // shall register its methods. Note that lazy native method resolution | 374 // shall register its methods. Note that lazy native method resolution |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 627 |
| 616 const JNINativeMethod kNativeMethods[] = { | 628 const JNINativeMethod kNativeMethods[] = { |
| 617 {"nativeLoadLibrary", | 629 {"nativeLoadLibrary", |
| 618 "(" | 630 "(" |
| 619 "Ljava/lang/String;" | 631 "Ljava/lang/String;" |
| 620 "J" | 632 "J" |
| 621 "Lorg/chromium/base/library_loader/Linker$LibInfo;" | 633 "Lorg/chromium/base/library_loader/Linker$LibInfo;" |
| 622 ")" | 634 ")" |
| 623 "Z", | 635 "Z", |
| 624 reinterpret_cast<void*>(&LoadLibrary)}, | 636 reinterpret_cast<void*>(&LoadLibrary)}, |
| 637 {"nativeLibraryFilenameInZipFile", |
| 638 "(" |
| 639 "Ljava/lang/String;" |
| 640 ")" |
| 641 "Ljava/lang/String;", |
| 642 reinterpret_cast<void*>(&LibraryFilenameInZipFile)}, |
| 625 {"nativeLoadLibraryInZipFile", | 643 {"nativeLoadLibraryInZipFile", |
| 626 "(" | 644 "(" |
| 627 "Ljava/lang/String;" | 645 "Ljava/lang/String;" |
| 628 "Ljava/lang/String;" | 646 "Ljava/lang/String;" |
| 629 "J" | 647 "J" |
| 630 "Lorg/chromium/base/library_loader/Linker$LibInfo;" | 648 "Lorg/chromium/base/library_loader/Linker$LibInfo;" |
| 631 ")" | 649 ")" |
| 632 "Z", | 650 "Z", |
| 633 reinterpret_cast<void*>(&LoadLibraryInZipFile)}, | 651 reinterpret_cast<void*>(&LoadLibraryInZipFile)}, |
| 634 {"nativeRunCallbackOnUiThread", | 652 {"nativeRunCallbackOnUiThread", |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 crazy_context_t* context = GetCrazyContext(); | 730 crazy_context_t* context = GetCrazyContext(); |
| 713 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 731 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
| 714 | 732 |
| 715 // Register the function that the crazy linker can call to post code | 733 // Register the function that the crazy linker can call to post code |
| 716 // for later execution. | 734 // for later execution. |
| 717 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 735 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
| 718 | 736 |
| 719 LOG_INFO("%s: Done", __FUNCTION__); | 737 LOG_INFO("%s: Done", __FUNCTION__); |
| 720 return JNI_VERSION_1_4; | 738 return JNI_VERSION_1_4; |
| 721 } | 739 } |
| OLD | NEW |