Пример #1
0
GraphMotif::~GraphMotif()
{
  Attr		*attrctx;
  int		sts;

  closing_down = 1;

  if ( trace_started)
    close_trace( 0);

  sts = attr_list.get_first( (void **) &attrctx);
  while ( sts) {
    delete attrctx;
    attr_list.remove( (void *) attrctx);
    sts = attr_list.get_first( (void **) &attrctx);
  }

  localdb_free();

  for ( int i = 0; i < grow_cnt; i++) {
    grow_SetCtxUserData( grow_stack[i]->ctx, 0);
    delete grow_stack[i];
  }
  grow_SetCtxUserData( grow->ctx, 0);
  delete grow;
  XtDestroyWidget( form_widget);
}
Пример #2
0
int main (int argc, char * argv[])
{
  long mis_preds = 0;
  long num_branches = 0;
  uint32_t pc = 0;
  bool outcome = false;

  // Initialize the predictor
  init_predictor ();

  if (argc == 2)
    setup_trace (argv[1]);
  else
    setup_trace (NULL);

  // Read the number of instructions from the trace
  uint32_t stat_num_insts = 0;
  if (fread (&stat_num_insts, sizeof (uint32_t), 1, stream) != 1) {
    printf ("Could not read intput file\n");
    return 1;
  }
  stat_num_insts = ntohl (stat_num_insts);

  // Read each branch from the trace
  while (read_branch (&pc, &outcome)) {

    pc = ntohl (pc);

    num_branches ++;
    
    // Make a prediction and compare with actual outcome
    if (make_prediction (pc) != outcome)
      mis_preds ++;

    // Train the predictor
    train_predictor (pc, outcome);
  }

  // Print out the mispredict statistics
  printf ("Branches\t\t%10d\n", num_branches);
  printf ("Incorrect\t\t%10d\n", mis_preds);
  float mis_pred_rate = 100*(float)mis_preds / float(num_branches);
  printf ("100*wrong_predicts/total branches is %8d / %8d = %7.3f\n", mis_preds, num_branches, mis_pred_rate);

  if (argc == 2)
    close_trace ();
  
  return 0;
}
Пример #3
0
void tracing_stop()
{
  /* If not tracing return */
  if (tracepid == 0)
    return;

  monitor_printf(default_mon, "Stop tracing process %d\n", tracepid);
  print_trace_stats();

  /* Get system stop usage */
  struct rusage stopUsage;
  if (getrusage(RUSAGE_SELF, &stopUsage) == 0) {
    double startUT = (double)startUsage.ru_utime.tv_sec +
                    (double)startUsage.ru_utime.tv_usec / 1e6;
    double startST = (double)startUsage.ru_stime.tv_sec +
                    (double)startUsage.ru_stime.tv_usec / 1e6;
    double stopUT = (double)stopUsage.ru_utime.tv_sec +
                    (double)stopUsage.ru_utime.tv_usec / 1e6;
    double stopST = (double)stopUsage.ru_stime.tv_sec +
                    (double)stopUsage.ru_stime.tv_usec / 1e6;

    double userProcessTime = (stopUT - startUT);
    double systemProcessTime = (stopST - startST);
    double processTime =  userProcessTime + systemProcessTime;

    monitor_printf (default_mon, "Processing time: %g U: %g S: %g\n",
      processTime, userProcessTime, systemProcessTime);
  }
  else {
    monitor_printf(default_mon, "Could not get usage\n");
  }


  if (tracelog) {
    close_trace(tracelog);
    tracelog = 0;
  }
  tracepid = 0;
  header_already_written = 0;

  if (tracenetlog) {
    fclose(tracenetlog);
    tracenetlog = 0;
  }

  if (tracehooklog) {
    fclose(tracehooklog);
    tracehooklog = 0;
  }

  if (alloclog) {
    fclose(alloclog);
    alloclog = 0;
  }

  // Clear statistics
  clear_trace_stats();

  // Clear received_data flag
  received_tainted_data = 0;

// Print file with all functions offsets
#if PRINT_FUNCTION_MAP
  //map_to_file(functionsname);
#endif

  if (conf_save_state_at_trace_stop) {
    char statename[128];
    snprintf(statename, 128, "%s.state", tracename);

#ifdef STATE_VERSION_20
    int err = 
      save_state_by_cr3(tracecr3, statename);
#else
    int err = 
      save_state_by_cr3(tracecr3, statename, conf_save_state_at_trace_stop);
#endif // #ifdef STATE_VERSION_20

    if (err) {
      monitor_printf(default_mon, "Could not save state");
    }
  }

  /* Clear tracing child */
  if (tracing_child) {
    tracing_child = 0;
    skip_trace_write = 0;
    trackproc_stop();
  }

  /* Unregister block and instruction callbacks */
  if (block_begin_cb_handle != DECAF_NULL_HANDLE) {
    DECAF_unregister_callback(DECAF_BLOCK_BEGIN_CB, block_begin_cb_handle);
    block_begin_cb_handle = DECAF_NULL_HANDLE;
  }
  if (insn_begin_cb_handle != DECAF_NULL_HANDLE) {
    DECAF_unregister_callback(DECAF_INSN_BEGIN_CB, insn_begin_cb_handle);
    insn_begin_cb_handle = DECAF_NULL_HANDLE;
  }
  if (insn_end_cb_handle != DECAF_NULL_HANDLE) {
    DECAF_unregister_callback(DECAF_INSN_END_CB, insn_end_cb_handle);
    insn_end_cb_handle = DECAF_NULL_HANDLE;
  }

}
Пример #4
0
int tracing_start(uint32_t pid, const char *filename)
{
  /* Copy trace filename to global variable */
  strncpy(tracename, filename, 128);

  /* Set name for functions file */
  snprintf(functionsname, 128, "%s.functions", filename);

  /* If previous trace did not close properly, close files now */
  if (tracelog)
    close_trace(tracelog);
  if (tracenetlog)
    fclose(tracenetlog);

  /* Initialize trace file */
  tracelog = fopen(filename, "w");
  if (0 == tracelog) {
    perror("tracing_start");
    tracepid = 0;
    tracecr3 = 0;
    return -1;
  }
  setvbuf(tracelog, filebuf, _IOFBF, FILEBUFSIZE);

  /* Initialize netlog file */
  char netname[128];
  snprintf(netname, 128, "%s.netlog", filename);
  tracenetlog = fopen(netname, "w");
  if (0 == tracenetlog) {
    perror("tracing_start");
    tracepid = 0;
    tracecr3 = 0;
    return -1;
  }
  else {
    fprintf(tracenetlog, "Flow       Off  Data\n");
    fflush(tracenetlog);
  }

  /* Set PID and CR3 of the process to be traced */
  tracecr3 = find_cr3(pid);
  if (0 == tracecr3) {
    monitor_printf(default_mon, 
                  "CR3 for PID %d not found. Tracing all processes!\n",pid);
    tracepid = -1;
  }
  else {
    tracepid = pid;
  }
  monitor_printf(default_mon, "PID: %d CR3: 0x%08x\n", tracepid, tracecr3);

  /* Initialize disassembler */
  xed2_init();

  /* Clear trace statistics */
  clear_trace_stats();

  /* Clear skip taint flags */
  init_st();

  /* Initialize hooks only for this process */
  decaf_plugin->monitored_cr3 = tracecr3;

  /* Get system start usage */
  if (getrusage(RUSAGE_SELF, &startUsage) != 0)
    monitor_printf (default_mon, "Could not get start usage\n");

  // If tracing child, load process tracking hooks
  if (tracing_child) {
    trackproc_start(pid);
    load_hooks_in_plugin(&tracecr3, "group_process.so", hook_dirname);
  }

  /* Register block and instruction callbacks */
  block_begin_cb_handle =
    DECAF_register_callback(DECAF_BLOCK_BEGIN_CB, tracing_block_begin, NULL);

  insn_begin_cb_handle =
    DECAF_register_callback(DECAF_INSN_BEGIN_CB,
                            tracing_insn_begin, &should_monitor);
  insn_end_cb_handle =
    DECAF_register_callback(DECAF_INSN_END_CB,
                        tracing_insn_end, &should_monitor);

  return 0;
}