lib/mm/mm.c
errval_t mm_free(struct mm *mm, struct capref cap, genpaddr_t base, gensize_t size)
{
	errval_t err;
	struct mmnode *curr = mm->head;
	while (curr) {
		if (curr->base == base && curr->size == size) {
			curr->type = NodeType_Free;
							
			err = cap_destroy(curr->cap.cap);
			if (err_is_fail(err)) {
		        return err;
		    }
						
			if (curr->next && curr->next->type == NodeType_Free) {
				curr->size += curr->next->size;
				struct mmnode *del_node = curr->next;
				curr->next = curr->next->next;
				if (curr->next) {
					curr->next->prev = curr;
				}
				slab_free(&mm->slabs, del_node);
			}
			if (curr->prev && curr->prev->type == NodeType_Free) {
				curr->prev->size += curr->size;
				struct mmnode *del_node = curr;
				curr->prev->next = curr->next;
				if (curr->next) {
					curr->next->prev = curr->prev;
				}
				slab_free(&mm->slabs, del_node);
			}
			break;
		}
		curr = curr->next;
	}
	return SYS_ERR_OK;

}
/**
 * Free a certain region (for later re-use).
 *
 * \param       mm        The memory manager.
 * \param       cap       The capability to free.
 * \param       base      The physical base address of the region.
 * \param       size      The size of the region.
 */
Free a certain region (for later re-use).
\param       mm        The memory manager.
\param       cap       The capability to free.
\param       base      The physical base address of the region.
\param       size      The size of the region.
Free a certain region ( for later re - use ) . \ param mm The memory manager . \ param cap The capability to free . \ param base The physical base address of the region . \ param size The size of the region .
errval_t mm_free(struct mm *mm, struct capref cap, genpaddr_t base, gensize_t size)
{
	errval_t err;
	struct mmnode *curr = mm->head;
	while (curr) {
		if (curr->base == base && curr->size == size) {
			curr->type = NodeType_Free;
			err = cap_destroy(curr->cap.cap);
			if (err_is_fail(err)) {
		        return err;
		    }
			if (curr->next && curr->next->type == NodeType_Free) {
				curr->size += curr->next->size;
				struct mmnode *del_node = curr->next;
				curr->next = curr->next->next;
				if (curr->next) {
					curr->next->prev = curr;
				}
				slab_free(&mm->slabs, del_node);
			}
			if (curr->prev && curr->prev->type == NodeType_Free) {
				curr->prev->size += curr->size;
				struct mmnode *del_node = curr;
				curr->prev->next = curr->next;
				if (curr->next) {
					curr->next->prev = curr->prev;
				}
				slab_free(&mm->slabs, del_node);
			}
			break;
		}
		curr = curr->next;
	}
	return SYS_ERR_OK;
}
errval_t mm_free ( struct mm * mm , struct capref cap , genpaddr_t base , gensize_t size ) { errval_t err ; struct mmnode * curr = mm -> head ; while ( curr ) { if ( curr -> base == base && curr -> size == size ) { curr -> type = NodeType_Free ; err = cap_destroy ( curr -> cap . cap ) ; if ( err_is_fail ( err ) ) { return err ; } if ( curr -> next && curr -> next -> type == NodeType_Free ) { curr -> size += curr -> next -> size ; struct mmnode * del_node = curr -> next ; curr -> next = curr -> next -> next ; if ( curr -> next ) { curr -> next -> prev = curr ; } slab_free ( & mm -> slabs , del_node ) ; } if ( curr -> prev && curr -> prev -> type == NodeType_Free ) { curr -> prev -> size += curr -> size ; struct mmnode * del_node = curr ; curr -> prev -> next = curr -> next ; if ( curr -> next ) { curr -> next -> prev = curr -> prev ; } slab_free ( & mm -> slabs , del_node ) ; } break ; } curr = curr -> next ; } return SYS_ERR_OK ; }
Free a certain region (for later re-use).
Free a certain region ( for later re - use ) .