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
3 // found in the LICENSE file.
5 package org.chromium.chromium_linker_test_apk;
7 import android.util.Log;
9 import org.chromium.base.JNINamespace;
10 import org.chromium.base.library_loader.Linker;
13 * A class that is only used in linker test APK to perform runtime checks
14 * in the current process.
16 @JNINamespace("content")
17 public class LinkerTests implements Linker.TestRunner {
18 private static final String TAG = "LinkerTests";
20 public LinkerTests() {}
23 public boolean runChecks(int memoryDeviceConfig,
24 boolean isBrowserProcess) {
25 boolean checkSharedRelro;
26 if (isBrowserProcess) {
27 switch (Linker.BROWSER_SHARED_RELRO_CONFIG) {
28 case Linker.BROWSER_SHARED_RELRO_CONFIG_NEVER:
29 checkSharedRelro = false;
31 case Linker.BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
32 // A shared RELRO should only be used on low-end devices.
34 (memoryDeviceConfig == Linker.MEMORY_DEVICE_CONFIG_LOW);
36 case Linker.BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
37 // Always check for a shared RELRO.
38 checkSharedRelro = true;
41 Log.e(TAG, "Invalid shared RELRO linker configuration: " +
42 Linker.BROWSER_SHARED_RELRO_CONFIG);
46 // Service processes should always use a shared RELRO section.
47 checkSharedRelro = true;
51 return nativeCheckForSharedRelros(isBrowserProcess);
53 return nativeCheckForNoSharedRelros(isBrowserProcess);
56 // Check that there are shared RELRO sections in the current process,
57 // and that they are properly mapped read-only. Returns true on success.
58 private static native boolean nativeCheckForSharedRelros(boolean isBrowserProcess);
60 // Check that there are no shared RELRO sections in the current process,
61 // return true on success.
62 private static native boolean nativeCheckForNoSharedRelros(boolean isBrowserProcess);