Example #1
0
void value_set_analysis_fivrt::add_vars(
  const goto_functionst &goto_functions)
{
  // get the globals
  std::list<value_set_fivrt::entryt> globals;
  get_globals(globals);

  value_set_fivrt &v=state.value_set;
  v.add_vars(globals);

  forall_goto_functions(f_it, goto_functions)
  {
    // get the locals
    std::set<irep_idt> locals;
    get_local_identifiers(f_it->second, locals);

    for(auto l : locals)
    {
      const symbolt &symbol=ns.lookup(l);

      std::list<value_set_fivrt::entryt> entries;
      get_entries(symbol, entries);
      v.add_vars(entries);
    }
  }
Example #2
0
/**
	Changes the directory to the given path
	@param fat_fs FS_Instance to find all the information from
	@param current_directory The location of the current directory
	@param path The name of the directory we want to change into
	@return Location of the new directory we are in
**/
FS_CurrentDir change_dir(FS_Instance *fat_fs, FS_CurrentDir current_directory, char *path){
	char *tokens = strtok(path, "/\\");
	uint32_t directory = current_directory;
	while(NULL != tokens) {
		current_directory = directory;
		FS_EntryList *list = get_entries(fat_fs, (uint32_t)directory);
		uint8_t found = 0;
		while(NULL != list) {
			FS_Entry *entry = list->node;
			if((current_directory == directory) && (check_mask(entry->entry->DIR_Attr, ATTR_DIRECTORY))) {
				char *file_name = get_file_name(entry->entry);
				if(strcmp(tokens, file_name) == 0) {
					found = 1;
					directory = (entry->entry->DIR_FstClusHI << 8) + entry->entry->DIR_FstClusLO;
				}
				free(file_name);
			}
			FS_EntryList *curr = list;
			list = list->next;
			entry_list_cleanup(curr);
		}
		if(!found) {
			printf("Couldn't find directory.\n");
			directory = current_directory;
			break;
		}
		tokens = strtok(NULL, "/\\");
	}
	return directory;
}
Example #3
0
void
itbl_init (void)
{
  struct itbl_entry *e, **es;
  e_processor procn;
  e_type type;

  if (!itbl_have_entries)
    return;

  /* Since register names don't have a prefix, put them in the symbol table so
     they can't be used as symbols.  This simplifies argument parsing as
     we can let gas parse registers for us.  */
  /* Use symbol_create instead of symbol_new so we don't try to
     output registers into the object file's symbol table.  */

  for (type = e_regtype0; type < e_nregtypes; type++)
    for (procn = e_p0; procn < e_nprocs; procn++)
      {
	es = get_entries (procn, type);
	for (e = *es; e; e = e->next)
	  {
	    symbol_table_insert (symbol_create (e->name, reg_section,
						e->value, &zero_address_frag));
	  }
      }
  append_insns_as_macros ();
}
Example #4
0
static void
import_clicked_cb (GtkButton *button, RBImportDialog *dialog)
{
	GList *entries;
	RBSource *library_source;
	RBTrackTransferBatch *batch;

	entries = get_entries (dialog);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->copy_check)) == FALSE) {
		dialog->priv->add_entry_list = g_list_concat (dialog->priv->add_entry_list, entries);

		if (dialog->priv->add_entries_id == 0) {
			dialog->priv->add_entries_id = g_idle_add ((GSourceFunc) add_entries, dialog);
		}
	} else {
		g_object_get (dialog->priv->shell, "library-source", &library_source, NULL);

		batch = rb_source_paste (library_source, entries);
		g_list_free_full (entries, (GDestroyNotify) rhythmdb_entry_unref);
		g_object_unref (library_source);

		/* delete source entries as they finish being copied */
		g_signal_connect (batch, "track-done", G_CALLBACK (copy_track_done_cb), dialog);
		g_signal_connect (batch, "complete", G_CALLBACK (copy_complete_cb), dialog);
	}

}
Example #5
0
void
polyglot_book_get_move(const struct book *book,
			const struct position *position,
			size_t msize, move moves[msize])
{

	moves[0] = 0;
	if (msize < 2)
		return;

	struct entry entries[msize - 1];
	struct search search = {.entries = entries,
				.count = 0,
				.max_count = msize - 1,
				.file = book->file,
				.size = book->polyglot_book.size, };

	enum player side;

	side = white;
	search.key = position_polyglot_key(position, side);
	if (get_entries(&search) != 0)
		search.count = 0;

	if (search.count == 0) {
		side = black;
		search.key = position_polyglot_key(position, side);
		if (get_entries(&search) != 0) {
			search.count = 0;
		}

		if (search.count == 0)
			return;
	}

	sort_entries(search.count, entries);

	pick_legal_moves(&search, position, side, moves);
}

