| OLD | NEW |
| (Empty) |
| 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/validator_arm/cpuid_arm.h" | |
| 11 | |
| 12 | |
| 13 void NaClSetAllCPUFeaturesArm(NaClCPUFeatures *f) { | |
| 14 /* TODO(jfb) Use a safe cast in this interface. */ | |
| 15 NaClCPUFeaturesArm *features = (NaClCPUFeaturesArm *) f; | |
| 16 /* Pedantic: avoid using memset, as in x86's nacl_cpuid.c. */ | |
| 17 int id; | |
| 18 /* Ensure any padding is zeroed. */ | |
| 19 NaClClearCPUFeaturesArm(features); | |
| 20 for (id = 0; id < NaClCPUFeatureArm_Max; ++id) { | |
| 21 NaClSetCPUFeatureArm(features, id, 1); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 void NaClGetCurrentCPUFeaturesArm(NaClCPUFeatures *f) { | |
| 26 /* TODO(jfb) Use a safe cast in this interface. */ | |
| 27 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 NaClSetCPUFeatureArm(features, NaClCPUFeatureArm_CanUseTstMem, 0); | |
| 33 } | |
| 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 int NaClFixCPUFeaturesArm(NaClCPUFeatures *f) { | |
| 41 /* TODO(jfb) Use a safe cast in this interface. */ | |
| 42 NaClCPUFeaturesArm *features = (NaClCPUFeaturesArm *) f; | |
| 43 NaClCPUFeatureArmID fid; | |
| 44 int rvalue = 1; | |
| 45 | |
| 46 for (fid = 0; fid < NaClCPUFeatureArm_Max; fid++) { | |
| 47 if (kFixedFeatureArmCPUModel[fid]) { | |
| 48 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 NaClGetCPUFeatureArmName(fid)); | |
| 53 rvalue = 0; /* set return value to indicate failure */ | |
| 54 } | |
| 55 } else { | |
| 56 /* Feature is not in the fixed model. | |
| 57 * Ensure cpu_features does not have it either. | |
| 58 */ | |
| 59 NaClSetCPUFeatureArm(features, fid, 0); | |
| 60 } | |
| 61 } | |
| 62 return rvalue; | |
| 63 } | |
| 64 | |
| 65 void NaClSetCPUFeatureArm(NaClCPUFeaturesArm *f, NaClCPUFeatureArmID id, | |
| 66 int state) { | |
| 67 f->data[id] = (char) state; | |
| 68 } | |
| 69 | |
| 70 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/validator_arm/cpuid_arm_features.h" | |
| 74 # undef NACL_ARM_CPU_FEATURE | |
| 75 }; | |
| 76 return ((unsigned)id < NaClCPUFeatureArm_Max) ? | |
| 77 kFeatureArmNames[id] : "INVALID"; | |
| 78 } | |
| 79 | |
| 80 void NaClClearCPUFeaturesArm(NaClCPUFeaturesArm *features) { | |
| 81 memset(features, 0, sizeof(*features)); | |
| 82 } | |
| 83 | |
| 84 void NaClCopyCPUFeaturesArm(NaClCPUFeaturesArm *target, | |
| 85 const NaClCPUFeaturesArm *source) { | |
| 86 memcpy(target, source, sizeof(*target)); | |
| 87 } | |
| OLD | NEW |