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 12 matching lines...) Expand all Loading... |
23 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 64 | 23 #if NACL_ARCH(NACL_BUILD_ARCH) != NACL_x86 || NACL_BUILD_SUBARCH != 64 |
24 # error "Can't compile, target is for x86-64" | 24 # error "Can't compile, target is for x86-64" |
25 #endif | 25 #endif |
26 | 26 |
27 | 27 |
28 static NaClValidationStatus ApplyDfaValidator_x86_64( | 28 static NaClValidationStatus ApplyDfaValidator_x86_64( |
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 int pnacl_mode, |
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 ForbidRewriteCallbackData callback_data; |
| 43 callback_data.pnacl_mode = pnacl_mode; |
42 UNREFERENCED_PARAMETER(guest_addr); | 44 UNREFERENCED_PARAMETER(guest_addr); |
43 | 45 |
44 if (stubout_mode) | 46 if (stubout_mode) |
45 return NaClValidationFailedNotImplemented; | 47 return NaClValidationFailedNotImplemented; |
46 if (!NaClArchSupportedX86(cpu_features)) | 48 if (!NaClArchSupportedX86(cpu_features)) |
47 return NaClValidationFailedCpuNotSupported; | 49 return NaClValidationFailedCpuNotSupported; |
48 if (size & kBundleMask) | 50 if (size & kBundleMask) |
49 return NaClValidationFailed; | 51 return NaClValidationFailed; |
50 | 52 |
51 /* | 53 /* |
52 * If the validation caching interface is available and it would be | 54 * If the validation caching interface is available and it would be |
53 * inexpensive to do so, perform a query. | 55 * inexpensive to do so, perform a query. |
54 */ | 56 */ |
55 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) | 57 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) |
56 query = cache->CreateQuery(cache->handle); | 58 query = cache->CreateQuery(cache->handle); |
57 if (query != NULL) { | 59 if (query != NULL) { |
58 const char validator_id[] = "x86-64 dfa"; | 60 const char validator_id[] = "x86-64 dfa"; |
59 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 61 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
60 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 62 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
61 NaClAddCodeIdentity(data, size, metadata, cache, query); | 63 NaClAddCodeIdentity(data, size, metadata, cache, query); |
62 if (cache->QueryKnownToValidate(query)) { | 64 if (cache->QueryKnownToValidate(query)) { |
63 cache->DestroyQuery(query); | 65 cache->DestroyQuery(query); |
64 return NaClValidationSucceeded; | 66 return NaClValidationSucceeded; |
65 } | 67 } |
66 } | 68 } |
67 | 69 |
68 if (readonly_text) { | 70 if (readonly_text) { |
69 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 71 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, |
70 NaClDfaProcessValidationError, | 72 NaClDfaProcessValidationError, |
71 NULL)) | 73 NULL)) |
72 status = NaClValidationSucceeded; | 74 status = NaClValidationSucceeded; |
73 } else { | 75 } else { |
74 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 76 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, |
75 NaClDfaStubOutCPUUnsupportedInstruction, | 77 NaClDfaForbidOrRewriteInstruction, |
76 &did_stubout)) | 78 &callback_data)) |
77 status = NaClValidationSucceeded; | 79 status = NaClValidationSucceeded; |
78 } | 80 } |
79 | 81 |
80 if (status != NaClValidationSucceeded && errno == ENOMEM) | 82 if (status != NaClValidationSucceeded && errno == ENOMEM) |
81 status = NaClValidationFailedOutOfMemory; | 83 status = NaClValidationFailedOutOfMemory; |
82 | 84 |
83 /* 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. */ |
84 if (query != NULL) { | 86 if (query != NULL) { |
85 if (status == NaClValidationSucceeded && did_stubout == 0) | 87 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
86 cache->SetKnownToValidate(query); | 88 cache->SetKnownToValidate(query); |
87 cache->DestroyQuery(query); | 89 cache->DestroyQuery(query); |
88 } | 90 } |
89 | 91 |
90 return status; | 92 return status; |
91 } | 93 } |
92 | 94 |
93 | 95 |
94 static NaClValidationStatus ValidatorCodeCopy_x86_64( | 96 static NaClValidationStatus ValidatorCodeCopy_x86_64( |
95 uintptr_t guest_addr, | 97 uintptr_t guest_addr, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 sizeof(NaClCPUFeaturesX86), | 302 sizeof(NaClCPUFeaturesX86), |
301 NaClSetAllCPUFeaturesX86, | 303 NaClSetAllCPUFeaturesX86, |
302 NaClGetCurrentCPUFeaturesX86, | 304 NaClGetCurrentCPUFeaturesX86, |
303 NaClFixCPUFeaturesX86, | 305 NaClFixCPUFeaturesX86, |
304 IsOnInstBoundary_x86_64, | 306 IsOnInstBoundary_x86_64, |
305 }; | 307 }; |
306 | 308 |
307 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { | 309 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { |
308 return &validator; | 310 return &validator; |
309 } | 311 } |
OLD | NEW |