Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: base/android/linker/linker_jni.cc

Issue 1216703003: [android] Remove unpack library fallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak documentation to not allow null context Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 #if RESERVE_BREAKPAD_GUARD_REGION 651 #if RESERVE_BREAKPAD_GUARD_REGION
652 // Allow for a Breakpad guard region ahead of the returned address. 652 // Allow for a Breakpad guard region ahead of the returned address.
653 address = reinterpret_cast<void*>( 653 address = reinterpret_cast<void*>(
654 reinterpret_cast<uintptr_t>(address) + kBreakpadGuardRegionBytes); 654 reinterpret_cast<uintptr_t>(address) + kBreakpadGuardRegionBytes);
655 #endif 655 #endif
656 656
657 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address); 657 LOG_INFO("%s: Random base load address is %p\n", __FUNCTION__, address);
658 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address)); 658 return static_cast<jlong>(reinterpret_cast<uintptr_t>(address));
659 } 659 }
660 660
661 // Get the full path of a library in the zip file
662 // (lib/<abi>/crazy.<lib_name>).
663 //
664 // |env| is the current JNI environment handle.
665 // |clazz| is the static class handle which is not used here.
666 // |lib_name| is the library base name.
667 // Returns the full path (or empty string on failure).
668 jstring GetLibraryFilePathInZipFile(JNIEnv* env,
669 jclass clazz,
670 jstring lib_name) {
671 String lib_name_str(env, lib_name);
672 const char* lib_name_c_str = lib_name_str.c_str();
673 char buffer[kMaxFilePathLengthInZip + 1];
674 if (crazy_library_file_path_in_zip_file(
675 lib_name_c_str, buffer, sizeof(buffer)) == CRAZY_STATUS_FAILURE) {
676 LOG_ERROR("%s: Failed to get full filename for library '%s'",
677 __FUNCTION__, lib_name_c_str);
678 buffer[0] = '\0';
679 }
680 return env->NewStringUTF(buffer);
681 }
682
683 // Check whether a library is page aligned and uncompressed in the APK file.
684 //
685 // |env| is the current JNI environment handle.
686 // |clazz| is the static class handle which is not used here.
687 // |apkfile_name| is the filename of the APK.
688 // |library_name| is the library base name.
689 // Returns true if page aligned and uncompressed.
690 jboolean CheckLibraryIsMappableInApk(JNIEnv* env, jclass clazz,
691 jstring apkfile_name,
692 jstring library_name) {
693 String apkfile_name_str(env, apkfile_name);
694 const char* apkfile_name_c_str = apkfile_name_str.c_str();
695 String library_name_str(env, library_name);
696 const char* library_name_c_str = library_name_str.c_str();
697
698 LOG_INFO("%s: Checking if %s is page-aligned and uncompressed in %s\n",
699 __FUNCTION__, library_name_c_str, apkfile_name_c_str);
700 jboolean mappable = crazy_linker_check_library_is_mappable_in_zip_file(
701 apkfile_name_c_str, library_name_c_str) == CRAZY_STATUS_SUCCESS;
702 LOG_INFO("%s: %s\n", __FUNCTION__, mappable ? "Mappable" : "NOT mappable");
703
704 return mappable;
705 }
706
707 const JNINativeMethod kNativeMethods[] = { 661 const JNINativeMethod kNativeMethods[] = {
708 {"nativeLoadLibrary", 662 {"nativeLoadLibrary",
709 "(" 663 "("
710 "Ljava/lang/String;" 664 "Ljava/lang/String;"
711 "J" 665 "J"
712 "Lorg/chromium/base/library_loader/Linker$LibInfo;" 666 "Lorg/chromium/base/library_loader/Linker$LibInfo;"
713 ")" 667 ")"
714 "Z", 668 "Z",
715 reinterpret_cast<void*>(&LoadLibrary)}, 669 reinterpret_cast<void*>(&LoadLibrary)},
716 {"nativeLoadLibraryInZipFile", 670 {"nativeLoadLibraryInZipFile",
(...skipping 30 matching lines...) Expand all
747 "(" 701 "("
748 ")" 702 ")"
749 "Z", 703 "Z",
750 reinterpret_cast<void*>(&CanUseSharedRelro)}, 704 reinterpret_cast<void*>(&CanUseSharedRelro)},
751 {"nativeGetRandomBaseLoadAddress", 705 {"nativeGetRandomBaseLoadAddress",
752 "(" 706 "("
753 "J" 707 "J"
754 ")" 708 ")"
755 "J", 709 "J",
756 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)}, 710 reinterpret_cast<void*>(&GetRandomBaseLoadAddress)},
757 {"nativeGetLibraryFilePathInZipFile", 711 };
758 "("
759 "Ljava/lang/String;"
760 ")"
761 "Ljava/lang/String;",
762 reinterpret_cast<void*>(&GetLibraryFilePathInZipFile)},
763 {"nativeCheckLibraryIsMappableInApk",
764 "("
765 "Ljava/lang/String;"
766 "Ljava/lang/String;"
767 ")"
768 "Z",
769 reinterpret_cast<void*>(&CheckLibraryIsMappableInApk)}, };
770 712
771 } // namespace 713 } // namespace
772 714
773 // JNI_OnLoad() hook called when the linker library is loaded through 715 // JNI_OnLoad() hook called when the linker library is loaded through
774 // the regular System.LoadLibrary) API. This shall save the Java VM 716 // the regular System.LoadLibrary) API. This shall save the Java VM
775 // handle and initialize LibInfo fields. 717 // handle and initialize LibInfo fields.
776 jint JNI_OnLoad(JavaVM* vm, void* reserved) { 718 jint JNI_OnLoad(JavaVM* vm, void* reserved) {
777 LOG_INFO("%s: Entering", __FUNCTION__); 719 LOG_INFO("%s: Entering", __FUNCTION__);
778 // Get new JNIEnv 720 // Get new JNIEnv
779 JNIEnv* env; 721 JNIEnv* env;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 crazy_context_t* context = GetCrazyContext(); 757 crazy_context_t* context = GetCrazyContext();
816 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4); 758 crazy_context_set_java_vm(context, vm, JNI_VERSION_1_4);
817 759
818 // Register the function that the crazy linker can call to post code 760 // Register the function that the crazy linker can call to post code
819 // for later execution. 761 // for later execution.
820 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL); 762 crazy_context_set_callback_poster(context, &PostForLaterExecution, NULL);
821 763
822 LOG_INFO("%s: Done", __FUNCTION__); 764 LOG_INFO("%s: Done", __FUNCTION__);
823 return JNI_VERSION_1_4; 765 return JNI_VERSION_1_4;
824 } 766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698