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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 if (NativeLibraries.sUseLinker) { | 230 if (NativeLibraries.sUseLinker) { |
231 if (DEBUG) Log.i(TAG, "Loading lib" + TAG + ".so"); | 231 if (DEBUG) Log.i(TAG, "Loading lib" + TAG + ".so"); |
232 try { | 232 try { |
233 System.loadLibrary(TAG); | 233 System.loadLibrary(TAG); |
234 } catch (UnsatisfiedLinkError e) { | 234 } catch (UnsatisfiedLinkError e) { |
235 // In a component build, the ".cr" suffix is added to each l
ibrary name. | 235 // In a component build, the ".cr" suffix is added to each l
ibrary name. |
236 Log.w(TAG, "Couldn't load lib" + TAG + ".so, trying lib" + T
AG + ".cr.so"); | 236 Log.w(TAG, "Couldn't load lib" + TAG + ".so, trying lib" + T
AG + ".cr.so"); |
237 System.loadLibrary(TAG + ".cr"); | 237 System.loadLibrary(TAG + ".cr"); |
238 } | 238 } |
239 sRelroSharingSupported = nativeCanUseSharedRelro(); | 239 sRelroSharingSupported = nativeCanUseSharedRelro(); |
240 if (!sRelroSharingSupported) | 240 if (!sRelroSharingSupported) { |
241 Log.w(TAG, "This system cannot safely share RELRO sections")
; | 241 Log.w(TAG, "This system cannot safely share RELRO sections")
; |
242 else { | 242 } else { |
243 if (DEBUG) Log.i(TAG, "This system supports safe shared RELR
O sections"); | 243 if (DEBUG) Log.i(TAG, "This system supports safe shared RELR
O sections"); |
244 } | 244 } |
245 | 245 |
246 if (sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT) { | 246 if (sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT) { |
247 sMemoryDeviceConfig = SysUtils.isLowEndDevice() | 247 sMemoryDeviceConfig = SysUtils.isLowEndDevice() |
248 ? MEMORY_DEVICE_CONFIG_LOW : MEMORY_DEVICE_CONFIG_NO
RMAL; | 248 ? MEMORY_DEVICE_CONFIG_LOW : MEMORY_DEVICE_CONFIG_NO
RMAL; |
249 } | 249 } |
250 | 250 |
251 switch (BROWSER_SHARED_RELRO_CONFIG) { | 251 switch (BROWSER_SHARED_RELRO_CONFIG) { |
252 case BROWSER_SHARED_RELRO_CONFIG_NEVER: | 252 case BROWSER_SHARED_RELRO_CONFIG_NEVER: |
253 sBrowserUsesSharedRelro = false; | 253 sBrowserUsesSharedRelro = false; |
254 break; | 254 break; |
255 case BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY: | 255 case BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY: |
256 sBrowserUsesSharedRelro = | 256 sBrowserUsesSharedRelro = |
257 (sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW
); | 257 (sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW
); |
258 if (sBrowserUsesSharedRelro) | 258 if (sBrowserUsesSharedRelro) { |
259 Log.w(TAG, "Low-memory device: shared RELROs used in
all processes"); | 259 Log.w(TAG, "Low-memory device: shared RELROs used in
all processes"); |
| 260 } |
260 break; | 261 break; |
261 case BROWSER_SHARED_RELRO_CONFIG_ALWAYS: | 262 case BROWSER_SHARED_RELRO_CONFIG_ALWAYS: |
262 Log.w(TAG, "Beware: shared RELROs used in all processes!
"); | 263 Log.w(TAG, "Beware: shared RELROs used in all processes!
"); |
263 sBrowserUsesSharedRelro = true; | 264 sBrowserUsesSharedRelro = true; |
264 break; | 265 break; |
265 default: | 266 default: |
266 assert false : "Unreached"; | 267 assert false : "Unreached"; |
267 break; | 268 break; |
268 } | 269 } |
269 } else { | 270 } else { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 */ | 339 */ |
339 public static void setMemoryDeviceConfig(int memoryDeviceConfig) { | 340 public static void setMemoryDeviceConfig(int memoryDeviceConfig) { |
340 if (DEBUG) Log.i(TAG, "setMemoryDeviceConfig(" + memoryDeviceConfig + ")
called"); | 341 if (DEBUG) Log.i(TAG, "setMemoryDeviceConfig(" + memoryDeviceConfig + ")
called"); |
341 // Sanity check. This method should only be called during tests. | 342 // Sanity check. This method should only be called during tests. |
342 assert NativeLibraries.sEnableLinkerTests; | 343 assert NativeLibraries.sEnableLinkerTests; |
343 synchronized (Linker.class) { | 344 synchronized (Linker.class) { |
344 assert sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT; | 345 assert sMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_INIT; |
345 assert memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW | 346 assert memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW |
346 || memoryDeviceConfig == MEMORY_DEVICE_CONFIG_NORMAL; | 347 || memoryDeviceConfig == MEMORY_DEVICE_CONFIG_NORMAL; |
347 if (DEBUG) { | 348 if (DEBUG) { |
348 if (memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) | 349 if (memoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) { |
349 Log.i(TAG, "Simulating a low-memory device"); | 350 Log.i(TAG, "Simulating a low-memory device"); |
350 else | 351 } else { |
351 Log.i(TAG, "Simulating a regular-memory device"); | 352 Log.i(TAG, "Simulating a regular-memory device"); |
| 353 } |
352 } | 354 } |
353 sMemoryDeviceConfig = memoryDeviceConfig; | 355 sMemoryDeviceConfig = memoryDeviceConfig; |
354 } | 356 } |
355 } | 357 } |
356 | 358 |
357 /** | 359 /** |
358 * Call this method to determine if this chromium project must | 360 * Call this method to determine if this chromium project must |
359 * use this linker. If not, System.loadLibrary() should be used to load | 361 * use this linker. If not, System.loadLibrary() should be used to load |
360 * libraries instead. | 362 * libraries instead. |
361 */ | 363 */ |
362 public static boolean isUsed() { | 364 public static boolean isUsed() { |
363 // Only GYP targets that are APKs and have the 'use_chromium_linker' var
iable | 365 // Only GYP targets that are APKs and have the 'use_chromium_linker' var
iable |
364 // defined as 1 will use this linker. For all others (the default), the | 366 // defined as 1 will use this linker. For all others (the default), the |
365 // auto-generated NativeLibraries.sUseLinker variable will be false. | 367 // auto-generated NativeLibraries.sUseLinker variable will be false. |
366 if (!NativeLibraries.sUseLinker) | 368 if (!NativeLibraries.sUseLinker) return false; |
367 return false; | |
368 | 369 |
369 synchronized (Linker.class) { | 370 synchronized (Linker.class) { |
370 ensureInitializedLocked(); | 371 ensureInitializedLocked(); |
371 // At the moment, there is also no point in using this linker if the | 372 // At the moment, there is also no point in using this linker if the |
372 // system does not support RELRO sharing safely. | 373 // system does not support RELRO sharing safely. |
373 return sRelroSharingSupported; | 374 return sRelroSharingSupported; |
374 } | 375 } |
375 } | 376 } |
376 | 377 |
377 /** | 378 /** |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 String libName = entry.getKey(); | 687 String libName = entry.getKey(); |
687 LibInfo libInfo = entry.getValue(); | 688 LibInfo libInfo = entry.getValue(); |
688 if (!nativeUseSharedRelro(libName, libInfo)) { | 689 if (!nativeUseSharedRelro(libName, libInfo)) { |
689 Log.w(TAG, "Could not use shared RELRO section for " + libName); | 690 Log.w(TAG, "Could not use shared RELRO section for " + libName); |
690 } else { | 691 } else { |
691 if (DEBUG) Log.i(TAG, "Using shared RELRO section for " + libNam
e); | 692 if (DEBUG) Log.i(TAG, "Using shared RELRO section for " + libNam
e); |
692 } | 693 } |
693 } | 694 } |
694 | 695 |
695 // In service processes, close all file descriptors from the map now. | 696 // In service processes, close all file descriptors from the map now. |
696 if (!sInBrowserProcess) | 697 if (!sInBrowserProcess) closeLibInfoMap(relroMap); |
697 closeLibInfoMap(relroMap); | |
698 | 698 |
699 if (DEBUG) Log.i(TAG, "Linker.useSharedRelrosLocked() exiting"); | 699 if (DEBUG) Log.i(TAG, "Linker.useSharedRelrosLocked() exiting"); |
700 } | 700 } |
701 | 701 |
702 /** | 702 /** |
703 * Load a native shared library with the Chromium linker. If the zip file | 703 * Load a native shared library with the Chromium linker. If the zip file |
704 * is not null, the shared library must be uncompressed and page aligned | 704 * is not null, the shared library must be uncompressed and page aligned |
705 * inside the zipfile. Note the crazy linker treats libraries and files as | 705 * inside the zipfile. Note the crazy linker treats libraries and files as |
706 * equivalent, so you can only open one library in a given zip file. The | 706 * equivalent, so you can only open one library in a given zip file. The |
707 * library must not be the Chromium linker library. | 707 * library must not be the Chromium linker library. |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 } | 1134 } |
1135 } | 1135 } |
1136 | 1136 |
1137 // The map of libraries that are currently loaded in this process. | 1137 // The map of libraries that are currently loaded in this process. |
1138 private static HashMap<String, LibInfo> sLoadedLibraries = null; | 1138 private static HashMap<String, LibInfo> sLoadedLibraries = null; |
1139 | 1139 |
1140 // Used to pass the shared RELRO Bundle through Binder. | 1140 // Used to pass the shared RELRO Bundle through Binder. |
1141 public static final String EXTRA_LINKER_SHARED_RELROS = | 1141 public static final String EXTRA_LINKER_SHARED_RELROS = |
1142 "org.chromium.base.android.linker.shared_relros"; | 1142 "org.chromium.base.android.linker.shared_relros"; |
1143 } | 1143 } |
OLD | NEW |