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.
8 * Defines the user API to the state associated with matching instructions.
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_
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"
20 /* The meta model of an x86 opcode instruction. */
23 /* The (user) representation of the parsed x86 instruction. */
26 /* Defines the state used to match an instruction, while walking
27 * instructions using the NaClInstIter.
29 typedef struct NaClInstState NaClInstState;
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.
38 NaClPcAddress NaClInstStatePrintableAddress(NaClInstState* state);
40 /* Given an iterator state, return the corresponding opcode (instruction)
41 * that matches the currently matched instruction of the corresponding
42 * instruction iterator.
44 const struct NaClInst* NaClInstStateInst(NaClInstState* state);
46 /* Given an iterator state, return the corresponding expression tree
47 * denoting the currently matched instruction of the corresponding
48 * instruction iterator.
50 struct NaClExpVector* NaClInstStateExpVector(NaClInstState* state);
52 /* Returns true if the instruction defined by the given state could
53 * be decoded into a valid instruction.
55 Bool NaClInstStateIsValid(NaClInstState* state);
57 /* Given an iterator state, return the number of bytes matched
58 * by the currently matched instruction of the corresponding
59 * instruction iterator.
61 uint8_t NaClInstStateLength(NaClInstState* state);
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.
67 uint8_t NaClInstStateByte(NaClInstState* state, uint8_t index);
69 /* Returns the operand size (measured in bytes) of the instruction state. */
70 uint8_t NaClInstStateOperandSize(NaClInstState* state);
72 /* Returns the address size (measured in bits) of the instruction state. */
73 uint8_t NaClInstStateAddressSize(NaClInstState* state);
77 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_STATE_H_ */