size_t
polyglot_book_size(const struct book *book)
{
	return book->polyglot_book.size;
}
Example #6
0
static struct itbl_entry *
find_entry_byname (e_processor processor,
		   e_type type, char *n)
{
  struct itbl_entry *e, **es;

  es = get_entries (processor, type);
  for (e = *es; e; e = e->next)	/* for each entry, ...  */
    {
      if (!strcmp (e->name, n))
	return e;
    }
  return 0;
}
static uint32_t setup_timestamp_menu(Window *window) {
  
  // Get saved timestamps and create an array for them
  num_entries = get_entries(&entries);
  smenu_items = (SimpleMenuItem *) malloc(sizeof(SimpleMenuItem) * num_entries);
  
  // For each time_t (epoch) timestamp, convert to string for menu display
  for (uint32_t i = 0; i < num_entries; i++) {
    time_t epoch = entries[i];
    struct tm *timedata = localtime(&epoch);
    char *title = (char *) malloc(64 * sizeof(char));  // Need non-stack mem
    strftime(title, 64, get_format(), timedata);
    smenu_items[i] = (SimpleMenuItem) {
//       .title = title,
//       .subtitle = NULL,
      .title = NULL,
      .subtitle = title,
      .callback = NULL
    };
  }
  
  // Setup the section with the items
  smenu_sections[0] = (SimpleMenuSection) {
    .title = "Timestamps",
    .num_items = num_entries,
    .items = smenu_items
  };
  
  // Setup the menu layer, give it the items, and push the new window.
  smenu_layer = simple_menu_layer_create(
                  GRect(0, 0, 144, 152),
                  window,
                  smenu_sections,
                  NSECTIONS,
                  NULL);  //The last one is void *ctx which can be abitrary data passed to callbacks
  layer_add_child(window_get_root_layer(window), (Layer *) smenu_layer);
  window_stack_push(window, true);
  
  return num_entries;
}

static void setup_no_entries_window(Window *window) {
  TextLayer *text_layer = text_layer_create(GRect(0,0,144,152));
  text_layer_set_text(text_layer, no_entries_text);
  layer_add_child(window_get_root_layer(window), (Layer *) text_layer);
  window_stack_push(window, true);
}
Example #8
0
int rootfs_readdir_r(const void* cfg, void * handle, int loc, struct dirent * entry){
	int total;
	const sysfs_t * list;
	list = (const sysfs_t*)cfg;
	//this loads the loc mounted filesystem

	//count the total entries
	total = get_entries(list);
	if ( loc < total ){
		entry->d_ino = loc;
		strcpy(entry->d_name, &(list[loc].mount_path[1]));
		return loc;
	}

	//don't set errno (this just means we are past the end of the list)
	return -1;
}
Example #9
0
int list_tar_entries (char* tarname, int verbose) {
  if (file_exists(tarname) == -1) {
    printf("tarino-native: Archive \'%s\' does not exist.\n", tarname);
    return -1;
  }

  int offsets[10000];
  get_entry_offsets(tarname, offsets);
  int entries = get_entries(offsets);
  if (verbose == 1) {
    printf("tarino-native: Listing %d entries from archive.\n\n", entries);
  }
  int i;
  for (i = 0; i < entries; i++) {
    extract_entry(tarname, offsets[i], 0, verbose, 0);
  }
  return 0;
}
Example #10
0
static struct itbl_entry *
alloc_entry (e_processor processor, e_type type,
	     char *name, unsigned long value)
{
  struct itbl_entry *e, **es;
  if (!name)
    return 0;
  e = XNEW (struct itbl_entry);
  if (e)
    {
      memset (e, 0, sizeof (struct itbl_entry));
      e->name = xstrdup (name);
      e->processor = processor;
      e->type = type;
      e->value = value;
      es = get_entries (e->processor, e->type);
      e->next = *es;
      *es = e;
    }
  return e;
}
Example #11
0
static struct itbl_entry *
find_entry_byval (e_processor processor, e_type type,
		  unsigned long val, struct itbl_range *r)
{
  struct itbl_entry *e, **es;
  unsigned long eval;

  es = get_entries (processor, type);
  for (e = *es; e; e = e->next)	/* for each entry, ...  */
    {
      if (processor != e->processor)
	continue;
      /* For insns, we might not know the range of the opcode,
	 * so a range of 0 will allow this routine to match against
	 * the range of the entry to be compared with.
	 * This could cause ambiguities.
	 * For operands, we get an extracted value and a range.
	 */
      /* if range is 0, mask val against the range of the compared entry.  */
      if (r == 0)		/* if no range passed, must be whole 32-bits
			 * so create 32-bit value from entry's range */
	{
	  eval = apply_range (e->value, e->range);
	  val &= apply_range (0xffffffff, e->range);
	}
      else if ((r->sbit == e->range.sbit && r->ebit == e->range.ebit)
	       || (e->range.sbit == 0 && e->range.ebit == 0))
	{
	  eval = apply_range (e->value, *r);
	  val = apply_range (val, *r);
	}
      else
	continue;
      if (val == eval)
	return e;
    }
  return 0;
}
Example #12
0
void value_set_analysis_fivrt::add_vars(
  const goto_programt &goto_program)
{
  typedef std::list<value_set_fivrt::entryt> entry_listt;

  // get the globals
  entry_listt globals;
  get_globals(globals);

  // get the locals
  goto_programt::decl_identifierst locals;
  goto_program.get_decl_identifiers(locals);

  // cache the list for the locals to speed things up
  typedef std::unordered_map<irep_idt, entry_listt, irep_id_hash> entry_cachet;
  entry_cachet entry_cache;

  value_set_fivrt &v=state.value_set;
  v.add_vars(globals);

  for(auto l : locals)
  {
    // cache hit?
    entry_cachet::const_iterator e_it=entry_cache.find(l);

    if(e_it==entry_cache.end())
    {
      const symbolt &symbol=ns.lookup(l);

      std::list<value_set_fivrt::entryt> &entries=entry_cache[l];
      get_entries(symbol, entries);
      v.add_vars(entries);
    }
    else
      v.add_vars(e_it->second);
  }
}
struct node* setup_tree(char* namestring) {
   char line_buffer[80];

