Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: src/trusted/validator_ragel/dfa_validate_32.c

Issue 1234393005: A mechanism to identify/forbid/"rewrite" non-temporal instructions (and other) (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Renaming Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 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 /*
(...skipping 13 matching lines...) Expand all
65 } 67 }
66 } 68 }
67 69
68 if (readonly_text) { 70 if (readonly_text) {
69 if (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, 71 if (ValidateChunkIA32(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 (ValidateChunkIA32(data, size, 0 /*options*/, cpu_features, 76 if (ValidateChunkIA32(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 if (status != NaClValidationSucceeded && errno == ENOMEM) 81 if (status != NaClValidationSucceeded && errno == ENOMEM)
80 status = NaClValidationFailedOutOfMemory; 82 status = NaClValidationFailedOutOfMemory;
81 83
82 /* Cache the result if validation succeeded and the code was not modified. */ 84 /* Cache the result if validation succeeded and the code was not modified. */
83 if (query != NULL) { 85 if (query != NULL) {
84 if (status == NaClValidationSucceeded && did_stubout == 0) 86 if (status == NaClValidationSucceeded && callback_data.did_rewrite == 0)
85 cache->SetKnownToValidate(query); 87 cache->SetKnownToValidate(query);
86 cache->DestroyQuery(query); 88 cache->DestroyQuery(query);
87 } 89 }
88 90
89 return status; 91 return status;
90 } 92 }
91 93
92 94
93 static NaClValidationStatus ValidatorCopy_x86_32( 95 static NaClValidationStatus ValidatorCopy_x86_32(
94 uintptr_t guest_addr, 96 uintptr_t guest_addr,
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 sizeof(NaClCPUFeaturesX86), 362 sizeof(NaClCPUFeaturesX86),
361 NaClSetAllCPUFeaturesX86, 363 NaClSetAllCPUFeaturesX86,
362 NaClGetCurrentCPUFeaturesX86, 364 NaClGetCurrentCPUFeaturesX86,
363 NaClFixCPUFeaturesX86, 365 NaClFixCPUFeaturesX86,
364 IsOnInstBoundary_x86_32, 366 IsOnInstBoundary_x86_32,
365 }; 367 };
366 368
367 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) { 369 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32(void) {
368 return &validator; 370 return &validator;
369 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698