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-32 architecture. */ | 7 /* Implement the Validator API for the x86-32 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-32 dfa"; | 61 const char validator_id[] = "x86-32 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) != 0; |
| 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 (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 80 if (ValidateChunkIA32(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 (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 85 if (ValidateChunkIA32(data, size, options, cpu_features, |
78 NaClDfaStubOutUnsupportedInstruction, | 86 NaClDfaStubOutUnsupportedInstruction, |
79 &callback_data)) | 87 &callback_data)) |
80 status = NaClValidationSucceeded; | 88 status = NaClValidationSucceeded; |
81 } | 89 } |
| 90 |
82 if (status != NaClValidationSucceeded && errno == ENOMEM) | 91 if (status != NaClValidationSucceeded && errno == ENOMEM) |
83 status = NaClValidationFailedOutOfMemory; | 92 status = NaClValidationFailedOutOfMemory; |
84 | 93 |
85 /* 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. */ |
86 if (query != NULL) { | 95 if (query != NULL) { |
87 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) | 96 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
88 cache->SetKnownToValidate(query); | 97 cache->SetKnownToValidate(query); |
89 cache->DestroyQuery(query); | 98 cache->DestroyQuery(query); |
90 } | 99 } |
91 | 100 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 sizeof(NaClCPUFeaturesX86), | 373 sizeof(NaClCPUFeaturesX86), |
365 NaClSetAllCPUFeaturesX86, | 374 NaClSetAllCPUFeaturesX86, |
366 NaClGetCurrentCPUFeaturesX86, | 375 NaClGetCurrentCPUFeaturesX86, |
367 NaClFixCPUFeaturesX86, | 376 NaClFixCPUFeaturesX86, |
368 IsOnInstBoundary_x86_32, | 377 IsOnInstBoundary_x86_32, |
369 }; | 378 }; |
370 | 379 |
371 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { | 380 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { |
372 return &validator; | 381 return &validator; |
373 } | 382 } |
OLD | NEW |