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

Side by Side Diff: base/android/java/src/org/chromium/base/library_loader/Linker.java

Issue 611393002: Rationalize and fix chromium android linker histogram recording. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrite for clearer histogram recording. Created 6 years, 2 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 package org.chromium.base.library_loader; 5 package org.chromium.base.library_loader;
6 6
7 import android.os.Bundle; 7 import android.os.Bundle;
8 import android.os.Parcel; 8 import android.os.Parcel;
9 import android.os.ParcelFileDescriptor; 9 import android.os.ParcelFileDescriptor;
10 import android.os.Parcelable; 10 import android.os.Parcelable;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 208
209 // The map of all RELRO sections either created or used in this process. 209 // The map of all RELRO sections either created or used in this process.
210 private static Bundle sSharedRelros = null; 210 private static Bundle sSharedRelros = null;
211 211
212 // Current common random base load address. 212 // Current common random base load address.
213 private static long sBaseLoadAddress = 0; 213 private static long sBaseLoadAddress = 0;
214 214
215 // Current fixed-location load address for the next library called by loadLi brary(). 215 // Current fixed-location load address for the next library called by loadLi brary().
216 private static long sCurrentLoadAddress = 0; 216 private static long sCurrentLoadAddress = 0;
217 217
218 // Becomes true if any library fails to load at a given, non-0, fixed addres s.
219 private static boolean sLoadAtFixedAddressFailed = false;
220
221 // Becomes true once prepareLibraryLoad() has been called. 218 // Becomes true once prepareLibraryLoad() has been called.
222 private static boolean sPrepareLibraryLoadCalled = false; 219 private static boolean sPrepareLibraryLoadCalled = false;
223 220
224 // Used internally to initialize the linker's static data. Assume lock is he ld. 221 // Used internally to initialize the linker's static data. Assume lock is he ld.
225 private static void ensureInitializedLocked() { 222 private static void ensureInitializedLocked() {
226 assert Thread.holdsLock(Linker.class); 223 assert Thread.holdsLock(Linker.class);
227 224
228 if (!sInitialized) { 225 if (!sInitialized) {
229 sRelroSharingSupported = false; 226 sRelroSharingSupported = false;
230 if (NativeLibraries.USE_LINKER) { 227 if (NativeLibraries.USE_LINKER) {
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 690 }
694 691
695 // In service processes, close all file descriptors from the map now. 692 // In service processes, close all file descriptors from the map now.
696 if (!sInBrowserProcess) 693 if (!sInBrowserProcess)
697 closeLibInfoMap(relroMap); 694 closeLibInfoMap(relroMap);
698 695
699 if (DEBUG) Log.i(TAG, "Linker.useSharedRelrosLocked() exiting"); 696 if (DEBUG) Log.i(TAG, "Linker.useSharedRelrosLocked() exiting");
700 } 697 }
701 698
702 /** 699 /**
703 * Returns whether the linker was unable to load one library at a given fixe d address.
704 *
705 * @return true if at least one library was not loaded at the expected fixed address.
706 */
707 public static boolean loadAtFixedAddressFailed() {
708 return sLoadAtFixedAddressFailed;
709 }
710
711 /**
712 * Load a native shared library with the Chromium linker. 700 * Load a native shared library with the Chromium linker.
713 * The shared library is uncompressed and page aligned inside the zipfile. 701 * The shared library is uncompressed and page aligned inside the zipfile.
714 * Note the crazy linker treats libraries and files as equivalent, 702 * Note the crazy linker treats libraries and files as equivalent,
715 * so you can only open one library in a given zip file. 703 * so you can only open one library in a given zip file.
716 * 704 *
717 * @param zipfile The filename of the zipfile contain the library. 705 * @param zipfile The filename of the zipfile contain the library.
718 * @param library The library's base name. 706 * @param library The library's base name.
719 */ 707 */
720 public static void loadLibraryInZipFile(String zipfile, String library) { 708 public static void loadLibraryInZipFile(String zipfile, String library) {
721 loadLibraryMaybeInZipFile(zipfile, library); 709 loadLibraryMaybeInZipFile(zipfile, library);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 752
765 LibInfo libInfo = new LibInfo(); 753 LibInfo libInfo = new LibInfo();
766 long loadAddress = 0; 754 long loadAddress = 0;
767 if ((sInBrowserProcess && sBrowserUsesSharedRelro) || sWaitForShared Relros) { 755 if ((sInBrowserProcess && sBrowserUsesSharedRelro) || sWaitForShared Relros) {
768 // Load the library at a fixed address. 756 // Load the library at a fixed address.
769 loadAddress = sCurrentLoadAddress; 757 loadAddress = sCurrentLoadAddress;
770 } 758 }
771 759
772 String sharedRelRoName = libName; 760 String sharedRelRoName = libName;
773 if (zipFile != null) { 761 if (zipFile != null) {
774 if (!nativeLoadLibraryInZipFile( 762 if (!nativeLoadLibraryInZipFile(zipFile, libName, loadAddress, l ibInfo)) {
775 zipFile, libName, loadAddress, libInfo)) { 763 String errorMessage = "Unable to load library: " + libName +
776 String errorMessage = 764 ", in: " + zipFile;
777 "Unable to load library: " + libName + " in: " +
778 zipFile;
779 Log.e(TAG, errorMessage); 765 Log.e(TAG, errorMessage);
780 throw new UnsatisfiedLinkError(errorMessage); 766 throw new UnsatisfiedLinkError(errorMessage);
781 } 767 }
782 sharedRelRoName = zipFile; 768 sharedRelRoName = zipFile;
783 } else { 769 } else {
784 if (!nativeLoadLibrary(libName, loadAddress, libInfo)) { 770 if (!nativeLoadLibrary(libName, loadAddress, libInfo)) {
785 String errorMessage = "Unable to load library: " + libName; 771 String errorMessage = "Unable to load library: " + libName;
786 Log.e(TAG, errorMessage); 772 Log.e(TAG, errorMessage);
787 throw new UnsatisfiedLinkError(errorMessage); 773 throw new UnsatisfiedLinkError(errorMessage);
788 } 774 }
789 } 775 }
790 // Keep track whether the library has been loaded at the expected lo ad address.
791 if (loadAddress != 0 && loadAddress != libInfo.mLoadAddress)
792 sLoadAtFixedAddressFailed = true;
793 776
794 // Print the load address to the logcat when testing the linker. The format 777 // Print the load address to the logcat when testing the linker. The format
795 // of the string is expected by the Python test_runner script as one of: 778 // of the string is expected by the Python test_runner script as one of:
796 // BROWSER_LIBRARY_ADDRESS: <library-name> <address> 779 // BROWSER_LIBRARY_ADDRESS: <library-name> <address>
797 // RENDERER_LIBRARY_ADDRESS: <library-name> <address> 780 // RENDERER_LIBRARY_ADDRESS: <library-name> <address>
798 // Where <library-name> is the library name, and <address> is the he xadecimal load 781 // Where <library-name> is the library name, and <address> is the he xadecimal load
799 // address. 782 // address.
800 if (NativeLibraries.ENABLE_LINKER_TESTS) { 783 if (NativeLibraries.ENABLE_LINKER_TESTS) {
801 Log.i(TAG, String.format( 784 Log.i(TAG, String.format(
802 Locale.US, 785 Locale.US,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1044 }
1062 } 1045 }
1063 1046
1064 // The map of libraries that are currently loaded in this process. 1047 // The map of libraries that are currently loaded in this process.
1065 private static HashMap<String, LibInfo> sLoadedLibraries = null; 1048 private static HashMap<String, LibInfo> sLoadedLibraries = null;
1066 1049
1067 // Used to pass the shared RELRO Bundle through Binder. 1050 // Used to pass the shared RELRO Bundle through Binder.
1068 public static final String EXTRA_LINKER_SHARED_RELROS = 1051 public static final String EXTRA_LINKER_SHARED_RELROS =
1069 "org.chromium.base.android.linker.shared_relros"; 1052 "org.chromium.base.android.linker.shared_relros";
1070 } 1053 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698