LCOV - code coverage report
Current view: directory - src/trusted/validator/x86/decoder - nc_inst_iter.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 63 42 66.7 %
Date: 2014-06-18 Functions: 0 0 -

       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                 : 
      11                 : #include "native_client/src/trusted/validator/x86/decoder/nc_inst_iter.h"
      12                 : 
      13                 : #include <stdio.h>
      14                 : #include <stdlib.h>
      15                 : 
      16                 : #include "native_client/src/shared/platform/nacl_log.h"
      17                 : #include "native_client/src/trusted/validator/x86/decoder/nc_inst_state.h"
      18                 : #include "native_client/src/trusted/validator/x86/decoder/nc_inst_state_internal.h"
      19                 : #include "native_client/src/trusted/validator/x86/decoder/nc_inst_trans.h"
      20                 : #include "native_client/src/trusted/validator/x86/decoder/ncop_exps.h"
      21                 : 
      22                 : /* To turn on debugging of instruction decoding, change value of
      23                 :  * DEBUGGING to 1.
      24                 :  */
      25                 : #define DEBUGGING 0
      26                 : 
      27                 : #include "native_client/src/shared/utils/debugging.h"
      28                 : 
      29                 : #include "native_client/src/trusted/validator/x86/decoder/nc_inst_iter_inl.c"
      30                 : 
      31               0 : static void NaClInstIterLogError(const char* error_message) {
      32               0 :   NaClLog(LOG_ERROR, "*ERROR* %s\n", error_message);
      33               0 : }
      34                 : 
      35               0 : void NaClInstIterFatal(const char* error_message) {
      36               0 :   NaClInstIterLogError(error_message);
      37               0 :   exit(1);
      38               0 : }
      39                 : 
      40                 : /* Default handler for errors found while parsing the memory segment.*/
      41                 : static void NaClInstIterReportRemainingMemoryError(
      42               0 :     NCRemainingMemoryError error,
      43               0 :     struct NCRemainingMemory* memory) {
      44               0 :   NaClInstIterLogError(NCRemainingMemoryErrorMessage(error));
      45               0 : }
      46                 : 
      47                 : NaClInstIter* NaClInstIterCreateWithLookback(
      48            2304 :     const struct NaClDecodeTables* decoder_tables,
      49            2304 :     NaClSegment* segment,
      50            2304 :     size_t lookback_size) {
      51            2304 :   NaClInstIter* iter;
      52                 :   /* Guarantee we don't wrap around while computing buffer index updates. */
      53            4608 :   assert(((lookback_size + 1) * 2 + 1) > lookback_size);
      54            2304 :   iter = (NaClInstIter*) malloc(sizeof(NaClInstIter));
      55            2304 :   if (NULL != iter) {
      56            2304 :     iter->segment = segment;
      57            2304 :     NCRemainingMemoryInit(segment->mbase, segment->size, &iter->memory);
      58            2304 :     iter->memory.error_fn = NaClInstIterReportRemainingMemoryError;
      59            2304 :     iter->index = 0;
      60            2304 :     iter->inst_count = 0;
      61            2304 :     iter->buffer_size = lookback_size + 1;
      62            2304 :     iter->buffer_index = 0;
      63                 :     iter->buffer = (NaClInstState*)
      64            2304 :         calloc(iter->buffer_size, sizeof iter->buffer[0]);
      65            2304 :     if (NULL == iter->buffer) {
      66               0 :       free(iter);
      67               0 :       iter = NULL;
      68               0 :     } else {
      69            2304 :       size_t i;
      70           20678 :       for (i = 0; i < iter->buffer_size; ++i) {
      71            8035 :         iter->buffer[i].inst = NULL;
      72            8035 :         NCInstBytesInitMemory(&iter->buffer[i].bytes, &iter->memory);
      73            8035 :       }
      74                 :     }
      75            2304 :   }
      76            2304 :   iter->decoder_tables = (struct NaClDecodeTables*) decoder_tables;
      77            2304 :   return iter;
      78                 : }
      79                 : 
      80                 : NaClInstIter* NaClInstIterCreate(
      81            1604 :     const struct NaClDecodeTables* decoder_tables,
      82            1604 :     NaClSegment* segment) {
      83            1604 :   return NaClInstIterCreateWithLookback(decoder_tables, segment, 0);
      84                 : }
      85                 : 
      86            2304 : void NaClInstIterDestroy(NaClInstIter* iter) {
      87            2304 :   if (NULL != iter) {
      88            2304 :     free(iter->buffer);
      89            2304 :     free(iter);
      90            2304 :   }
      91            2304 : }
      92                 : 
      93              15 : NaClInstState* NaClInstIterGetUndecodedState(NaClInstIter* iter) {
      94              15 :   return NaClInstIterGetUndecodedStateInline(iter);
      95                 : }
      96                 : 
      97            3506 : NaClInstState* NaClInstIterGetState(NaClInstIter* iter) {
      98            3506 :   return NaClInstIterGetStateInline(iter);
      99                 : }
     100                 : 
     101               0 : Bool NaClInstIterHasLookbackState(NaClInstIter* iter, size_t distance) {
     102               0 :   return NaClInstIterHasLookbackStateInline(iter, distance);
     103                 : }
     104                 : 
     105               0 : NaClInstState* NaClInstIterGetLookbackState(NaClInstIter* iter,
     106               0 :                                             size_t distance) {
     107               0 :   return NaClInstIterGetLookbackStateInline(iter, distance);
     108                 : }
     109                 : 
     110            5095 : Bool NaClInstIterHasNext(NaClInstIter* iter) {
     111            5095 :   return NaClInstIterHasNextInline(iter);
     112                 : }
     113                 : 
     114            3506 : void NaClInstIterAdvance(NaClInstIter* iter) {
     115            3506 :   NaClInstIterAdvanceInline(iter);
     116            3506 : }
     117                 : 
     118               0 : uint8_t* NaClInstIterGetInstMemory(NaClInstIter* iter) {
     119               0 :   return NaClInstIterGetInstMemoryInline(iter);
     120                 : }

Generated by: LCOV version 1.7