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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 : NaClValidationSucceeded; /* or at least to this point! */ | 38 : NaClValidationSucceeded; /* or at least to this point! */ |
39 } | 39 } |
40 | 40 |
41 static NaClValidationStatus ApplyValidator_x86_64( | 41 static NaClValidationStatus ApplyValidator_x86_64( |
42 uintptr_t guest_addr, | 42 uintptr_t guest_addr, |
43 uint8_t *data, | 43 uint8_t *data, |
44 size_t size, | 44 size_t size, |
45 int stubout_mode, | 45 int stubout_mode, |
46 int readonly_text, | 46 int readonly_text, |
47 const NaClCPUFeatures *f, | 47 const NaClCPUFeatures *f, |
| 48 const struct NaClValidationMetadata *metadata, |
48 struct NaClValidationCache *cache) { | 49 struct NaClValidationCache *cache) { |
49 /* TODO(jfb) Use a safe cast here. */ | 50 /* TODO(jfb) Use a safe cast here. */ |
50 const NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; | 51 const NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; |
51 struct NaClValidatorState *vstate; | 52 struct NaClValidatorState *vstate; |
52 NaClValidationStatus status; | 53 NaClValidationStatus status; |
53 void *query = NULL; | 54 void *query = NULL; |
54 | 55 |
55 /* Check that the given parameter values are supported. */ | 56 /* Check that the given parameter values are supported. */ |
56 if (stubout_mode && readonly_text) | 57 if (stubout_mode && readonly_text) |
57 return NaClValidationFailedNotImplemented; | 58 return NaClValidationFailedNotImplemented; |
58 | 59 |
59 if (!NaClArchSupportedX86(cpu_features)) | 60 if (!NaClArchSupportedX86(cpu_features)) |
60 return NaClValidationFailedCpuNotSupported; | 61 return NaClValidationFailedCpuNotSupported; |
61 | 62 |
62 /* Don't cache in stubout mode. */ | 63 /* Don't cache in stubout mode. */ |
63 if (stubout_mode) | 64 if (stubout_mode) |
64 cache = NULL; | 65 cache = NULL; |
65 | 66 |
66 /* If the validation caching interface is available, perform a query. */ | 67 /* If the validation caching interface is available, perform a query. */ |
67 if (cache != NULL) | 68 if (cache != NULL) |
68 query = cache->CreateQuery(cache->handle); | 69 query = cache->CreateQuery(cache->handle); |
69 if (query != NULL) { | 70 if (query != NULL) { |
70 const char validator_id[] = "x86-64"; | 71 const char validator_id[] = "x86-64"; |
71 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 72 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
72 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 73 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
73 cache->AddData(query, data, size); | 74 AddCodeIdentity(data, size, metadata, cache, query); |
74 if (cache->QueryKnownToValidate(query)) { | 75 if (cache->QueryKnownToValidate(query)) { |
75 cache->DestroyQuery(query); | 76 cache->DestroyQuery(query); |
76 return NaClValidationSucceeded; | 77 return NaClValidationSucceeded; |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 /* Init then validator state. */ | 81 /* Init then validator state. */ |
81 status = NaClValidatorSetup_x86_64( | 82 status = NaClValidatorSetup_x86_64( |
82 guest_addr, size, readonly_text, cpu_features, &vstate); | 83 guest_addr, size, readonly_text, cpu_features, &vstate); |
83 if (status != NaClValidationSucceeded) { | 84 if (status != NaClValidationSucceeded) { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 ApplyValidatorCodeReplacement_x86_64, | 232 ApplyValidatorCodeReplacement_x86_64, |
232 sizeof(NaClCPUFeaturesX86), | 233 sizeof(NaClCPUFeaturesX86), |
233 NaClSetAllCPUFeaturesX86, | 234 NaClSetAllCPUFeaturesX86, |
234 NaClGetCurrentCPUFeaturesX86, | 235 NaClGetCurrentCPUFeaturesX86, |
235 NaClFixCPUFeaturesX86, | 236 NaClFixCPUFeaturesX86, |
236 }; | 237 }; |
237 | 238 |
238 const struct NaClValidatorInterface *NaClValidatorCreate_x86_64(void) { | 239 const struct NaClValidatorInterface *NaClValidatorCreate_x86_64(void) { |
239 return &validator; | 240 return &validator; |
240 } | 241 } |
OLD | NEW |