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

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: upload error retry Created 8 years, 7 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
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 * 11
12 * Note that the API is designed to use the NACL_SUBARCH_NAME 12 #if NACL_WINDOWS == 0
13 * macro. This macro encapsulates the target architecture the 13 #include <stdint.h>
Nick Bray 2012/05/22 23:46:31 Comment: why?
pasko-google - do not use 2012/05/23 14:28:11 this is old portion of code, I replaced it in the
14 * code is being compiled for into the name of the function. 14 #endif
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 15
31 #include "native_client/src/include/nacl_base.h" 16 #include "native_client/src/include/nacl_base.h"
32 #include "native_client/src/shared/utils/types.h"
33 #include "native_client/src/trusted/validator/cpufeatures.h" 17 #include "native_client/src/trusted/validator/cpufeatures.h"
34 18
35 EXTERN_C_BEGIN 19 EXTERN_C_BEGIN
36 20
37 struct NaClValidationCache; 21 struct NaClValidationCache;
38 22
39 /* Defines possible validation status values. */ 23 /* Defines possible validation status values. */
40 typedef enum NaClValidationStatus { 24 typedef enum NaClValidationStatus {
41 /* The call to the validator succeeded. */ 25 /* The call to the validator succeeded. */
42 NaClValidationSucceeded, 26 NaClValidationSucceeded,
43 /* The call to the validator failed (Reason unspecified) */ 27 /* The call to the validator failed (Reason unspecified) */
44 NaClValidationFailed, 28 NaClValidationFailed,
45 /* The call to the validator failed, due to not enough memory. */ 29 /* The call to the validator failed, due to not enough memory. */
46 NaClValidationFailedOutOfMemory, 30 NaClValidationFailedOutOfMemory,
47 /* The call to the validator failed, due to it not being implemented yet. */ 31 /* The call to the validator failed, due to it not being implemented yet. */
48 NaClValidationFailedNotImplemented, 32 NaClValidationFailedNotImplemented,
49 /* The call to the validator failed, because the CPU is not supported. */ 33 /* The call to the validator failed, because the CPU is not supported. */
50 NaClValidationFailedCpuNotSupported, 34 NaClValidationFailedCpuNotSupported,
51 /* The call to the validator failed, due to segment alignment issues. */ 35 /* The call to the validator failed, due to segment alignment issues. */
52 NaClValidationFailedSegmentationIssue 36 NaClValidationFailedSegmentationIssue
53 } NaClValidationStatus; 37 } NaClValidationStatus;
54 38
55 /* Applies the validator, as defined by sel_ldr. That is, run the 39 /* Function type for applying a Validator, as defined by sel_ldr. That is, run
56 * validator where performance is critical. 40 * the validator where performance is critical.
41 *
57 * Parameters are: 42 * 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 43 * guest_addr - The virtual pc to assume with the beginning address of the
61 * code segment. Typically, this is the corresponding addresss that 44 * code segment. Typically, this is the corresponding addresss that
62 * will be used by objdump. 45 * will be used by objdump.
63 * data - The contents of the code segment to be validated. 46 * data - The contents of the code segment to be validated.
64 * size - The size of the code segment to be validated. 47 * size - The size of the code segment to be validated.
65 * stubout_mode - Whether the validator should stub out disallowed 48 * stubout_mode - Whether the validator should stub out disallowed
66 * instructions. This applies the validator silently, stubbing out 49 * instructions. This applies the validator silently, stubbing out
67 * instructions that may not validate with a suitable halt 50 * instructions that may not validate with a suitable halt
68 * instruction. Note: The return status of NaClValidationSucceeded in 51 * instruction. Note: The return status of NaClValidationSucceeded in
69 * this case does not necessarily imply that all illegal instructions 52 * this case does not necessarily imply that all illegal instructions
70 * have been stubbed out. It is the responsibility of the caller to 53 * 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 54 * 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 55 * valid. Typically used as the first step of a stubout tool (either
73 * in sel_ldr or command-line tool). 56 * in sel_ldr or command-line tool).
74 * readonly_text - If code should be considered read-only. 57 * readonly_text - If code should be considered read-only.
75 * cpu_features - The CPU features to support while validating. 58 * cpu_features - The CPU features to support while validating.
76 * cache - Pointer to NaCl validation cache. 59 * cache - Pointer to NaCl validation cache.
77 */ 60 */
78 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator, 61 typedef NaClValidationStatus (*NaClValidateFunc) (
79 NACL_TARGET_ARCH, 62 uintptr_t guest_addr,
80 NACL_TARGET_SUBARCH)( 63 uint8_t *data,
81 uintptr_t guest_addr, 64 size_t size,
82 uint8_t *data, 65 int stubout_mode,
83 size_t size, 66 int readonly_text,
84 int stubout_mode, 67 const NaClCPUFeatures *cpu_features,
85 int readonly_text,
86 const NaClCPUFeatures *cpu_features,
87 struct NaClValidationCache *cache); 68 struct NaClValidationCache *cache);
88 69
89 /* Applies the DFA-based validator as in the ApplyValidator case described 70 /* Function type to copy instruction safely. Returns non-zero on success.
90 * above. The interface of this new validator must remain the same as of the 71 * Exposed by the Service Runtime.
91 * ApplyValidator. Less arguments will be ignored as the new validator
92 * implements features, such as stubout mode.
93 */ 72 */
94 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyDfaValidator, 73 typedef int (*NaClCopyInstructionFunc) (
95 NACL_TARGET_ARCH, 74 uint8_t *dst,
96 NACL_TARGET_SUBARCH)( 75 uint8_t *src,
97 uintptr_t guest_addr, 76 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 77
105 /* Applies the validator, as used in a command-line tool to report issues. 78 /* Function type for applying a Validator to copy code from an existing code
106 * Note: This is intentionally separated from ApplyValidator, since it need 79 * segment to a new code segment.
107 * not be performance critical. 80 *
81 * Note: Current implementations use the instruction decoders, which may
82 * require that the code segment match native client rules.
83 *
108 * Parameters are: 84 * 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 85 * guest_addr - The virtual pc to assume with the beginning address of the
112 * code segment. Typically, this is the corresponding addresss that 86 * code segment. Typically, this is the corresponding addresss that
113 * will be used by objdump. 87 * will be used by objdump.
114 * data - The contents of the code segment to be validated. 88 * data_old - The contents of the original code segment.
115 * size - The size of the code segment to be validated. 89 * data_new - The addres of the new code segment for which the original
90 * code segment should be copied into.
91 * size - The size of the passed code segments.
116 * cpu_features - The CPU features to support while validating. 92 * cpu_features - The CPU features to support while validating.
93 * copy_func - Function to perform copying with.
117 */ 94 */
118 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely, 95 typedef NaClValidationStatus (*NaClCopyCodeFunc) (
119 NACL_TARGET_ARCH, 96 uintptr_t guest_addr,
120 NACL_TARGET_SUBARCH)( 97 uint8_t *data_old,
121 uintptr_t guest_addr, 98 uint8_t *data_new,
122 uint8_t *data, 99 size_t size,
123 size_t size, 100 const NaClCPUFeatures *cpu_features,
124 const NaClCPUFeatures *cpu_features); 101 const NaClCopyInstructionFunc copy_func);
125 102
126 /* Applies validator to new code segment, assuming that it was updated 103 /* Function type for applying a Validator on small updates to previously
127 * from the previously validated old code segment. Assumes that instruction 104 * validated code segments.
128 * sizes are the same. Only allows changes in branches that don't change 105 *
129 * instruction sizes. 106 * Assumes that instruction sizes are the same. Only allows changes in branches
Nick Bray 2012/05/22 23:46:31 FYI, I believe this documentation is incorrect. T
pasko-google - do not use 2012/05/23 14:28:11 Yes, when I looked at that later, I found that the
107 * that don't change instruction sizes.
108 *
130 * Parameters are: 109 * Parameters are:
131 * guest_addr - The virtual pc to assume with the beginning address of the 110 * guest_addr - The virtual pc to assume with the beginning address of the
132 * code segment. Typically, this is the corresponding addresss that 111 * code segment. Typically, this is the corresponding addresss that
133 * will be used by objdump. 112 * will be used by objdump.
134 * data_old - The contents of the original code segment. 113 * data_old - The contents of the original code segment.
135 * data_new - The contents of the new code segment that should be validated. 114 * data_new - The contents of the new code segment that should be validated.
136 * size - The size of the passed code segments. 115 * size - The size of the passed code segments.
137 * cpu_features - The CPU features to support while validating. 116 * cpu_features - The CPU features to support while validating.
138 */ 117 */
139 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, 118 typedef NaClValidationStatus (*NaClValidateCodeReplacementFunc) (
140 NACL_TARGET_ARCH, 119 uintptr_t guest_addr,
141 NACL_TARGET_SUBARCH)( 120 uint8_t *data_old,
142 uintptr_t guest_addr, 121 uint8_t *data_new,
143 uint8_t *data_old, 122 size_t size,
144 uint8_t *data_new, 123 const NaClCPUFeatures *cpu_features);
145 size_t size,
146 const NaClCPUFeatures *cpu_features);
147 124
148 /* Runs the validator to copy code from an existing code segment to a new 125 /* The full set of validator API. */
149 * code segment. 126 struct NaClValidatorInterface {
150 * 127 NaClValidateFunc Validate;
151 * Note: Current implementations uses the instruction decoders, which may 128 NaClCopyCodeFunc CopyCode;
152 * require that the code segment match native client rules. 129 NaClValidateCodeReplacementFunc ValidateCodeReplacement;
130 };
131
132 /* Make a choice of validating functions. */
133 extern const struct NaClValidatorInterface* NaClCreateValidator();
134
135 /* Known Validator API initializers. Private. Do not use outside validator. */
136 extern const struct NaClValidatorInterface* NaClValidatorCreate_x86_64();
Nick Bray 2012/05/22 23:46:31 "extern" not needed for function declarations. Sc
pasko-google - do not use 2012/05/23 14:28:11 yes, the main rationale to have it here was to avo
137 extern const struct NaClValidatorInterface* NaClValidatorCreate_x86_32();
138 extern const struct NaClValidatorInterface* NaClDfaValidatorCreate_x86_32();
139 extern const struct NaClValidatorInterface* NaClDfaValidatorCreate_x86_64();
140 extern const struct NaClValidatorInterface* NaClValidatorCreateArm();
141
142 /* Applies the validator, as used in a command-line tool to report issues.
143 * Note: This is intentionally separated from ApplyValidator, since it need
144 * not be performance critical.
153 * 145 *
154 * Parameters are: 146 * Parameters are:
155 * guest_addr - The virtual pc to assume with the beginning address of the 147 * guest_addr - The virtual pc to assume with the beginning address of the
156 * code segment. Typically, this is the corresponding addresss that 148 * code segment. Typically, this is the corresponding addresss that
157 * will be used by objdump. 149 * will be used by objdump.
158 * data_old - The contents of the original code segment. 150 * data - The contents of the code segment to be validated.
159 * data_new - The addres of the new code segment for which the original 151 * 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. 152 * cpu_features - The CPU features to support while validating.
163 */ 153 */
164 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, 154 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely,
165 NACL_TARGET_ARCH, 155 NACL_TARGET_ARCH,
166 NACL_TARGET_SUBARCH)( 156 NACL_TARGET_SUBARCH)(
167 uintptr_t guest_addr, 157 uintptr_t guest_addr,
Nick Bray 2012/05/22 23:46:31 You've eliminated whitespace alignment elsewhere (
pasko-google - do not use 2012/05/23 14:28:11 Done.
168 uint8_t *data_old, 158 uint8_t *data,
169 uint8_t *data_new, 159 size_t size,
170 size_t size, 160 const NaClCPUFeatures *cpu_features);
171 const NaClCPUFeatures *cpu_features);
172 161
173 EXTERN_C_END 162 EXTERN_C_END
174 163
175 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */ 164 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698