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 StubOutCallbackData callback_data; | |
Petr Hosek
2015/07/28 19:05:46
ditto
ruiq
2015/07/28 21:34:56
Done.
| |
43 callback_data.pnacl_mode = pnacl_mode; | |
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 /* |
52 * If the validation caching interface is available and it would be | 55 * If the validation caching interface is available and it would be |
53 * inexpensive to do so, perform a query. | 56 * inexpensive to do so, perform a query. |
54 */ | 57 */ |
55 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) | 58 if (cache != NULL && NaClCachingIsInexpensive(cache, metadata)) |
56 query = cache->CreateQuery(cache->handle); | 59 query = cache->CreateQuery(cache->handle); |
57 if (query != NULL) { | 60 if (query != NULL) { |
58 const char validator_id[] = "x86-64 dfa"; | 61 const char validator_id[] = "x86-64 dfa"; |
59 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); | 62 cache->AddData(query, (uint8_t *) validator_id, sizeof(validator_id)); |
60 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); | 63 cache->AddData(query, (uint8_t *) cpu_features, sizeof(*cpu_features)); |
61 NaClAddCodeIdentity(data, size, metadata, cache, query); | 64 NaClAddCodeIdentity(data, size, metadata, cache, query); |
62 if (cache->QueryKnownToValidate(query)) { | 65 if (cache->QueryKnownToValidate(query)) { |
63 cache->DestroyQuery(query); | 66 cache->DestroyQuery(query); |
64 return NaClValidationSucceeded; | 67 return NaClValidationSucceeded; |
65 } | 68 } |
66 } | 69 } |
67 | 70 |
68 if (readonly_text) { | 71 if (readonly_text) { |
69 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 72 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, |
70 NaClDfaProcessValidationError, | 73 NaClDfaProcessValidationError, |
Petr Hosek
2015/07/28 19:05:46
Could you please align this line to start on the s
ruiq
2015/07/28 22:00:30
Done.
| |
71 NULL)) | 74 NULL)) |
72 status = NaClValidationSucceeded; | 75 status = NaClValidationSucceeded; |
73 } else { | 76 } else { |
74 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, | 77 if (ValidateChunkAMD64(data, size, 0 /*options*/, cpu_features, |
75 NaClDfaStubOutCPUUnsupportedInstruction, | 78 NaClDfaStubOutUnsupportedInstruction, |
Petr Hosek
2015/07/28 19:05:46
ditto
ruiq
2015/07/28 22:00:30
Done.
| |
76 &did_stubout)) | 79 &callback_data)) |
77 status = NaClValidationSucceeded; | 80 status = NaClValidationSucceeded; |
78 } | 81 } |
79 | 82 |
80 if (status != NaClValidationSucceeded && errno == ENOMEM) | 83 if (status != NaClValidationSucceeded && errno == ENOMEM) |
81 status = NaClValidationFailedOutOfMemory; | 84 status = NaClValidationFailedOutOfMemory; |
82 | 85 |
83 /* Cache the result if validation succeeded and the code was not modified. */ | 86 /* Cache the result if validation succeeded and the code was not modified. */ |
84 if (query != NULL) { | 87 if (query != NULL) { |
85 if (status == NaClValidationSucceeded && did_stubout == 0) | 88 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0) |
86 cache->SetKnownToValidate(query); | 89 cache->SetKnownToValidate(query); |
87 cache->DestroyQuery(query); | 90 cache->DestroyQuery(query); |
88 } | 91 } |
89 | 92 |
90 return status; | 93 return status; |
91 } | 94 } |
92 | 95 |
93 | 96 |
94 static NaClValidationStatus ValidatorCodeCopy_x86_64( | 97 static NaClValidationStatus ValidatorCodeCopy_x86_64( |
95 uintptr_t guest_addr, | 98 uintptr_t guest_addr, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 sizeof(NaClCPUFeaturesX86), | 303 sizeof(NaClCPUFeaturesX86), |
301 NaClSetAllCPUFeaturesX86, | 304 NaClSetAllCPUFeaturesX86, |
302 NaClGetCurrentCPUFeaturesX86, | 305 NaClGetCurrentCPUFeaturesX86, |
303 NaClFixCPUFeaturesX86, | 306 NaClFixCPUFeaturesX86, |
304 IsOnInstBoundary_x86_64, | 307 IsOnInstBoundary_x86_64, |
305 }; | 308 }; |
306 | 309 |
307 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { | 310 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64(void) { |
308 return &validator; | 311 return &validator; |
309 } | 312 } |
OLD | NEW |