Home | History | Annotate | Download | only in chromium_linker_test_apk
      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.
      4 
      5 package org.chromium.chromium_linker_test_apk;
      6 
      7 import android.util.Log;
      8 
      9 import org.chromium.base.JNINamespace;
     10 import org.chromium.base.library_loader.Linker;
     11 
     12 /**
     13  *  A class that is only used in linker test APK to perform runtime checks
     14  * in the current process.
     15  */
     16 @JNINamespace("content")
     17 public class LinkerTests implements Linker.TestRunner {
     18     private static final String TAG = "LinkerTests";
     19 
     20     public LinkerTests() {}
     21 
     22     @Override
     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;
     30                     break;
     31                 case Linker.BROWSER_SHARED_RELRO_CONFIG_LOW_RAM_ONLY:
     32                     // A shared RELRO should only be used on low-end devices.
     33                     checkSharedRelro =
     34                             (memoryDeviceConfig == Linker.MEMORY_DEVICE_CONFIG_LOW);
     35                     break;
     36                 case Linker.BROWSER_SHARED_RELRO_CONFIG_ALWAYS:
     37                     // Always check for a shared RELRO.
     38                     checkSharedRelro = true;
     39                     break;
     40                 default:
     41                     Log.e(TAG, "Invalid shared RELRO linker configuration: " +
     42                           Linker.BROWSER_SHARED_RELRO_CONFIG);
     43                     return false;
     44             }
     45         } else {
     46           // Service processes should always use a shared RELRO section.
     47           checkSharedRelro = true;
     48         }
     49 
     50         if (checkSharedRelro)
     51             return nativeCheckForSharedRelros(isBrowserProcess);
     52         else
     53             return nativeCheckForNoSharedRelros(isBrowserProcess);
     54     }
     55 
     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);
     59 
     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);
     63 
     64 }
     65