Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| 11 #include <stdlib.h> | 11 #include <stdlib.h> |
| 12 #include <string.h> | 12 #include <string.h> |
| 13 | 13 |
| 14 #include "native_client/src/trusted/validator_ragel/unreviewed/validator_interna l.h" | 14 #include "native_client/src/trusted/validator_ragel/validator_internal.h" |
| 15 | 15 |
| 16 %%{ | 16 %%{ |
| 17 machine x86_64_validator; | 17 machine x86_64_validator; |
| 18 alphtype unsigned char; | 18 alphtype unsigned char; |
| 19 variable p current_position; | 19 variable p current_position; |
| 20 variable pe end_of_bundle; | 20 variable pe end_of_bundle; |
| 21 variable eof end_of_bundle; | 21 variable eof end_of_bundle; |
| 22 variable cs current_state; | 22 variable cs current_state; |
| 23 | 23 |
| 24 include byte_machine "byte_machines.rl"; | 24 include byte_machine "byte_machines.rl"; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 @{ | 211 @{ |
| 212 instruction_start -= 7; | 212 instruction_start -= 7; |
| 213 if (RMFromModRM(instruction_start[2]) != | 213 if (RMFromModRM(instruction_start[2]) != |
| 214 RMFromModRM(instruction_start[6]) || | 214 RMFromModRM(instruction_start[6]) || |
| 215 RMFromModRM(instruction_start[2]) != RMFromModRM(*current_position)) | 215 RMFromModRM(instruction_start[2]) != RMFromModRM(*current_position)) |
| 216 instruction_info_collected |= UNRECOGNIZED_INSTRUCTION; | 216 instruction_info_collected |= UNRECOGNIZED_INSTRUCTION; |
| 217 BitmapClearBit(valid_targets, (instruction_start - data) + 4); | 217 BitmapClearBit(valid_targets, (instruction_start - data) + 4); |
| 218 BitmapClearBit(valid_targets, (instruction_start - data) + 7); | 218 BitmapClearBit(valid_targets, (instruction_start - data) + 7); |
| 219 restricted_register = NO_REG; | 219 restricted_register = NO_REG; |
| 220 } | | 220 } | |
| 221 | 221 |
|
Brad Chen
2012/09/28 19:38:34
It would be helpful to have a comment before every
| |
| 222 # rex.R?X? and $~0x1f, %eax/%ecx/%edx/%ebx/%esp/%ebp/%esi/%edi | 222 # rex.R?X? and $~0x1f, %eax/%ecx/%edx/%ebx/%esp/%ebp/%esi/%edi |
| 223 ((REX_RX 0x83 (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6|0xe7) 0xe0 | 223 ((REX_RX 0x83 (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6|0xe7) 0xe0 |
| 224 # add %r15,%rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi | 224 # add %r15,%rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi |
|
Brad Chen
2012/09/28 19:38:34
A comment stating explicitly this is computing the
khim
2012/09/28 20:26:26
Well, there two groups in two different places:
%r
| |
| 225 b_0100_10x1 0x03 (0xc7|0xcf|0xd7|0xdf|0xe7|0xef|0xf7|0xff) | 225 b_0100_10x1 0x03 (0xc7|0xcf|0xd7|0xdf|0xe7|0xef|0xf7|0xff) |
| 226 # callq %rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi | 226 # callq %rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi |
| 227 ((REX_WRX? 0xff (0xd0|0xd1|0xd2|0xd3|0xd4|0xd5|0xd6|0xd7)) | | 227 ((REX_WRX? 0xff (0xd0|0xd1|0xd2|0xd3|0xd4|0xd5|0xd6|0xd7)) | |
| 228 # jmpq %rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi | 228 # jmpq %rax/%rcx/%rdx/%rbx/%rsp/%rbp/%rsi/%rdi |
| 229 (REX_WRX? 0xff (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6|0xe7)))) | | 229 (REX_WRX? 0xff (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6|0xe7)))) | |
| 230 | 230 |
| 231 # and $~0x1f, %r8d/%r9d/%r10d/%r11d/%r12d/%r13d/%r14d | 231 # and $~0x1f, %r8d/%r9d/%r10d/%r11d/%r12d/%r13d/%r14d |
| 232 (b_0100_0xx1 0x83 (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6) 0xe0 | 232 (b_0100_0xx1 0x83 (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6) 0xe0 |
| 233 # add %r15, %r8d/%r9d/%r10d/%r11d/%r12d/%r13d/%r14d | 233 # add %r15, %r8d/%r9d/%r10d/%r11d/%r12d/%r13d/%r14d |
| 234 b_0100_11x1 0x03 (0xc7|0xcf|0xd7|0xdf|0xe7|0xef|0xf7) | 234 b_0100_11x1 0x03 (0xc7|0xcf|0xd7|0xdf|0xe7|0xef|0xf7) |
| 235 # callq %r8/%r9/%r10/%r11/%r12/%r13/%r14 | 235 # callq %r8/%r9/%r10/%r11/%r12/%r13/%r14 |
| 236 ((b_0100_xxx1 0xff (0xd0|0xd1|0xd2|0xd3|0xd4|0xd5|0xd6)) | | 236 ((b_0100_xxx1 0xff (0xd0|0xd1|0xd2|0xd3|0xd4|0xd5|0xd6)) | |
| 237 # jmpq %r8/%r9/%r10/%r11/%r12/%r13/%r14 | 237 # jmpq %r8/%r9/%r10/%r11/%r12/%r13/%r14 |
| 238 (b_0100_xxx1 0xff (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6))))) | 238 (b_0100_xxx1 0xff (0xe0|0xe1|0xe2|0xe3|0xe4|0xe5|0xe6))))) |
|
Brad Chen
2012/09/28 19:38:34
The more repetitive the comments are, the less use
khim
2012/09/28 20:26:26
Well, I need to somehow show that we are handling
Brad Chen
2012/09/28 23:21:02
Thanks for the feedback. Just in case it's not cle
| |
| 239 @{ | 239 @{ |
| 240 instruction_start -= 7; | 240 instruction_start -= 7; |
| 241 if (RMFromModRM(instruction_start[2]) != | 241 if (RMFromModRM(instruction_start[2]) != |
| 242 RegFromModRM(instruction_start[6]) || | 242 RegFromModRM(instruction_start[6]) || |
| 243 RMFromModRM(instruction_start[2]) != RMFromModRM(*current_position)) | 243 RMFromModRM(instruction_start[2]) != RMFromModRM(*current_position)) |
| 244 instruction_info_collected |= UNRECOGNIZED_INSTRUCTION; | 244 instruction_info_collected |= UNRECOGNIZED_INSTRUCTION; |
| 245 BitmapClearBit(valid_targets, (instruction_start - data) + 4); | 245 BitmapClearBit(valid_targets, (instruction_start - data) + 4); |
|
Brad Chen
2012/09/28 19:38:34
Could you add a level of procedural indirection so
khim
2012/09/28 20:26:26
Done.
| |
| 246 BitmapClearBit(valid_targets, (instruction_start - data) + 7); | 246 BitmapClearBit(valid_targets, (instruction_start - data) + 7); |
| 247 restricted_register = NO_REG; | 247 restricted_register = NO_REG; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 # EMMS/SSE2/AVX instructions which have implicit %ds:(%rsi) operand | 250 # EMMS/SSE2/AVX instructions which have implicit %ds:(%rsi) operand |
| 251 # maskmovq %mmX,%mmY | 251 # maskmovq %mmX,%mmY |
| 252 maskmovq = | 252 maskmovq = |
| 253 REX_WRXB? (0x0f 0xf7) | 253 REX_WRXB? (0x0f 0xf7) |
| 254 @CPUFeature_EMMX modrm_registers; | 254 @CPUFeature_EMMX modrm_registers; |
| 255 # maskmovdqu %xmmX, %xmmY | 255 # maskmovdqu %xmmX, %xmmY |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 user_callback, callback_data); | 533 user_callback, callback_data); |
| 534 | 534 |
| 535 /* We only use malloc for a large code sequences */ | 535 /* We only use malloc for a large code sequences */ |
| 536 if (size > sizeof valid_targets_small) { | 536 if (size > sizeof valid_targets_small) { |
| 537 free(jump_dests); | 537 free(jump_dests); |
| 538 free(valid_targets); | 538 free(valid_targets); |
| 539 } | 539 } |
| 540 if (!result) errno = EINVAL; | 540 if (!result) errno = EINVAL; |
| 541 return result; | 541 return result; |
| 542 } | 542 } |
| OLD | NEW |