Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / validator / x86 / ncval_reg_sfi / ncvalidate_utils.h
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 /* Some useful utilities for validator patterns. */
8
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__
11
12 #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc.h"
13
14 struct NaClInstState;
15 struct NaClExpVector;
16 struct NaClDecodeTables;
17 struct NaClValidatorState;
18
19 /* Special flag set to find set/use of an operand. */
20 extern const NaClOpFlags NaClOpSetOrUse;
21
22 /* Returns true if the instruction is a binary operation with
23  * the given mnemonic name, and whose arguments are the given registers.
24  *
25  * Parameters:
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.
31  */
32 Bool NaClIsBinaryUsingRegisters(const NaClInst* inst,
33                                 NaClMnemonic name,
34                                 struct NaClExpVector* vector,
35                                 NaClOpKind reg_1,
36                                 NaClOpKind reg_2);
37
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.
41  *
42  * Parameters:
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
48  *             the or value.
49  */
50 Bool NaClIsBinarySetUsingRegisters(const struct NaClDecodeTables* tables,
51                                    const NaClInst* opcode,
52                                    NaClMnemonic name,
53                                    struct NaClExpVector* vector,
54                                    NaClOpKind reg_1,
55                                    NaClOpKind reg_2);
56
57 /* Returns true if the instruction corresponds to a move from
58  * REG_USE to REG_SET.
59  *
60  * Parameters:
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.
65  */
66 Bool NaClIsMovUsingRegisters(const struct NaClDecodeTables* tables,
67                              const NaClInst* inst,
68                              struct NaClExpVector* vector,
69                              NaClOpKind reg_set,
70                              NaClOpKind reg_use);
71
72 /* Returns true if the given instruction's first operand corresponds to
73  * a set of the register with the given name.
74  *
75  * Parameters:
76  *   state - The instruction state to check.
77  *   reg_name - The name of the register to check if set.
78  */
79 Bool NaClOperandOneIsRegisterSet(struct NaClInstState* state,
80                                  NaClOpKind reg_name);
81
82 /* Returns true if the given instruction's first operand corresponds to
83  * a 32-bit value that is zero extended.
84  *
85  * Parameters:
86  *   state - The instruction state to check.
87  */
88 Bool NaClOperandOneZeroExtends(struct NaClInstState* state);
89
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.
94  */
95 Bool NaClAssignsRegisterWithZeroExtends32(
96     struct NaClValidatorState* state, /* Validator state associated with
97                                        * the current instruction.
98                                        */
99     size_t distance,                  /* Number of instruction to look back for
100                                        * zero-extending instruction.
101                                        */
102     NaClOpKind reg32);                /* 32-bit register that gets extended
103                                         * by the specified instruction.
104                                        */
105
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.
111  */
112 Bool NaClAssignsRegisterWithZeroExtends64(
113     struct NaClValidatorState* state, /* Validator state associated with
114                                        * the current instruction.
115                                        */
116     size_t distance,                  /* Number of instruction to look back for
117                                        * zero-extending instruction.
118                                        */
119     NaClOpKind reg64);                /* 64-bit register that gets extended
120                                         * by the specified instruction.
121                                        */
122
123 #endif  /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_NCVAL_REG_SFI_NCVALIDATE_UTILS_H__ */