| 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-64 architecture. */ | 7 /* Implement the ApplyValidator API for the x86-64 architecture. */ |
| 8 #include <assert.h> | 8 #include <assert.h> |
| 9 #include "native_client/src/shared/platform/nacl_log.h" | 9 #include "native_client/src/shared/platform/nacl_log.h" |
| 10 #include "native_client/src/trusted/validator/ncvalidate.h" | 10 #include "native_client/src/trusted/validator/ncvalidate.h" |
| 11 #include "native_client/src/trusted/validator/validation_cache.h" | 11 #include "native_client/src/trusted/validator/validation_cache.h" |
| 12 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter.
h" | 12 #include "native_client/src/trusted/validator/x86/ncval_reg_sfi/ncvalidate_iter.
h" |
| 13 | 13 |
| 14 /* Be sure the correct compile flags are defined for this. */ | 14 /* Be sure the correct compile flags are defined for this. */ |
| 15 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 | 15 #if NACL_ARCH(NACL_TARGET_ARCH) != NACL_x86 |
| 16 # error("Can't compile, target is for x86-64") | 16 # error("Can't compile, target is for x86-64") |
| 17 #else | 17 #else |
| 18 # if NACL_TARGET_SUBARCH != 64 | 18 # if NACL_TARGET_SUBARCH != 64 |
| 19 # error("Can't compile, target is for x86-64") | 19 # error("Can't compile, target is for x86-64") |
| 20 # endif | 20 # endif |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 NaClValidationStatus NaClValidatorSetup_x86_64( | 23 NaClValidationStatus NaClValidatorSetup_x86_64( |
| 24 intptr_t guest_addr, | 24 intptr_t guest_addr, |
| 25 size_t size, | 25 size_t size, |
| 26 int bundle_size, | |
| 27 int readonly_text, | 26 int readonly_text, |
| 28 const NaClCPUFeaturesX86 *cpu_features, | 27 const NaClCPUFeaturesX86 *cpu_features, |
| 29 struct NaClValidatorState** vstate_ptr) { | 28 struct NaClValidatorState** vstate_ptr) { |
| 30 *vstate_ptr = NaClValidatorStateCreate(guest_addr, size, bundle_size, RegR15, | 29 *vstate_ptr = NaClValidatorStateCreate(guest_addr, size, RegR15, |
| 31 readonly_text, cpu_features); | 30 readonly_text, cpu_features); |
| 32 return (*vstate_ptr == NULL) | 31 return (*vstate_ptr == NULL) |
| 33 ? NaClValidationFailedOutOfMemory | 32 ? NaClValidationFailedOutOfMemory |
| 34 : NaClValidationSucceeded; /* or at least to this point! */ | 33 : NaClValidationSucceeded; /* or at least to this point! */ |
| 35 } | 34 } |
| 36 | 35 |
| 37 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, x86, 64) ( | 36 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, x86, 64) ( |
| 38 enum NaClSBKind sb_kind, | 37 enum NaClSBKind sb_kind, |
| 39 uintptr_t guest_addr, | 38 uintptr_t guest_addr, |
| 40 uint8_t *data, | 39 uint8_t *data, |
| 41 size_t size, | 40 size_t size, |
| 42 int bundle_size, | |
| 43 int stubout_mode, | 41 int stubout_mode, |
| 44 int readonly_text, | 42 int readonly_text, |
| 45 const NaClCPUFeaturesX86 *cpu_features, | 43 const NaClCPUFeaturesX86 *cpu_features, |
| 46 struct NaClValidationCache *cache) { | 44 struct NaClValidationCache *cache) { |
| 47 struct NaClValidatorState *vstate; | 45 struct NaClValidatorState *vstate; |
| 48 NaClValidationStatus status; | 46 NaClValidationStatus status; |
| 49 void *query = NULL; | 47 void *query = NULL; |
| 50 | 48 |
| 51 /* Check that the given parameter values are supported. */ | 49 /* Check that the given parameter values are supported. */ |
| 52 if (sb_kind != NACL_SB_DEFAULT) | 50 if (sb_kind != NACL_SB_DEFAULT) |
| 53 return NaClValidationFailedNotImplemented; | 51 return NaClValidationFailedNotImplemented; |
| 54 | 52 |
| 55 if (bundle_size != 16 && bundle_size != 32) | |
| 56 return NaClValidationFailedNotImplemented; | |
| 57 | |
| 58 if (stubout_mode && readonly_text) | 53 if (stubout_mode && readonly_text) |
| 59 return NaClValidationFailedNotImplemented; | 54 return NaClValidationFailedNotImplemented; |
| 60 | 55 |
| 61 if (!NaClArchSupported(cpu_features)) | 56 if (!NaClArchSupported(cpu_features)) |
| 62 return NaClValidationFailedCpuNotSupported; | 57 return NaClValidationFailedCpuNotSupported; |
| 63 | 58 |
| 64 /* Don't cache in stubout mode. */ | 59 /* Don't cache in stubout mode. */ |
| 65 if (stubout_mode) | 60 if (stubout_mode) |
| 66 cache = NULL; | 61 cache = NULL; |
| 67 | 62 |
| 68 /* If the validation caching interface is available, perform a query. */ | 63 /* If the validation caching interface is available, perform a query. */ |
| 69 if (cache != NULL) | 64 if (cache != NULL) |
| 70 query = cache->CreateQuery(cache->handle); | 65 query = cache->CreateQuery(cache->handle); |
| 71 if (query != NULL) { | 66 if (query != NULL) { |
| 72 const char validator_id[] = "x86-64"; | 67 const char validator_id[] = "x86-64"; |
| 73 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 68 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
| 74 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 69 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
| 75 cache->AddData(query, data, size); | 70 cache->AddData(query, data, size); |
| 76 if (cache->QueryKnownToValidate(query)) { | 71 if (cache->QueryKnownToValidate(query)) { |
| 77 cache->DestroyQuery(query); | 72 cache->DestroyQuery(query); |
| 78 return NaClValidationSucceeded; | 73 return NaClValidationSucceeded; |
| 79 } | 74 } |
| 80 } | 75 } |
| 81 | 76 |
| 82 /* Init then validator state. */ | 77 /* Init then validator state. */ |
| 83 status = NaClValidatorSetup_x86_64( | 78 status = NaClValidatorSetup_x86_64( |
| 84 guest_addr, size, bundle_size, readonly_text, cpu_features, &vstate); | 79 guest_addr, size, readonly_text, cpu_features, &vstate); |
| 85 if (status != NaClValidationSucceeded) { | 80 if (status != NaClValidationSucceeded) { |
| 86 if (query != NULL) | 81 if (query != NULL) |
| 87 cache->DestroyQuery(query); | 82 cache->DestroyQuery(query); |
| 88 return status; | 83 return status; |
| 89 } | 84 } |
| 90 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR); | 85 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR); |
| 91 NaClValidatorStateSetDoStubOut(vstate, stubout_mode); | 86 NaClValidatorStateSetDoStubOut(vstate, stubout_mode); |
| 92 | 87 |
| 93 /* Validate. */ | 88 /* Validate. */ |
| 94 NaClValidateSegment(data, guest_addr, size, vstate); | 89 NaClValidateSegment(data, guest_addr, size, vstate); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 NaClValidatorStateDestroy(vstate); | 101 NaClValidatorStateDestroy(vstate); |
| 107 return status; | 102 return status; |
| 108 } | 103 } |
| 109 | 104 |
| 110 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, x86, 64) | 105 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, x86, 64) |
| 111 (enum NaClSBKind sb_kind, | 106 (enum NaClSBKind sb_kind, |
| 112 uintptr_t guest_addr, | 107 uintptr_t guest_addr, |
| 113 uint8_t *data_old, | 108 uint8_t *data_old, |
| 114 uint8_t *data_new, | 109 uint8_t *data_new, |
| 115 size_t size, | 110 size_t size, |
| 116 int bundle_size, | |
| 117 const NaClCPUFeaturesX86 *cpu_features) { | 111 const NaClCPUFeaturesX86 *cpu_features) { |
| 118 NaClValidationStatus status; | 112 NaClValidationStatus status; |
| 119 struct NaClValidatorState *vstate; | 113 struct NaClValidatorState *vstate; |
| 120 | 114 |
| 121 /* Check that the given parameter values are supported. */ | 115 /* Check that the given parameter values are supported. */ |
| 122 if (sb_kind != NACL_SB_DEFAULT) | 116 if (sb_kind != NACL_SB_DEFAULT) |
| 123 return NaClValidationFailedNotImplemented; | 117 return NaClValidationFailedNotImplemented; |
| 124 | 118 |
| 125 if (bundle_size != 16 && bundle_size != 32) | |
| 126 return NaClValidationFailedNotImplemented; | |
| 127 | |
| 128 if (!NaClArchSupported(cpu_features)) | 119 if (!NaClArchSupported(cpu_features)) |
| 129 return NaClValidationFailedCpuNotSupported; | 120 return NaClValidationFailedCpuNotSupported; |
| 130 | 121 |
| 131 /* Init then validator state. */ | 122 /* Init then validator state. */ |
| 132 status = NaClValidatorSetup_x86_64(guest_addr, size, bundle_size, FALSE, | 123 status = NaClValidatorSetup_x86_64(guest_addr, size, FALSE, |
| 133 cpu_features, &vstate); | 124 cpu_features, &vstate); |
| 134 if (status != NaClValidationSucceeded) | 125 if (status != NaClValidationSucceeded) |
| 135 return status; | 126 return status; |
| 136 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR); | 127 NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR); |
| 137 | 128 |
| 138 /* Validate. */ | 129 /* Validate. */ |
| 139 NaClValidateSegmentPair(data_old, data_new, guest_addr, size, vstate); | 130 NaClValidateSegmentPair(data_old, data_new, guest_addr, size, vstate); |
| 140 status = NaClValidatesOk(vstate) ? | 131 status = NaClValidatesOk(vstate) ? |
| 141 NaClValidationSucceeded : NaClValidationFailed; | 132 NaClValidationSucceeded : NaClValidationFailed; |
| 142 | 133 |
| 143 NaClValidatorStateDestroy(vstate); | 134 NaClValidatorStateDestroy(vstate); |
| 144 return status; | 135 return status; |
| 145 } | 136 } |
| OLD | NEW |