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.
5 package org.chromium.content_linker_test_apk;
7 import android.util.Log;
9 import org.chromium.base.JNINamespace;
10 import org.chromium.content.app.Linker;
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";
18 public LinkerTests() {}
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;
28 case Linker.BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
29 // A shared RELRO should only be used on low-end devices.
31 (memoryDeviceConfig == Linker.MEMORY_DEVICE_CONFIG_LOW);
33 case Linker.BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
34 // Always check for a shared RELRO.
35 checkSharedRelro = true;
38 Log.e(TAG, "Invalid shared RELRO linker configuration: " +
39 Linker.BROWSER_SHARED_RELRO_CONFIG);
43 // Service processes should always use a shared RELRO section.
44 checkSharedRelro = true;
48 return nativeCheckForSharedRelros(isBrowserProcess);
50 return nativeCheckForNoSharedRelros(isBrowserProcess);
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);
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);