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 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 (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 78 if (ValidateChunkAMD64(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 (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 83 if (ValidateChunkAMD64(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 = ValidateChunkAMD64(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 } |
82 | 99 |
83 if (status != NaClValidationSucceeded && errno == ENOMEM) | 100 if (status != NaClValidationSucceeded && errno == ENOMEM) |
84 status = NaClValidationFailedOutOfMemory; | 101 status = NaClValidationFailedOutOfMemory; |
85 | 102 |
86 /* 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. */ |
87 if (query != NULL) { | 104 if (query != NULL) { |
88 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) | 105 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
89 cache->SetKnownToValidate(query); | 106 cache->SetKnownToValidate(query); |
90 cache->DestroyQuery(query); | 107 cache->DestroyQuery(query); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 sizeof(NaClCPUFeaturesX86), | 321 sizeof(NaClCPUFeaturesX86), |
305 NaClSetAllCPUFeaturesX86, | 322 NaClSetAllCPUFeaturesX86, |
306 NaClGetCurrentCPUFeaturesX86, | 323 NaClGetCurrentCPUFeaturesX86, |
307 NaClFixCPUFeaturesX86, | 324 NaClFixCPUFeaturesX86, |
308 IsOnInstBoundary_x86_64, | 325 IsOnInstBoundary_x86_64, |
309 }; | 326 }; |
310 | 327 |
311 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { | 328 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { |
312 return &validator; | 329 return &validator; |
313 } | 330 } |
OLD | NEW |