| 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 /* Implement the ApplyValidator API for the x86-32 architecture. */ | 7 /* Implement the ApplyValidator API for the x86-32 architecture. */ |
| 8 | 8 |
| 9 #include "native_client/src/trusted/validator/ncvalidate.h" | 9 #include "native_client/src/trusted/validator/ncvalidate.h" |
| 10 #include "native_client/src/trusted/validator/validation_cache.h" | 10 #include "native_client/src/trusted/validator/validation_cache.h" |
| 11 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h" | 11 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate.h" |
| 12 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detai
led.h" | 12 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_detai
led.h" |
| 13 /* HACK to get access to didstubout */ | 13 /* HACK to get access to didstubout */ |
| 14 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_inter
naltypes.h" | 14 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_inter
naltypes.h" |
| 15 #include <assert.h> | 15 #include <assert.h> |
| 16 | 16 |
| 17 /* Be sure the correct compile flags are defined for this. */ | 17 /* Be sure the correct compile flags are defined for this. */ |
| 18 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 | 18 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 |
| 19 # error("Can't compile, target is for x86-32") | 19 # error("Can't compile, target is for x86-32") |
| 20 #else | 20 #else |
| 21 # if NACL_TARGET_SUBARCH != 32 | 21 # if NACL_TARGET_SUBARCH != 32 |
| 22 # error("Can't compile, target is for x86-32") | 22 # error("Can't compile, target is for x86-32") |
| 23 # endif | 23 # endif |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( | 26 static NaClValidationStatus ApplyValidator_x86_32( |
| 27 uintptr_t guest_addr, | 27 uintptr_t guest_addr, |
| 28 uint8_t *data, | 28 uint8_t *data, |
| 29 size_t size, | 29 size_t size, |
| 30 int stubout_mode, | 30 int stubout_mode, |
| 31 int readonly_text, | 31 int readonly_text, |
| 32 const NaClCPUFeaturesX86 *cpu_features, | 32 const NaClCPUFeaturesX86 *cpu_features, |
| 33 struct NaClValidationCache *cache) { | 33 struct NaClValidationCache *cache) { |
| 34 struct NCValidatorState *vstate; | 34 struct NCValidatorState *vstate; |
| 35 int validator_result = 0; | 35 int validator_result = 0; |
| 36 void *query = NULL; | 36 void *query = NULL; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 if (validator_result == 0 && !NCValidatorDidStubOut(vstate)) | 83 if (validator_result == 0 && !NCValidatorDidStubOut(vstate)) |
| 84 cache->SetKnownToValidate(query); | 84 cache->SetKnownToValidate(query); |
| 85 cache->DestroyQuery(query); | 85 cache->DestroyQuery(query); |
| 86 } | 86 } |
| 87 | 87 |
| 88 NCValidateFreeState(&vstate); | 88 NCValidateFreeState(&vstate); |
| 89 return (validator_result == 0 || stubout_mode) | 89 return (validator_result == 0 || stubout_mode) |
| 90 ? NaClValidationSucceeded : NaClValidationFailed; | 90 ? NaClValidationSucceeded : NaClValidationFailed; |
| 91 } | 91 } |
| 92 | 92 |
| 93 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, x86, 32) | 93 static NaClValidationStatus ApplyValidatorCodeReplacement_x86_32( |
| 94 (uintptr_t guest_addr, | 94 uintptr_t guest_addr, |
| 95 uint8_t *data_old, | 95 uint8_t *data_old, |
| 96 uint8_t *data_new, | 96 uint8_t *data_new, |
| 97 size_t size, | 97 size_t size, |
| 98 const NaClCPUFeaturesX86 *cpu_features) { | 98 const NaClCPUFeaturesX86 *cpu_features) { |
| 99 /* Check that the given parameter values are supported. */ | 99 /* Check that the given parameter values are supported. */ |
| 100 if (!NaClArchSupported(cpu_features)) | 100 if (!NaClArchSupported(cpu_features)) |
| 101 return NaClValidationFailedCpuNotSupported; | 101 return NaClValidationFailedCpuNotSupported; |
| 102 | 102 |
| 103 return NCValidateSegmentPair(data_old, data_new, guest_addr, | 103 return NCValidateSegmentPair(data_old, data_new, guest_addr, |
| 104 size, cpu_features) | 104 size, cpu_features) |
| 105 ? NaClValidationSucceeded : NaClValidationFailed; | 105 ? NaClValidationSucceeded : NaClValidationFailed; |
| 106 } | 106 } |
| 107 |
| 108 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, x86, 32) |
| 109 (uintptr_t guest_addr, |
| 110 uint8_t *data_old, |
| 111 uint8_t *data_new, |
| 112 size_t size, |
| 113 const NaClCPUFeaturesX86 *cpu_features); |
| 114 |
| 115 static struct NaClValidatorInterface validator = { |
| 116 ApplyValidator_x86_32, |
| 117 NACL_SUBARCH_NAME(ApplyValidatorCopy, x86, 32), |
| 118 ApplyValidatorCodeReplacement_x86_32, |
| 119 }; |
| 120 |
| 121 void NaClValidatorInit_x86_32(struct NaClValidatorInterface **val) { |
| 122 *val = &validator; |
| 123 } |
| OLD | NEW |