Esempio n. 1
0
char* _convert_float_to_str(float input){
	ssize_t expected = snprintf(NULL, 0, "%f", input);
	char* buf = malloc(sizeof(char) * (expected + 1));
	if(!buf) _seam_fatal("Failed to allocate buf for float to string!");
	snprintf(buf, expected + 1, "%f", input);
	_make_node(buf);
	return buf;
}
Esempio n. 2
0
char* _string_join(char* str1, char* str2){
	int str1len = strlen(str1);
	int str2len = strlen(str2);

	int len = str1len + str2len + 1;
	char* buf = malloc(sizeof(char) * len);
	if(!buf) _seam_fatal("Failed to allocate for string join!");
	strcpy(buf, str1);
	strcpy( (buf + str1len) , str2);
	_make_node(buf);
	return buf;
}
Esempio n. 3
0
static int _refill_pool(struct allocman *alloc, utspace_trickle_t *trickle, uint32_t size_bits)
{
    uint32_t i;
    int error;
    struct utspace_trickle_node *node;
    uint32_t cookie;
    node = _make_node(alloc, &error);
    if (error) {
        return error;
    }
    /* Check if there are untypeds >= 5 size_bits from us */
    for (i = size_bits + 5 > 31 ? 31 : size_bits + 5; i < 32; i++) {
        if (trickle->heads[i]) {
            i = size_bits + 5;
            break;
        }
    }
    if (i == 32) {
        /* Search for the biggest one near us */
        for (i = size_bits + 5 > 31 ? 31 : size_bits + 5; i > size_bits; i--) {
            if (trickle->heads[i]) {
                break;
            }
        }
    }
    if (i != size_bits) {
        cookie = _utspace_trickle_alloc(alloc, trickle, i, seL4_UntypedObject, NULL, &error);
        if (!error) {
            struct utspace_trickle_node *parent = _cookie_to_node(cookie);
            uint32_t offset = _cookie_to_offset(cookie);
            node->ut = parent->ut;
            node->offset = parent->offset + (offset << (i));
            if (parent->paddr) {
                node->paddr = parent->paddr + (offset << (i));
            } else {
                node->paddr = 0;
            }
            node->parent_cookie = cookie;
            node->bitmap_bits = i - size_bits + 1;
            node->bitmap = _make_bitmap(node->bitmap_bits);
            node->next = node->prev = NULL;
            _insert_node(&trickle->heads[size_bits], node);
            return 0;
        }
    }
    _free_node(alloc, node);
    return 1;
}
Esempio n. 4
0
/* when mem is not NULL, we create the path if it doesn't exist yet */
static struct dm_config_node *_find_or_make_node(struct dm_pool *mem,
						 struct dm_config_node *parent,
						 const char *path)
{
	const char *e;
	struct dm_config_node *cn = parent ? parent->child : NULL;
	struct dm_config_node *cn_found = NULL;

	while (cn || mem) {
		/* trim any leading slashes */
		while (*path && (*path == sep))
			path++;

		/* find the end of this segment */
		for (e = path; *e && (*e != sep); e++) ;

		/* hunt for the node */
		cn_found = NULL;

		while (cn) {
			if (_tok_match(cn->key, path, e)) {
				/* Inefficient */
				if (!cn_found)
					cn_found = cn;
				else
					log_warn("WARNING: Ignoring duplicate"
						 " config node: %s ("
						 "seeking %s)", cn->key, path);
			}

			cn = cn->sib;
		}

		if (!cn_found && mem) {
			if (!(cn_found = _make_node(mem, path, e, parent)))
				return_NULL;
		}

		if (cn_found && *e) {
			parent = cn_found;
			cn = cn_found->child;
		} else
			return cn_found;
		path = e;
	}

	return NULL;
}
Esempio n. 5
0
int _utspace_trickle_add_uts(allocman_t *alloc, void *_trickle, uint32_t num, cspacepath_t *uts, uint32_t *size_bits, uint32_t *paddr) {
    utspace_trickle_t *trickle = (utspace_trickle_t*) _trickle;
    struct utspace_trickle_node *nodes[num];
    cspacepath_t *uts_copy[num];
    int error;
    int i;
    for (i = 0; i < num; i++) {
        nodes[i] = _make_node(alloc, &error);
        if (error) {
            for (i--; i >= 0; i--) {
                _free_node(alloc, nodes[i]);
                allocman_mspace_free(alloc, uts_copy[i], sizeof(cspacepath_t));
            }
            return error;
        }
        uts_copy[i] = allocman_mspace_alloc(alloc, sizeof(cspacepath_t), &error);
        if (error) {
            _free_node(alloc, nodes[i]);
            for (i--; i >= 0; i--) {
                _free_node(alloc, nodes[i]);
                allocman_mspace_free(alloc, uts_copy[i], sizeof(cspacepath_t));
            }
        }
    }
    for (i = 0; i < num; i++) {
        *uts_copy[i] = uts[i];
        nodes[i]->ut = uts_copy[i];
        nodes[i]->offset = 0;
        nodes[i]->paddr = paddr[i];
        nodes[i]->parent_cookie = 0;
        nodes[i]->next = nodes[i]->prev = NULL;
        /* Start with only 1 thing free */
        nodes[i]->bitmap = BIT(31);
        nodes[i]->bitmap_bits = 1;
        _insert_node(&trickle->heads[size_bits[i]], nodes[i]);
    }
    return 0;
}