OLD | NEW |
1 /* native_client/src/trusted/validator_ragel/gen/validator_x86_32.c | 1 /* native_client/src/trusted/validator_ragel/gen/validator_x86_32.c |
2 * THIS FILE IS AUTO-GENERATED. DO NOT EDIT. | 2 * THIS FILE IS AUTO-GENERATED. DO NOT EDIT. |
3 * Compiled for ia32 mode. | 3 * Compiled for ia32 mode. |
4 */ | 4 */ |
5 | 5 |
6 /* | 6 /* |
7 * This is the core of ia32-mode validator. Please note that this file | 7 * This is the core of ia32-mode validator. Please note that this file |
8 * combines ragel machine description and C language actions. Please read | 8 * combines ragel machine description and C language actions. Please read |
9 * validator_internals.html first to understand how the whole thing is built: | 9 * validator_internals.html first to understand how the whole thing is built: |
10 * it explains how the byte sequences are constructed, what constructs like | 10 * it explains how the byte sequences are constructed, what constructs like |
11 * "@{}" or "REX_WRX?" mean, etc. | 11 * "@{}" or "REX_WRX?" mean, etc. |
12 */ | 12 */ |
13 | 13 |
14 #include <assert.h> | 14 #include <assert.h> |
15 #include <errno.h> | 15 #include <errno.h> |
16 #include <stddef.h> | 16 #include <stddef.h> |
17 #include <stdio.h> | 17 #include <stdio.h> |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 #include <string.h> | 19 #include <string.h> |
20 | 20 |
21 #include "native_client/src/trusted/validator_ragel/bitmap.h" | 21 #include "native_client/src/trusted/validator_ragel/bitmap.h" |
22 #include "native_client/src/trusted/validator_ragel/unreviewed/validator_interna
l.h" | 22 #include "native_client/src/trusted/validator_ragel/validator_internal.h" |
23 | 23 |
24 /* Ignore this information: it's not used by security model in IA32 mode. */ | 24 /* Ignore this information: it's not used by security model in IA32 mode. */ |
25 #undef GET_VEX_PREFIX3 | 25 #undef GET_VEX_PREFIX3 |
26 #define GET_VEX_PREFIX3 0 | 26 #define GET_VEX_PREFIX3 0 |
27 #undef SET_VEX_PREFIX3 | 27 #undef SET_VEX_PREFIX3 |
28 #define SET_VEX_PREFIX3(P) | 28 #define SET_VEX_PREFIX3(P) |
29 | 29 |
30 | 30 |
31 | 31 |
32 | 32 |
| 33 /* |
| 34 * The "write data" statement causes Ragel to emit the constant static data |
| 35 * needed by the ragel machine. |
| 36 */ |
33 | 37 |
34 static const int x86_32_validator_start = 233; | 38 static const int x86_32_validator_start = 233; |
35 static const int x86_32_validator_first_final = 233; | 39 static const int x86_32_validator_first_final = 233; |
36 static const int x86_32_validator_error = 0; | 40 static const int x86_32_validator_error = 0; |
37 | 41 |
38 static const int x86_32_validator_en_main = 233; | 42 static const int x86_32_validator_en_main = 233; |
39 | 43 |
40 | 44 |
41 | 45 |
42 | |
43 Bool ValidateChunkIA32(const uint8_t *data, size_t size, | 46 Bool ValidateChunkIA32(const uint8_t *data, size_t size, |
44 uint32_t options, | 47 uint32_t options, |
45 const NaClCPUFeaturesX86 *cpu_features, | 48 const NaClCPUFeaturesX86 *cpu_features, |
46 ValidationCallbackFunc user_callback, | 49 ValidationCallbackFunc user_callback, |
47 void *callback_data) { | 50 void *callback_data) { |
48 bitmap_word valid_targets_small; | 51 bitmap_word valid_targets_small; |
49 bitmap_word jump_dests_small; | 52 bitmap_word jump_dests_small; |
50 bitmap_word *valid_targets; | 53 bitmap_word *valid_targets; |
51 bitmap_word *jump_dests; | 54 bitmap_word *jump_dests; |
52 const uint8_t *current_position; | 55 const uint8_t *current_position; |
(...skipping 16 matching lines...) Expand all Loading... |
69 free(jump_dests); | 72 free(jump_dests); |
70 free(valid_targets); | 73 free(valid_targets); |
71 errno = ENOMEM; | 74 errno = ENOMEM; |
72 return FALSE; | 75 return FALSE; |
73 } | 76 } |
74 } | 77 } |
75 | 78 |
76 /* | 79 /* |
77 * This option is usually used in tests: we will process the whole chunk | 80 * This option is usually used in tests: we will process the whole chunk |
78 * in one pass. Usually each bundle is processed separately which means | 81 * in one pass. Usually each bundle is processed separately which means |
79 * instructions (and super-instructions) can not cross borders of the bundle. | 82 * instructions (and "superinstructions") can not cross borders of the bundle. |
80 */ | 83 */ |
81 if (options & PROCESS_CHUNK_AS_A_CONTIGUOUS_STREAM) | 84 if (options & PROCESS_CHUNK_AS_A_CONTIGUOUS_STREAM) |
82 end_of_bundle = data + size; | 85 end_of_bundle = data + size; |
83 else | 86 else |
84 end_of_bundle = data + kBundleSize; | 87 end_of_bundle = data + kBundleSize; |
85 | 88 |
86 /* | 89 /* |
87 * Main loop. Here we process the data array bundle-after-bundle. | 90 * Main loop. Here we process the data array bundle-after-bundle. |
88 * Ragel-produced DFA does all the checks with one exception: direct jumps. | 91 * Ragel-produced DFA does all the checks with one exception: direct jumps. |
89 * It collects the two arrays: valid_targets and jump_dests which are used | 92 * It collects the two arrays: valid_targets and jump_dests which are used |
90 * to test direct jumps later. | 93 * to test direct jumps later. |
91 */ | 94 */ |
92 for (current_position = data; | 95 for (current_position = data; |
93 current_position < data + size; | 96 current_position < data + size; |
94 current_position = end_of_bundle, | 97 current_position = end_of_bundle, |
95 end_of_bundle = current_position + kBundleSize) { | 98 end_of_bundle = current_position + kBundleSize) { |
96 /* Start of the instruction being processed. */ | 99 /* Start of the instruction being processed. */ |
97 const uint8_t *instruction_begin = current_position; | 100 const uint8_t *instruction_begin = current_position; |
98 /* Only used locally in the end_of_instruction_cleanup action. */ | 101 /* Only used locally in the end_of_instruction_cleanup action. */ |
99 const uint8_t *instruction_end; | 102 const uint8_t *instruction_end; |
100 uint32_t instruction_info_collected = 0; | 103 uint32_t instruction_info_collected = 0; |
101 int current_state; | 104 int current_state; |
102 | 105 |
| 106 /* |
| 107 * The "write init" statement causes Ragel to emit initialization code. |
| 108 * This should be executed once before the ragel machine is started. |
| 109 */ |
103 | 110 |
104 { | 111 { |
105 ( current_state) = x86_32_validator_start; | 112 ( current_state) = x86_32_validator_start; |
106 } | 113 } |
107 | 114 |
| 115 /* |
| 116 * The "write exec" statement causes Ragel to emit the ragel machine's |
| 117 * execution code. |
| 118 */ |
108 | 119 |
109 { | 120 { |
110 if ( ( current_position) == ( end_of_bundle) ) | 121 if ( ( current_position) == ( end_of_bundle) ) |
111 goto _test_eof; | 122 goto _test_eof; |
112 switch ( ( current_state) ) | 123 switch ( ( current_state) ) |
113 { | 124 { |
114 tr0: | 125 tr0: |
115 { | 126 { |
116 /* Mark start of this instruction as a valid target for jump. */ | 127 /* Mark start of this instruction as a valid target for jump. */ |
117 MarkValidJumpTarget(instruction_begin - data, valid_targets); | 128 MarkValidJumpTarget(instruction_begin - data, valid_targets); |
(...skipping 9514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9632 */ | 9643 */ |
9633 result &= ProcessInvalidJumpTargets(data, size, valid_targets, jump_dests, | 9644 result &= ProcessInvalidJumpTargets(data, size, valid_targets, jump_dests, |
9634 user_callback, callback_data); | 9645 user_callback, callback_data); |
9635 | 9646 |
9636 /* We only use malloc for a large code sequences */ | 9647 /* We only use malloc for a large code sequences */ |
9637 if (jump_dests != &jump_dests_small) free(jump_dests); | 9648 if (jump_dests != &jump_dests_small) free(jump_dests); |
9638 if (valid_targets != &valid_targets_small) free(valid_targets); | 9649 if (valid_targets != &valid_targets_small) free(valid_targets); |
9639 if (!result) errno = EINVAL; | 9650 if (!result) errno = EINVAL; |
9640 return result; | 9651 return result; |
9641 } | 9652 } |
OLD | NEW |