Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / content / shell / android / linker_test_apk / src / org / chromium / content_linker_test_apk / LinkerTests.java
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content_linker_test_apk;
6
7 import android.util.Log;
8
9 import org.chromium.base.JNINamespace;
10 import org.chromium.content.app.Linker;
11
12 // A class that is only used in linker test APK to perform runtime checks
13 // in the current process.
14 @JNINamespace("content")
15 public class LinkerTests implements Linker.TestRunner {
16     private static final String TAG = "LinkerTests";
17
18     public LinkerTests() {}
19
20     public boolean runChecks(int memoryDeviceConfig,
21                              boolean isBrowserProcess) {
22         boolean checkSharedRelro;
23         if (isBrowserProcess) {
24             switch (Linker.BROWSER_SHARED_RELRO_CONFIG) {
25                 case Linker.BROWSER_SHARED_RELRO_CONFIG_NEVER:
26                     checkSharedRelro = false;
27                     break;
28                 case Linker.BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
29                     // A shared RELRO should only be used on low-end devices.
30                     checkSharedRelro =
31                             (memoryDeviceConfig == Linker.MEMORY_DEVICE_CONFIG_LOW);
32                     break;
33                 case Linker.BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
34                     // Always check for a shared RELRO.
35                     checkSharedRelro = true;
36                     break;
37                 default:
38                     Log.e(TAG, "Invalid shared RELRO linker configuration: " +
39                           Linker.BROWSER_SHARED_RELRO_CONFIG);
40                     return false;
41             }
42         } else {
43           // Service processes should always use a shared RELRO section.
44           checkSharedRelro = true;
45         }
46
47         if (checkSharedRelro)
48             return nativeCheckForSharedRelros(isBrowserProcess);
49         else
50             return nativeCheckForNoSharedRelros(isBrowserProcess);
51     }
52
53     // Check that there are shared RELRO sections in the current process,
54     // and that they are properly mapped read-only. Returns true on success.
55     private static native boolean nativeCheckForSharedRelros(boolean isBrowserProcess);
56
57     // Check that there are no shared RELRO sections in the current process,
58     // return true on success.
59     private static native boolean nativeCheckForNoSharedRelros(boolean isBrowserProcess);
60
61 }