Beispiel #1
0
void generateUseDef(vertex_t* vertex_list, int nvertex, int nsym, int nactive, Random* r, bool print_input){
    //printf("in generateUseDef\n");
	int j;
	int sym;

    for(int i = 0; i < nvertex; ++i){

		if(print_input){
			printf("[%d] usedef = {", vertex_list[i].index);
		}
		for (j = 0; j < nactive; ++j) {
			sym = abs(nextRand(r)) % nsym;

			if (j % 4 != 0) {
				if(!bitset_get_bit(vertex_list[i].def, sym)){//!bitset_get_bit(v->def, sym)){

					if(print_input){
						printf(" u %d", sym);
					}
					bitset_set_bit(vertex_list[i].use, sym);//bitset_set_bit(v->use, sym, true);
				}
			}else{
				if(!bitset_get_bit(vertex_list[i].use, sym)){//!bitset_get_bit(v->use, sym)){
					if(print_input){
						printf(" d %d", sym);
					}
					bitset_set_bit(vertex_list[i].def, sym);//bitset_set_bit(v->def, sym, true);
				}
			}
		}
		if(print_input){
			printf("}\n");
		}
	}
}
Beispiel #2
0
int main(int argc, char * argv[]) {
  struct bitset_t * b = bitset_alloc(65);
  bitset_set_bit(b, 0);
  bitset_set_bit(b, 5);
  bitset_set_bit(b, 3);
  bitset_set_bit(b, 10);
  bitset_set_bit(b, 59);
  bitset_reset_bit(b, 10);
  fprintf(stdout, "bitset = ");
  bitset_print(b, stdout);
  fputs("\n", stdout);
  return 0;
}
static int
fdevent_linux_rtsig_event_add(fdevents * ev, int fde_ndx, int fd, int events)
{
	/*
	 * known index 
	 */
	if (fde_ndx != -1)
	{
		if (ev->pollfds[fde_ndx].fd == fd)
		{
			ev->pollfds[fde_ndx].events = events;

			return fde_ndx;
		}
		fprintf(stderr, "%s.%d: add: (%d, %d)\n", __FILE__, __LINE__,
				fde_ndx, ev->pollfds[fde_ndx].fd);
		SEGFAULT();
	}

	if (ev->unused.used > 0)
	{
		int k = ev->unused.ptr[--ev->unused.used];

		ev->pollfds[k].fd = fd;
		ev->pollfds[k].events = events;

		bitset_set_bit(ev->sigbset, fd);

		return k;
	} else
	{
		if (ev->size == 0)
		{
			ev->size = 16;
			ev->pollfds = malloc(sizeof(*ev->pollfds) * ev->size);
		} else if (ev->size == ev->used)
		{
			ev->size += 16;
			ev->pollfds = realloc(ev->pollfds, sizeof(*ev->pollfds) * ev->size);
		}

		ev->pollfds[ev->used].fd = fd;
		ev->pollfds[ev->used].events = events;

		bitset_set_bit(ev->sigbset, fd);

		return ev->used++;
	}
}
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
}
void networkReadCallbackPerRead(NetworkAddress networkAddr, ADDRINT start, size_t length, void *v)
{
    int tag;
    bitset *s = bitset_init(NUMBER_OF_TAINT_MARKS);
    assert(taintGen);
    tag = taintGen->nextTaintMark();
    //taint entire buffer with 1 mark
    bitset_set_bit(s, tag);

    ADDRINT end = start + length;
    for(ADDRINT addr = start; addr < end; addr++) {
        memTaintMap[addr] = bitset_copy(s);
    }
    bitset_free(s);

    taintAssignmentLog << tag << " - [" << networkAddr.strAddress << "] -> " << std::hex << start << "-" << std::hex << end - 1<< "\n";
    taintAssignmentLog.flush();

#ifdef TRACE
    if(tracing) {
        log << "\t" << std::hex << start << "-" << std::hex << end - 1 << " <- read(" << tag << ")\n";
        log.flush();
    }
#endif
}
/**
 * This function creates a binary representation of the huffman tree in order to serialize it to a file. 
 * The binary representation is created recursively by traversing the tree in an in-order fashion.
 * For each non-leaf node encountered a 0 is stored in the binary representation, whereas for the leaf
 * nodes an 1 is stored followed by the byte assigned to the node.
 */
