Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / native_client / src / trusted / validator / x86 / decoder / nc_inst_state.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 /*
8  * Defines the user API to the state associated with matching instructions.
9  */
10
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_STATE_H_
12 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_STATE_H_
13
14 #include "native_client/src/include/portability.h"
15 #include "native_client/src/shared/utils/types.h"
16 #include "native_client/src/trusted/validator/types_memory_model.h"
17
18 EXTERN_C_BEGIN
19
20 /* The meta model of an x86 opcode instruction. */
21 struct NaClInst;
22
23 /* The (user) representation of the parsed x86 instruction. */
24 struct NaClExpVector;
25
26 /* Defines the state used to match an instruction, while walking
27  * instructions using the NaClInstIter.
28  */
29 typedef struct NaClInstState NaClInstState;
30
31 struct NaClInst;
32
33 /* Returns the address (i.e. program counter) associated with the currently
34  * matched instruction, assuming the code segment has been mapped to vbase.
35  * This value should not be used to influence validation because it would make
36  * the validation algorithm position dependent.
37  */
38 NaClPcAddress NaClInstStatePrintableAddress(NaClInstState* state);
39
40 /* Given an iterator state, return the corresponding opcode (instruction)
41  * that matches the currently matched instruction of the corresponding
42  * instruction iterator.
43  */
44 const struct NaClInst* NaClInstStateInst(NaClInstState* state);
45
46 /* Given an iterator state, return the corresponding expression tree
47  * denoting the currently matched instruction of the corresponding
48  * instruction iterator.
49  */
50 struct NaClExpVector* NaClInstStateExpVector(NaClInstState* state);
51
52 /* Returns true if the instruction defined by the given state could
53  * be decoded into a valid instruction.
54  */
55 Bool NaClInstStateIsValid(NaClInstState* state);
56
57 /* Given an iterator state, return the number of bytes matched
58  * by the currently matched instruction of the corresponding
59  * instruction iterator.
60  */
61 uint8_t NaClInstStateLength(NaClInstState* state);
62
63 /* Given an iterator state, return the index-th byte of the
64  * currently matched instruction. Index must be less than
65  * the value of the corresponding call to NaClInstStateLength.
66  */
67 uint8_t NaClInstStateByte(NaClInstState* state, uint8_t index);
68
69 /* Returns the operand size (measured in bytes) of the instruction state. */
70 uint8_t NaClInstStateOperandSize(NaClInstState* state);
71
72 /* Returns the address size (measured in bits) of the instruction state. */
73 uint8_t NaClInstStateAddressSize(NaClInstState* state);
74
75 EXTERN_C_END
76
77 #endif  /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_STATE_H_ */