| 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 ApplyDfaValidator API for the x86-32 architecture. */ | 7 /* Implement the Validator API for the x86-32 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_ragel/unreviewed/validator.h" | 12 #include "native_client/src/trusted/validator_ragel/unreviewed/validator.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-32") | 16 # error("Can't compile, target is for x86-32") |
| 17 #else | 17 #else |
| 18 # if NACL_TARGET_SUBARCH != 32 | 18 # if NACL_TARGET_SUBARCH != 32 |
| 19 # error("Can't compile, target is for x86-32") | 19 # error("Can't compile, target is for x86-32") |
| 20 # endif | 20 # endif |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 | 23 |
| 24 static void ProcessError(const uint8_t *ptr, void *userdata) { | 24 static void ProcessError(const uint8_t *ptr, void *userdata) { |
| 25 UNREFERENCED_PARAMETER(ptr); | 25 UNREFERENCED_PARAMETER(ptr); |
| 26 UNREFERENCED_PARAMETER(userdata); | 26 UNREFERENCED_PARAMETER(userdata); |
| 27 } | 27 } |
| 28 | 28 |
| 29 NaClValidationStatus NACL_SUBARCH_NAME(ApplyDfaValidator, x86, 32) ( | 29 NaClValidationStatus ApplyDfaValidator_x86_32( |
| 30 uintptr_t guest_addr, | 30 uintptr_t guest_addr, |
| 31 uint8_t *data, | 31 uint8_t *data, |
| 32 size_t size, | 32 size_t size, |
| 33 int stubout_mode, | 33 int stubout_mode, |
| 34 int readonly_text, | 34 int readonly_text, |
| 35 const NaClCPUFeaturesX86 *cpu_features, | 35 const NaClCPUFeaturesX86 *cpu_features, |
| 36 struct NaClValidationCache *cache) { | 36 struct NaClValidationCache *cache) { |
| 37 UNREFERENCED_PARAMETER(guest_addr); | 37 UNREFERENCED_PARAMETER(guest_addr); |
| 38 UNREFERENCED_PARAMETER(cache); | 38 UNREFERENCED_PARAMETER(cache); |
| 39 | 39 |
| 40 if (stubout_mode || readonly_text) { | 40 if (stubout_mode || readonly_text) { |
| 41 return NaClValidationFailedNotImplemented; | 41 return NaClValidationFailedNotImplemented; |
| 42 } | 42 } |
| 43 if (!NaClArchSupported(cpu_features)) { | 43 if (!NaClArchSupported(cpu_features)) { |
| 44 return NaClValidationFailedCpuNotSupported; | 44 return NaClValidationFailedCpuNotSupported; |
| 45 } | 45 } |
| 46 if (ValidateChunkIA32(data, size, cpu_features, ProcessError, 0) == 0) { | 46 if (ValidateChunkIA32(data, size, cpu_features, ProcessError, 0) == 0) { |
| 47 return NaClValidationSucceeded; | 47 return NaClValidationSucceeded; |
| 48 } | 48 } |
| 49 return NaClValidationFailed; | 49 return NaClValidationFailed; |
| 50 } | 50 } |
| 51 |
| 52 static NaClValidationStatus ValidatorCopyNotImplemented( |
| 53 uintptr_t guest_addr, |
| 54 uint8_t *data_old, |
| 55 uint8_t *data_new, |
| 56 size_t size, |
| 57 const NaClCPUFeatures *cpu_features, |
| 58 NaClCopyInstructionFunc copy_func) { |
| 59 UNREFERENCED_PARAMETER(guest_addr); |
| 60 UNREFERENCED_PARAMETER(data_old); |
| 61 UNREFERENCED_PARAMETER(data_new); |
| 62 UNREFERENCED_PARAMETER(size); |
| 63 UNREFERENCED_PARAMETER(cpu_features); |
| 64 UNREFERENCED_PARAMETER(copy_func); |
| 65 return NaClValidationFailedNotImplemented; |
| 66 } |
| 67 |
| 68 static NaClValidationStatus ValidatorCodeReplacementNotImplemented( |
| 69 uintptr_t guest_addr, |
| 70 uint8_t *data_old, |
| 71 uint8_t *data_new, |
| 72 size_t size, |
| 73 const NaClCPUFeatures *cpu_features) { |
| 74 UNREFERENCED_PARAMETER(guest_addr); |
| 75 UNREFERENCED_PARAMETER(data_old); |
| 76 UNREFERENCED_PARAMETER(data_new); |
| 77 UNREFERENCED_PARAMETER(size); |
| 78 UNREFERENCED_PARAMETER(cpu_features); |
| 79 return NaClValidationFailedNotImplemented; |
| 80 } |
| 81 |
| 82 static const struct NaClValidatorInterface validator = { |
| 83 ApplyDfaValidator_x86_32, |
| 84 ValidatorCopyNotImplemented, |
| 85 ValidatorCodeReplacementNotImplemented, |
| 86 }; |
| 87 |
| 88 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32() { |
| 89 return &validator; |
| 90 } |
| OLD | NEW |