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.
7 /* Some useful utilities for validator patterns. */
9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NCVALIDATE_UTILS_H__
10 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NCVALIDATE_UTILS_H__
12 #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc.h"
16 struct NaClDecodeTables;
17 struct NaClValidatorState;
19 /* Special flag set to find set/use of an operand. */
20 extern const NaClOpFlags NaClOpSetOrUse;
22 /* Returns true if the instruction is a binary operation with
23 * the given mnemonic name, and whose arguments are the given registers.
26 * inst - The opcode corresponding to the instruction to check.
27 * name - The mnemonic name of the instruction.
28 * vector - The expression vector corresponding to the instruction to check.
29 * reg_1 - The register expected as the first argument
30 * reg_2 - The register expected as the second argument.
32 Bool NaClIsBinaryUsingRegisters(const NaClInst* inst,
34 struct NaClExpVector* vector,
38 /* Returns true if the instruction corresponds to a binary operation whose
39 * result is put into REG_SET, and the resulst is computed using the values in
40 * REG_SET and REG_USE.
43 * inst - The opcode corresponding to the instruction to check.
44 * name - The mnemonic name of the binary operation.
45 * vector - The expression vector corresponding to the instruction to check.
46 * reg_set - The register set by the binary operation.
47 * reg_use - The register whose value is used (along with reg_set) to generate
50 Bool NaClIsBinarySetUsingRegisters(const struct NaClDecodeTables* tables,
51 const NaClInst* opcode,
53 struct NaClExpVector* vector,
57 /* Returns true if the instruction corresponds to a move from
61 * inst - The opcode corresponding to the instruction to check.
62 * vector - The expression vector corresponding to the instruction to check.
63 * reg_set - The register set by the move.
64 * reg_use - The register whose value is used to define the set.
66 Bool NaClIsMovUsingRegisters(const struct NaClDecodeTables* tables,
68 struct NaClExpVector* vector,
72 /* Returns true if the given instruction's first operand corresponds to
73 * a set of the register with the given name.
76 * state - The instruction state to check.
77 * reg_name - The name of the register to check if set.
79 Bool NaClOperandOneIsRegisterSet(struct NaClInstState* state,
82 /* Returns true if the given instruction's first operand corresponds to
83 * a 32-bit value that is zero extended.
86 * state - The instruction state to check.
88 Bool NaClOperandOneZeroExtends(struct NaClInstState* state);
90 /* Applies the precondition "ZeroExtends(reg32)" to the specified instruction.
91 * That is, returns true if the "distance" previous instruction
92 * is binary where the first operand is a register set on the given register,
93 * and the second operand corresponds to a 32-bit value that is zero extended.
95 Bool NaClAssignsRegisterWithZeroExtends32(
96 struct NaClValidatorState* state, /* Validator state associated with
97 * the current instruction.
99 size_t distance, /* Number of instruction to look back for
100 * zero-extending instruction.
102 NaClOpKind reg32); /* 32-bit register that gets extended
103 * by the specified instruction.
106 /* Applies the precondition "ZeroExtends(reg32)" to the specified instruction.
107 * That is, returns true if the "distance" previous instruction
108 * is binary where the first operand is the corresponding 32-bit register
109 * of the given 64-bit register, and the second operand corresponds to a
110 * 32-bit value that is zero extended.
112 Bool NaClAssignsRegisterWithZeroExtends64(
113 struct NaClValidatorState* state, /* Validator state associated with
114 * the current instruction.
116 size_t distance, /* Number of instruction to look back for
117 * zero-extending instruction.
119 NaClOpKind reg64); /* 64-bit register that gets extended
120 * by the specified instruction.
123 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NCVALIDATE_UTILS_H__ */