| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, NACL_TARGET_ARCH, 32) ( |
| 27 enum NaClSBKind sb_kind, | 27 enum NaClSBKind sb_kind, |
| 28 uintptr_t guest_addr, | 28 uintptr_t guest_addr, |
| 29 uint8_t *data, | 29 uint8_t *data, |
| 30 size_t size, | 30 size_t size, |
| 31 int bundle_size, | |
| 32 int stubout_mode, | 31 int stubout_mode, |
| 33 int readonly_text, | 32 int readonly_text, |
| 34 const NaClCPUFeaturesX86 *cpu_features, | 33 const NaClCPUFeaturesX86 *cpu_features, |
| 35 struct NaClValidationCache *cache) { | 34 struct NaClValidationCache *cache) { |
| 36 struct NCValidatorState *vstate; | 35 struct NCValidatorState *vstate; |
| 37 int validator_result = 0; | 36 int validator_result = 0; |
| 38 void *query = NULL; | 37 void *query = NULL; |
| 39 | 38 |
| 40 /* Check that the given parameter values are supported. */ | 39 /* Check that the given parameter values are supported. */ |
| 41 if (sb_kind != NACL_SB_DEFAULT) | 40 if (sb_kind != NACL_SB_DEFAULT) |
| 42 return NaClValidationFailedNotImplemented; | 41 return NaClValidationFailedNotImplemented; |
| 43 | 42 |
| 44 if (bundle_size != 16 && bundle_size != 32) | |
| 45 return NaClValidationFailedNotImplemented; | |
| 46 | |
| 47 if (stubout_mode && readonly_text) | 43 if (stubout_mode && readonly_text) |
| 48 return NaClValidationFailedNotImplemented; | 44 return NaClValidationFailedNotImplemented; |
| 49 | 45 |
| 50 if (!NaClArchSupported(cpu_features)) | 46 if (!NaClArchSupported(cpu_features)) |
| 51 return NaClValidationFailedCpuNotSupported; | 47 return NaClValidationFailedCpuNotSupported; |
| 52 | 48 |
| 53 /* Don't cache in stubout mode. */ | 49 /* Don't cache in stubout mode. */ |
| 54 if (stubout_mode) | 50 if (stubout_mode) |
| 55 cache = NULL; | 51 cache = NULL; |
| 56 | 52 |
| 57 /* If the validation caching interface is available, perform a query. */ | 53 /* If the validation caching interface is available, perform a query. */ |
| 58 if (cache != NULL) | 54 if (cache != NULL) |
| 59 query = cache->CreateQuery(cache->handle); | 55 query = cache->CreateQuery(cache->handle); |
| 60 if (query != NULL) { | 56 if (query != NULL) { |
| 61 const char validator_id[] = "x86-32"; | 57 const char validator_id[] = "x86-32"; |
| 62 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 58 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
| 63 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 59 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
| 64 cache->AddData(query, data, size); | 60 cache->AddData(query, data, size); |
| 65 if (cache->QueryKnownToValidate(query)) { | 61 if (cache->QueryKnownToValidate(query)) { |
| 66 cache->DestroyQuery(query); | 62 cache->DestroyQuery(query); |
| 67 return NaClValidationSucceeded; | 63 return NaClValidationSucceeded; |
| 68 } | 64 } |
| 69 } | 65 } |
| 70 | 66 |
| 71 /* Init then validator state. */ | 67 /* Init then validator state. */ |
| 72 /* TODO(ncbray) make "detailed" a parameter. */ | 68 /* TODO(ncbray) make "detailed" a parameter. */ |
| 73 if (stubout_mode) { | 69 if (stubout_mode) { |
| 74 vstate = NCValidateInitDetailed(guest_addr, size, bundle_size, | 70 vstate = NCValidateInitDetailed(guest_addr, size, cpu_features); |
| 75 cpu_features); | |
| 76 } else { | 71 } else { |
| 77 vstate = NCValidateInit(guest_addr, size, bundle_size, readonly_text, | 72 vstate = NCValidateInit(guest_addr, size, readonly_text, cpu_features); |
| 78 cpu_features); | |
| 79 } | 73 } |
| 80 if (vstate == NULL) { | 74 if (vstate == NULL) { |
| 81 if (query != NULL) | 75 if (query != NULL) |
| 82 cache->DestroyQuery(query); | 76 cache->DestroyQuery(query); |
| 83 return NaClValidationFailedOutOfMemory; | 77 return NaClValidationFailedOutOfMemory; |
| 84 } | 78 } |
| 85 NCValidateSetStubOutMode(vstate, stubout_mode); | 79 NCValidateSetStubOutMode(vstate, stubout_mode); |
| 86 | 80 |
| 87 /* Validate. */ | 81 /* Validate. */ |
| 88 NCValidateSegment(data, guest_addr, size, vstate); | 82 NCValidateSegment(data, guest_addr, size, vstate); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 99 return (validator_result == 0 || stubout_mode) | 93 return (validator_result == 0 || stubout_mode) |
| 100 ? NaClValidationSucceeded : NaClValidationFailed; | 94 ? NaClValidationSucceeded : NaClValidationFailed; |
| 101 } | 95 } |
| 102 | 96 |
| 103 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, x86, 32) | 97 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, x86, 32) |
| 104 (enum NaClSBKind sb_kind, | 98 (enum NaClSBKind sb_kind, |
| 105 uintptr_t guest_addr, | 99 uintptr_t guest_addr, |
| 106 uint8_t *data_old, | 100 uint8_t *data_old, |
| 107 uint8_t *data_new, | 101 uint8_t *data_new, |
| 108 size_t size, | 102 size_t size, |
| 109 int bundle_size, | |
| 110 const NaClCPUFeaturesX86 *cpu_features) { | 103 const NaClCPUFeaturesX86 *cpu_features) { |
| 111 /* Check that the given parameter values are supported. */ | 104 /* Check that the given parameter values are supported. */ |
| 112 if (sb_kind != NACL_SB_DEFAULT) | 105 if (sb_kind != NACL_SB_DEFAULT) |
| 113 return NaClValidationFailedNotImplemented; | 106 return NaClValidationFailedNotImplemented; |
| 114 | 107 |
| 115 if (bundle_size != 16 && bundle_size != 32) | |
| 116 return NaClValidationFailedNotImplemented; | |
| 117 | |
| 118 if (!NaClArchSupported(cpu_features)) | 108 if (!NaClArchSupported(cpu_features)) |
| 119 return NaClValidationFailedCpuNotSupported; | 109 return NaClValidationFailedCpuNotSupported; |
| 120 | 110 |
| 121 return NCValidateSegmentPair(data_old, data_new, guest_addr, | 111 return NCValidateSegmentPair(data_old, data_new, guest_addr, |
| 122 size, bundle_size, cpu_features) | 112 size, cpu_features) |
| 123 ? NaClValidationSucceeded : NaClValidationFailed; | 113 ? NaClValidationSucceeded : NaClValidationFailed; |
| 124 } | 114 } |
| OLD | NEW |