Example #1
0
static int find_identical_file(struct entry *orig, struct entry *newfile)
{
	if (orig == newfile)
		return 1;
	if (!orig)
		return 0;
	if (orig->size == newfile->size && (orig->path || orig->uncompressed))
	{
		map_entry(orig);
		map_entry(newfile);
		if (!memcmp(orig->uncompressed, newfile->uncompressed, orig->size))
		{
			newfile->same = orig;
			unmap_entry(newfile);
			unmap_entry(orig);
			return 1;
		}
		unmap_entry(newfile);
		unmap_entry(orig);
	}
	return (find_identical_file(orig->child, newfile) ||
		find_identical_file(orig->next, newfile));
}
Example #2
0
void Bus::end_of_elaboration() {
	// for each target connected to this bus initiator port
	for (int i = 0; i < initiator.size(); ++i) {
		// get the target
		ensitlm::compatible_socket *target =
		    dynamic_cast<ensitlm::compatible_socket *>(initiator[i]);
		if (!target) {
			std::cerr << name()
			          << ": target is not a tlm_target_socket\n";
			abort();
		}
		// get the set of port maps which correspond to this name
		std::pair<port_map_t::iterator, port_map_t::iterator> it =
		    port_map.equal_range(target);
		// if no port map corresponds
		if (it.first == it.second) {
			std::cerr << name() << ": no address map information "
			                       "available for target "
			          << target->name() << "\n";
			abort();
		}
		// iterate through port maps
		for (port_map_t::iterator j = it.first; j != it.second; ++j) {
			std::pair<addr_range, int> map_entry((*j).second, i);
			// add to address map and check for conflicts
			if (!addr_map.insert(map_entry).second) {
				std::pair<addr_range, int> map_entry_bis =
				    (*addr_map.find((*j).second));
				int k = map_entry_bis.second;
				ensitlm::compatible_socket *target_bis =
				    dynamic_cast<ensitlm::compatible_socket *>(
				        initiator[k]);
				std::cerr << name() << ": address map conflict "
				                       "between target ports "
				          << target->name() << " and "
				          << target_bis->name() << "\n";
				abort();
			}
		}
	}
	//   #ifdef DEBUG
	print_addr_map();
	//   #endif
}
Example #3
0
/*
 * Traverse the entry tree, writing data for every item that has
 * non-null entry->path (i.e. every non-empty regfile) and non-null
 * entry->uncompressed (i.e. every symlink).
 */
static unsigned int write_data(struct entry *entry, char *base, unsigned int offset)
{
	do {
		if (entry->path || entry->uncompressed) {
			if (entry->same) {
				set_data_offset(entry, base, entry->same->offset);
				entry->offset = entry->same->offset;
			}
			else {
				set_data_offset(entry, base, offset);
				entry->offset = offset;
				map_entry(entry);
				offset = do_compress(base, offset, entry->name, entry->uncompressed, entry->size);
				unmap_entry(entry);
			}
		}
		else if (entry->child)
			offset = write_data(entry->child, base, offset);
		entry=entry->next;
	} while (entry);
	return offset;
}
Example #4
0
void fac_map_put(fac_map_t *map, const char *key, void *value)
{
    uintptr_t pos;
    struct s_map_entry *entry;
    unsigned int index;
    struct s_map_page *page;
    unsigned int hash = fac_hashcode(key);
    unsigned int base = (hash / MAP_PAGE_ENTRIES) * MAP_PAGE_ENTRIES;

    if (map->base == 0) {
        map->base = base;
        map->top = base;
        page = (struct s_map_page *)*(map->pages);
    } else {
        pos = (base - map->base) * map->pagesize;

        /*
         * não tenta realocar se há páginas
         * disponíveis na tabela.
         */
        if ((base < map->base) || (base > map->top)) {
            map_realloc(map, base);
            if (base == map->base)
                pos = 0;

            page = map_pages_init();
            pos += (uintptr_t)map->pages;
            *((uintptr_t *)pos) = (uintptr_t)page;
        } else {
            pos += (uintptr_t)map->pages;
            page = (struct s_map_page *)*((uintptr_t *)pos);

            if (page == NULL) {
                page = map_pages_init();
                *((uintptr_t *)pos) = (uintptr_t)page;
            }
        }
    }

    index = hash - base;
    entry = page->entries[index];
    if (entry == NULL) {
        page->entries[index] = map_entry(key, value);
        fac_list_add(map->keys, key);
        map->size++;
    } else {
        if (entry->key == NULL) {
            entry->key = key;
            entry->value = value;
            fac_list_add(map->keys, key);
            return;
        }

        /* se houver colisão */
        if (strcmp(entry->key, key) != 0) {
            if (entry->list == NULL)
                entry->list = fac_list_ini();
            fac_list_add(entry->list, map_entry(key, value));
            fac_list_add(map->keys, key);
        } else {
            entry->value = value;
        }
    }
}