OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.Build; | 7 import android.os.Build; |
8 import android.os.Bundle; | 8 import android.os.Bundle; |
9 import android.os.Parcel; | 9 import android.os.Parcel; |
10 import android.os.ParcelFileDescriptor; | 10 import android.os.ParcelFileDescriptor; |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) { | 496 if (mMemoryDeviceConfig == MEMORY_DEVICE_CONFIG_LOW) { |
497 Log.i(TAG, "Simulating a low-memory device"); | 497 Log.i(TAG, "Simulating a low-memory device"); |
498 } else { | 498 } else { |
499 Log.i(TAG, "Simulating a regular-memory device"); | 499 Log.i(TAG, "Simulating a regular-memory device"); |
500 } | 500 } |
501 } | 501 } |
502 } | 502 } |
503 } | 503 } |
504 | 504 |
505 /** | 505 /** |
506 * Determine whether a library is the linker library. | 506 * Determine whether a library is the linker library. Also deal with the |
| 507 * component build that adds a .cr suffix to the name. |
507 * | 508 * |
508 * @param library the name of the library. | 509 * @param library the name of the library. |
509 * @return true is the library is the Linker's own JNI library. | 510 * @return true is the library is the Linker's own JNI library. |
510 */ | 511 */ |
511 public boolean isChromiumLinkerLibrary(String library) { | 512 public boolean isChromiumLinkerLibrary(String library) { |
512 return library.equals(LINKER_JNI_LIBRARY); | 513 return library.equals(LINKER_JNI_LIBRARY) || library.equals(LINKER_JNI_L
IBRARY + ".cr"); |
513 } | 514 } |
514 | 515 |
515 /** | 516 /** |
516 * Load the Linker JNI library. Throws UnsatisfiedLinkError on error. | 517 * Load the Linker JNI library. Throws UnsatisfiedLinkError on error. |
| 518 * In a component build, the suffix ".cr" is added to each library name, so |
| 519 * if the initial load fails we retry with a suffix. |
517 */ | 520 */ |
518 protected static void loadLinkerJniLibrary() { | 521 protected static void loadLinkerJniLibrary() { |
519 String libName = "lib" + LINKER_JNI_LIBRARY + ".so"; | 522 String libName = "lib" + LINKER_JNI_LIBRARY + ".so"; |
520 if (DEBUG) { | 523 if (DEBUG) { |
521 Log.i(TAG, "Loading " + libName); | 524 Log.i(TAG, "Loading " + libName); |
522 } | 525 } |
523 System.loadLibrary(LINKER_JNI_LIBRARY); | 526 try { |
| 527 System.loadLibrary(LINKER_JNI_LIBRARY); |
| 528 } catch (UnsatisfiedLinkError e) { |
| 529 Log.w(TAG, "Couldn't load " + libName + ", trying " + libName + ".cr
"); |
| 530 System.loadLibrary(LINKER_JNI_LIBRARY + ".cr"); |
| 531 } |
524 } | 532 } |
525 | 533 |
526 /** | 534 /** |
527 * Obtain a random base load address at which to place loaded libraries. | 535 * Obtain a random base load address at which to place loaded libraries. |
528 * | 536 * |
529 * @return new base load address | 537 * @return new base load address |
530 */ | 538 */ |
531 protected long getRandomBaseLoadAddress() { | 539 protected long getRandomBaseLoadAddress() { |
532 // nativeGetRandomBaseLoadAddress() returns an address at which it has p
reviously | 540 // nativeGetRandomBaseLoadAddress() returns an address at which it has p
reviously |
533 // successfully mapped an area larger than the largest library we expect
to load, | 541 // successfully mapped an area larger than the largest library we expect
to load, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 * Return a random address that should be free to be mapped with the given s
ize. | 824 * Return a random address that should be free to be mapped with the given s
ize. |
817 * Maps an area large enough for the largest library we might attempt to loa
d, | 825 * Maps an area large enough for the largest library we might attempt to loa
d, |
818 * and if successful then unmaps it and returns the address of the area allo
cated | 826 * and if successful then unmaps it and returns the address of the area allo
cated |
819 * by the system (with ASLR). The idea is that this area should remain free
of | 827 * by the system (with ASLR). The idea is that this area should remain free
of |
820 * other mappings until we map our library into it. | 828 * other mappings until we map our library into it. |
821 * | 829 * |
822 * @return address to pass to future mmap, or 0 on error. | 830 * @return address to pass to future mmap, or 0 on error. |
823 */ | 831 */ |
824 private static native long nativeGetRandomBaseLoadAddress(); | 832 private static native long nativeGetRandomBaseLoadAddress(); |
825 } | 833 } |
OLD | NEW |