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.content.app; | 5 package org.chromium.content.app; |
6 | 6 |
7 import android.content.Intent; | 7 import android.os.Parcel; |
| 8 import android.os.Parcelable; |
8 | 9 |
9 import java.util.Locale; | 10 import java.util.Locale; |
10 | 11 |
| 12 import javax.annotation.concurrent.Immutable; |
| 13 |
11 /** | 14 /** |
12 * A class to hold information passed from the browser process to each | 15 * A class to hold information passed from the browser process to each |
13 * service one when using the chromium linker. For more information, read the | 16 * service one when using the chromium linker. For more information, read the |
14 * technical notes in Linker.java. | 17 * technical notes in Linker.java. |
15 */ | 18 */ |
16 public class ChromiumLinkerParams { | 19 @Immutable |
| 20 public class ChromiumLinkerParams implements Parcelable { |
17 // Use this base address to load native shared libraries. If 0, ignore other
members. | 21 // Use this base address to load native shared libraries. If 0, ignore other
members. |
18 public final long mBaseLoadAddress; | 22 public final long mBaseLoadAddress; |
19 | 23 |
20 // If true, wait for a shared RELRO Bundle just after loading the libraries. | 24 // If true, wait for a shared RELRO Bundle just after loading the libraries. |
21 public final boolean mWaitForSharedRelro; | 25 public final boolean mWaitForSharedRelro; |
22 | 26 |
23 // If not empty, name of Linker.TestRunner implementation that needs to be | 27 // If not empty, name of Linker.TestRunner implementation that needs to be |
24 // registered in the service process. | 28 // registered in the service process. |
25 public final String mTestRunnerClassNameForTesting; | 29 public final String mTestRunnerClassNameForTesting; |
26 | 30 |
27 // If mTestRunnerClassNameForTesting is not empty, the Linker implementation | 31 // If mTestRunnerClassNameForTesting is not empty, the Linker implementation |
28 // to force for testing. | 32 // to force for testing. |
29 public final int mLinkerImplementationForTesting; | 33 public final int mLinkerImplementationForTesting; |
30 | 34 |
31 private static final String EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS = | 35 public ChromiumLinkerParams(long baseLoadAddress, boolean waitForSharedRelro
) { |
32 "org.chromium.content.common.linker_params.base_load_address"; | |
33 | |
34 private static final String EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO = | |
35 "org.chromium.content.common.linker_params.wait_for_shared_relro"; | |
36 | |
37 private static final String EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME = | |
38 "org.chromium.content.common.linker_params.test_runner_class_name"; | |
39 | |
40 private static final String EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION = | |
41 "org.chromium.content.common.linker_params.linker_implementation"; | |
42 | |
43 public ChromiumLinkerParams(long baseLoadAddress, | |
44 boolean waitForSharedRelro) { | |
45 mBaseLoadAddress = baseLoadAddress; | 36 mBaseLoadAddress = baseLoadAddress; |
46 mWaitForSharedRelro = waitForSharedRelro; | 37 mWaitForSharedRelro = waitForSharedRelro; |
47 mTestRunnerClassNameForTesting = null; | 38 mTestRunnerClassNameForTesting = null; |
48 mLinkerImplementationForTesting = 0; | 39 mLinkerImplementationForTesting = 0; |
49 } | 40 } |
50 | 41 |
51 /** | 42 /** |
52 * Use this constructor to create a LinkerParams instance for testing. | 43 * Use this constructor to create a LinkerParams instance for testing. |
53 */ | 44 */ |
54 public ChromiumLinkerParams(long baseLoadAddress, | 45 public ChromiumLinkerParams(long baseLoadAddress, |
55 boolean waitForSharedRelro, | 46 boolean waitForSharedRelro, |
56 String testRunnerClassName, | 47 String testRunnerClassName, |
57 int linkerImplementation) { | 48 int linkerImplementation) { |
58 mBaseLoadAddress = baseLoadAddress; | 49 mBaseLoadAddress = baseLoadAddress; |
59 mWaitForSharedRelro = waitForSharedRelro; | 50 mWaitForSharedRelro = waitForSharedRelro; |
60 mTestRunnerClassNameForTesting = testRunnerClassName; | 51 mTestRunnerClassNameForTesting = testRunnerClassName; |
61 mLinkerImplementationForTesting = linkerImplementation; | 52 mLinkerImplementationForTesting = linkerImplementation; |
62 } | 53 } |
63 | 54 |
64 /** | 55 ChromiumLinkerParams(Parcel in) { |
65 * Use this constructor to recreate a LinkerParams instance from an Intent. | 56 mBaseLoadAddress = in.readLong(); |
66 * | 57 mWaitForSharedRelro = in.readInt() != 0; |
67 * @param intent An Intent, its content must have been populated by a previo
us | 58 mTestRunnerClassNameForTesting = in.readString(); |
68 * call to addIntentExtras(). | 59 mLinkerImplementationForTesting = in.readInt(); |
69 */ | |
70 public ChromiumLinkerParams(Intent intent) { | |
71 mBaseLoadAddress = | |
72 intent.getLongExtra(EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS, 0); | |
73 mWaitForSharedRelro = | |
74 intent.getBooleanExtra(EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO
, false); | |
75 mTestRunnerClassNameForTesting = | |
76 intent.getStringExtra(EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME
); | |
77 mLinkerImplementationForTesting = | |
78 intent.getIntExtra(EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION, 0)
; | |
79 } | 60 } |
80 | 61 |
81 /** | 62 @Override |
82 * Ensure this LinkerParams instance is sent to a service process by adding | 63 public int describeContents() { |
83 * it to an intent's extras. | 64 return 0; |
84 * | |
85 * @param intent An Intent use to start or connect to the child service proc
ess. | |
86 */ | |
87 public void addIntentExtras(Intent intent) { | |
88 intent.putExtra(EXTRA_LINKER_PARAMS_BASE_LOAD_ADDRESS, mBaseLoadAddress)
; | |
89 intent.putExtra(EXTRA_LINKER_PARAMS_WAIT_FOR_SHARED_RELRO, mWaitForShare
dRelro); | |
90 intent.putExtra(EXTRA_LINKER_PARAMS_TEST_RUNNER_CLASS_NAME, mTestRunnerC
lassNameForTesting); | |
91 intent.putExtra(EXTRA_LINKER_PARAMS_LINKER_IMPLEMENTATION, mLinkerImplem
entationForTesting); | |
92 } | 65 } |
93 | 66 |
| 67 @Override |
| 68 public void writeToParcel(Parcel dest, int flags) { |
| 69 dest.writeLong(mBaseLoadAddress); |
| 70 dest.writeInt(mWaitForSharedRelro ? 1 : 0); |
| 71 dest.writeString(mTestRunnerClassNameForTesting); |
| 72 dest.writeInt(mLinkerImplementationForTesting); |
| 73 } |
| 74 |
| 75 public static final Parcelable.Creator<ChromiumLinkerParams> CREATOR = |
| 76 new Parcelable.Creator<ChromiumLinkerParams>() { |
| 77 @Override |
| 78 public ChromiumLinkerParams createFromParcel(Parcel in) { |
| 79 return new ChromiumLinkerParams(in); |
| 80 } |
| 81 |
| 82 @Override |
| 83 public ChromiumLinkerParams[] newArray(int size) { |
| 84 return new ChromiumLinkerParams[size]; |
| 85 } |
| 86 }; |
| 87 |
94 // For debugging traces only. | 88 // For debugging traces only. |
95 @Override | 89 @Override |
96 public String toString() { | 90 public String toString() { |
97 return String.format(Locale.US, | 91 return String.format(Locale.US, |
98 "LinkerParams(baseLoadAddress:0x%x, waitForSharedRelro:%s, " | 92 "LinkerParams(baseLoadAddress:0x%x, waitForSharedRelro:%s, " |
99 + "testRunnerClassName:%s, linkerImplementation:%d", | 93 + "testRunnerClassName:%s, linkerImplementation:%d", |
100 mBaseLoadAddress, | 94 mBaseLoadAddress, Boolean.toString(mWaitForSharedRelro), |
101 mWaitForSharedRelro ? "true" : "false", | 95 mTestRunnerClassNameForTesting, mLinkerImplementationForTesting)
; |
102 mTestRunnerClassNameForTesting, | |
103 mLinkerImplementationForTesting); | |
104 } | 96 } |
105 } | 97 } |
OLD | NEW |