Esempio n. 1
0
void networkReadCallbackPerByte(NetworkAddress networkAddr, ADDRINT start, size_t length, void *v)
{
    int tag;

    assert(taintGen);
    bitset *s = bitset_init(NUMBER_OF_TAINT_MARKS);

    ADDRINT end = start + length;
    for(ADDRINT addr = start; addr < end; addr++) {
        tag = taintGen->nextTaintMark();
        bitset_set_bit(s, tag);
        memTaintMap[addr] = bitset_copy(s);
        bitset_reset(s);
    }
    bitset_free(s);

    ADDRINT currAddress = start;
    while (currAddress < end) {
        taintAssignmentLog << tag << " - [" << networkAddr.strAddress << "] -> " << std::hex << currAddress++ << "\n";
    }
    taintAssignmentLog.flush();

#ifdef TRACE
    if(tracing) {
        log << "\t" << std::hex << start << "-" << std::hex << end - 1 << " <- read\n";
        log.flush();
    }
#endif
}
Esempio n. 2
0
static int* _factoradic_to_permutation_step(int *data, int length, int *result, int index, Bitset *old) {
  if (index < length) {
    int nth = bitset_nth_bit_true(old, data[index] + 1);
    result[index] = nth;
    bitset_reset(old, nth);
    return _factoradic_to_permutation_step(data, length, result, index + 1, old);
  }
  free_bitset(old);
  return result;
}
Esempio n. 3
0
static int* _permutation_to_factoradic_step(int *data, int length, int index, int *result, Bitset* old) {
  if (index < length) {
    int count = bitset_count_part(old, 0, data[index] - 1);
    if (count < 0) count = 0;
    result[index] = count;
    bitset_reset(old, data[index]);
    return _permutation_to_factoradic_step(data, length, index + 1, result, old);
  }
  free_bitset(old);
  return result;
}
Esempio n. 4
0
static void
flush_shift (state *s, int token)
{
  transitions *trans = s->transitions;
  int i;

  bitset_reset (lookahead_set, token);
  for (i = 0; i < trans->num; i++)
    if (!TRANSITION_IS_DISABLED (trans, i)
	&& TRANSITION_SYMBOL (trans, i) == token)
      TRANSITION_DISABLE (trans, i);
}
Esempio n. 5
0
void assign_colours(){
	rga_node * node;
	rga_node_map * map;
	rga_node * w;
	bitset * used_colours = bitset_new(num_registers);
	while(node = rga_node_list_pop(selectStack)){
		bitset_reset(used_colours);
		map = adjList[node->id];
		while(map != 0){
			w = get_alias(map->node);
			if(w->set == RGA_COLOURED_NODES || w->set == RGA_PRECOLOURED){
				bitset_set(used_colours, colour[w->id]-1);
			}
			map = map->prev;
		}
		if(bitset_all_on(used_colours)){
			rga_node_list_push(spilledNodes, node);
			#ifdef DEBUG_MODE
			printf("Node v%u has become an actual spill\n", node->id);
			#endif
			node->set = RGA_SPILLED_NODES;
		}else{
			rga_node_list_push(colouredNodes, node);
			node->set = RGA_COLOURED_NODES;
			colour[node->id] = bitset_first_off(used_colours, 0) + 1;
			#ifdef DEBUG_MODE
			printf("v%u = reg%u\n", node->id, colour[node->id]-1);
			#endif
		}
	}
	w = coalescedNodes->end;
	while(w != 0){
		colour[w->id] = colour[get_alias(w)->id];
		w = w->prev;
	}
}
Esempio n. 6
0
static void
flush_reduce (bitset lookahead_tokens, int token)
{
  bitset_reset (lookahead_tokens, token);
}
Esempio n. 7
0
rd_vlist * mem_alloc(rd_instr * code,
	rd_vlist * vlist,
	unsigned int match_types,
	unsigned int ret_type,
	unsigned int type_size){

	//start local variables
	flow_graph * graph;
	flow_node * node;

	rga_node * x, * y;
	rga_node_map * list;
	rga_move * move;

	rd_vlist * new_list;
	rd_instr * ins;
	rd_var * v;

	bitset * live;

	unsigned int def_pos, live_pos, set_size, last_id, i;

	bitset * used_colours;
	//end local variables
	
	//perform flow analysis
	graph = flow_generate_graph(code, vlist, 0, 0, match_types);

	//allocate space for node and move information
	initial          = rga_node_list_new();
	coalescedNodes   = rga_node_list_new();
	colouredNodes    = rga_node_list_new();

	coalescedMoves   = rga_move_list_new();
	constrainedMoves = rga_move_list_new();
	worklistMoves    = rga_move_list_new();
	
	nodes = new rga_node *[vlist->num_vars];
	adjSet = new bitset *[vlist->num_vars];
	adjList = new rga_node_map *[vlist->num_vars];
	alias = new rga_node *[vlist->num_vars];
	colour = new unsigned char[vlist->num_vars];

	//initialise memory variables
	for(i = 0; i < vlist->num_vars; i++){
		nodes[i] = rga_node_new(0);
		rga_node_list_push(initial, nodes[i]);
		nodes[i]->set = RGA_INITIAL;
		colour[i] = 0;
		adjList[i] = 0;
		adjSet[i] = bitset_new(vlist->num_vars);
		alias[i] = 0;
	}

	//build the graph
	node = graph->end;
	def_pos = live_pos = 0;
	while(node != 0){
		ins = node->data;
		live = bitset_copy(node->liveout);
		if(ins->type == RD_SET && ins->p1->type & match_types && ins->p2->type & match_types){
			bitset_sub(live, node->use);
			if(!rga_move_list_exists(worklistMoves, nodes[ins->p1->id], nodes[ins->p2->id])){
				move = rga_move_new(nodes[ins->p1->id], nodes[ins->p2->id]);
				rga_move_list_push(worklistMoves, move);
				move->set = RGA_WORKLIST_MOVES;
			}
		}
		bitset_or(live, node->def);
		while((def_pos = bitset_first_on(node->def, def_pos)) != ~0){
			while((live_pos = bitset_first_on(live, live_pos)) != ~0){
				mem_add_edge(nodes[live_pos], nodes[def_pos]);
				live_pos++;
			}
			live_pos = 0;
			def_pos++;
		}
		def_pos = 0;
		node = node->prev;
	}

	//coalesce phase
	while(!rga_move_list_isempty(worklistMoves)){
		move = rga_move_list_pop(worklistMoves);
		x = get_alias(move->a);
		y = get_alias(move->b);
		if(x == y){
			rga_move_list_push(coalescedMoves, move);
			move->set = RGA_COALESCED_MOVES;
		}else if(bitset_check(adjSet[x->id], y->id) || bitset_check(adjSet[x->id], y->id)){
			rga_move_list_push(constrainedMoves, move);
			move->set = RGA_CONSTRAINED_MOVES;
		}else{
			rga_move_list_push(coalescedMoves, move);
			move->set = RGA_COALESCED_MOVES;
			list = adjList[y->id];
			rga_node_list_remove(initial, y);
			rga_node_list_push(coalescedNodes, y);
			y->set = RGA_COALESCED_NODES;
			alias[y->id] = x;
			while(list != 0){
				if(list->node->set != RGA_COALESCED_NODES){
					mem_add_edge(list->node, x);
				}
				list = list->prev;
			}
		}
	}

	//simplify and select phase
	new_list = rd_varlist(0);
	set_size = 0;
	last_id = 0;
	used_colours = bitset_new(vlist->num_vars);
	while(x = rga_node_list_pop(initial)){
		bitset_reset(used_colours);
		list = adjList[x->id];
		while(list != 0){
			y = get_alias(list->node);
			if(y->set == RGA_COLOURED_NODES){
				bitset_set(used_colours, colour[y->id]);
			}
			list = list->prev;
		}
		rga_node_list_push(colouredNodes, x);
		x->set = RGA_COLOURED_NODES;
		colour[x->id] = bitset_first_off(used_colours, 0);
		if(rd_vlist_find(new_list, colour[x->id]) == 0){
			rd_vlist_add(new_list, colour[x->id], ret_type, 0, 0, type_size);
		}
		if(colour[x->id] > last_id){
			last_id = colour[x->id];
		}
		#ifdef DEBUG_MODE
		printf("mem%u gets %u\n", x->id, colour[x->id]);
		#endif
	}
	bitset_delete(used_colours);

	new_list->num_vars = last_id + 1;

	//set the colour of coalesced nodes
	x = coalescedNodes->end;
	while(x != 0){
		colour[x->id] = colour[get_alias(x)->id];
		//rd_vlist_add(new_list, colour[x->id], ret_type, 0, 0, type_size);
		#ifdef DEBUG_MODE		
		printf("mem%u gets %u\n", x->id, colour[x->id]);
		#endif
		x = x->prev;
	}

	node = graph->end;
	while(node != 0){
		if(node->data->p1 != 0){
			if(node->data->p1->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p1->id]);
				if(v != 0){
					node->data->p1 = v;
				}
			}
		}
		if(node->data->p2 != 0){
			if(node->data->p2->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p2->id]);
				if(v != 0){
					node->data->p2 = v;
				}
			}
		}
		if(node->data->p3 != 0){
			if(node->data->p3->type & match_types){
				v = rd_vlist_find(new_list, colour[node->data->p3->id]);
				if(v != 0){
					node->data->p3 = v;
				}
			}
		}
		node = node->prev;
	}

	//clean up
	delete initial;
	delete coalescedNodes;
	delete colouredNodes;

	delete coalescedMoves;
	delete constrainedMoves;
	delete worklistMoves;

	for(i = 0; i < vlist->num_vars; i++){
		delete nodes[i];
		if(adjList[i] != 0){
			delete adjList[i];
		}
		bitset_delete(adjSet[i]);
	}

	delete[] nodes;
	delete[] adjSet;
	delete[] adjList;
	delete[] alias;
	delete[] colour;

	rga_reset();

	return new_list;
}