| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2011 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 an instruction (decoder) iterator that processes code segments. | |
| 9 * | |
| 10 * The typical use is of the form: | |
| 11 * | |
| 12 * NaClSegment segment; | |
| 13 * NaClInstIter* iter; | |
| 14 * NaClDecodeTables* tables; | |
| 15 * ... | |
| 16 * for (iter = NaClInstIterCreate(tables, &segment); | |
| 17 * NaClInstIterHasNext(iter); | |
| 18 * NaClInstIterAdvance(iter)) { | |
| 19 * NaClInstState* state = NaClInstIterGetState(iter); | |
| 20 * ... | |
| 21 * } | |
| 22 * NaClInstIterDestroy(iter); | |
| 23 */ | |
| 24 | |
| 25 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_h_ | |
| 26 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_h_ | |
| 27 | |
| 28 #include "native_client/src/shared/utils/types.h" | |
| 29 #include "native_client/src/trusted/validator/x86/decoder/ncopcode_desc.h" | |
| 30 | |
| 31 EXTERN_C_BEGIN | |
| 32 | |
| 33 /* Defines a code segment in the elf file. */ | |
| 34 struct NaClSegment; | |
| 35 | |
| 36 /* Defines the internal state associated with a parsed instruction.*/ | |
| 37 struct NaClInstState; | |
| 38 | |
| 39 struct NaClDecodeTables; | |
| 40 | |
| 41 /* Defines the structure of an instruction iterator, which walks | |
| 42 * the code segment, one instruction at a time. | |
| 43 */ | |
| 44 typedef struct NaClInstIter NaClInstIter; | |
| 45 | |
| 46 /* Allocate and initialize an instruction iterator for the given code segment. | |
| 47 */ | |
| 48 NaClInstIter* NaClInstIterCreate(const struct NaClDecodeTables* decoder_tables, | |
| 49 struct NaClSegment* segment); | |
| 50 | |
| 51 /* Allocate and initialize an instruction iterator for the given code segment. | |
| 52 * Add internal buffering that will allow one to look back the given number | |
| 53 * of instructions from the current point of the iterator. | |
| 54 */ | |
| 55 NaClInstIter* NaClInstIterCreateWithLookback( | |
| 56 const struct NaClDecodeTables* decoder_tables, | |
| 57 struct NaClSegment* segment, | |
| 58 size_t lookback_size); | |
| 59 | |
| 60 /* Delete the instruction iterator created by either | |
| 61 * NaClInstIterCreate or NaClInstIterCreateWithLookback. | |
| 62 */ | |
| 63 void NaClInstIterDestroy(NaClInstIter* iter); | |
| 64 | |
| 65 /* Return true if there are more instructions in the code segment | |
| 66 * to iterate over. | |
| 67 */ | |
| 68 Bool NaClInstIterHasNext(NaClInstIter* iter); | |
| 69 | |
| 70 /* Return a state containing the currently matched instruction defined | |
| 71 * by the given instruction iterator. Note: This instruction is only | |
| 72 * valid until the next call to NaClInstIteratorAdvance. | |
| 73 */ | |
| 74 struct NaClInstState* NaClInstIterGetState(NaClInstIter* iter); | |
| 75 | |
| 76 /* Returns true iff it is valid to look back the given distance. */ | |
| 77 Bool NaClInstIterHasLookbackState(NaClInstIter* iter, size_t distance); | |
| 78 | |
| 79 /* Return a state containing the instruction matched distance elements ago | |
| 80 * from the currently matched instruction (zero corresponds to the currently | |
| 81 * matched instruction). Note: This instruction is only valid until the next | |
| 82 * call to NaClInstIteratorAdvance. | |
| 83 */ | |
| 84 struct NaClInstState* NaClInstIterGetLookbackState( | |
| 85 NaClInstIter* iter, size_t distance); | |
| 86 | |
| 87 /* Advance the iterator past the current instruction. */ | |
| 88 void NaClInstIterAdvance(NaClInstIter* iter); | |
| 89 | |
| 90 /* Returns the memory address of the beginning of the currently | |
| 91 * matched instruction. | |
| 92 */ | |
| 93 uint8_t* NaClInstIterGetInstMemory(NaClInstIter* iter); | |
| 94 | |
| 95 EXTERN_C_END | |
| 96 | |
| 97 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_h_ */ | |
| OLD | NEW |