| 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/x86/ncval_seg_sfi/ncvalidate.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_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 */ |
| 14 #include "native_client/src/trusted/validator/x86/ncval_seg_sfi/ncvalidate_inter
naltypes.h" |
| 12 #include <assert.h> | 15 #include <assert.h> |
| 13 | 16 |
| 14 /* Be sure the correct compile flags are defined for this. */ | 17 /* Be sure the correct compile flags are defined for this. */ |
| 15 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 | 18 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 |
| 16 # error("Can't compile, target is for x86-32") | 19 # error("Can't compile, target is for x86-32") |
| 17 #else | 20 #else |
| 18 # if NACL_TARGET_SUBARCH != 32 | 21 # if NACL_TARGET_SUBARCH != 32 |
| 19 # error("Can't compile, target is for x86-32") | 22 # error("Can't compile, target is for x86-32") |
| 20 # endif | 23 # endif |
| 21 #endif | 24 #endif |
| 22 | 25 |
| 23 static NaClValidationStatus NCApplyValidatorSilently_x86_32( | 26 static NaClValidationStatus NCApplyValidatorSilently_x86_32( |
| 24 uintptr_t guest_addr, | 27 uintptr_t guest_addr, |
| 25 uint8_t *data, | 28 uint8_t *data, |
| 26 size_t size, | 29 size_t size, |
| 27 int bundle_size, | 30 int bundle_size, |
| 28 NaClCPUFeaturesX86 *cpu_features) { | 31 NaClCPUFeaturesX86 *cpu_features, |
| 32 struct NaClValidationCache *cache) { |
| 29 struct NCValidatorState *vstate; | 33 struct NCValidatorState *vstate; |
| 30 int validator_result = 0; | 34 int validator_result = 0; |
| 35 void *query = NULL; |
| 36 |
| 37 if (cache != NULL) |
| 38 query = cache->CreateQuery(cache->handle); |
| 39 |
| 40 if (query != NULL) { |
| 41 const char validator_id[] = "x86-32"; |
| 42 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
| 43 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
| 44 cache->AddData(query, data, size); |
| 45 if (cache->QueryKnownToValidate(query)) { |
| 46 cache->DestroyQuery(query); |
| 47 return NaClValidationSucceeded; |
| 48 } |
| 49 } |
| 31 | 50 |
| 32 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features); | 51 vstate = NCValidateInit(guest_addr, size, bundle_size, cpu_features); |
| 33 if (vstate == NULL) return NaClValidationFailedOutOfMemory; | 52 if (vstate == NULL) { |
| 53 if (query != NULL) |
| 54 cache->DestroyQuery(query); |
| 55 return NaClValidationFailedOutOfMemory; |
| 56 } |
| 34 NCValidateSegment(data, guest_addr, size, vstate); | 57 NCValidateSegment(data, guest_addr, size, vstate); |
| 35 validator_result = NCValidateFinish(vstate); | 58 validator_result = NCValidateFinish(vstate); |
| 59 |
| 60 if (query != NULL) { |
| 61 /* Don't cache the result if the code is modified. */ |
| 62 if (validator_result == 0 && !NCValidatorDidStubOut(vstate)) |
| 63 cache->SetKnownToValidate(query); |
| 64 cache->DestroyQuery(query); |
| 65 } |
| 66 |
| 36 NCValidateFreeState(&vstate); | 67 NCValidateFreeState(&vstate); |
| 37 return (validator_result == 0) | 68 return (validator_result == 0) |
| 38 ? NaClValidationSucceeded : NaClValidationFailed; | 69 ? NaClValidationSucceeded : NaClValidationFailed; |
| 39 } | 70 } |
| 40 | 71 |
| 41 NaClValidationStatus NCApplyValidatorStubout_x86_32( | 72 NaClValidationStatus NCApplyValidatorStubout_x86_32( |
| 42 uintptr_t guest_addr, | 73 uintptr_t guest_addr, |
| 43 uint8_t *data, | 74 uint8_t *data, |
| 44 size_t size, | 75 size_t size, |
| 45 int bundle_size, | 76 int bundle_size, |
| 46 NaClCPUFeaturesX86 *cpu_features) { | 77 NaClCPUFeaturesX86 *cpu_features) { |
| 47 struct NCValidatorState *vstate; | 78 struct NCValidatorState *vstate; |
| 48 | 79 |
| 49 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features); | 80 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, cpu_features); |
| 50 if (vstate == NULL) return NaClValidationFailedOutOfMemory; | 81 if (vstate == NULL) return NaClValidationFailedOutOfMemory; |
| 51 NCValidateSetStubOutMode(vstate, 1); | 82 NCValidateSetStubOutMode(vstate, 1); |
| 52 NCValidateSegment(data, guest_addr, size, vstate); | 83 NCValidateSegment(data, guest_addr, size, vstate); |
| 53 NCValidateFinish(vstate); | 84 NCValidateFinish(vstate); |
| 54 NCValidateFreeState(&vstate); | 85 NCValidateFreeState(&vstate); |
| 55 return NaClValidationSucceeded; | 86 return NaClValidationSucceeded; |
| 56 } | 87 } |
| 57 | 88 |
| 58 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( | 89 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( |
| 59 enum NaClSBKind sb_kind, | 90 enum NaClSBKind sb_kind, |
| 60 NaClApplyValidationKind kind, | 91 NaClApplyValidationKind kind, |
| 61 uintptr_t guest_addr, | 92 uintptr_t guest_addr, |
| 62 uint8_t *data, | 93 uint8_t *data, |
| 63 size_t size, | 94 size_t size, |
| 64 int bundle_size, | 95 int bundle_size, |
| 65 NaClCPUFeaturesX86 *cpu_features) { | 96 NaClCPUFeaturesX86 *cpu_features, |
| 97 struct NaClValidationCache *cache) { |
| 66 NaClValidationStatus status = NaClValidationFailedNotImplemented; | 98 NaClValidationStatus status = NaClValidationFailedNotImplemented; |
| 67 assert(NACL_SB_DEFAULT == sb_kind); | 99 assert(NACL_SB_DEFAULT == sb_kind); |
| 68 if (bundle_size == 16 || bundle_size == 32) { | 100 if (bundle_size == 16 || bundle_size == 32) { |
| 69 if (!NaClArchSupported(cpu_features)) | 101 if (!NaClArchSupported(cpu_features)) |
| 70 return NaClValidationFailedCpuNotSupported; | 102 return NaClValidationFailedCpuNotSupported; |
| 71 switch (kind) { | 103 switch (kind) { |
| 72 case NaClApplyCodeValidation: | 104 case NaClApplyCodeValidation: |
| 73 status = NCApplyValidatorSilently_x86_32( | 105 status = NCApplyValidatorSilently_x86_32( |
| 74 guest_addr, data, size, bundle_size, cpu_features); | 106 guest_addr, data, size, bundle_size, cpu_features, cache); |
| 75 break; | 107 break; |
| 76 case NaClApplyValidationDoStubout: | 108 case NaClApplyValidationDoStubout: |
| 77 status = NCApplyValidatorStubout_x86_32( | 109 status = NCApplyValidatorStubout_x86_32( |
| 78 guest_addr, data, size, bundle_size, cpu_features); | 110 guest_addr, data, size, bundle_size, cpu_features); |
| 79 break; | 111 break; |
| 80 default: | 112 default: |
| 81 /* If reached, it isn't implemented (yet). */ | 113 /* If reached, it isn't implemented (yet). */ |
| 82 break; | 114 break; |
| 83 } | 115 } |
| 84 } | 116 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 99 if (!NaClArchSupported(cpu_features)) { | 131 if (!NaClArchSupported(cpu_features)) { |
| 100 status = NaClValidationFailedCpuNotSupported; | 132 status = NaClValidationFailedCpuNotSupported; |
| 101 } else { | 133 } else { |
| 102 status = NCValidateSegmentPair(data_old, data_new, guest_addr, | 134 status = NCValidateSegmentPair(data_old, data_new, guest_addr, |
| 103 size, bundle_size, cpu_features) | 135 size, bundle_size, cpu_features) |
| 104 ? NaClValidationSucceeded : NaClValidationFailed; | 136 ? NaClValidationSucceeded : NaClValidationFailed; |
| 105 } | 137 } |
| 106 } | 138 } |
| 107 return status; | 139 return status; |
| 108 } | 140 } |
| OLD | NEW |