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.Bundle; | 7 import android.os.Bundle; |
8 import android.os.SystemClock; | 8 import android.os.SystemClock; |
9 | 9 |
10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Initialized to mBaseLoadAddress in prepareLibraryLoad(), and then adjuste
d as each | 55 // Initialized to mBaseLoadAddress in prepareLibraryLoad(), and then adjuste
d as each |
56 // library is loaded by loadLibrary(). | 56 // library is loaded by loadLibrary(). |
57 private long mCurrentLoadAddress = -1; | 57 private long mCurrentLoadAddress = -1; |
58 | 58 |
59 // Becomes true once prepareLibraryLoad() has been called. | 59 // Becomes true once prepareLibraryLoad() has been called. |
60 private boolean mPrepareLibraryLoadCalled = false; | 60 private boolean mPrepareLibraryLoadCalled = false; |
61 | 61 |
62 // The map of libraries that are currently loaded in this process. | 62 // The map of libraries that are currently loaded in this process. |
63 private HashMap<String, LibInfo> mLoadedLibraries = null; | 63 private HashMap<String, LibInfo> mLoadedLibraries = null; |
64 | 64 |
65 // The directory used to hold shared RELRO data files. Set up by prepareLibr
aryLoad(). | |
66 private String mDataDirectory = null; | |
67 | |
68 // Private singleton constructor, and singleton factory method. | 65 // Private singleton constructor, and singleton factory method. |
69 private ModernLinker() { } | 66 private ModernLinker() { } |
70 static Linker create() { | 67 static Linker create() { |
71 return new ModernLinker(); | 68 return new ModernLinker(); |
72 } | 69 } |
73 | 70 |
74 // Used internally to initialize the linker's data. Assumes lock is held. | 71 // Used internally to initialize the linker's data. Assumes lock is held. |
75 private void ensureInitializedLocked() { | 72 private void ensureInitializedLocked() { |
76 assert Thread.holdsLock(mLock); | 73 assert Thread.holdsLock(mLock); |
77 assert NativeLibraries.sUseLinker; | 74 assert NativeLibraries.sUseLinker; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // and create an empty shared RELROs map. For service processes, the
shared | 112 // and create an empty shared RELROs map. For service processes, the
shared |
116 // RELROs map must remain null until set by useSharedRelros(). | 113 // RELROs map must remain null until set by useSharedRelros(). |
117 if (mInBrowserProcess) { | 114 if (mInBrowserProcess) { |
118 setupBaseLoadAddressLocked(); | 115 setupBaseLoadAddressLocked(); |
119 mSharedRelros = new HashMap<String, LibInfo>(); | 116 mSharedRelros = new HashMap<String, LibInfo>(); |
120 } | 117 } |
121 | 118 |
122 // Create an empty loaded libraries map. | 119 // Create an empty loaded libraries map. |
123 mLoadedLibraries = new HashMap<String, LibInfo>(); | 120 mLoadedLibraries = new HashMap<String, LibInfo>(); |
124 | 121 |
125 // Retrieve the data directory from base. | |
126 mDataDirectory = PathUtils.getDataDirectory(null); | |
127 | |
128 // Start the current load address at the base load address. | 122 // Start the current load address at the base load address. |
129 mCurrentLoadAddress = mBaseLoadAddress; | 123 mCurrentLoadAddress = mBaseLoadAddress; |
130 | 124 |
131 mPrepareLibraryLoadCalled = true; | 125 mPrepareLibraryLoadCalled = true; |
132 } | 126 } |
133 } | 127 } |
134 | 128 |
135 /** | 129 /** |
136 * Call this method just after loading all native shared libraries in this p
rocess. | 130 * Call this method just after loading all native shared libraries in this p
rocess. |
137 * If not in the browser, closes the LibInfo entries used for RELRO sharing. | 131 * If not in the browser, closes the LibInfo entries used for RELRO sharing. |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 throw new UnsatisfiedLinkError(errorMessage); | 381 throw new UnsatisfiedLinkError(errorMessage); |
388 } | 382 } |
389 } | 383 } |
390 | 384 |
391 LibInfo libInfo = new LibInfo(); | 385 LibInfo libInfo = new LibInfo(); |
392 | 386 |
393 if (mInBrowserProcess && mCurrentLoadAddress != 0) { | 387 if (mInBrowserProcess && mCurrentLoadAddress != 0) { |
394 // We are in the browser, and with a current load address that i
ndicates that | 388 // We are in the browser, and with a current load address that i
ndicates that |
395 // there is enough address space for shared RELRO to operate. Cr
eate the | 389 // there is enough address space for shared RELRO to operate. Cr
eate the |
396 // shared RELRO, and store it in the map. | 390 // shared RELRO, and store it in the map. |
397 String relroPath = mDataDirectory + "/RELRO:" + libFilePath; | 391 String relroPath = PathUtils.getDataDirectory(null) + "/RELRO:"
+ libFilePath; |
398 if (nativeCreateSharedRelro(dlopenExtPath, | 392 if (nativeCreateSharedRelro(dlopenExtPath, |
399 mCurrentLoadAddress, relroPath, libI
nfo)) { | 393 mCurrentLoadAddress, relroPath, libI
nfo)) { |
400 mSharedRelros.put(dlopenExtPath, libInfo); | 394 mSharedRelros.put(dlopenExtPath, libInfo); |
401 } else { | 395 } else { |
402 String errorMessage = "Unable to create shared relro: " + re
lroPath; | 396 String errorMessage = "Unable to create shared relro: " + re
lroPath; |
403 Log.w(TAG, errorMessage); | 397 Log.w(TAG, errorMessage); |
404 } | 398 } |
405 } else if (!mInBrowserProcess && mCurrentLoadAddress != 0 && mWaitFo
rSharedRelros) { | 399 } else if (!mInBrowserProcess && mCurrentLoadAddress != 0 && mWaitFo
rSharedRelros) { |
406 // We are in a service process, again with a current load addres
s that is | 400 // We are in a service process, again with a current load addres
s that is |
407 // suitable for shared RELRO, and we are to wait for shared RELR
Os. So | 401 // suitable for shared RELRO, and we are to wait for shared RELR
Os. So |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 * @param relroPath Path to the shared RELRO file for this library. | 480 * @param relroPath Path to the shared RELRO file for this library. |
487 * @param libInfo libInfo instance. On success, the mRelroStart, mRelroSize | 481 * @param libInfo libInfo instance. On success, the mRelroStart, mRelroSize |
488 * and mRelroFd will be set. | 482 * and mRelroFd will be set. |
489 * @return true on success, false otherwise. | 483 * @return true on success, false otherwise. |
490 */ | 484 */ |
491 private static native boolean nativeCreateSharedRelro(String dlopenExtPath, | 485 private static native boolean nativeCreateSharedRelro(String dlopenExtPath, |
492 long loadAddress, | 486 long loadAddress, |
493 String relroPath, | 487 String relroPath, |
494 LibInfo libInfo); | 488 LibInfo libInfo); |
495 } | 489 } |
OLD | NEW |