LCOV - code coverage report
Current view: directory - src/trusted/cpu_features/arch/arm - cpu_arm.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 36 0 0.0 %
Date: 2014-09-25 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include <string.h>
       8                 : 
       9                 : #include "native_client/src/shared/platform/nacl_log.h"
      10                 : #include "native_client/src/trusted/cpu_features/arch/arm/cpu_arm.h"
      11                 : 
      12                 : 
      13               0 : void NaClSetAllCPUFeaturesArm(NaClCPUFeatures *f) {
      14                 :   /* TODO(jfb) Use a safe cast in this interface. */
      15               0 :   NaClCPUFeaturesArm *features = (NaClCPUFeaturesArm *) f;
      16                 :   /* Pedantic: avoid using memset, as in x86's cpu_x86.c. */
      17                 :   int id;
      18                 :   /* Ensure any padding is zeroed. */
      19               0 :   NaClClearCPUFeaturesArm(features);
      20               0 :   for (id = 0; id < NaClCPUFeatureArm_Max; ++id) {
      21               0 :     NaClSetCPUFeatureArm(features, id, 1);
      22               0 :   }
      23               0 : }
      24                 : 
      25               0 : void NaClGetCurrentCPUFeaturesArm(NaClCPUFeatures *f) {
      26                 :   /* TODO(jfb) Use a safe cast in this interface. */
      27               0 :   NaClCPUFeaturesArm *features = (NaClCPUFeaturesArm *) f;
      28                 :   /*
      29                 :    * TODO(jfb) Create a whitelist of CPUs that don't leak information when
      30                 :    *           TST+LDR and TST+STR are used. Disallow all for now.
      31                 :    */
      32               0 :   NaClSetCPUFeatureArm(features, NaClCPUFeatureArm_CanUseTstMem, 0);
      33               0 : }
      34                 : 
      35                 : /* This array defines the CPU feature model for fixed-feature CPU mode. */
      36                 : static const int kFixedFeatureArmCPUModel[NaClCPUFeatureArm_Max] = {
      37                 :   0 /* NaClCPUFeatureArm_CanUseTstMem */
      38                 : };
      39                 : 
      40               0 : int NaClFixCPUFeaturesArm(NaClCPUFeatures *f) {
      41                 :   /* TODO(jfb) Use a safe cast in this interface. */
      42               0 :   NaClCPUFeaturesArm *features = (NaClCPUFeaturesArm *) f;
      43                 :   NaClCPUFeatureArmID fid;
      44               0 :   int rvalue = 1;
      45                 : 
      46               0 :   for (fid = 0; fid < NaClCPUFeatureArm_Max; fid++) {
      47               0 :     if (kFixedFeatureArmCPUModel[fid]) {
      48               0 :       if (!NaClGetCPUFeatureArm(features, fid)) {
      49                 :         /* This CPU is missing a required feature. */
      50                 :         NaClLog(LOG_ERROR,
      51                 :                 "This CPU is missing a feature required by fixed-mode: %s\n",
      52               0 :                 NaClGetCPUFeatureArmName(fid));
      53               0 :         rvalue = 0;  /* set return value to indicate failure */
      54                 :       }
      55               0 :     } else {
      56                 :       /* Feature is not in the fixed model.
      57                 :        * Ensure cpu_features does not have it either.
      58                 :        */
      59               0 :       NaClSetCPUFeatureArm(features, fid, 0);
      60                 :     }
      61               0 :   }
      62               0 :   return rvalue;
      63               0 : }
      64                 : 
      65                 : void NaClSetCPUFeatureArm(NaClCPUFeaturesArm *f, NaClCPUFeatureArmID id,
      66               0 :                           int state) {
      67               0 :   f->data[id] = (char) state;
      68               0 : }
      69                 : 
      70               0 : const char *NaClGetCPUFeatureArmName(NaClCPUFeatureArmID id) {
      71                 :   static const char *kFeatureArmNames[NaClCPUFeatureArm_Max] = {
      72                 : # define NACL_ARM_CPU_FEATURE(name) NACL_TO_STRING(name),
      73                 : # include "native_client/src/trusted/cpu_features/arch/arm/cpu_arm_features.h"
      74                 : # undef NACL_ARM_CPU_FEATURE
      75                 :   };
      76                 :   return ((unsigned)id < NaClCPUFeatureArm_Max) ?
      77               0 :       kFeatureArmNames[id] : "INVALID";
      78               0 : }
      79                 : 
      80               0 : void NaClClearCPUFeaturesArm(NaClCPUFeaturesArm *features) {
      81               0 :   memset(features, 0, sizeof(*features));
      82               0 : }
      83                 : 
      84                 : void NaClCopyCPUFeaturesArm(NaClCPUFeaturesArm *target,
      85               0 :                             const NaClCPUFeaturesArm *source) {
      86               0 :   memcpy(target, source, sizeof(*target));
      87               0 : }

Generated by: LCOV version 1.7