| OLD | NEW |
| (Empty) |
| 1 /* | |
| 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 | |
| 4 * found in the LICENSE file. | |
| 5 */ | |
| 6 | |
| 7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_PROTECT_BASE_H_
_ | |
| 8 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_PROTECT_BASE_H_
_ | |
| 9 | |
| 10 #include "native_client/src/shared/utils/types.h" | |
| 11 #include "native_client/src/trusted/validator/x86/decoder/gen/ncopcode_operand_k
ind.h" | |
| 12 | |
| 13 /* nc_protect_base.h - For 64-bit mode, verifies that no instruction | |
| 14 * changes the value of the base register. | |
| 15 */ | |
| 16 | |
| 17 /* | |
| 18 * Note: The function BaseRegisterValidator is used as a validator | |
| 19 * function to be applied to a validated segment, as defined in | |
| 20 * ncvalidate_iter.h. | |
| 21 */ | |
| 22 | |
| 23 /* The model of a validator state. */ | |
| 24 struct NaClValidatorState; | |
| 25 | |
| 26 /* The state associated with a decoded instruction. */ | |
| 27 struct NaClInstState; | |
| 28 | |
| 29 /* Defines locals used by the NaClBaseRegisterValidator to | |
| 30 * record registers set in the current instruction, that are | |
| 31 * a problem if not used correctly in the next instruction. | |
| 32 */ | |
| 33 typedef struct NaClRegisterLocals { | |
| 34 /* Points to an instruction that contains an assignment to register ESP, | |
| 35 * or NULL if the instruction doesn't set ESP. This is done so that we | |
| 36 * can check if the next instruction uses the value of ESP to update RSP | |
| 37 * (if not, we need to report that ESP is incorrectly assigned). | |
| 38 */ | |
| 39 struct NaClInstState* esp_set_inst; | |
| 40 /* Points to the instruction that contains an assignment to register EBP, | |
| 41 * or NULL if the instruction doesn't set EBP. This is done so that we | |
| 42 * can check if the next instruciton uses the value of EBP to update RBP | |
| 43 * (if not, we need to report that EBP is incorrectly assigned). | |
| 44 */ | |
| 45 struct NaClInstState* ebp_set_inst; | |
| 46 } NaClRegisterLocals; | |
| 47 | |
| 48 /* Ths size of the circular buffer, used to keep track of registers | |
| 49 * assigned in the previous instruction, that must be correctly used | |
| 50 * in the current instruction, or reported as an error. | |
| 51 */ | |
| 52 #define NACL_REGISTER_LOCALS_BUFFER_SIZE 2 | |
| 53 | |
| 54 /* A circular buffer of two elements, used to keep track of the | |
| 55 * current/previous instruction. | |
| 56 */ | |
| 57 typedef struct NaClBaseRegisterLocals { | |
| 58 NaClRegisterLocals buffer[NACL_REGISTER_LOCALS_BUFFER_SIZE]; | |
| 59 int previous_index; | |
| 60 int current_index; | |
| 61 } NaClBaseRegisterLocals; | |
| 62 | |
| 63 /* Initializes memory to hold local information for validator | |
| 64 * NaClBaseRegisterValidator. Returns true if successful. | |
| 65 */ | |
| 66 void NaClBaseRegisterMemoryInitialize(struct NaClValidatorState* state); | |
| 67 | |
| 68 /* Validator function to check that the base register is never set. */ | |
| 69 void NaClBaseRegisterValidator(struct NaClValidatorState* state); | |
| 70 | |
| 71 | |
| 72 /* Post iteration validator summarization function. */ | |
| 73 void NaClBaseRegisterSummarize(struct NaClValidatorState* state); | |
| 74 | |
| 75 /* Checks for pattern | |
| 76 * op %reg32), ... | |
| 77 * lea %reg64, [%reg64+%rbase*1] | |
| 78 * | |
| 79 * where reg64 is the passed 64-bit register, reg32 is the | |
| 80 * corresponding 32-bit register, and op is a 32-bit zero-extending | |
| 81 * operation (such as mov). | |
| 82 */ | |
| 83 Bool NaClAcceptLeaWithMoveLea32To64(struct NaClValidatorState* state, | |
| 84 NaClOpKind reg); | |
| 85 | |
| 86 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NC_PROTECT_BASE
_H__ */ | |
| OLD | NEW |