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

Side by Side Diff: src/trusted/validator/ncvalidate.h

Issue 10134056: Refactor the process of choosing validators. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: more aesthetics Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « src/trusted/validator/build.scons ('k') | src/trusted/validator/validation_cache_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ 7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__
8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ 8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__
9 9
10 /* Defines the API to the native client validation code. 10 /* Defines the API exposed by the Native Client validators. */
11 *
12 * Note that the API is designed to use the NACL_SUBARCH_NAME
13 * macro. This macro encapsulates the target architecture the
14 * code is being compiled for into the name of the function.
15 * This lets the API call different functions based on the
16 * target architecture the code is being compiled for. It also allows
17 * the maintainers of the compiled libraries to change the implementation
18 * without having to update the API callers.
19 *
20 * The macro NACL_SUBARCH_NAME(name, arch, subarch) prepends "NaCl_"
21 * to the function name, and suffixes it with the architecture and
22 * corresponding subarchitecture (with underscores separating it).
23 * Hence, for example, NACL_SUBARCH_NAME(ApplyValidator, x86, 64)
24 * would generate the function name NaCL_ApplyValidator_x86_64.
25 */
26 /* TODO(bradchen): Cleanup the interface to the validator. There
27 * are too many combinations of different calls and input parameters,
28 * making this interface hard to understand and hard to modify.
29 */
30 11
31 #include "native_client/src/include/nacl_base.h" 12 #include "native_client/src/include/nacl_base.h"
32 #include "native_client/src/shared/utils/types.h" 13 #include "native_client/src/include/portability.h"
33 #include "native_client/src/trusted/validator/cpufeatures.h" 14 #include "native_client/src/trusted/validator/cpufeatures.h"
34 15
35 EXTERN_C_BEGIN 16 EXTERN_C_BEGIN
36 17
37 struct NaClValidationCache; 18 struct NaClValidationCache;
38 19
39 /* Defines possible validation status values. */ 20 /* Defines possible validation status values. */
40 typedef enum NaClValidationStatus { 21 typedef enum NaClValidationStatus {
41 /* The call to the validator succeeded. */ 22 /* The call to the validator succeeded. */
42 NaClValidationSucceeded, 23 NaClValidationSucceeded,
43 /* The call to the validator failed (Reason unspecified) */ 24 /* The call to the validator failed (Reason unspecified) */
44 NaClValidationFailed, 25 NaClValidationFailed,
45 /* The call to the validator failed, due to not enough memory. */ 26 /* The call to the validator failed, due to not enough memory. */
46 NaClValidationFailedOutOfMemory, 27 NaClValidationFailedOutOfMemory,
47 /* The call to the validator failed, due to it not being implemented yet. */ 28 /* The call to the validator failed, due to it not being implemented yet. */
48 NaClValidationFailedNotImplemented, 29 NaClValidationFailedNotImplemented,
49 /* The call to the validator failed, because the CPU is not supported. */ 30 /* The call to the validator failed, because the CPU is not supported. */
50 NaClValidationFailedCpuNotSupported, 31 NaClValidationFailedCpuNotSupported,
51 /* The call to the validator failed, due to segment alignment issues. */ 32 /* The call to the validator failed, due to segment alignment issues. */
52 NaClValidationFailedSegmentationIssue 33 NaClValidationFailedSegmentationIssue
53 } NaClValidationStatus; 34 } NaClValidationStatus;
54 35
55 /* Applies the validator, as defined by sel_ldr. That is, run the 36 /* Function type for applying a validator, as defined by sel_ldr. That is, run
56 * validator where performance is critical. 37 * the validator where performance is critical.
38 *
57 * Parameters are: 39 * Parameters are:
58 * local_cpu: True if local cpu rules should be applied.
59 * Otherwise, assume no cpu specific rules.
60 * guest_addr - The virtual pc to assume with the beginning address of the 40 * guest_addr - The virtual pc to assume with the beginning address of the
61 * code segment. Typically, this is the corresponding addresss that 41 * code segment. Typically, this is the corresponding addresss that
62 * will be used by objdump. 42 * will be used by objdump.
63 * data - The contents of the code segment to be validated. 43 * data - The contents of the code segment to be validated.
64 * size - The size of the code segment to be validated. 44 * size - The size of the code segment to be validated.
65 * stubout_mode - Whether the validator should stub out disallowed 45 * stubout_mode - Whether the validator should stub out disallowed
66 * instructions. This applies the validator silently, stubbing out 46 * instructions. This applies the validator silently, stubbing out
67 * instructions that may not validate with a suitable halt 47 * instructions that may not validate with a suitable halt
68 * instruction. Note: The return status of NaClValidationSucceeded in 48 * instruction. Note: The return status of NaClValidationSucceeded in
69 * this case does not necessarily imply that all illegal instructions 49 * this case does not necessarily imply that all illegal instructions
70 * have been stubbed out. It is the responsibility of the caller to 50 * have been stubbed out. It is the responsibility of the caller to
71 * call the validator a second time to see if the stubbed code is 51 * call the validator a second time to see if the stubbed code is
72 * valid. Typically used as the first step of a stubout tool (either 52 * valid. Typically used as the first step of a stubout tool (either
73 * in sel_ldr or command-line tool). 53 * in sel_ldr or command-line tool).
74 * readonly_text - If code should be considered read-only. 54 * readonly_text - If code should be considered read-only.
75 * cpu_features - The CPU features to support while validating. 55 * cpu_features - The CPU features to support while validating.
76 * cache - Pointer to NaCl validation cache. 56 * cache - Pointer to NaCl validation cache.
77 */ 57 */
78 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, 58 typedef NaClValidationStatus (*NaClValidateFunc)(
79 NACL_TARGET_ARCH, 59 uintptr_t guest_addr,
80 NACL_TARGET_SUBARCH)( 60 uint8_t *data,
81 uintptr_t guest_addr, 61 size_t size,
82 uint8_t *data, 62 int stubout_mode,
83 size_t size, 63 int readonly_text,
84 int stubout_mode, 64 const NaClCPUFeatures *cpu_features,
85 int readonly_text,
86 const NaClCPUFeatures *cpu_features,
87 struct NaClValidationCache *cache); 65 struct NaClValidationCache *cache);
88 66
89 /* Applies the DFA-based validator as in the ApplyValidator case described 67 /* Function type to copy an instruction safely. Returns non-zero on success.
90 * above. The interface of this new validator must remain the same as of the 68 * Implemented by the Service Runtime.
91 * ApplyValidator. Less arguments will be ignored as the new validator
92 * implements features, such as stubout mode.
93 */ 69 */
94 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyDfaValidator, 70 typedef int (*NaClCopyInstructionFunc)(
95 NACL_TARGET_ARCH, 71 uint8_t *dst,
96 NACL_TARGET_SUBARCH)( 72 uint8_t *src,
97 uintptr_t guest_addr, 73 uint8_t sz);
98 uint8_t *data,
99 size_t size,
100 int stubout_mode,
101 int readonly_text,
102 const NaClCPUFeatures *cpu_features,
103 struct NaClValidationCache *cache);
104 74
105 /* Applies the validator, as used in a command-line tool to report issues. 75 /* Function type for applying a validator to copy code from an existing code
106 * Note: This is intentionally separated from ApplyValidator, since it need 76 * segment to a new code segment.
107 * not be performance critical. 77 *
78 * Note: Current implementations use the instruction decoders, which may
79 * require that the code segment match the Native Client rules.
80 *
108 * Parameters are: 81 * Parameters are:
109 * local_cpu: True if local cpu rules should be applied.
110 * Otherwise, assume no cpu specific rules.
111 * guest_addr - The virtual pc to assume with the beginning address of the 82 * guest_addr - The virtual pc to assume with the beginning address of the
112 * code segment. Typically, this is the corresponding addresss that 83 * code segment. Typically, this is the corresponding addresss that
113 * will be used by objdump. 84 * will be used by objdump.
114 * data - The contents of the code segment to be validated. 85 * data_old - The contents of the original code segment.
115 * size - The size of the code segment to be validated. 86 * data_new - The addres of the new code segment for which the original
87 * code segment should be copied into.
88 * size - The size of the passed code segments.
116 * cpu_features - The CPU features to support while validating. 89 * cpu_features - The CPU features to support while validating.
90 * copy_func - Function to perform copying with.
117 */ 91 */
118 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely, 92 typedef NaClValidationStatus (*NaClCopyCodeFunc)(
119 NACL_TARGET_ARCH, 93 uintptr_t guest_addr,
120 NACL_TARGET_SUBARCH)( 94 uint8_t *data_old,
121 uintptr_t guest_addr, 95 uint8_t *data_new,
122 uint8_t *data, 96 size_t size,
123 size_t size, 97 const NaClCPUFeatures *cpu_features,
124 const NaClCPUFeatures *cpu_features); 98 NaClCopyInstructionFunc copy_func);
125 99
126 /* Applies validator to new code segment, assuming that it was updated 100 /* Function type for applying a validator on small updates to previously
127 * from the previously validated old code segment. Assumes that instruction 101 * validated code segments.
128 * sizes are the same. Only allows changes in branches that don't change 102 *
129 * instruction sizes. 103 * Assumes that instruction sizes are the same. Only allows changes in branches
104 * that don't change instruction sizes.
105 *
130 * Parameters are: 106 * Parameters are:
131 * guest_addr - The virtual pc to assume with the beginning address of the 107 * guest_addr - The virtual pc to assume with the beginning address of the
132 * code segment. Typically, this is the corresponding addresss that 108 * code segment. Typically, this is the corresponding addresss that
133 * will be used by objdump. 109 * will be used by objdump.
134 * data_old - The contents of the original code segment. 110 * data_old - The contents of the original code segment.
135 * data_new - The contents of the new code segment that should be validated. 111 * data_new - The contents of the new code segment that should be validated.
136 * size - The size of the passed code segments. 112 * size - The size of the passed code segments.
137 * cpu_features - The CPU features to support while validating. 113 * cpu_features - The CPU features to support while validating.
138 */ 114 */
139 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, 115 typedef NaClValidationStatus (*NaClValidateCodeReplacementFunc)(
140 NACL_TARGET_ARCH, 116 uintptr_t guest_addr,
141 NACL_TARGET_SUBARCH)( 117 uint8_t *data_old,
142 uintptr_t guest_addr, 118 uint8_t *data_new,
143 uint8_t *data_old, 119 size_t size,
144 uint8_t *data_new, 120 const NaClCPUFeatures *cpu_features);
145 size_t size,
146 const NaClCPUFeatures *cpu_features);
147 121
148 /* Runs the validator to copy code from an existing code segment to a new 122 /* The full set of validator APIs. */
149 * code segment. 123 struct NaClValidatorInterface {
150 * 124 NaClValidateFunc Validate;
151 * Note: Current implementations uses the instruction decoders, which may 125 NaClCopyCodeFunc CopyCode;
152 * require that the code segment match native client rules. 126 NaClValidateCodeReplacementFunc ValidateCodeReplacement;
127 };
128
129 /* Make a choice of validating functions. */
130 const struct NaClValidatorInterface *NaClCreateValidator();
131
132 /* Known Validator API initializers. Private. Do not use outside validator. */
133 const struct NaClValidatorInterface *NaClValidatorCreate_x86_64();
134 const struct NaClValidatorInterface *NaClValidatorCreate_x86_32();
135 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_32();
136 const struct NaClValidatorInterface *NaClDfaValidatorCreate_x86_64();
137 const struct NaClValidatorInterface *NaClValidatorCreateArm();
138
139 /* Applies the validator, as used in a command-line tool to report issues.
140 * Note: This is intentionally separated from ApplyValidator, since it need
141 * not be performance critical.
153 * 142 *
154 * Parameters are: 143 * Parameters are:
155 * guest_addr - The virtual pc to assume with the beginning address of the 144 * guest_addr - The virtual pc to assume with the beginning address of the
156 * code segment. Typically, this is the corresponding addresss that 145 * code segment. Typically, this is the corresponding addresss that
157 * will be used by objdump. 146 * will be used by objdump.
158 * data_old - The contents of the original code segment. 147 * data - The contents of the code segment to be validated.
159 * data_new - The addres of the new code segment for which the original 148 * size - The size of the code segment to be validated.
160 * code segment should be copied into.
161 * size - The size of the passed code segments.
162 * cpu_features - The CPU features to support while validating. 149 * cpu_features - The CPU features to support while validating.
163 */ 150 */
164 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, 151 NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely,
165 NACL_TARGET_ARCH, 152 NACL_TARGET_ARCH,
166 NACL_TARGET_SUBARCH)( 153 NACL_TARGET_SUBARCH)(
167 uintptr_t guest_addr, 154 uintptr_t guest_addr,
168 uint8_t *data_old, 155 uint8_t *data,
169 uint8_t *data_new, 156 size_t size,
170 size_t size,
171 const NaClCPUFeatures *cpu_features); 157 const NaClCPUFeatures *cpu_features);
172 158
173 EXTERN_C_END 159 EXTERN_C_END
174 160
175 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */ 161 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */
OLDNEW
« no previous file with comments | « src/trusted/validator/build.scons ('k') | src/trusted/validator/validation_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698