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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 char buffer[kMaxFilePathLengthInZip + 1]; | 602 char buffer[kMaxFilePathLengthInZip + 1]; |
603 if (crazy_library_file_path_in_zip_file( | 603 if (crazy_library_file_path_in_zip_file( |
604 lib_name_c_str, buffer, sizeof(buffer)) == CRAZY_STATUS_FAILURE) { | 604 lib_name_c_str, buffer, sizeof(buffer)) == CRAZY_STATUS_FAILURE) { |
605 LOG_ERROR("%s: Failed to get full filename for library '%s'", | 605 LOG_ERROR("%s: Failed to get full filename for library '%s'", |
606 __FUNCTION__, lib_name_c_str); | 606 __FUNCTION__, lib_name_c_str); |
607 buffer[0] = '\0'; | 607 buffer[0] = '\0'; |
608 } | 608 } |
609 return env->NewStringUTF(buffer); | 609 return env->NewStringUTF(buffer); |
610 } | 610 } |
611 | 611 |
| 612 // Prefault the pages of a native library stored in a zip file. |
| 613 // |
| 614 // |env| is the current JNI environment handle. |
| 615 // |clazz| is the static class handle which is not used here. |
| 616 // |lib_name| is the library base name. |
| 617 // Returns true for success. |
| 618 jboolean PrefaultLibraryInZipFile(JNIEnv* env, jclass clazz, |
| 619 jstring zip_filename, jstring lib_name) { |
| 620 char path_in_zip[kMaxFilePathLengthInZip + 1]; |
| 621 crazy_status_t status; |
| 622 String lib_name_str(env, lib_name); |
| 623 String zip_filename_str(env, zip_filename); |
| 624 int offset, size; |
| 625 |
| 626 status = crazy_library_file_path_in_zip_file(lib_name_str.c_str(), |
| 627 path_in_zip, 256); |
| 628 if (status == CRAZY_STATUS_FAILURE) return false; |
| 629 status = crazy_library_offset_size_in_zip_file(zip_filename_str.c_str(), |
| 630 path_in_zip, &offset, &size); |
| 631 if (status == CRAZY_STATUS_FAILURE) return false; |
| 632 status = crazy_prefault_library(zip_filename_str.c_str(), offset, size); |
| 633 return true; |
| 634 } |
| 635 |
| 636 // Prefault the pages of a native library. |
| 637 // |
| 638 // |env| is the current JNI environment handle. |
| 639 // |clazz| is the static class handle which is not used here. |
| 640 // |lib_filename| is the library file name. |
| 641 // Returns true for success. |
| 642 jboolean PrefaultLibraryInFile(JNIEnv* env, jclass clazz, |
| 643 jstring lib_filename) { |
| 644 String lib_filename_str(env, lib_filename); |
| 645 |
| 646 return (crazy_prefault_library(lib_filename_str.c_str(), 0, -1) |
| 647 == CRAZY_STATUS_SUCCESS); |
| 648 } |
| 649 |
612 // Check whether the device supports mapping the APK file with executable | 650 // Check whether the device supports mapping the APK file with executable |
613 // permission. | 651 // permission. |
614 // | 652 // |
615 // |env| is the current JNI environment handle. | 653 // |env| is the current JNI environment handle. |
616 // |clazz| is the static class handle which is not used here. | 654 // |clazz| is the static class handle which is not used here. |
617 // |apkfile_name| is the filename of the APK. | 655 // |apkfile_name| is the filename of the APK. |
618 // Returns true if supported. | 656 // Returns true if supported. |
619 jboolean CheckMapExecSupport(JNIEnv* env, jclass clazz, jstring apkfile_name) { | 657 jboolean CheckMapExecSupport(JNIEnv* env, jclass clazz, jstring apkfile_name) { |
620 String apkfile_name_str(env, apkfile_name); | 658 String apkfile_name_str(env, apkfile_name); |
621 const char* apkfile_name_c_str = apkfile_name_str.c_str(); | 659 const char* apkfile_name_c_str = apkfile_name_str.c_str(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 "J" | 761 "J" |
724 ")" | 762 ")" |
725 "J", | 763 "J", |
726 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, | 764 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, |
727 {"nativeGetLibraryFilePathInZipFile", | 765 {"nativeGetLibraryFilePathInZipFile", |
728 "(" | 766 "(" |
729 "Ljava/lang/String;" | 767 "Ljava/lang/String;" |
730 ")" | 768 ")" |
731 "Ljava/lang/String;", | 769 "Ljava/lang/String;", |
732 reinterpret_cast<void*>(&GetLibraryFilePathInZipFile)}, | 770 reinterpret_cast<void*>(&GetLibraryFilePathInZipFile)}, |
| 771 {"nativePrefaultLibraryInFile", |
| 772 "(" |
| 773 "Ljava/lang/String;" |
| 774 ")" |
| 775 "Z", |
| 776 reinterpret_cast<void*>(&PrefaultLibraryInFile) |
| 777 }, |
| 778 {"nativePrefaultLibraryInZipFile", |
| 779 "(" |
| 780 "Ljava/lang/String;" |
| 781 "Ljava/lang/String;" |
| 782 ")" |
| 783 "Z", |
| 784 reinterpret_cast<void*>(&PrefaultLibraryInZipFile) |
| 785 }, |
733 {"nativeCheckMapExecSupport", | 786 {"nativeCheckMapExecSupport", |
734 "(" | 787 "(" |
735 "Ljava/lang/String;" | 788 "Ljava/lang/String;" |
736 ")" | 789 ")" |
737 "Z", | 790 "Z", |
738 reinterpret_cast<void*>(&CheckMapExecSupport)}, | 791 reinterpret_cast<void*>(&CheckMapExecSupport)}, |
739 {"nativeCheckLibraryIsMappableInApk", | 792 {"nativeCheckLibraryIsMappableInApk", |
740 "(" | 793 "(" |
741 "Ljava/lang/String;" | 794 "Ljava/lang/String;" |
742 "Ljava/lang/String;" | 795 "Ljava/lang/String;" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 crazy_context_t* context = GetCrazyContext(); | 839 crazy_context_t* context = GetCrazyContext(); |
787 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); | 840 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); |
788 | 841 |
789 // Register the function that the crazy linker can call to post code | 842 // Register the function that the crazy linker can call to post code |
790 // for later execution. | 843 // for later execution. |
791 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); | 844 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); |
792 | 845 |
793 LOG_INFO("%s: Done", __FUNCTION__); | 846 LOG_INFO("%s: Done", __FUNCTION__); |
794 return JNI_VERSION_1_4; | 847 return JNI_VERSION_1_4; |
795 } | 848 } |
OLD | NEW |