lib/mm/mm.c
errval_t mm_add(struct mm *mm, struct capref cap, genpaddr_t base, size_t size)
{
	errval_t err;
	struct mmnode *node = (struct mmnode*) slab_alloc(&mm->slabs);
    assert(node != NULL);
	node->cap.base = base;
	node->cap.size = size;

	node->base = base;
	node->size = size;
	node->type = NodeType_Free;

		
	struct mmnode *curr = mm->head;
	if (curr == NULL) {
		mm->head = node;
	} else {
		while (curr->next) {
			curr = curr->next;
		}
		curr->next = node;
		node->prev = curr;
		node->next = NULL;
	}

	mm->initial_size = size;
	mm->initial_base = base;
	mm->initial_cap = cap;


	err = mm->slot_alloc(mm->slot_alloc_inst, 1, &(node->cap.cap));
	if (err_is_fail(err)) {
        return err;
    }
	err = cap_retype(node->cap.cap, mm->initial_cap, 0, mm->objtype, (gensize_t) size, 1);
	if (err_is_fail(err)) {
        return err;
    }

	return SYS_ERR_OK;
}
/**
 * Adds a capability to the memory manager.
 *
 * \param  cap  Capability to add
 * \param  base Physical base address of the capability
 * \param  size Size of the capability (in bytes)
 */
Adds a capability to the memory manager.
\param  cap  Capability to add
\param  base Physical base address of the capability
\param  size Size of the capability (in bytes)
Adds a capability to the memory manager . \ param cap Capability to add \ param base Physical base address of the capability \ param size Size of the capability ( in bytes )
errval_t mm_add(struct mm *mm, struct capref cap, genpaddr_t base, size_t size)
{
	errval_t err;
	struct mmnode *node = (struct mmnode*) slab_alloc(&mm->slabs);
    assert(node != NULL);
	node->cap.base = base;
	node->cap.size = size;
	node->base = base;
	node->size = size;
	node->type = NodeType_Free;
	struct mmnode *curr = mm->head;
	if (curr == NULL) {
		mm->head = node;
	} else {
		while (curr->next) {
			curr = curr->next;
		}
		curr->next = node;
		node->prev = curr;
		node->next = NULL;
	}
	mm->initial_size = size;
	mm->initial_base = base;
	mm->initial_cap = cap;
	err = mm->slot_alloc(mm->slot_alloc_inst, 1, &(node->cap.cap));
	if (err_is_fail(err)) {
        return err;
    }
	err = cap_retype(node->cap.cap, mm->initial_cap, 0, mm->objtype, (gensize_t) size, 1);
	if (err_is_fail(err)) {
        return err;
    }
	return SYS_ERR_OK;
}
errval_t mm_add ( struct mm * mm , struct capref cap , genpaddr_t base , size_t size ) { errval_t err ; struct mmnode * node = ( struct mmnode * ) slab_alloc ( & mm -> slabs ) ; assert ( node != NULL ) ; node -> cap . base = base ; node -> cap . size = size ; node -> base = base ; node -> size = size ; node -> type = NodeType_Free ; struct mmnode * curr = mm -> head ; if ( curr == NULL ) { mm -> head = node ; } else { while ( curr -> next ) { curr = curr -> next ; } curr -> next = node ; node -> prev = curr ; node -> next = NULL ; } mm -> initial_size = size ; mm -> initial_base = base ; mm -> initial_cap = cap ; err = mm -> slot_alloc ( mm -> slot_alloc_inst , 1 , & ( node -> cap . cap ) ) ; if ( err_is_fail ( err ) ) { return err ; } err = cap_retype ( node -> cap . cap , mm -> initial_cap , 0 , mm -> objtype , ( gensize_t ) size , 1 ) ; if ( err_is_fail ( err ) ) { return err ; } return SYS_ERR_OK ; }
Adds a capability to the memory manager.
Adds a capability to the memory manager .