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 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 * - Compute the fixed address to be used to load the same library | 129 * - Compute the fixed address to be used to load the same library |
130 * in service processes. | 130 * in service processes. |
131 * - Create a shared memory region populated with the RELRO region | 131 * - Create a shared memory region populated with the RELRO region |
132 * content pre-relocated for the specific fixed address above. | 132 * content pre-relocated for the specific fixed address above. |
133 * | 133 * |
134 * Note that these shared RELRO regions cannot be used inside the browser | 134 * Note that these shared RELRO regions cannot be used inside the browser |
135 * process. They are also never mapped into it. | 135 * process. They are also never mapped into it. |
136 * | 136 * |
137 * This behaviour is altered by the BROWSER_SHARED_RELRO_CONFIG configuration | 137 * This behaviour is altered by the BROWSER_SHARED_RELRO_CONFIG configuration |
138 * variable below, which may force the browser to load the libraries at | 138 * variable below, which may force the browser to load the libraries at |
139 * fixed addresses to. | 139 * fixed addresses too. |
140 * | 140 * |
141 * - Once all libraries are loaded in the browser process, one can call | 141 * - Once all libraries are loaded in the browser process, one can call |
142 * getSharedRelros() which returns a Bundle instance containing a map that | 142 * getSharedRelros() which returns a Bundle instance containing a map that |
143 * links each loaded library to its shared RELRO region. | 143 * links each loaded library to its shared RELRO region. |
144 * | 144 * |
145 * This Bundle must be passed to each service process, for example through | 145 * This Bundle must be passed to each service process, for example through |
146 * a Binder call (note that the Bundle includes file descriptors and cannot | 146 * a Binder call (note that the Bundle includes file descriptors and cannot |
147 * be added as an Intent extra). | 147 * be added as an Intent extra). |
148 * | 148 * |
149 * - In a service process, finishLibraryLoad() will block until the RELRO | 149 * - In a service process, finishLibraryLoad() will block until the RELRO |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 * for the browser process. | 375 * for the browser process. |
376 */ | 376 */ |
377 public static boolean isUsingBrowserSharedRelros() { | 377 public static boolean isUsingBrowserSharedRelros() { |
378 synchronized (Linker.class) { | 378 synchronized (Linker.class) { |
379 ensureInitializedLocked(); | 379 ensureInitializedLocked(); |
380 return sBrowserUsesSharedRelro; | 380 return sBrowserUsesSharedRelro; |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 /** | 384 /** |
| 385 * Call this method to determine if the linker is running in the browser |
| 386 * process. |
| 387 * |
| 388 * @return true if the linker is running in the browser process. |
| 389 */ |
| 390 public static boolean isInBrowserProcess() { |
| 391 synchronized (Linker.class) { |
| 392 ensureInitializedLocked(); |
| 393 return sInBrowserProcess; |
| 394 } |
| 395 } |
| 396 |
| 397 /** |
385 * Call this method to determine if the chromium project must load | 398 * Call this method to determine if the chromium project must load |
386 * the library directly from the zip file. | 399 * the library directly from the zip file. |
387 */ | 400 */ |
388 public static boolean isInZipFile() { | 401 public static boolean isInZipFile() { |
389 return NativeLibraries.USE_LIBRARY_IN_ZIP_FILE; | 402 return NativeLibraries.USE_LIBRARY_IN_ZIP_FILE; |
390 } | 403 } |
391 | 404 |
392 /** | 405 /** |
393 * Call this method just before loading any native shared libraries in this
process. | 406 * Call this method just before loading any native shared libraries in this
process. |
394 */ | 407 */ |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 // only. | 826 // only. |
814 sCurrentLoadAddress = libInfo.mLoadAddress + libInfo.mLoadSize; | 827 sCurrentLoadAddress = libInfo.mLoadAddress + libInfo.mLoadSize; |
815 } | 828 } |
816 | 829 |
817 sLoadedLibraries.put(libName, libInfo); | 830 sLoadedLibraries.put(libName, libInfo); |
818 if (DEBUG) Log.i(TAG, "Library details " + libInfo.toString()); | 831 if (DEBUG) Log.i(TAG, "Library details " + libInfo.toString()); |
819 } | 832 } |
820 } | 833 } |
821 | 834 |
822 /** | 835 /** |
| 836 * Check whether the device supports loading a library directly from the APK
file. |
| 837 * |
| 838 * @param apkFile Filename of the APK. |
| 839 * @return true if supported. |
| 840 */ |
| 841 public static boolean checkLibraryLoadFromApkSupport(String apkFile) { |
| 842 synchronized (Linker.class) { |
| 843 ensureInitializedLocked(); |
| 844 |
| 845 if (DEBUG) Log.i(TAG, "checkLibraryLoadFromApkSupported: " + apkFile
); |
| 846 boolean supported = nativeCheckLibraryLoadFromApkSupport(apkFile); |
| 847 if (DEBUG) Log.i(TAG, "Loading a library directly from the APK file
" + |
| 848 (supported ? "" : "NOT ") + "supported"); |
| 849 return supported; |
| 850 } |
| 851 } |
| 852 |
| 853 /** |
823 * Move activity from the native thread to the main UI thread. | 854 * Move activity from the native thread to the main UI thread. |
824 * Called from native code on its own thread. Posts a callback from | 855 * Called from native code on its own thread. Posts a callback from |
825 * the UI thread back to native code. | 856 * the UI thread back to native code. |
826 * | 857 * |
827 * @param opaque Opaque argument. | 858 * @param opaque Opaque argument. |
828 */ | 859 */ |
829 @CalledByNative | 860 @CalledByNative |
830 public static void postCallbackOnMainThread(final long opaque) { | 861 public static void postCallbackOnMainThread(final long opaque) { |
831 ThreadUtils.postOnUiThread(new Runnable() { | 862 ThreadUtils.postOnUiThread(new Runnable() { |
832 @Override | 863 @Override |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 * Maps an area of size bytes, and if successful then unmaps it and returns | 941 * Maps an area of size bytes, and if successful then unmaps it and returns |
911 * the address of the area allocated by the system (with ASLR). The idea is | 942 * the address of the area allocated by the system (with ASLR). The idea is |
912 * that this area should remain free of other mappings until we map our libr
ary | 943 * that this area should remain free of other mappings until we map our libr
ary |
913 * into it. | 944 * into it. |
914 * @param sizeBytes Size of area in bytes to search for. | 945 * @param sizeBytes Size of area in bytes to search for. |
915 * @return address to pass to future mmap, or 0 on error. | 946 * @return address to pass to future mmap, or 0 on error. |
916 */ | 947 */ |
917 private static native long nativeGetRandomBaseLoadAddress(long sizeBytes); | 948 private static native long nativeGetRandomBaseLoadAddress(long sizeBytes); |
918 | 949 |
919 /** | 950 /** |
| 951 * Native method which checks whether the device supports loading a library |
| 952 * directly from the APK file. |
| 953 * |
| 954 * @param apkFile Filename of the APK. |
| 955 * @return true if supported. |
| 956 * |
| 957 */ |
| 958 private static native boolean nativeCheckLibraryLoadFromApkSupport(String ap
kFile); |
| 959 |
| 960 /** |
920 * Record information for a given library. | 961 * Record information for a given library. |
921 * IMPORTANT: Native code knows about this class's fields, so | 962 * IMPORTANT: Native code knows about this class's fields, so |
922 * don't change them without modifying the corresponding C++ sources. | 963 * don't change them without modifying the corresponding C++ sources. |
923 * Also, the LibInfo instance owns the ashmem file descriptor. | 964 * Also, the LibInfo instance owns the ashmem file descriptor. |
924 */ | 965 */ |
925 public static class LibInfo implements Parcelable { | 966 public static class LibInfo implements Parcelable { |
926 | 967 |
927 public LibInfo() { | 968 public LibInfo() { |
928 mLoadAddress = 0; | 969 mLoadAddress = 0; |
929 mLoadSize = 0; | 970 mLoadSize = 0; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 } | 1085 } |
1045 } | 1086 } |
1046 | 1087 |
1047 // The map of libraries that are currently loaded in this process. | 1088 // The map of libraries that are currently loaded in this process. |
1048 private static HashMap<String, LibInfo> sLoadedLibraries = null; | 1089 private static HashMap<String, LibInfo> sLoadedLibraries = null; |
1049 | 1090 |
1050 // Used to pass the shared RELRO Bundle through Binder. | 1091 // Used to pass the shared RELRO Bundle through Binder. |
1051 public static final String EXTRA_LINKER_SHARED_RELROS = | 1092 public static final String EXTRA_LINKER_SHARED_RELROS = |
1052 "org.chromium.base.android.linker.shared_relros"; | 1093 "org.chromium.base.android.linker.shared_relros"; |
1053 } | 1094 } |
OLD | NEW |