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. Also deal with the | 506 * Determine whether a library is the linker library. |
507 * component build that adds a .cr suffix to the name. | |
508 * | 507 * |
509 * @param library the name of the library. | 508 * @param library the name of the library. |
510 * @return true is the library is the Linker's own JNI library. | 509 * @return true is the library is the Linker's own JNI library. |
511 */ | 510 */ |
512 public boolean isChromiumLinkerLibrary(String library) { | 511 public boolean isChromiumLinkerLibrary(String library) { |
513 return library.equals(LINKER_JNI_LIBRARY) || library.equals(LINKER_JNI_L
IBRARY + ".cr"); | 512 return library.equals(LINKER_JNI_LIBRARY); |
514 } | 513 } |
515 | 514 |
516 /** | 515 /** |
517 * Load the Linker JNI library. Throws UnsatisfiedLinkError on error. | 516 * 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. | |
520 */ | 517 */ |
521 protected static void loadLinkerJniLibrary() { | 518 protected static void loadLinkerJniLibrary() { |
522 String libName = "lib" + LINKER_JNI_LIBRARY + ".so"; | 519 String libName = "lib" + LINKER_JNI_LIBRARY + ".so"; |
523 if (DEBUG) { | 520 if (DEBUG) { |
524 Log.i(TAG, "Loading " + libName); | 521 Log.i(TAG, "Loading " + libName); |
525 } | 522 } |
526 try { | 523 System.loadLibrary(LINKER_JNI_LIBRARY); |
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 } | |
532 } | 524 } |
533 | 525 |
534 /** | 526 /** |
535 * Obtain a random base load address at which to place loaded libraries. | 527 * Obtain a random base load address at which to place loaded libraries. |
536 * | 528 * |
537 * @return new base load address | 529 * @return new base load address |
538 */ | 530 */ |
539 protected long getRandomBaseLoadAddress() { | 531 protected long getRandomBaseLoadAddress() { |
540 // nativeGetRandomBaseLoadAddress() returns an address at which it has p
reviously | 532 // nativeGetRandomBaseLoadAddress() returns an address at which it has p
reviously |
541 // successfully mapped an area larger than the largest library we expect
to load, | 533 // 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... |
824 * Return a random address that should be free to be mapped with the given s
ize. | 816 * Return a random address that should be free to be mapped with the given s
ize. |
825 * Maps an area large enough for the largest library we might attempt to loa
d, | 817 * Maps an area large enough for the largest library we might attempt to loa
d, |
826 * and if successful then unmaps it and returns the address of the area allo
cated | 818 * and if successful then unmaps it and returns the address of the area allo
cated |
827 * by the system (with ASLR). The idea is that this area should remain free
of | 819 * by the system (with ASLR). The idea is that this area should remain free
of |
828 * other mappings until we map our library into it. | 820 * other mappings until we map our library into it. |
829 * | 821 * |
830 * @return address to pass to future mmap, or 0 on error. | 822 * @return address to pass to future mmap, or 0 on error. |
831 */ | 823 */ |
832 private static native long nativeGetRandomBaseLoadAddress(); | 824 private static native long nativeGetRandomBaseLoadAddress(); |
833 } | 825 } |
OLD | NEW |