Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: src/trusted/validator/x86/decoder/nc_inst_iter_inl.c

Issue 625923004: Delete old x86 validator. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: rebase master Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 /* nc_inst_iter_inl.c - Holds inline routines for commonly used (simple)
8 * functions in nc_inst_iter.h. Used to speed up code. Inline routines
9 * correspond to the following functions in nc_inst_iter.h, but with
10 * an 'Inline' suffix:
11 *
12 * NaClInstIterGetState
13 * NaClInstIterGetLookbackState
14 * NaClInstIterHasLookbackState
15 * NaClInstIterHasNext
16 * NaClInstIterAdvance
17 * NaClInstIterGetInstMemory
18 */
19
20 #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_INL_h_
21 #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_INL_h_
22
23 #include <assert.h>
24
25 #include "native_client/src/trusted/validator/x86/decoder/nc_inst_iter.h"
26 #include "native_client/src/trusted/validator/x86/decoder/nc_inst_state.h"
27 #include "native_client/src/trusted/validator/x86/decoder/nc_inst_state_internal .h"
28 #include "native_client/src/trusted/validator/x86/nc_segment.h"
29
30 /* Default handler for errors while running instruction iterator.
31 * Should only be called when caller has incorrectly called a
32 * method.
33 */
34 void NaClInstIterFatal(const char* error_message);
35
36 static INLINE NaClInstState* NaClInstIterGetUndecodedStateInline(
37 NaClInstIter* iter) {
38 return &iter->buffer[iter->buffer_index];
39 }
40
41 static INLINE NaClInstState* NaClInstIterGetStateInline(NaClInstIter* iter) {
42 NaClInstState* state = NaClInstIterGetUndecodedStateInline(iter);
43 if (NULL == state->inst) {
44 NaClDecodeInst(iter, state);
45 }
46 return state;
47 }
48
49 static INLINE NaClInstState* NaClInstIterGetLookbackStateInline(
50 NaClInstIter* iter, size_t distance) {
51 NaClInstState* state;
52 assert(distance < iter->buffer_size);
53 assert(distance <= iter->inst_count);
54 state = &iter->buffer[((iter->buffer_index + iter->buffer_size) - distance)
55 % iter->buffer_size];
56 if (NULL == state->inst) {
57 NaClDecodeInst(iter, state);
58 }
59 return state;
60 }
61
62 static INLINE Bool NaClInstIterHasLookbackStateInline(
63 NaClInstIter* iter, size_t distance) {
64 return distance < iter->buffer_size && distance <= iter->inst_count;
65 }
66
67 static INLINE Bool NaClInstIterHasNextInline(NaClInstIter* iter) {
68 /*
69 DEBUG(NaClLog(LOG_INFO, "iter has next index %"NACL_PRIxNaClMemorySize
70 " < %"NACL_PRIxNaClMemorySize"\n",
71 iter->index, iter->segment->size));
72 */
73 return iter->index < iter->segment->size;
74 }
75
76 static INLINE void NaClInstIterAdvanceInline(NaClInstIter* iter) {
77 if (iter->index >= iter->segment->size) {
78 NaClInstIterFatal("NaClInstIterAdvance with no next element.");
79 }
80 NaClInstIterGetStateInline(iter);
81 iter->index += iter->memory.read_length;
82 ++iter->inst_count;
83 iter->buffer_index = (iter->buffer_index + 1) % iter->buffer_size;
84 /*
85 DEBUG(
86 NaClLog(LOG_INFO,
87 "iter advance: index %"NACL_PRIxNaClMemorySize", "
88 "buffer index %"NACL_PRIuS"\n",
89 iter->index, iter->buffer_index));
90 */
91 iter->buffer[iter->buffer_index].inst = NULL;
92 }
93
94 static INLINE uint8_t* NaClInstIterGetInstMemoryInline(NaClInstIter* iter) {
95 if (iter->index >= iter->segment->size) {
96 NaClInstIterFatal("NaClInstIterGetInstMemory with no next element.");
97 }
98 return iter->segment->mbase + iter->index;
99 }
100
101 #endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_X86_DECODER_NC_INST_ITER_INL_h_ */
OLDNEW
« no previous file with comments | « src/trusted/validator/x86/decoder/nc_inst_iter.c ('k') | src/trusted/validator/x86/decoder/nc_inst_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698