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

Side by Side Diff: src/trusted/validator/x86/testing/enuminsts/enuminsts.h

Issue 9861030: Modify enuminsts to be able to communicate matched instructions accross (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 8 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 /* 7 /*
8 * enuminsts.h 8 * enuminsts.h
9 * 9 *
10 * Defines the general API for defining decoder / validation tools to be 10 * Defines the general API for defining decoder / validation tools to be
11 * tested by the enumeration structure. 11 * tested by the enumeration structure.
12 */ 12 */
13 13
14 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_ 14 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_
15 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_ 15 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_
16 16
17 #include "native_client/src/include/nacl_macros.h" 17 #include "native_client/src/include/nacl_macros.h"
18 #include "native_client/src/shared/utils/types.h" 18 #include "native_client/src/shared/utils/types.h"
19 19
20 /* Defines routine to print out non-fatal error due to unexpected
21 * internal error.
22 */
23 extern void InternalError(const char *why);
24
25 /* Records that a fatal (i.e. non-recoverable) error occurred. */
26 extern void ReportFatalError(const char* why);
27
20 /* Structure holding decoder/validation tool to test. */ 28 /* Structure holding decoder/validation tool to test. */
21 struct NaClEnumeratorDecoder; 29 struct NaClEnumeratorDecoder;
22 30
23 /* Defines the maximum length of an instruction. */ 31 /* Defines the maximum length of an instruction. */
24 #define NACL_ENUM_MAX_INSTRUCTION_BYTES 30 32 #define NACL_ENUM_MAX_INSTRUCTION_BYTES 15
33
34 /* Defines an array containing the bytes defining an instruction. */
35 typedef uint8_t InstByteArray[NACL_ENUM_MAX_INSTRUCTION_BYTES];
36
25 37
26 /* Defines the maximum number of enumeration decoders one can run. */ 38 /* Defines the maximum number of enumeration decoders one can run. */
27 #define NACL_MAX_ENUM_DECODERS 2 39 #define NACL_MAX_ENUM_DECODERS 5
28 40
29 /* 41 /*
30 * Defines the data structure used by the driver to enumerate possible 42 * Defines the data structure used by the driver to enumerate possible
31 * instruction encodings. 43 * instruction encodings.
32 */ 44 */
33 typedef struct NaClEnumerator { 45 typedef struct NaClEnumerator {
34 /* Defines the buffer of bytes generated for an enumeration. 46 /* Defines the buffer of bytes generated for an enumeration.
35 */ 47 */
36 uint8_t _itext[NACL_ENUM_MAX_INSTRUCTION_BYTES]; 48 InstByteArray _itext;
37 49
38 /* Defines the actual number of bytes to be tried within _itext. */ 50 /* Defines the actual number of bytes to be tried within _itext. */
39 size_t _num_bytes; 51 size_t _num_bytes;
40 52
41 /* Defines the two enumerator decoders to apply. */ 53 /* Defines the two enumerator decoders to apply. */
42 struct NaClEnumeratorDecoder* _decoder[NACL_MAX_ENUM_DECODERS]; 54 struct NaClEnumeratorDecoder* _decoder[NACL_MAX_ENUM_DECODERS];
43 55
44 /* Defines the number of decoders being applied. */ 56 /* Defines the number of decoders being applied. */
45 size_t _num_decoders; 57 size_t _num_decoders;
46
47 /* Defines flag defining if only opcode bytes should be printed. */
48 Bool _print_opcode_bytes_only;
49
50 /*
51 * Returns true if the enumerated instruction should be printed out in
52 * a easily to read form. That is, the sequence of opcodes,
53 * followed by "#", followed by the instruction text.
54 */
55 Bool _print_enumerated_instruction;
56 } NaClEnumerator; 58 } NaClEnumerator;
57 59
58 /* Define the (virtual) function to parse the first instruction in the itext 60 /* Define the (virtual) function to parse the first instruction in the itext
59 * array of the enumerator. Assumes that the length of the first instruction 61 * array of the enumerator. Assumes that the length of the first instruction
60 * must be no larger than the _num_bytes field of the enumerator. 62 * must be no larger than the _num_bytes field of the enumerator.
61 */ 63 */
62 typedef void (*NaClDecoderParseInstFn)(NaClEnumerator* enmerator, 64 typedef void (*NaClDecoderParseInstFn)(const NaClEnumerator* enmerator,
63 int pc_address); 65 const int pc_address);
64 66
65 /* Defines the (virtual) function that returns the number of bytes in the 67 /* Defines the (virtual) function that returns the number of bytes in the
66 * disassembled instruction. 68 * disassembled instruction.
67 */ 69 */
68 typedef size_t (*NaClDecoderInstLengthFn)(NaClEnumerator* enumerator); 70 typedef size_t (*NaClDecoderInstLengthFn)(const NaClEnumerator* enumerator);
69 71
70 /* Defines the (virtual) function that prints out the textual description 72 /* Defines the (virtual) function that prints out the textual description
71 * of the parsed instruction. 73 * of the parsed instruction.
72 */ 74 */
73 typedef void (*NaClDecoderPrintInstFn)(NaClEnumerator* enumerator); 75 typedef void (*NaClDecoderPrintInstFn)(const NaClEnumerator* enumerator);
74 76
75 /* Defines the (virtual) function that returns the instruction mnemonic 77 /* Defines the (virtual) function that returns the instruction mnemonic
76 * for the disassembled instruction. 78 * for the disassembled instruction.
77 */ 79 */
78 typedef const char* (*NaClDecoderGetInstMnemonicFn)(NaClEnumerator* enumerator); 80 typedef const char*
81 (*NaClDecoderGetInstMnemonicFn)(const NaClEnumerator* enumerator);
79 82
80 /* Defines the (virtual) function that returns the number of operands in 83 /* Defines the (virtual) function that returns the number of operands in
81 * the disassembled instruction. 84 * the disassembled instruction.
82 */ 85 */
83 typedef size_t (*NaClDecoderGetInstNumOperandsFn)(NaClEnumerator* enumerator); 86 typedef size_t (*NaClDecoderGetInstNumOperandsFn)(
87 const NaClEnumerator* enumerator);
84 88
85 /* Defines the (virtual) function that returns a text string describing the 89 /* Defines the (virtual) function that returns a text string describing the
86 * operands of the instruciton (i.e. less the instruction mnemonic). 90 * operands of the instruciton (i.e. less the instruction mnemonic).
87 */ 91 */
88 typedef const char* 92 typedef const char*
89 (*NaClDecoderGetInstOperandsTextFn)(NaClEnumerator* enumerator); 93 (*NaClDecoderGetInstOperandsTextFn)(const NaClEnumerator* enumerator);
90 94
91 /* Defines the (virtual) function that returns true if operand n of the 95 /* Defines the (virtual) function that returns true if operand n of the
92 * disassembled instruction is a write to one of the registers RSP, RBP, 96 * disassembled instruction is a write to one of the registers RSP, RBP,
93 * or R15, and the disassembler can prove it (If it can't prove it, it 97 * or R15, and the disassembler can prove it (If it can't prove it, it
94 * should simply return FALSE). 98 * should simply return FALSE).
95 */ 99 */
96 typedef Bool 100 typedef Bool
97 (*NaClDecoderOperandWritesToReservedRegFn)(NaClEnumerator* enumerator, 101 (*NaClDecoderOperandWritesToReservedRegFn)(const NaClEnumerator* enumerator,
98 size_t n); 102 const size_t n);
99 103
100 /* Defines the (virtual) function that tests that the instruction is legal. 104 /* Defines the (virtual) function that tests that the instruction is legal.
101 */ 105 */
102 typedef Bool 106 typedef Bool
103 (*NaClDecoderIsInstLegalFn)(NaClEnumerator *enumerator); 107 (*NaClDecoderIsInstLegalFn)(const NaClEnumerator *enumerator);
104 108
105 /* Defines the (virtual) function that tests that the instruction 109 /* Defines the (virtual) function that tests that the instruction
106 * validates to the level the tester can test validation. 110 * validates to the level the tester can test validation.
107 */ 111 */
108 typedef Bool 112 typedef Bool
109 (*NaClDecoderMaybeInstValidatesFn)(NaClEnumerator* enumerator); 113 (*NaClDecoderMaybeInstValidatesFn)(const NaClEnumerator* enumerator);
110 114
111 /* Defines the (virtual) function that tests (to the limit it can) that 115 /* Defines the (virtual) function that tests (to the limit it can) that
112 * the given code segment validates. If the tester can't run the validator 116 * the given code segment validates. If the tester can't run the validator
113 * on the segment, it should return true. 117 * on the segment, it should return true.
114 */ 118 */
115 typedef Bool 119 typedef Bool
116 (*NaClDecoderMaybeSegmentValidatesFn)(NaClEnumerator* enumerator, 120 (*NaClDecoderMaybeSegmentValidatesFn)(const NaClEnumerator* enumerator,
117 uint8_t* segment, 121 const uint8_t* segment,
118 size_t size, 122 const size_t size,
119 int pc_address); 123 const int pc_address);
120 124
121 /* Defines the (virtual) function that processes the given global flag, 125 /* Defines the (virtual) function that processes the given global flag,
122 * in terms of the corresponding tester. 126 * in terms of the corresponding tester.
123 */ 127 */
124 typedef void (*NaClDecoderInstallFlagFn)(NaClEnumerator* enumerator, 128 typedef void (*NaClDecoderInstallFlagFn)(const NaClEnumerator* enumerator,
125 const char* flag_name, 129 const char* flag_name,
126 void* flag_address); 130 const void* flag_address);
127 131
128 /* 132 /*
129 * Defines the structure to hold a decoder/validation tool. Note that 133 * Defines the structure to hold a decoder/validation tool. Note that
130 * the validation part is optional, and does not need to be supplied. 134 * the validation part is optional, and does not need to be supplied.
131 * 135 *
132 * Note: This struct acts like a C++ class with single inhertence. Derived 136 * Note: This struct acts like a C++ class with single inhertence. Derived
133 * classes should define this as the first field in the struct, so that 137 * classes should define this as the first field in the struct, so that
134 * they can be casted up to a NaClEnumeratorDecoder pointer. 138 * they can be casted up to a NaClEnumeratorDecoder pointer.
135 * 139 *
136 * Note: Because not all decoders implement NaCl validation, some virtuals 140 * Note: Because not all decoders implement NaCl validation, some virtuals
137 * are optional, and can be defined using NULL. In addition, some decoders 141 * are optional, and can be defined using NULL. In addition, some decoders
138 * may not implement a full decoder, making it hard to define operands 142 * may not implement a full decoder, making it hard to define operands
139 * of an instruction. Hence, the following virtual functions (i.e. fields) 143 * of an instruction. Hence, the following virtual functions (i.e. fields)
140 * are optional: 144 * are optional:
141 * _get_inst_mnemonic_fn 145 * _get_inst_mnemonic_fn
142 * _get_inst_num_operands_fn 146 * _get_inst_num_operands_fn
143 * _get_inst_operands_text_fn; 147 * _get_inst_operands_text_fn;
144 * _writes_to_reserved_reg_fn; 148 * _writes_to_reserved_reg_fn;
145 * _maybe_inst_validates_fn; 149 * _maybe_inst_validates_fn;
146 * _segment_validates_fn; 150 * _segment_validates_fn;
147 */ 151 */
148 typedef struct NaClEnumeratorDecoder { 152 typedef struct NaClEnumeratorDecoder {
149 /* The identifying name for the tester. */ 153 /* The identifying name for the tester. */
150 const char* _id_name; 154 const char* _id_name;
151 /* True if the legal filter should be applied to this tester. That is, 155 /* True if the legal filter should be applied to this tester. That is,
152 * only report on instructions this tester finds to be a legal instruction. 156 * only report on instructions this tester finds to be a legal instruction.
153 * When false, filter out instructions that are illegal. 157 * When false, filter out instructions that are illegal.
158 * Note: This field is initialized by NaClPreregisterEnumeratorDecoder
159 * in enuminsts.c
154 */ 160 */
155 Bool _legal_only; 161 Bool _legal_only;
156 /* True if we should should not run comparison tests, but only print. */ 162 /* True if we should should not run comparison tests, but only print.
157 Bool _print_only; 163 * Note: This field is initialized by NaClPreregisterEnumeratorDecoder
164 * in enuminsts.c
165 */
166 Bool _print;
167 /* True if we should print out the matched opcode sequence for the decoder.
168 * Note: This field is initialized by NaClPreregisterEnumeratorDecoder
169 * in enuminsts.c
170 */
171 Bool _print_opcode_sequence;
172 /* True if we should print out the matched opcode sequence, as well as the
173 * mnemonic and operands (as returned by _get_inst_mnemonic_fn and
174 * _get_inst_operands_text_fn) as a comment after the matched opcode sequence.
175 * Note: This field is initialized by NaClPreregisterEnumeratorDecoder
176 * in enuminsts.c
177 */
178 Bool _print_opcode_sequence_plus_desc;
158 /* 179 /*
159 * Parses the first instruction in the itext array of the enumerator. Assumes 180 * Parses the first instruction in the itext array of the enumerator. Assumes
160 * that the length of the first instruction must be <= the _num_bytes field 181 * that the length of the first instruction must be <= the _num_bytes field
161 * of the enumerator. 182 * of the enumerator.
162 */ 183 */
163 NaClDecoderParseInstFn _parse_inst_fn; 184 NaClDecoderParseInstFn _parse_inst_fn;
164 /* 185 /*
165 * Returns the number of bytes in the disassembled instruction. 186 * Returns the number of bytes in the disassembled instruction.
166 */ 187 */
167 NaClDecoderInstLengthFn _inst_length_fn; 188 NaClDecoderInstLengthFn _inst_length_fn;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 NaClDecoderMaybeSegmentValidatesFn _segment_validates_fn; 228 NaClDecoderMaybeSegmentValidatesFn _segment_validates_fn;
208 /* Processes the given command line flag. */ 229 /* Processes the given command line flag. */
209 NaClDecoderInstallFlagFn _install_flag_fn; 230 NaClDecoderInstallFlagFn _install_flag_fn;
210 /* Holds the usage message to printed for the decoder in the (command-line) 231 /* Holds the usage message to printed for the decoder in the (command-line)
211 * usage function. 232 * usage function.
212 */ 233 */
213 const char* _usage_message; 234 const char* _usage_message;
214 } NaClEnumeratorDecoder; 235 } NaClEnumeratorDecoder;
215 236
216 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_ */ 237 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_TESTING_ENUMINSTS_ENUMINST_H_ */
OLDNEW
« no previous file with comments | « src/trusted/validator/x86/testing/enuminsts/Makefile ('k') | src/trusted/validator/x86/testing/enuminsts/enuminsts.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698