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 22 matching lines...) Expand all Loading... |
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 struct StubOutCallbackData callback_data; | 42 struct StubOutCallbackData callback_data; |
| 43 /* For revalidation */ |
| 44 struct StubOutCallbackData reval_callback_data; |
| 45 Bool reval_result = FALSE; |
| 46 |
43 callback_data.flags = flags; | 47 callback_data.flags = flags; |
44 callback_data.did_rewrite = 0; | 48 callback_data.did_rewrite = 0; |
| 49 reval_callback_data.flags = flags; |
| 50 reval_callback_data.did_rewrite = 0; |
45 UNREFERENCED_PARAMETER(guest_addr); | 51 UNREFERENCED_PARAMETER(guest_addr); |
46 | 52 |
47 if (stubout_mode) | 53 if (stubout_mode) |
48 return NaClValidationFailedNotImplemented; | 54 return NaClValidationFailedNotImplemented; |
49 if (!NaClArchSupportedX86(cpu_features)) | 55 if (!NaClArchSupportedX86(cpu_features)) |
50 return NaClValidationFailedCpuNotSupported; | 56 return NaClValidationFailedCpuNotSupported; |
51 if (size & kBundleMask) | 57 if (size & kBundleMask) |
52 return NaClValidationFailed; | 58 return NaClValidationFailed; |
53 | 59 |
54 /* | 60 /* |
(...skipping 14 matching lines...) Expand all Loading... |
69 } | 75 } |
70 | 76 |
71 if (readonly_text) { | 77 if (readonly_text) { |
72 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 78 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, |
73 NaClDfaProcessValidationError, | 79 NaClDfaProcessValidationError, |
74 NULL)) | 80 NULL)) |
75 status = NaClValidationSucceeded; | 81 status = NaClValidationSucceeded; |
76 } else { | 82 } else { |
77 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 83 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, |
78 NaClDfaStubOutUnsupportedInstruction, | 84 NaClDfaStubOutUnsupportedInstruction, |
79 &callback_data)) | 85 &callback_data)) { |
80 status = NaClValidationSucceeded; | 86 /* If code is rewritten, revalidate. */ |
| 87 if (callback_data.did_rewrite == 1) { |
| 88 reval_result = ValidateChunkIA32(data, size, 0 /*options*/, |
| 89 cpu_features, |
| 90 NaClDfaStubOutUnsupportedInstruction, |
| 91 &reval_callback_data); |
| 92 if (reval_result && reval_callback_data.did_rewrite == 0) |
| 93 status = NaClValidationSucceeded; |
| 94 } else { |
| 95 status = NaClValidationSucceeded; |
| 96 } |
| 97 } |
81 } | 98 } |
| 99 |
82 if (status != NaClValidationSucceeded && errno == ENOMEM) | 100 if (status != NaClValidationSucceeded && errno == ENOMEM) |
83 status = NaClValidationFailedOutOfMemory; | 101 status = NaClValidationFailedOutOfMemory; |
84 | 102 |
85 /* Cache the result if validation succeeded and the code was not modified. */ | 103 /* Cache the result if validation succeeded and the code was not modified. */ |
86 if (query != NULL) { | 104 if (query != NULL) { |
87 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) | 105 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
88 cache->SetKnownToValidate(query); | 106 cache->SetKnownToValidate(query); |
89 cache->DestroyQuery(query); | 107 cache->DestroyQuery(query); |
90 } | 108 } |
91 | 109 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 sizeof(NaClCPUFeaturesX86), | 382 sizeof(NaClCPUFeaturesX86), |
365 NaClSetAllCPUFeaturesX86, | 383 NaClSetAllCPUFeaturesX86, |
366 NaClGetCurrentCPUFeaturesX86, | 384 NaClGetCurrentCPUFeaturesX86, |
367 NaClFixCPUFeaturesX86, | 385 NaClFixCPUFeaturesX86, |
368 IsOnInstBoundary_x86_32, | 386 IsOnInstBoundary_x86_32, |
369 }; | 387 }; |
370 | 388 |
371 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { | 389 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { |
372 return &validator; | 390 return &validator; |
373 } | 391 } |
OLD | NEW |