Chromium Code Reviews| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 569 mmap(NULL, bytes, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 570 if (address == MAP_FAILED) { | 570 if (address == MAP_FAILED) { |
| 571 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); | 571 LOG_INFO("%s: Random base load address not determinable\n", __FUNCTION__); |
| 572 return 0; | 572 return 0; |
| 573 } | 573 } |
| 574 munmap(address, bytes); | 574 munmap(address, bytes); |
| 575 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); | 575 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); |
| 576 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address)); | 576 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 // Maximum filename length of a file in a zip file. | |
| 580 // Note(petrcermak): The same constant is defined in | |
| 581 // crazy_linker_library_list.cpp. | |
| 582 const size_t kMaxFilenameInZip = 256; | |
|
rmcilroy
2014/10/29 17:20:44
Could we just export this in crazy_linker.h instea
petrcermak
2014/10/30 19:55:07
Done. I moved the constant to crazy_linker.h so cr
| |
| 583 | |
| 584 // Get the full filename of a library in the zip file | |
| 585 // (lib/<abi>/crazy.<lib_name>). | |
| 586 // | |
| 587 // |env| is the current JNI environment handle. | |
| 588 // |clazz| is the static class handle which is not used here. | |
| 589 // |lib_name| is the library base name. | |
| 590 // Returns the full filename (or empty string on failure). | |
| 591 jstring GetLibraryFilenameInZipFile(JNIEnv* env, | |
| 592 jclass clazz, | |
| 593 jstring lib_name) { | |
| 594 String lib_name_str(env, lib_name); | |
| 595 const char* lib_name_c_str = lib_name_str.c_str(); | |
| 596 char buffer[kMaxFilenameInZip + 1]; | |
| 597 if (CRAZY_STATUS_SUCCESS != crazy_library_filename_in_zip_file( | |
| 598 lib_name_c_str, buffer, sizeof(buffer))) { | |
|
picksi1
2014/10/30 10:48:08
Are the backwards <constant>!=<variable> part of t
petrcermak
2014/10/30 19:55:07
Done.
| |
| 599 LOG_ERROR("%s: Failed to get full filename for library '%s'", | |
| 600 __FUNCTION__, lib_name_c_str); | |
| 601 buffer[0] = '\0'; | |
| 602 } | |
| 603 return env->NewStringUTF(buffer); | |
| 604 } | |
| 605 | |
| 579 // Check whether the device supports loading a library directly from the APK | 606 // Check whether the device supports loading a library directly from the APK |
| 580 // file. | 607 // file. |
| 581 // | 608 // |
| 582 // |env| is the current JNI environment handle. | 609 // |env| is the current JNI environment handle. |
| 583 // |clazz| is the static class handle which is not used here. | 610 // |clazz| is the static class handle which is not used here. |
| 584 // |apkfile_name| is the filename of the APK. | 611 // |apkfile_name| is the filename of the APK. |
| 585 // Returns true if supported. | 612 // Returns true if supported. |
| 586 jboolean CheckLibraryLoadFromApkSupport(JNIEnv* env, jclass clazz, | 613 jboolean CheckLibraryLoadFromApkSupport(JNIEnv* env, jclass clazz, |
| 587 jstring apkfile_name) { | 614 jstring apkfile_name) { |
| 588 String apkfile_name_str(env, apkfile_name); | 615 String apkfile_name_str(env, apkfile_name); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 "(" | 706 "(" |
| 680 ")" | 707 ")" |
| 681 "Z", | 708 "Z", |
| 682 reinterpret_cast<void*>(&CanUseSharedRelro)}, | 709 reinterpret_cast<void*>(&CanUseSharedRelro)}, |
| 683 {"nativeGetRandomBaseLoadAddress", | 710 {"nativeGetRandomBaseLoadAddress", |
| 684 "(" | 711 "(" |
| 685 "J" | 712 "J" |
| 686 ")" | 713 ")" |
| 687 "J", | 714 "J", |
| 688 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, | 715 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, |
| 689 {"nativeCheckLibraryLoadFromApkSupport", | 716 {"nativeGetLibraryFilenameInZipFile", |
| 690 "(" | 717 "(" |
| 691 "Ljava/lang/String;" | 718 "Ljava/lang/String;" |
| 692 ")" | 719 ")" |
| 693 "Z", | 720 "Ljava/lang/String;", |
| 694 reinterpret_cast<void*>(&CheckLibraryLoadFromApkSupport)}, | 721 reinterpret_cast<void*>(&GetLibraryFilenameInZipFile)}, |
| 695 {"nativeCheckLibraryAlignedInApk", | 722 {"nativeCheckLibraryLoadFromApkSupport", |
| 696 "(" | 723 "(" |
| 697 "Ljava/lang/String;" | 724 "Ljava/lang/String;" |
| 698 "Ljava/lang/String;" | 725 ")" |
| 699 ")" | 726 "Z", |
| 700 "Z", | 727 reinterpret_cast<void*>(&CheckLibraryLoadFromApkSupport)}, |
| 701 reinterpret_cast<void*>(&CheckLibraryAlignedInApk)}, }; | 728 {"nativeCheckLibraryAlignedInApk", |
| 729 "(" | |
| 730 "Ljava/lang/String;" | |
| 731 "Ljava/lang/String;" | |
| 732 ")" | |
| 733 "Z", | |
| 734 reinterpret_cast<void*>(&CheckLibraryAlignedInApk)}, }; | |
| 702 | 735 |
| 703 } // namespace | 736 } // namespace |
| 704 | 737 |
| 705 // JNI_OnLoad() hook called when the linker library is loaded through | 738 // JNI_OnLoad() hook called when the linker library is loaded through |
| 706 // the regular System.LoadLibrary) API. This shall save the Java VM | 739 // the regular System.LoadLibrary) API. This shall save the Java VM |
| 707 // handle and initialize LibInfo fields. | 740 // handle and initialize LibInfo fields. |
| 708 jint JNI_OnLoad(JavaVM* vm, void* reserved) { | 741 jint JNI_OnLoad(JavaVM* vm, void* reserved) { |
| 709 LOG_INFO("%s: Entering", __FUNCTION__); | 742 LOG_INFO("%s: Entering", __FUNCTION__); |
| 710 // Get new JNIEnv | 743 // Get new JNIEnv |
| 711 JNIEnv* env; | 744 JNIEnv* env; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 742 crazy_context_t* context = GetCrazyContext(); | 775 crazy_context_t* context = GetCrazyContext(); |
| 743 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 776 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
| 744 | 777 |
| 745 // Register the function that the crazy linker can call to post code | 778 // Register the function that the crazy linker can call to post code |
| 746 // for later execution. | 779 // for later execution. |
| 747 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 780 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
| 748 | 781 |
| 749 LOG_INFO("%s: Done", __FUNCTION__); | 782 LOG_INFO("%s: Done", __FUNCTION__); |
| 750 return JNI_VERSION_1_4; | 783 return JNI_VERSION_1_4; |
| 751 } | 784 } |
| OLD | NEW |