   struct node* treenode = malloc (sizeof(struct node));
   strncpy (treenode->name, namestring, strlen(namestring));

   printf("what is %s?\n", namestring);
   
   fgets(line_buffer, 80, stdin);
   *(strchr(line_buffer, '\n')) = '\0';

   if (is_internal(line_buffer)) {
      treenode->internal = 1;

      treenode->data = malloc(sizeof(struct internal_node));

      treenode->data->nd_i.entries = get_entries(line_buffer, &(treenode->data->nd_i.parts));
   }

   else {
      float cost;

      treenode->data = malloc(sizeof(int));
      treenode->internal = 0;

      sscanf(line_buffer, "%f", &cost);

      if (debug) {
         fprintf(debug_file, "\n[DEBUG] line_buffer contains string \'%s\'\n", line_buffer);      
         fprintf(debug_file, "[DEBUG] cost contains value %f\n\n", cost);
      }

      treenode->data->cost = cost;
   }

   return treenode;
}     
Example #14
0
int main(int argc, char *argv[])
{
  int x,m;
  char *qs;
  entry *entries;
    
  int n;
  char **list,**urls;
  
  /* récupération de la chaîne de paramètres */
  qs = get_query_string(argc,argv);

  /* récupération des couples (nom,valeur) */
  entries = get_entries(qs,&m);

  /* émission de l'entête */
  print_html_head("R&eacute;sultat");

  /* affichage éventuel des informations de debug */
  if (DEBUG) print_debug_query(entries,m,qs,argc,argv);

  /* lecture de la liste des images */
  list = readList("/u/q/quenotg/HMUL8R6A/PROJET/test/list.txt",&n);
  if (list == NULL) {printf("Failed to read %s file.\n","list.txt"); exitfail();}
  if (DEBUG) printf("Read list, %d images.<BR>\n",n);
  
  /* lecture des urls des images */
  urls = readList("/u/q/quenotg/HMUL8R6A/PROJET/test/urls.txt",&n);
  if (list == NULL) {printf("Failed to read %s file.\n","list.txt"); exitfail();}
  if (DEBUG) printf("Read list, %d images.<BR>\n",n);
  
  /* émission de la fin de corps et de document */
  print_html_tail();
    
  exit(0);
}
Example #15
0
bool IRCode::try_sync(DexCode* code) {
  std::unordered_map<MethodItemEntry*, uint32_t> entry_to_addr;
  uint32_t addr = 0;
  // Step 1, regenerate opcode list for the method, and
  // and calculate the opcode entries address offsets.
  TRACE(MTRANS, 5, "Emitting opcodes\n");
  for (auto miter = m_ir_list->begin(); miter != m_ir_list->end(); ++miter) {
    MethodItemEntry* mentry = &*miter;
    TRACE(MTRANS, 5, "Analyzing mentry %p\n", mentry);
    entry_to_addr[mentry] = addr;
    if (mentry->type == MFLOW_DEX_OPCODE) {
      TRACE(MTRANS, 5, "Emitting mentry %p at %08x\n", mentry, addr);
      addr += mentry->dex_insn->size();
    }
  }
  // Step 2, Branch relaxation: calculate branch offsets for if-* and goto
  // opcodes, resizing them where necessary. Since resizing opcodes affects
  // address offsets, we need to iterate this to a fixed point.
  //
  // For instructions that use address offsets but never need resizing (i.e.
  // switch and fill-array-data opcodes), we calculate their offsets after
  // we have reached the fixed point.
  TRACE(MTRANS, 5, "Recalculating branches\n");
  std::vector<MethodItemEntry*> multi_branches;
  std::unordered_map<MethodItemEntry*, std::vector<BranchTarget*>> multis;
  std::unordered_map<BranchTarget*, uint32_t> multi_targets;
  bool needs_resync = false;
  for (auto miter = m_ir_list->begin(); miter != m_ir_list->end(); ++miter) {
    MethodItemEntry* mentry = &*miter;
    if (entry_to_addr.find(mentry) == entry_to_addr.end()) {
      continue;
    }
    if (mentry->type == MFLOW_DEX_OPCODE) {
      auto opcode = mentry->dex_insn->opcode();
      if (dex_opcode::is_switch(opcode)) {
        multi_branches.push_back(mentry);
      }
    }
    if (mentry->type == MFLOW_TARGET) {
      BranchTarget* bt = mentry->target;
      if (bt->type == BRANCH_MULTI) {
        multis[bt->src].push_back(bt);
        multi_targets[bt] = entry_to_addr.at(mentry);
        // We can't fix the primary switch opcodes address until we emit
        // the fopcode, which comes later.
      } else if (bt->type == BRANCH_SIMPLE &&
                 dex_opcode::is_branch(bt->src->dex_insn->opcode())) {
        MethodItemEntry* branch_op_mie = bt->src;
        auto branch_addr = entry_to_addr.find(branch_op_mie);
        always_assert_log(branch_addr != entry_to_addr.end(),
                          "%s refers to nonexistent branch instruction",
                          SHOW(*mentry));
        int32_t branch_offset = entry_to_addr.at(mentry) - branch_addr->second;
        needs_resync |= !encode_offset(m_ir_list, mentry, branch_offset);
      }
    }
  }
  if (needs_resync) {
    return false;
  }

  size_t num_align_nops{0};
  auto& opout = code->reset_instructions();
  for (auto& mie : *m_ir_list) {
    // We are assuming that fill-array-data-payload opcodes are always at
    // the end of the opcode stream (we enforce that during instruction
    // lowering). I.e. they are only followed by other fill-array-data-payload
    // opcodes. So adjusting their addresses here does not require re-running
    // branch relaxation.
    entry_to_addr.at(&mie) += num_align_nops;
    if (mie.type == MFLOW_TARGET &&
        mie.target->src->dex_insn->opcode() == DOPCODE_FILL_ARRAY_DATA) {
      // This MFLOW_TARGET is right before a fill-array-data-payload opcode,
      // so we should make sure its address is aligned
      if (entry_to_addr.at(&mie) & 1) {
        opout.push_back(new DexInstruction(DOPCODE_NOP));
        ++entry_to_addr.at(&mie);
        ++num_align_nops;
      }
      mie.target->src->dex_insn->set_offset(entry_to_addr.at(&mie) -
                                            entry_to_addr.at(mie.target->src));
      continue;
    }
    if (mie.type != MFLOW_DEX_OPCODE) {
      continue;
    }
    TRACE(MTRANS, 6, "Emitting insn %s\n", SHOW(mie.dex_insn));
    opout.push_back(mie.dex_insn);
  }
  addr += num_align_nops;

  TRACE(MTRANS, 5, "Emitting multi-branches\n");
  // Step 3, generate multi-branch fopcodes
  for (auto multiopcode : multi_branches) {
    auto& targets = multis[multiopcode];
    auto multi_insn = multiopcode->dex_insn;
    std::sort(targets.begin(), targets.end(), multi_target_compare_case_key);
    always_assert_log(
        !targets.empty(), "need to have targets for %s", SHOW(*multiopcode));
    if (sufficiently_sparse(targets)) {
      // Emit sparse.
      const size_t count = (targets.size() * 4) + 2;
      auto sparse_payload = std::make_unique<uint16_t[]>(count);
      sparse_payload[0] = FOPCODE_SPARSE_SWITCH;
      sparse_payload[1] = targets.size();
      uint32_t* spkeys = (uint32_t*)&sparse_payload[2];
      uint32_t* sptargets =
          (uint32_t*)&sparse_payload[2 + (targets.size() * 2)];
      for (BranchTarget* target : targets) {
        *spkeys++ = target->case_key;
        *sptargets++ = multi_targets[target] - entry_to_addr.at(multiopcode);
      }
      // Emit align nop
      if (addr & 1) {
        DexInstruction* nop = new DexInstruction(DOPCODE_NOP);
        opout.push_back(nop);
        addr++;
      }
      // Insert the new fopcode...
      DexInstruction* fop =
          new DexOpcodeData(sparse_payload.get(), (int)(count - 1));
      opout.push_back(fop);
      // re-write the source opcode with the address of the
      // fopcode, increment the address of the fopcode.
      multi_insn->set_offset(addr - entry_to_addr.at(multiopcode));
      multi_insn->set_opcode(DOPCODE_SPARSE_SWITCH);
      addr += count;
    } else {
      // Emit packed.
      const uint64_t size = get_packed_switch_size(targets);
      always_assert(size <= std::numeric_limits<uint16_t>::max());
      const size_t count = (size * 2) + 4;
      auto packed_payload = std::make_unique<uint16_t[]>(count);
      packed_payload[0] = FOPCODE_PACKED_SWITCH;
      packed_payload[1] = size;
      uint32_t* psdata = (uint32_t*)&packed_payload[2];
      int32_t next_key = *psdata++ = targets.front()->case_key;
      for (BranchTarget* target : targets) {
        // Fill in holes with relative offsets that are falling through to the
        // instruction after the switch instruction
        for (; next_key != target->case_key; ++next_key) {
          *psdata++ = 3; // packed-switch statement is three code units
        }
        *psdata++ = multi_targets[target] - entry_to_addr.at(multiopcode);
        ++next_key;
      }
      // Emit align nop
      if (addr & 1) {
        DexInstruction* nop = new DexInstruction(DOPCODE_NOP);
        opout.push_back(nop);
        addr++;
      }
      // Insert the new fopcode...
      DexInstruction* fop =
          new DexOpcodeData(packed_payload.get(), (int)(count - 1));
      opout.push_back(fop);
      // re-write the source opcode with the address of the
      // fopcode, increment the address of the fopcode.
      multi_insn->set_offset(addr - entry_to_addr.at(multiopcode));
      multi_insn->set_opcode(DOPCODE_PACKED_SWITCH);
      addr += count;
    }
  }

  // Step 4, emit debug entries
  TRACE(MTRANS, 5, "Emitting debug entries\n");
  auto debugitem = code->get_debug_item();
  if (debugitem) {
    gather_debug_entries(m_ir_list, entry_to_addr, &debugitem->get_entries());
  }
  // Step 5, try/catch blocks
  TRACE(MTRANS, 5, "Emitting try items & catch handlers\n");
  auto& tries = code->get_tries();
  tries.clear();
  MethodItemEntry* active_try = nullptr;
  for (auto& mentry : *m_ir_list) {
    if (mentry.type != MFLOW_TRY) {
      continue;
    }
    auto& tentry = mentry.tentry;
    if (tentry->type == TRY_START) {
      always_assert(active_try == nullptr);
      active_try = &mentry;
      continue;
    }
    redex_assert(tentry->type == TRY_END);
    auto try_end = &mentry;
    auto try_start = active_try;
    active_try = nullptr;

    always_assert_log(
        try_start != nullptr, "unopened try_end found: %s", SHOW(*try_end));
    always_assert_log(try_start->tentry->catch_start ==
                          try_end->tentry->catch_start,
                      "mismatched try start (%s) and end (%s)",
                      SHOW(*try_start),
                      SHOW(*try_end));
    auto start_addr = entry_to_addr.at(try_start);
    auto end_addr = entry_to_addr.at(try_end);
    if (start_addr == end_addr) {
      continue;
    }

    DexCatches catches;
    for (auto mei = try_end->tentry->catch_start;
        mei != nullptr;
        mei = mei->centry->next) {
      if (mei->centry->next != nullptr) {
        always_assert(mei->centry->catch_type != nullptr);
      }
      catches.emplace_back(mei->centry->catch_type, entry_to_addr.at(mei));
    }
    split_and_insert_try_regions(start_addr, end_addr, catches, &tries);
  }
  always_assert_log(active_try == nullptr, "unclosed try_start found");

  std::sort(tries.begin(),
            tries.end(),
            [](const std::unique_ptr<DexTryItem>& a,
               const std::unique_ptr<DexTryItem>& b) {
              return a->m_start_addr < b->m_start_addr;
            });
  return true;
}
Example #16
0
int main(int argc, char **argv) {

   int events[1],i;
   long long counts[1];
   
   int retval,quiet;
   int l1_size,l2_size,l1_linesize,l2_entries;
   int arraysize;

   char test_string[]="Testing PAPI_L2_DCM predefined event...";
   
   quiet=test_quiet();

   retval = PAPI_library_init(PAPI_VER_CURRENT);
   if (retval != PAPI_VER_CURRENT) {
      if (!quiet) printf("Error! PAPI_library_init %d\n",retval);
      test_fail(test_string);
   }

   retval = PAPI_query_event(PAPI_L2_DCM);
   if (retval != PAPI_OK) {
      if (!quiet) printf("PAPI_L2_DCM not available\n");
      test_skip(test_string);
   }

   events[0]=PAPI_L2_DCM;

   l1_size=get_cachesize(L1D_CACHE,quiet,test_string);
   l1_linesize=get_linesize(L1D_CACHE,quiet,test_string);
   l2_size=get_cachesize(L2_CACHE,quiet,test_string);
   l2_entries=get_entries(L2_CACHE,quiet,test_string);

   /*******************************************************************/
   /* Test if the C compiler uses a sane number of data cache acceess */
   /*******************************************************************/

   arraysize=l2_size/sizeof(double);

   double *array;
   double aSumm = 0.0;

   if (!quiet) {
      printf("Allocating %ld bytes of memory (%d doubles)\n",
          arraysize*sizeof(double),arraysize);
   }

   array=calloc(arraysize,sizeof(double));
   if (array==NULL) {
      if (!quiet) printf("Error! Can't allocate memory\n");
      test_fail(test_string);
   }

   if (!quiet) printf("Write test:\n");
   PAPI_start_counters(events,1);
   
   for(i=0; i<arraysize; i++) { 
      array[i]=(double)i;
   }
     
   PAPI_stop_counters(counts,1);

   if (!quiet) {
      printf("\tL2 D misses: %lld\n",counts[0]);
      printf("\tShould be roughly (%d/(%d/%ld)): %ld\n",
          arraysize,l1_linesize,sizeof(double),
          arraysize/(l1_linesize/sizeof(double)));
   }

   PAPI_start_counters(events,1);
   
   for(i=0; i<arraysize; i++) { 
       aSumm += array[i]; 
   }
     
   PAPI_stop_counters(counts,1);

   if (!quiet) {
      printf("Read test (%lf):\n",aSumm);
      printf("\tL2 D misses: %lld\n",counts[0]);
      printf("\tShould be roughly (%d/(%d/%ld)): %ld\n",
          arraysize,l1_linesize,sizeof(double),
          arraysize/(l1_linesize/sizeof(double)));
   }

   PAPI_shutdown();

   test_pass(test_string);
   
   return 0;
}
Example #17
0
int main(int argc, char *argv[])
{
  int x,m;
  char *qs;
  entry *entries;
    
  int nbTrain,nbVal,nbDims,nbConcepts,c,**trainAnns,**valAnns,ret;
  char **trainList,**valList,**concepts,*name;
  float **trainDescriptors,**valDescriptors;
  
  /* récupération de la chaîne de paramètres */
  qs = get_query_string(argc,argv);

  /* récupération des couples (nom,valeur) */
  entries = get_entries(qs,&m);

  /* émission de l'entête */
  print_html_head("R&eacute;sultat");

  /* affichage éventuel des informations de debug */
  if (DEBUG) print_debug_query(entries,m,qs,argc,argv);

  trainList = readList("/usr/lib/cgi-bin/RIM/images/train/list.txt",&nbTrain);
  if (trainList == NULL) {printf("Failed to read %s file.\n","train/list.txt"); exitfail();}
  if (DEBUG) printf("Read train list, %d images.<BR>\n",nbTrain);
  
  valList = readList("/usr/lib/cgi-bin/RIM/images/val/list.txt",&nbVal);
  if (valList == NULL) {printf("Failed to read %s file.\n","val/list.txt"); exitfail();}
  if (DEBUG) printf("Read val list, %d images.<BR>\n",nbVal);
  
  trainDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/train/descriptors.bin",nbTrain,&nbDims);
  if (trainDescriptors == NULL) {printf("Failed to read %s file.\n","train/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read train descripors, %d images, %d dimensions.<BR>\n",nbTrain,nbDims);
  
  valDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/val/descriptors.bin",nbVal,&nbDims);
  if (valDescriptors == NULL) {printf("Failed to read %s file.\n","val/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read val descripors, %d images, %d dimensions.<BR>\n",nbVal,nbDims);
  
  concepts = readList("/usr/lib/cgi-bin/RIM/images/concepts.txt",&nbConcepts);
  if (concepts == NULL) {printf("Failed to read %s file.\n","concepts.txt"); exitfail();}
  if (DEBUG) printf("Read concept list, %d concepts.<BR>\n",nbConcepts);
  
  trainAnns = malloc(nbConcepts*sizeof(int *));
  if (trainAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read train annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/train/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    trainAnns[c] = readAnnotations(name,nbTrain);
    if (trainAnns[c] == NULL) {printf("Failed to read train/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  valAnns = malloc(nbConcepts*sizeof(int *));
  if (valAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read val annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/val/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    valAnns[c] = readAnnotations(name,nbVal);
    if (valAnns[c] == NULL) {printf("Failed to read val/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  /* émission de la fin de corps et de document */
  print_html_tail();
    
  exit(0);
}
Example #18
0
static void
append_insns_as_macros (void)
{
  struct ITBL_OPCODE_STRUCT *new_opcodes, *o;
  struct itbl_entry *e, **es;
  int n, size, new_size, new_num_opcodes;
#ifdef USE_MACROS
  int id;
#endif

  if (!itbl_have_entries)
    return;

  if (!itbl_num_opcodes)	/* no new instructions to add! */
    {
      return;
    }
  DBG (("previous num_opcodes=%d\n", ITBL_NUM_OPCODES));

  new_num_opcodes = ITBL_NUM_OPCODES + itbl_num_opcodes;
  ASSERT (new_num_opcodes >= itbl_num_opcodes);

  size = sizeof (struct ITBL_OPCODE_STRUCT) * ITBL_NUM_OPCODES;
  ASSERT (size >= 0);
  DBG (("I get=%d\n", size / sizeof (ITBL_OPCODES[0])));

  new_size = sizeof (struct ITBL_OPCODE_STRUCT) * new_num_opcodes;
  ASSERT (new_size > size);

  /* FIXME since ITBL_OPCODES culd be a static table,
		we can't realloc or delete the old memory.  */
  new_opcodes = (struct ITBL_OPCODE_STRUCT *) malloc (new_size);
  if (!new_opcodes)
    {
      printf (_("Unable to allocate memory for new instructions\n"));
      return;
    }
  if (size)			/* copy preexisting opcodes table */
    memcpy (new_opcodes, ITBL_OPCODES, size);

  /* FIXME! some NUMOPCODES are calculated expressions.
		These need to be changed before itbls can be supported.  */

#ifdef USE_MACROS
  id = ITBL_NUM_MACROS;		/* begin the next macro id after the last */
#endif
  o = &new_opcodes[ITBL_NUM_OPCODES];	/* append macro to opcodes list */
  for (n = e_p0; n < e_nprocs; n++)
    {
      es = get_entries (n, e_insn);
      for (e = *es; e; e = e->next)
	{
	  /* name,    args,   mask,       match,  pinfo
		 * {"li",      "t,i",  0x34000000, 0xffe00000, WR_t    },
		 * {"li",      "t,I",  0,    (int) M_LI,   INSN_MACRO  },
		 * Construct args from itbl_fields.
		*/
	  o->name = e->name;
	  o->args = strdup (form_args (e));
	  o->mask = apply_range (e->value, e->range);
	  /* FIXME how to catch during assembly? */
	  /* mask to identify this insn */
	  o->match = apply_range (e->value, e->range);
	  o->pinfo = 0;

#ifdef USE_MACROS
	  o->mask = id++;	/* FIXME how to catch during assembly? */
	  o->match = 0;		/* for macros, the insn_isa number */
	  o->pinfo = INSN_MACRO;
#endif

	  /* Don't add instructions which caused an error */
	  if (o->args)
	    o++;
	  else
	    new_num_opcodes--;
	}
    }
  ITBL_OPCODES = new_opcodes;
  ITBL_NUM_OPCODES = new_num_opcodes;

  /* FIXME
		At this point, we can free the entries, as they should have
		been added to the assembler's tables.
		Don't free name though, since name is being used by the new
		opcodes table.

		Eventually, we should also free the new opcodes table itself
		on exit.
	*/
}
Example #19
0
bool MethodTransform::try_sync() {
  TRACE(MTRANS, 5, "Syncing %s\n", SHOW(m_method));
  auto code = m_method->get_code();
  auto& opout = code->get_instructions();
  opout.clear();
  uint32_t addr = 0;
  addr_mei_t addr_to_mei;
  // Step 1, regenerate opcode list for the method, and
  // and calculate the opcode entries address offsets.
  TRACE(MTRANS, 5, "Emitting opcodes\n");
  for (auto miter = m_fmethod->begin(); miter != m_fmethod->end(); miter++) {
    MethodItemEntry* mentry = &*miter;
    TRACE(MTRANS, 5, "Analyzing mentry %p\n", mentry);
    mentry->addr = addr;
    if (mentry->type == MFLOW_OPCODE) {
      if ((mentry->insn->opcode() == FOPCODE_FILLED_ARRAY) && (addr & 1)) {
        opout.push_back(new DexInstruction(OPCODE_NOP));
        ++addr;
      }
      addr_to_mei[addr] = mentry;
      TRACE(MTRANS, 5, "Emitting mentry %p at %08x\n", mentry, addr);
      opout.push_back(mentry->insn);
      addr += mentry->insn->size();
    }
  }
  // Step 2, recalculate branches..., save off multi-branch data.
  TRACE(MTRANS, 5, "Recalculating branches\n");
  std::vector<MethodItemEntry*> multi_branches;
  std::unordered_map<MethodItemEntry*, std::vector<BranchTarget*>> multis;
  std::unordered_map<BranchTarget*, uint32_t> multi_targets;
  std::unordered_map<DexTryItem*, std::vector<MethodItemEntry*>> try_items;
  for (auto miter = m_fmethod->begin(); miter != m_fmethod->end(); miter++) {
    MethodItemEntry* mentry = &*miter;
    if (mentry->type == MFLOW_OPCODE) {
      auto opcode = mentry->insn->opcode();
      if (is_branch(opcode) && is_multi_branch(opcode)) {
        multi_branches.push_back(mentry);
      }
    }
    if (mentry->type == MFLOW_TARGET) {
      BranchTarget* bt = mentry->target;
      if (bt->type == BRANCH_MULTI) {
        multis[bt->src].push_back(bt);
        multi_targets[bt] = mentry->addr;
        // We can't fix the primary switch opcodes address until we emit
        // the fopcode, which comes later.
      } else if (bt->type == BRANCH_SIMPLE) {
        MethodItemEntry* tomutate = bt->src;
        int32_t branchoffset = mentry->addr - tomutate->addr;
        if ((tomutate->insn->opcode() == OPCODE_FILL_ARRAY_DATA) &&
            (mentry->addr & 1)) {
          ++branchoffset; // account for nop spacer
        }
        auto encode_result = encode_offset(tomutate->insn, branchoffset);
        if (!encode_result.success) {
          auto inst = tomutate->insn;
          tomutate->insn = new DexInstruction(encode_result.newopcode);
          delete inst;
          return false;
        }
      }
    }
    if (mentry->type == MFLOW_TRY) {
      try_items[mentry->tentry->tentry].push_back(mentry);
    }
  }
  TRACE(MTRANS, 5, "Emitting multi-branches\n");
  // Step 3, generate multi-branch fopcodes
  for (auto multiopcode : multi_branches) {
    auto targets = multis[multiopcode];
    std::sort(targets.begin(), targets.end(), multi_target_compare_index);
    if (multi_contains_gaps(targets)) {
      // Emit sparse.
      unsigned long count = (targets.size() * 4) + 2;
      uint16_t sparse_payload[count];
      sparse_payload[0] = FOPCODE_SPARSE_SWITCH;
      sparse_payload[1] = targets.size();
      uint32_t* spkeys = (uint32_t*)&sparse_payload[2];
      uint32_t* sptargets =
          (uint32_t*)&sparse_payload[2 + (targets.size() * 2)];
      for (auto target : targets) {
        *spkeys++ = target->index;
        *sptargets++ = multi_targets[target] - multiopcode->addr;
      }
      // Emit align nop
      if (addr & 1) {
        DexInstruction* nop = new DexInstruction(0);
        opout.push_back(nop);
        addr++;
      }
      // Insert the new fopcode...
      DexInstruction* fop = new DexOpcodeData(sparse_payload, (int) (count - 1));
      opout.push_back(fop);
      // re-write the source opcode with the address of the
      // fopcode, increment the address of the fopcode.
      encode_offset(multiopcode->insn, addr - multiopcode->addr);
      multiopcode->insn->set_opcode(OPCODE_SPARSE_SWITCH);
      addr += count;
    } else {
      // Emit packed.
      unsigned long count = (targets.size() * 2) + 4;
      uint16_t packed_payload[count];
      packed_payload[0] = FOPCODE_PACKED_SWITCH;
      packed_payload[1] = targets.size();
      uint32_t* psdata = (uint32_t*)&packed_payload[2];
      *psdata++ = targets.front()->index;
      for (auto target : targets) {
        *psdata++ = multi_targets[target] - multiopcode->addr;
      }
      // Emit align nop
      if (addr & 1) {
        DexInstruction* nop = new DexInstruction(0);
        opout.push_back(nop);
        addr++;
      }
      // Insert the new fopcode...
      DexInstruction* fop = new DexOpcodeData(packed_payload, (int) (count - 1));
      opout.push_back(fop);
      // re-write the source opcode with the address of the
      // fopcode, increment the address of the fopcode.
      encode_offset(multiopcode->insn, addr - multiopcode->addr);
      multiopcode->insn->set_opcode(OPCODE_PACKED_SWITCH);
      addr += count;
    }
  }

  // Step 4, emit debug opcodes
  TRACE(MTRANS, 5, "Emitting debug opcodes\n");
  auto debugitem = code->get_debug_item();
  if (debugitem) {
    auto& entries = debugitem->get_entries();
    entries.clear();
    for (auto& mentry : *m_fmethod) {
      if (mentry.type == MFLOW_DEBUG) {
        entries.emplace_back(mentry.addr, mentry.dbgop->clone());
      } else if (mentry.type == MFLOW_POSITION) {
        entries.emplace_back(mentry.addr, mentry.pos);
      }
    }
  }
  // Step 5, try/catch blocks
  auto& tries = code->get_tries();
  tries.clear();
  for (auto tryitem : try_items) {
    DexTryItem* dextry = tryitem.first;
    auto& tryentries = tryitem.second;
    sort(tryentries.begin(), tryentries.end(), order_try_entries);
    dextry->m_catches.clear();
    MethodItemEntry* try_start = nullptr;
    bool suppress = false;
    for (auto tryentry : tryentries) {
      switch (tryentry->tentry->type) {
      case TRY_START:
        dextry->m_start_addr = tryentry->addr;
        try_start = tryentry;
        break;
      case TRY_END:
        assert(try_start != nullptr);
        assert(try_start->addr <= tryentry->addr);
        dextry->m_insn_count = tryentry->addr - try_start->addr;
        if (dextry->m_insn_count == 0) {
          suppress = true;
        }
        break;
      case TRY_CATCH:
        if (tryentry->tentry->centry == nullptr) {
          /* Catch all */
          dextry->m_catchall = tryentry->addr;
        } else {
          dextry->m_catches.push_back(
              std::make_pair(tryentry->tentry->centry, tryentry->addr));
        }
        break;
      default:
        always_assert_log(false, "Invalid try entry type");
      }
    }
    if (!suppress) {
      tries.push_back(dextry);
    }
  }
  std::sort(tries.begin(),
            tries.end(),
            [](const DexTryItem* a, const DexTryItem* b) {
              return a->m_start_addr < b->m_start_addr;
            });
  return true;
}
Example #20
0
int
main(int argc, char **argv)
{
	int i, ap;
	cmd_t cmd;
	int cnt = 0;
	int fd;
	int rv = 0;
	hyprlofs_entry_t *e = NULL;
	hyprlofs_entries_t ents;

	if (argc < 3) {
		(void) fprintf(stderr, "%s\n", usage);
		exit(1);
	}

	if ((fd = open(argv[1], O_RDONLY)) < 0) {
		perror("can't open hyprlofs mount");
		exit(1);
	}

	if (strcmp(argv[2], "add") == 0) {
		cmd = CMD_ADD;
	} else if (strcmp(argv[2], "rm") == 0) {
		cmd = CMD_RM;
	} else if (strcmp(argv[2], "clear") == 0) {
		cmd = CMD_CLR;
	} else if (strcmp(argv[2], "addl") == 0) {
		cmd = CMD_ADDL;
	} else if (strcmp(argv[2], "get") == 0) {
		cmd = CMD_GET;
	} else {
		(void) fprintf(stderr, "%s\n", usage);
		exit(1);
	}

	/* Count up the number of parameters. The arg format varies w/ cmd */
	switch (cmd) {
	case CMD_ADD:
		for (i = 3; i < argc; i++) {
			/* argv[i] is the file path */

			/* The next arg is the alias */
			if (++i >= argc) {
				(void) fprintf(stderr, "missing alias for %s\n",
				    argv[i - 1]);
				exit(1);
			}

			cnt++;
		}
		break;
	case CMD_ADDL:
		cnt = argc - 3;
		break;
	case CMD_RM:
		cnt = argc - 3;
		break;
	case CMD_CLR:	/*FALLTHRU*/
	case CMD_GET:
		if (argc > 3) {
			(void) fprintf(stderr, "%s\n", usage);
			exit(1);
		}
		break;
	}

	if (cnt > 0) {
		if ((e = (hyprlofs_entry_t *)malloc(sizeof (hyprlofs_entry_t) *
		    cnt)) == NULL) {
			(void) fprintf(stderr, "out of memory\n");
			exit(1);
		}
	}

	/*
	 * Format up the args.
	 * We only setup the path member for the add cmd.
	 * We won't run this loop for the clear cmd.
	 * The addl command is special since we use basename to get the alias.
	 */
	for (i = 0, ap = 3; i < cnt; i++, ap++) {
		if (cmd == CMD_ADDL) {
			e[i].hle_path = argv[ap];
			e[i].hle_plen = strlen(e[i].hle_path);

			e[i].hle_name = basename(argv[ap]);
			e[i].hle_nlen = strlen(e[i].hle_name);

			continue;
		}

		if (cmd == CMD_ADD) {
			e[i].hle_path = argv[ap++];
			e[i].hle_plen = strlen(e[i].hle_path);
		}

		e[i].hle_name = argv[ap];
		e[i].hle_nlen = strlen(e[i].hle_name);
	}

	ents.hle_entries = e;
	ents.hle_len = cnt;

	switch (cmd) {
	case CMD_ADD:	/*FALLTHRU*/
	case CMD_ADDL:
		if (ioctl(fd, HYPRLOFS_ADD_ENTRIES, &ents) < 0)  {
			perror("ioctl");
			rv = 1;
		}
		break;
	case CMD_RM:
		if (ioctl(fd, HYPRLOFS_RM_ENTRIES, &ents) < 0)  {
			perror("ioctl");
			rv = 1;
		}
		break;
	case CMD_CLR:
		if (ioctl(fd, HYPRLOFS_RM_ALL) < 0)  {
			perror("ioctl");
			rv = 1;
		}
		break;
	case CMD_GET:
		rv = get_entries(fd);
		break;
	}

	(void) close(fd);
	if (cnt > 0)
		free(e);
	return (rv);
}