| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 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 | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/trusted/validator_arm/ncvalidate.h" | 7 #include "native_client/src/trusted/validator_arm/ncvalidate.h" |
| 8 | 8 |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "native_client/src/include/nacl_string.h" | 12 #include "native_client/src/include/nacl_string.h" |
| 13 #include "native_client/src/include/portability.h" | 13 #include "native_client/src/include/portability.h" |
| 14 #include "native_client/src/trusted/validator_arm/cpuid_arm.h" | 14 #include "native_client/src/trusted/validator_arm/cpuid_arm.h" |
| 15 #include "native_client/src/trusted/validator_arm/model.h" |
| 15 #include "native_client/src/trusted/validator_arm/validator.h" | 16 #include "native_client/src/trusted/validator_arm/validator.h" |
| 16 #include "native_client/src/trusted/validator_arm/model.h" | |
| 17 #include "native_client/src/trusted/validator/ncvalidate.h" | 17 #include "native_client/src/trusted/validator/ncvalidate.h" |
| 18 | 18 |
| 19 using nacl_arm_val::SfiValidator; | 19 using nacl_arm_val::SfiValidator; |
| 20 using nacl_arm_val::CodeSegment; | 20 using nacl_arm_val::CodeSegment; |
| 21 using nacl_arm_dec::Register; | 21 using nacl_arm_dec::Register; |
| 22 using nacl_arm_dec::RegisterList; | 22 using nacl_arm_dec::RegisterList; |
| 23 using nacl_arm_dec::kRegisterStack; | 23 using nacl_arm_dec::kRegisterStack; |
| 24 using std::vector; | 24 using std::vector; |
| 25 | 25 |
| 26 class EarlyExitProblemSink : public nacl_arm_val::ProblemSink { | 26 class EarlyExitProblemSink : public nacl_arm_val::ProblemSink { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 UNREFERENCED_PARAMETER(problem_code); | 39 UNREFERENCED_PARAMETER(problem_code); |
| 40 UNREFERENCED_PARAMETER(ref_vaddr); | 40 UNREFERENCED_PARAMETER(ref_vaddr); |
| 41 | 41 |
| 42 problems_ = true; | 42 problems_ = true; |
| 43 } | 43 } |
| 44 virtual bool should_continue() { | 44 virtual bool should_continue() { |
| 45 return !problems_; | 45 return !problems_; |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 static NaClValidationStatus ValidatorCopyNotImplemented( |
| 50 uintptr_t guest_addr, |
| 51 uint8_t *data_old, |
| 52 uint8_t *data_new, |
| 53 size_t size, |
| 54 const NaClCPUFeatures *cpu_features, |
| 55 const NaClCopyInstructionFunc copy_func) { |
| 56 UNREFERENCED_PARAMETER(guest_addr); |
| 57 UNREFERENCED_PARAMETER(data_old); |
| 58 UNREFERENCED_PARAMETER(data_new); |
| 59 UNREFERENCED_PARAMETER(size); |
| 60 UNREFERENCED_PARAMETER(cpu_features); |
| 61 UNREFERENCED_PARAMETER(copy_func); |
| 62 return NaClValidationFailedNotImplemented; |
| 63 } |
| 64 |
| 65 static NaClValidationStatus ValidatorCodeReplacementNotImplemented( |
| 66 uintptr_t guest_addr, |
| 67 uint8_t *data_old, |
| 68 uint8_t *data_new, |
| 69 size_t size, |
| 70 const NaClCPUFeatures *cpu_features) { |
| 71 UNREFERENCED_PARAMETER(guest_addr); |
| 72 UNREFERENCED_PARAMETER(data_old); |
| 73 UNREFERENCED_PARAMETER(data_new); |
| 74 UNREFERENCED_PARAMETER(size); |
| 75 UNREFERENCED_PARAMETER(cpu_features); |
| 76 return NaClValidationFailedNotImplemented; |
| 77 } |
| 78 |
| 49 EXTERN_C_BEGIN | 79 EXTERN_C_BEGIN |
| 50 | 80 |
| 51 int NCValidateSegment(uint8_t *mbase, uint32_t vbase, size_t size) { | 81 int NCValidateSegment(uint8_t *mbase, uint32_t vbase, size_t size) { |
| 52 SfiValidator validator( | 82 SfiValidator validator( |
| 53 16, // bytes per bundle | 83 16, // bytes per bundle |
| 54 1U * 1024 * 1024 * 1024, // bytes of code space | 84 1U * 1024 * 1024 * 1024, // bytes of code space |
| 55 1U * 1024 * 1024 * 1024, // bytes of data space | 85 1U * 1024 * 1024 * 1024, // bytes of data space |
| 56 RegisterList(Register(9)), | 86 RegisterList(Register(9)), |
| 57 RegisterList(kRegisterStack)); | 87 RegisterList(kRegisterStack)); |
| 58 | 88 |
| 59 EarlyExitProblemSink sink; | 89 EarlyExitProblemSink sink; |
| 60 | 90 |
| 61 vector<CodeSegment> segments; | 91 vector<CodeSegment> segments; |
| 62 segments.push_back(CodeSegment(mbase, vbase, size)); | 92 segments.push_back(CodeSegment(mbase, vbase, size)); |
| 63 | 93 |
| 64 bool success = validator.validate(segments, &sink); | 94 bool success = validator.validate(segments, &sink); |
| 65 if (!success) return 2; // for compatibility with old validator | 95 if (!success) return 2; // for compatibility with old validator |
| 66 return 0; | 96 return 0; |
| 67 } | 97 } |
| 68 | 98 |
| 69 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, arm, 32) ( | 99 static NaClValidationStatus ApplyValidatorArm( |
| 70 uintptr_t guest_addr, | 100 uintptr_t guest_addr, |
| 71 uint8_t *data, | 101 uint8_t *data, |
| 72 size_t size, | 102 size_t size, |
| 73 int stubout_mode, | 103 int stubout_mode, |
| 74 int readonly_text, | 104 int readonly_text, |
| 75 const NaClCPUFeaturesArm *cpu_features, | 105 const NaClCPUFeatures *cpu_features, |
| 76 struct NaClValidationCache *cache) { | 106 struct NaClValidationCache *cache) { |
| 77 UNREFERENCED_PARAMETER(cpu_features); | 107 UNREFERENCED_PARAMETER(cpu_features); |
| 78 /* The ARM validator is currently unsafe w.r.t. caching. */ | 108 /* The ARM validator is currently unsafe w.r.t. caching. */ |
| 79 UNREFERENCED_PARAMETER(cache); | 109 UNREFERENCED_PARAMETER(cache); |
| 80 | 110 |
| 81 if (stubout_mode) | 111 if (stubout_mode) |
| 82 return NaClValidationFailedNotImplemented; | 112 return NaClValidationFailedNotImplemented; |
| 83 if (readonly_text) | 113 if (readonly_text) |
| 84 return NaClValidationFailedNotImplemented; | 114 return NaClValidationFailedNotImplemented; |
| 85 | 115 |
| 86 return ((0 == NCValidateSegment(data, guest_addr, size)) | 116 return ((0 == NCValidateSegment(data, guest_addr, size)) |
| 87 ? NaClValidationSucceeded : NaClValidationFailed); | 117 ? NaClValidationSucceeded : NaClValidationFailed); |
| 88 } | 118 } |
| 89 | 119 |
| 90 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, arm, 32) | 120 static struct NaClValidatorInterface validator = { |
| 91 (uintptr_t guest_addr, | 121 ApplyValidatorArm, |
| 92 uint8_t *data_old, | 122 ValidatorCopyNotImplemented, |
| 93 uint8_t *data_new, | 123 ValidatorCodeReplacementNotImplemented, |
| 94 size_t size, | 124 }; |
| 95 const NaClCPUFeaturesArm *cpu_features) { | |
| 96 UNREFERENCED_PARAMETER(guest_addr); | |
| 97 UNREFERENCED_PARAMETER(data_old); | |
| 98 UNREFERENCED_PARAMETER(data_new); | |
| 99 UNREFERENCED_PARAMETER(size); | |
| 100 UNREFERENCED_PARAMETER(cpu_features); | |
| 101 return NaClValidationFailedNotImplemented; | |
| 102 } | |
| 103 | 125 |
| 104 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, arm, 32) | 126 const struct NaClValidatorInterface* NaClValidatorCreateArm() { |
| 105 (uintptr_t guest_addr, | 127 return &validator; |
| 106 uint8_t *data_old, | |
| 107 uint8_t *data_new, | |
| 108 size_t size, | |
| 109 const NaClCPUFeaturesArm *cpu_features) { | |
| 110 UNREFERENCED_PARAMETER(guest_addr); | |
| 111 UNREFERENCED_PARAMETER(data_old); | |
| 112 UNREFERENCED_PARAMETER(data_new); | |
| 113 UNREFERENCED_PARAMETER(size); | |
| 114 UNREFERENCED_PARAMETER(cpu_features); | |
| 115 return NaClValidationFailedNotImplemented; | |
| 116 } | 128 } |
| 117 | 129 |
| 118 EXTERN_C_END | 130 EXTERN_C_END |
| OLD | NEW |