Exemplo n.º 1
0
void injectFunc(long llfi_index, unsigned size, 
                char *buf, unsigned my_reg_index, unsigned reg_pos, char* opcode_str) {
  fprintf(stderr, "MSG: injectFunc() has being called\n");
  if (! fiFlag) return;
  start_tracing_flag = TRACING_FI_RUN_FAULT_INSERTED; //Tell instTraceLib that we have injected a fault

  unsigned fi_bit, fi_bytepos, fi_bitpos;
  unsigned char oldbuf;
  
  //======== Add opcode_str QINING @MAR 11th========
  unsigned fi_num_bits;
  fi_num_bits = config.fi_num_bits;
  char* score_board = (char*) calloc (size, sizeof(char));
  //================================================
  //======== Add opcode_str QINING @MAR 11th========
  int runs =0;
  /*BEHROOZ: We give value to fi_cycle_to_print because we want to make sure that the 
    fi_cycle that is printed in the for loop has the correct value when it 
    comes to cases where we want to both inject in more than one bit and also
    inject in more than one location.*/
  long long fi_cycle_to_print = config.fi_cycle;
  //================================================
  for(runs = 0; runs < fi_num_bits && runs < size; runs++){
  	  // NOTE: if fi_bit specified, use it, otherwise, randomly generate
	  if (config.fi_bit >= 0)
	    fi_bit = config.fi_bit;
	  else
	  {
	    //======== Add opcode_str QINING @MAR 11th========
	    do{
	    	fi_bit = rand() / (RAND_MAX * 1.0) * size;
	    }while(score_board[fi_bit] == 1);
	    score_board[fi_bit] = 1;
	    //================================================
	  }
	  assert (fi_bit < size && "fi_bit larger than the target size");
	  fi_bytepos = fi_bit / 8;
	  fi_bitpos = fi_bit % 8;
	  
	  memcpy(&oldbuf, &buf[fi_bytepos], 1);
	
	  //======== Add opcode_str QINING @MAR 11th========
	  fprintf(injectedfaultsFile, 
          "FI stat: fi_type=%s, fi_max_multiple=%d, fi_index=%ld, fi_cycle=%lld, fi_reg_index=%u, "
          "fi_reg_pos=%u, fi_reg_width=%u, fi_bit=%u, opcode=%s\n", config.fi_type, config.fi_max_multiple,
          llfi_index, fi_cycle_to_print, my_reg_index, reg_pos, size, fi_bit, opcode_str);
	  /*BEHROOZ: The below line is substituted with the above one as there was an 
           issue when we wanted to both inject in multiple bits and multiple
           locations.
           llfi_index, config.fi_cycle, my_reg_index, reg_pos, size, fi_bit, opcode_str);*/
	  //===============================================================
 	  fflush(injectedfaultsFile); 
	  //===============================================================
	  
	  //======== Add second corrupted regs QINING @MAR 27th===========
	  //update the fi_cycle to the fi_second_cycle,
	  // so later procedures can still use fi_cycle to print stat info
	  if(config.fi_second_cycle != -1)
	  {
	  	config.fi_cycle = config.fi_second_cycle;
	  	config.fi_second_cycle = -1;
	  }
          /*BEHROOZ: Add multiple corrupted regs*/
          else
          {
              long long next_cycle = -1;
              int index = 0;
              for(index = 0; index < fi_next_cycles_count && next_cycle == -1; index++)
              {
                   if(config.fi_next_cycles[index] != -1)
                   {
                        next_cycle = config.fi_next_cycles[index];
	                config.fi_cycle = next_cycle;
	  	        config.fi_next_cycles[index] = -1;
                   }                   
              }
          }
	  //==============================================================
  	  injectFaultImpl(config.fi_type, llfi_index, size, fi_bit, buf);
  }
  //==================================================
  /*
  debug(("FI stat: fi_type=%s, fi_index=%ld, fi_cycle=%lld, fi_reg_index=%u, "
         "fi_bit=%u, size=%u, old=0x%hhx, new=0x%hhx\n", config.fi_type,
            llfi_index, config.fi_cycle, my_reg_index, fi_bit, 
            size,  oldbuf, buf[fi_bytepos]));
*/
}
Exemplo n.º 2
0
void injectFunc(long llfi_index, unsigned size, 
                char *buf, unsigned my_reg_index, unsigned reg_pos, char* opcode_str) {
  fprintf(stderr, "MSG: injectFunc() has being called\n");
  if (! fiFlag) return;
  start_tracing_flag = TRACING_FI_RUN_FAULT_INSERTED; //Tell instTraceLib that we have injected a fault

  unsigned fi_bit, fi_bytepos, fi_bitpos;
  unsigned char oldbuf;
  
  //======== Add opcode_str QINING @MAR 11th========
  unsigned fi_num_bits;
  fi_num_bits = config.fi_num_bits;
  char* score_board = (char*) calloc (size, sizeof(char));
  //================================================
  //======== Add opcode_str QINING @MAR 11th========
  int runs =0;
  long long fi_cycle_to_print = config.fi_cycle;
  for(runs = 0; runs < fi_num_bits && runs < size; runs++){
  	  // NOTE: if fi_bit specified, use it, otherwise, randomly generate
	  if (config.fi_bit >= 0)
	    fi_bit = config.fi_bit;
	  else
	  {
	    //======== Add opcode_str QINING @MAR 11th========
	    do{
	    	fi_bit = rand() / (RAND_MAX * 1.0) * size;
	    }while(score_board[fi_bit] == 1);
	    score_board[fi_bit] = 1;
	    //================================================
	  }
	  assert (fi_bit < size && "fi_bit larger than the target size");
	  fi_bytepos = fi_bit / 8;
	  fi_bitpos = fi_bit % 8;
	  
	  memcpy(&oldbuf, &buf[fi_bytepos], 1);
	
	  //======== Add opcode_str QINING @MAR 11th========
	  fprintf(injectedfaultsFile, 
          "FI stat: fi_type=%s, fi_index=%ld, fi_cycle=%lld, fi_reg_index=%u, "
          "fi_reg_pos=%u, fi_reg_width=%u, fi_bit=%u, opcode=%s\n", config.fi_type,
          llfi_index, fi_cycle_to_print, my_reg_index, reg_pos, size, fi_bit, opcode_str);
 	  fflush(injectedfaultsFile); 
	  //================================================
	  
	  //======== Add second corrupted regs QINING @MAR 27th===========
	  //update the fi_cycle to the fi_second_cycle,
	  // so later procedures can still use fi_cycle to print stat info
	  if(config.fi_second_cycle != -1)
	  {
	  	config.fi_cycle = config.fi_second_cycle;
	  	config.fi_second_cycle = -1;
	  }
	  //==============================================================
  	  injectFaultImpl(config.fi_type, llfi_index, size, fi_bit, buf);
  }
  //==================================================
  /*
  debug(("FI stat: fi_type=%s, fi_index=%ld, fi_cycle=%lld, fi_reg_index=%u, "
         "fi_bit=%u, size=%u, old=0x%hhx, new=0x%hhx\n", config.fi_type,
            llfi_index, config.fi_cycle, my_reg_index, fi_bit, 
            size,  oldbuf, buf[fi_bytepos]));
*/
}