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 12 matching lines...) Expand all Loading... |
23 # endif | 23 # endif |
24 #endif | 24 #endif |
25 | 25 |
26 static NaClValidationStatus ApplyValidator_x86_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 NaClCPUFeatures *f, | 32 const NaClCPUFeatures *f, |
| 33 const struct NaClValidationMetadata *metadata, |
33 struct NaClValidationCache *cache) { | 34 struct NaClValidationCache *cache) { |
34 /* TODO(jfb) Use a safe cast here. */ | 35 /* TODO(jfb) Use a safe cast here. */ |
35 const NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; | 36 const NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; |
36 struct NCValidatorState *vstate; | 37 struct NCValidatorState *vstate; |
37 int validator_result = 0; | 38 int validator_result = 0; |
38 void *query = NULL; | 39 void *query = NULL; |
39 | 40 |
40 /* Check that the given parameter values are supported. */ | 41 /* Check that the given parameter values are supported. */ |
41 if (stubout_mode && readonly_text) | 42 if (stubout_mode && readonly_text) |
42 return NaClValidationFailedNotImplemented; | 43 return NaClValidationFailedNotImplemented; |
43 | 44 |
44 if (!NaClArchSupportedX86(cpu_features)) | 45 if (!NaClArchSupportedX86(cpu_features)) |
45 return NaClValidationFailedCpuNotSupported; | 46 return NaClValidationFailedCpuNotSupported; |
46 | 47 |
47 /* Don't cache in stubout mode. */ | 48 /* Don't cache in stubout mode. */ |
48 if (stubout_mode) | 49 if (stubout_mode) |
49 cache = NULL; | 50 cache = NULL; |
50 | 51 |
51 /* If the validation caching interface is available, perform a query. */ | 52 /* If the validation caching interface is available, perform a query. */ |
52 if (cache != NULL) | 53 if (cache != NULL) |
53 query = cache->CreateQuery(cache->handle); | 54 query = cache->CreateQuery(cache->handle); |
54 if (query != NULL) { | 55 if (query != NULL) { |
55 const char validator_id[] = "x86-32"; | 56 const char validator_id[] = "x86-32"; |
56 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 57 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
57 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 58 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
58 cache->AddData(query, data, size); | 59 AddCodeIdentity(data, size, metadata, cache, query); |
59 if (cache->QueryKnownToValidate(query)) { | 60 if (cache->QueryKnownToValidate(query)) { |
60 cache->DestroyQuery(query); | 61 cache->DestroyQuery(query); |
61 return NaClValidationSucceeded; | 62 return NaClValidationSucceeded; |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 /* Init then validator state. */ | 66 /* Init then validator state. */ |
66 /* TODO(ncbray) make "detailed" a parameter. */ | 67 /* TODO(ncbray) make "detailed" a parameter. */ |
67 if (stubout_mode) { | 68 if (stubout_mode) { |
68 vstate = NCValidateInitDetailed(guest_addr, size, cpu_features); | 69 vstate = NCValidateInitDetailed(guest_addr, size, cpu_features); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 ApplyValidatorCodeReplacement_x86_32, | 171 ApplyValidatorCodeReplacement_x86_32, |
171 sizeof(NaClCPUFeaturesX86), | 172 sizeof(NaClCPUFeaturesX86), |
172 NaClSetAllCPUFeaturesX86, | 173 NaClSetAllCPUFeaturesX86, |
173 NaClGetCurrentCPUFeaturesX86, | 174 NaClGetCurrentCPUFeaturesX86, |
174 NaClFixCPUFeaturesX86, | 175 NaClFixCPUFeaturesX86, |
175 }; | 176 }; |
176 | 177 |
177 const struct NaClValidatorInterface *NaClValidatorCreate_x86_32(void) { | 178 const struct NaClValidatorInterface *NaClValidatorCreate_x86_32(void) { |
178 return &validator; | 179 return &validator; |
179 } | 180 } |
OLD | NEW |