static int huffman_tree_serialize_recurse(huffman_node* curr_node, bitset* tree_binary_rep, int *bits_stored) {

    int resize_status = check_and_resize_bitset(tree_binary_rep, *bits_stored);
    if(resize_status != HUFFMAN_SUCCESS) {
        return resize_status;
    }

    if(curr_node->is_leaf) {
        bitset_set_bit(tree_binary_rep, *bits_stored);
        (*bits_stored)++;

        unsigned char byte = curr_node->which_char;
        for(int i = 0; i < 8; i++) {
            unsigned char mask = 1 << (8 - i - 1);
            int bit = (byte & mask) != 0;
            
            resize_status = check_and_resize_bitset(tree_binary_rep, *bits_stored);
            if(resize_status != HUFFMAN_SUCCESS) {
                return resize_status;
            }

            if(bit == 1) {
                bitset_set_bit(tree_binary_rep, *bits_stored);
            } else {
                bitset_clear_bit(tree_binary_rep, *bits_stored);
            }

            (*bits_stored)++;
        }

    } else {
        bitset_clear_bit(tree_binary_rep, *bits_stored);
        (*bits_stored)++;

        int left_status = huffman_tree_serialize_recurse(curr_node->left, tree_binary_rep, bits_stored);
        if(left_status != HUFFMAN_SUCCESS) {
            return left_status;
        }

        int right_status = huffman_tree_serialize_recurse(curr_node->right, tree_binary_rep, bits_stored);
        if(right_status != HUFFMAN_SUCCESS) {
            return right_status;
        }
    }
 
    return HUFFMAN_SUCCESS;
}
static int
fdevent_freebsd_kqueue_event_add(fdevents * ev, int fde_ndx, int fd, int events)
{
	int filter, ret;
	struct kevent kev;
	struct timespec ts;

	UNUSED(fde_ndx);

	filter = (events & FDEVENT_IN) ? EVFILT_READ : EVFILT_WRITE;

	EV_SET(&kev, fd, filter, EV_ADD | EV_CLEAR, 0, 0, NULL);

	ts.tv_sec = 0;
	ts.tv_nsec = 0;

	ret = kevent(ev->kq_fd, &kev, 1, NULL, 0, &ts);

	if (ret == -1)
	{
		fprintf(stderr, "%s.%d: kqueue failed polling: %s\n",
				__FILE__, __LINE__, strerror(errno));

		return -1;
	}

	if (filter == EVFILT_READ)
	{
		bitset_set_bit(ev->kq_bevents, fd);
	} else
	{
		bitset_clear_bit(ev->kq_bevents, fd);
	}

	return fd;
}
Beispiel #8
0
int main(int argc, char** argv)
{
	
	int show_details = 0;

	printf("\nShow details,run: %s details.\n",argv[0]);
	if(argc > 1)
	{
		if(strcmp("details",argv[1]) == 0)
		{
			show_details = 1;	
		}
	}

	bitset *s = bitset_init(200);
	bitset_set_bit(s, 0);
	bitset_set_bit(s, 1);
	bitset_set_bit(s, 2);
	bitset_set_bit(s, 3);
	bitset_set_bit(s, 4);
	bitset_set_bit(s, 5);
	bitset_set_bit(s, 6);
	bitset_set_bit(s, 7);
	bitset_set_bit(s, 8);
	bitset_set_bit(s, 9);
	bitset_set_bit(s, 10);
	bitset_print(s);
	bitset_clear_bit(s, 1);
	bitset_clear_bit(s, 4);
	bitset_clear_bit(s, 7);
	bitset_print(s);
	
	size_t pos = bitset_get_first_unused_bit_pos(s);
	printf("pos : %d\n", pos);
	bitset_set_bit(s, pos);
	pos = bitset_get_first_unused_bit_pos(s);
	printf("pos : %d\n", pos);
	
	bitset_free(s);
	run(1);

    return (EXIT_SUCCESS);
}