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 Validator API for the x86-64 architecture. */ | 7 /* Implement the Validator API for the x86-64 architecture. */ |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 int stubout_mode, | 32 int stubout_mode, |
33 uint32_t flags, | 33 uint32_t flags, |
34 int readonly_text, | 34 int readonly_text, |
35 const NaClCPUFeatures *f, | 35 const NaClCPUFeatures *f, |
36 const struct NaClValidationMetadata *metadata, | 36 const struct NaClValidationMetadata *metadata, |
37 struct NaClValidationCache *cache) { | 37 struct NaClValidationCache *cache) { |
38 /* TODO(jfb) Use a safe cast here. */ | 38 /* TODO(jfb) Use a safe cast here. */ |
39 NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; | 39 NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; |
40 enum NaClValidationStatus status = NaClValidationFailed; | 40 enum NaClValidationStatus status = NaClValidationFailed; |
41 void *query = NULL; | 41 void *query = NULL; |
| 42 uint32_t options; |
42 struct StubOutCallbackData callback_data; | 43 struct StubOutCallbackData callback_data; |
43 callback_data.flags = flags; | 44 |
44 callback_data.did_rewrite = 0; | |
45 UNREFERENCED_PARAMETER(guest_addr); | 45 UNREFERENCED_PARAMETER(guest_addr); |
46 | 46 |
47 if (stubout_mode) | 47 if (stubout_mode) |
48 return NaClValidationFailedNotImplemented; | 48 return NaClValidationFailedNotImplemented; |
49 if (!NaClArchSupportedX86(cpu_features)) | 49 if (!NaClArchSupportedX86(cpu_features)) |
50 return NaClValidationFailedCpuNotSupported; | 50 return NaClValidationFailedCpuNotSupported; |
51 if (size & kBundleMask) | 51 if (size & kBundleMask) |
52 return NaClValidationFailed; | 52 return NaClValidationFailed; |
53 | 53 |
54 /* | 54 /* |
55 * If the validation caching interface is available and it would be | 55 * If the validation caching interface is available and it would be |
56 * inexpensive to do so, perform a query. | 56 * inexpensive to do so, perform a query. |
57 */ | 57 */ |
58 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) | 58 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) |
59 query = cache->CreateQuery(cache->handle); | 59 query = cache->CreateQuery(cache->handle); |
60 if (query != NULL) { | 60 if (query != NULL) { |
61 const char validator_id[] = "x86-64 dfa"; | 61 const char validator_id[] = "x86-64 dfa"; |
62 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 62 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
63 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 63 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
64 NaClAddCodeIdentity(data, size, metadata, cache, query); | 64 NaClAddCodeIdentity(data, size, metadata, cache, query); |
65 if (cache->QueryKnownToValidate(query)) { | 65 if (cache->QueryKnownToValidate(query)) { |
66 cache->DestroyQuery(query); | 66 cache->DestroyQuery(query); |
67 return NaClValidationSucceeded; | 67 return NaClValidationSucceeded; |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
| 71 options = 0; |
| 72 callback_data.flags = flags; |
| 73 callback_data.chunk_processed_as_a_contiguous_stream = |
| 74 options & PROCESS_CHUNK_AS_A_CONTIGUOUS_STREAM; |
| 75 callback_data.bundle_begin_offset = (uintptr_t) data & kBundleMask; |
| 76 callback_data.cpu_features = cpu_features; |
| 77 callback_data.did_rewrite = 0; |
| 78 |
71 if (readonly_text) { | 79 if (readonly_text) { |
72 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 80 if (ValidateChunkAMD64(data, size, options, cpu_features, |
73 NaClDfaProcessValidationError, | 81 NaClDfaProcessValidationError, |
74 NULL)) | 82 NULL)) |
75 status = NaClValidationSucceeded; | 83 status = NaClValidationSucceeded; |
76 } else { | 84 } else { |
77 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 85 if (ValidateChunkAMD64(data, size, options, cpu_features, |
78 NaClDfaStubOutUnsupportedInstruction, | 86 NaClDfaStubOutUnsupportedInstruction, |
79 &callback_data)) | 87 &callback_data)) |
80 status = NaClValidationSucceeded; | 88 status = NaClValidationSucceeded; |
81 } | 89 } |
82 | 90 |
83 if (status != NaClValidationSucceeded && errno == ENOMEM) | 91 if (status != NaClValidationSucceeded && errno == ENOMEM) |
84 status = NaClValidationFailedOutOfMemory; | 92 status = NaClValidationFailedOutOfMemory; |
85 | 93 |
86 /* Cache the result if validation succeeded and the code was not modified. */ | 94 /* Cache the result if validation succeeded and the code was not modified. */ |
87 if (query != NULL) { | 95 if (query != NULL) { |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 sizeof(NaClCPUFeaturesX86), | 312 sizeof(NaClCPUFeaturesX86), |
305 NaClSetAllCPUFeaturesX86, | 313 NaClSetAllCPUFeaturesX86, |
306 NaClGetCurrentCPUFeaturesX86, | 314 NaClGetCurrentCPUFeaturesX86, |
307 NaClFixCPUFeaturesX86, | 315 NaClFixCPUFeaturesX86, |
308 IsOnInstBoundary_x86_64, | 316 IsOnInstBoundary_x86_64, |
309 }; | 317 }; |
310 | 318 |
311 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { | 319 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { |
312 return &validator; | 320 return &validator; |
313 } | 321 } |
OLD | NEW |