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 12 matching lines...) Expand all Loading... |
23 */ | 23 */ |
24 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 32 | 24 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 32 |
25 # error "Can't compile, target is for x86-32" | 25 # error "Can't compile, target is for x86-32" |
26 #endif | 26 #endif |
27 | 27 |
28 NaClValidationStatus ApplyDfaValidator_x86_32( | 28 NaClValidationStatus ApplyDfaValidator_x86_32( |
29 uintptr_t guest_addr, | 29 uintptr_t guest_addr, |
30 uint8_t *data, | 30 uint8_t *data, |
31 size_t size, | 31 size_t size, |
32 int stubout_mode, | 32 int stubout_mode, |
| 33 uint32_t flags, |
33 int readonly_text, | 34 int readonly_text, |
34 const NaClCPUFeatures *f, | 35 const NaClCPUFeatures *f, |
35 const struct NaClValidationMetadata *metadata, | 36 const struct NaClValidationMetadata *metadata, |
36 struct NaClValidationCache *cache) { | 37 struct NaClValidationCache *cache) { |
37 /* TODO(jfb) Use a safe cast here. */ | 38 /* TODO(jfb) Use a safe cast here. */ |
38 NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; | 39 NaClCPUFeaturesX86 *cpu_features = (NaClCPUFeaturesX86 *) f; |
39 enum NaClValidationStatus status = NaClValidationFailed; | 40 enum NaClValidationStatus status = NaClValidationFailed; |
40 int did_stubout = 0; | |
41 void *query = NULL; | 41 void *query = NULL; |
| 42 struct StubOutCallbackData callback_data; |
| 43 callback_data.flags = flags; |
| 44 callback_data.did_rewrite = 0; |
42 UNREFERENCED_PARAMETER(guest_addr); | 45 UNREFERENCED_PARAMETER(guest_addr); |
43 | 46 |
44 if (stubout_mode) | 47 if (stubout_mode) |
45 return NaClValidationFailedNotImplemented; | 48 return NaClValidationFailedNotImplemented; |
46 if (!NaClArchSupportedX86(cpu_features)) | 49 if (!NaClArchSupportedX86(cpu_features)) |
47 return NaClValidationFailedCpuNotSupported; | 50 return NaClValidationFailedCpuNotSupported; |
48 if (size & kBundleMask) | 51 if (size & kBundleMask) |
49 return NaClValidationFailed; | 52 return NaClValidationFailed; |
50 | 53 |
51 /* | 54 /* |
(...skipping 13 matching lines...) Expand all Loading... |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 if (readonly_text) { | 71 if (readonly_text) { |
69 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 72 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, |
70 NaClDfaProcessValidationError, | 73 NaClDfaProcessValidationError, |
71 NULL)) | 74 NULL)) |
72 status = NaClValidationSucceeded; | 75 status = NaClValidationSucceeded; |
73 } else { | 76 } else { |
74 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, | 77 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, |
75 NaClDfaStubOutCPUUnsupportedInstruction, | 78 NaClDfaStubOutUnsupportedInstruction, |
76 &did_stubout)) | 79 &callback_data)) |
77 status = NaClValidationSucceeded; | 80 status = NaClValidationSucceeded; |
78 } | 81 } |
79 if (status != NaClValidationSucceeded && errno == ENOMEM) | 82 if (status != NaClValidationSucceeded && errno == ENOMEM) |
80 status = NaClValidationFailedOutOfMemory; | 83 status = NaClValidationFailedOutOfMemory; |
81 | 84 |
82 /* Cache the result if validation succeeded and the code was not modified. */ | 85 /* Cache the result if validation succeeded and the code was not modified. */ |
83 if (query != NULL) { | 86 if (query != NULL) { |
84 if (status == NaClValidationSucceeded && did_stubout == 0) | 87 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
85 cache->SetKnownToValidate(query); | 88 cache->SetKnownToValidate(query); |
86 cache->DestroyQuery(query); | 89 cache->DestroyQuery(query); |
87 } | 90 } |
88 | 91 |
89 return status; | 92 return status; |
90 } | 93 } |
91 | 94 |
92 | 95 |
93 static NaClValidationStatus ValidatorCopy_x86_32( | 96 static NaClValidationStatus ValidatorCopy_x86_32( |
94 uintptr_t guest_addr, | 97 uintptr_t guest_addr, |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 sizeof(NaClCPUFeaturesX86), | 364 sizeof(NaClCPUFeaturesX86), |
362 NaClSetAllCPUFeaturesX86, | 365 NaClSetAllCPUFeaturesX86, |
363 NaClGetCurrentCPUFeaturesX86, | 366 NaClGetCurrentCPUFeaturesX86, |
364 NaClFixCPUFeaturesX86, | 367 NaClFixCPUFeaturesX86, |
365 IsOnInstBoundary_x86_32, | 368 IsOnInstBoundary_x86_32, |
366 }; | 369 }; |
367 | 370 |
368 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { | 371 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { |
369 return &validator; | 372 return &validator; |
370 } | 373 } |
OLD | NEW |