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

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: draft that does not fully build 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 to the native client validation code. */
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/shared/utils/types.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 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidator,
79 NACL_TARGET_ARCH, 59 NACL_TARGET_ARCH,
80 NACL_TARGET_SUBARCH)( 60 NACL_TARGET_SUBARCH)(
81 uintptr_t guest_addr, 61 uintptr_t guest_addr,
82 uint8_t *data, 62 uint8_t *data,
83 size_t size, 63 size_t size,
84 int stubout_mode, 64 int stubout_mode,
85 int readonly_text, 65 int readonly_text,
86 const NaClCPUFeatures *cpu_features, 66 const NaClCPUFeatures *cpu_features,
87 struct NaClValidationCache *cache); 67 struct NaClValidationCache *cache);
88 68
89 /* Applies the DFA-based validator as in the ApplyValidator case described 69 typedef NaClValidationStatus (*NaClValidateFunc) (
90 * above. The interface of this new validator must remain the same as of the 70 uintptr_t guest_addr,
91 * ApplyValidator. Less arguments will be ignored as the new validator 71 uint8_t *data,
92 * implements features, such as stubout mode. 72 size_t size,
93 */ 73 int stubout_mode,
94 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyDfaValidator, 74 int readonly_text,
95 NACL_TARGET_ARCH, 75 const NaClCPUFeatures *cpu_features,
96 NACL_TARGET_SUBARCH)(
97 uintptr_t guest_addr,
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); 76 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.
117 */ 93 */
118 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely, 94 typedef NaClValidationStatus (*NaClValidateCopyFunc) (
119 NACL_TARGET_ARCH, 95 uintptr_t guest_addr,
120 NACL_TARGET_SUBARCH)( 96 uint8_t *data_old,
121 uintptr_t guest_addr, 97 uint8_t *data_new,
122 uint8_t *data, 98 size_t size,
123 size_t size, 99 const NaClCPUFeatures *cpu_features);
124 const NaClCPUFeatures *cpu_features);
125 100
126 /* Applies validator to new code segment, assuming that it was updated 101 /* Function type for applying a Validator on small updates to previously
127 * from the previously validated old code segment. Assumes that instruction 102 * validated code segments.
128 * sizes are the same. Only allows changes in branches that don't change 103 *
129 * instruction sizes. 104 * Assumes that instruction sizes are the same. Only allows changes in branches
105 * that don't change instruction sizes.
106 *
130 * Parameters are: 107 * Parameters are:
131 * guest_addr - The virtual pc to assume with the beginning address of the 108 * guest_addr - The virtual pc to assume with the beginning address of the
132 * code segment. Typically, this is the corresponding addresss that 109 * code segment. Typically, this is the corresponding addresss that
133 * will be used by objdump. 110 * will be used by objdump.
134 * data_old - The contents of the original code segment. 111 * data_old - The contents of the original code segment.
135 * data_new - The contents of the new code segment that should be validated. 112 * data_new - The contents of the new code segment that should be validated.
136 * size - The size of the passed code segments. 113 * size - The size of the passed code segments.
137 * cpu_features - The CPU features to support while validating. 114 * cpu_features - The CPU features to support while validating.
138 */ 115 */
139 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCodeReplacement, 116 typedef NaClValidationStatus (*NaClValidateCodeReplacementFunc) (
140 NACL_TARGET_ARCH, 117 uintptr_t guest_addr,
141 NACL_TARGET_SUBARCH)( 118 uint8_t *data_old,
142 uintptr_t guest_addr, 119 uint8_t *data_new,
143 uint8_t *data_old, 120 size_t size,
144 uint8_t *data_new, 121 const NaClCPUFeatures *cpu_features);
145 size_t size,
146 const NaClCPUFeatures *cpu_features);
147 122
148 /* Runs the validator to copy code from an existing code segment to a new 123 /* The full set of validator API. */
149 * code segment. 124 struct NaClValidatorInterface {
150 * 125 NaClValidateFunc Validate;
151 * Note: Current implementations uses the instruction decoders, which may 126 NaClValidateCopyFunc ValidateCopy;
Nick Bray 2012/04/27 22:21:36 Nit: swap position of Copy and Replacement? (Copy
pasko-google - do not use 2012/05/12 12:18:40 no need to apologize :) Replace is important for J
pasko-google - do not use 2012/05/17 10:20:15 I was wrong. ValidateCodeReplacement and CopyCode
152 * require that the code segment match native client rules. 127 NaClValidateCodeReplacementFunc ValidateCodeReplacement;
128 };
129
130 /* Known Validator API initializers. */
131 extern void NaClValidatorInit_x86_64(struct NaClValidatorInterface **val);
132 extern void NaClValidatorInit_x86_32(struct NaClValidatorInterface **val);
133 extern void NaClDfaValidatorInit_x86_32(struct NaClValidatorInterface **val);
134 extern void NaClDfaValidatorInit_x86_64(struct NaClValidatorInterface **val);
135 extern void NaClValidatorInitArm(struct NaClValidatorInterface **val);
136
137 /* Make a messy choice for validating functions and record it in NaClApp. */
138 extern void NaClSelectValidator(struct NaClValidatorInterface **val);
139
140 /* Applies the validator, as used in a command-line tool to report issues.
141 * Note: This is intentionally separated from ApplyValidator, since it need
142 * not be performance critical.
153 * 143 *
154 * Parameters are: 144 * Parameters are:
155 * guest_addr - The virtual pc to assume with the beginning address of the 145 * guest_addr - The virtual pc to assume with the beginning address of the
156 * code segment. Typically, this is the corresponding addresss that 146 * code segment. Typically, this is the corresponding addresss that
157 * will be used by objdump. 147 * will be used by objdump.
158 * data_old - The contents of the original code segment. 148 * data - The contents of the code segment to be validated.
159 * data_new - The addres of the new code segment for which the original 149 * 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. 150 * cpu_features - The CPU features to support while validating.
163 */ 151 */
164 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorCopy, 152 extern NaClValidationStatus NACL_SUBARCH_NAME(ApplyValidatorVerbosely,
165 NACL_TARGET_ARCH, 153 NACL_TARGET_ARCH,
166 NACL_TARGET_SUBARCH)( 154 NACL_TARGET_SUBARCH)(
167 uintptr_t guest_addr, 155 uintptr_t guest_addr,
168 uint8_t *data_old, 156 uint8_t *data,
169 uint8_t *data_new, 157 size_t size,
170 size_t size, 158 const NaClCPUFeatures *cpu_features);
171 const NaClCPUFeatures *cpu_features);
172 159
173 EXTERN_C_END 160 EXTERN_C_END
174 161
175 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */ 162 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVALIDATE_H__ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698