From 9ff45cb4979725d3f50b3b09f02fb009d250035d Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 5 Feb 2024 23:46:17 +0100 Subject: [PATCH] Implement freeing ressource on uAS destroy --- core/uaddrspace.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/uaddrspace.c b/core/uaddrspace.c index 80f5ead..e6bb34f 100644 --- a/core/uaddrspace.c +++ b/core/uaddrspace.c @@ -127,12 +127,21 @@ int uAddrSpaceDelete(struct uAddrSpace *addr) struct uAddrVirtualReg *reg; list_collapse_named(addr->listVirtualReg, reg, nextInAddrSpace, prevInAddrSpace) { - // TODO Implement me with real ressources - assertmsg(reg->res == NULL, "Unsupported mapper ressource"); - // This is memory allocated for the heap just unmap it to free it - pr_devel("Freeing heap 0x%lx for process %s\n", reg->addr, processGetName(addr->process)); - pageUnmap(reg->addr); - free(reg); + if (reg->res == NULL) { + // This is memory allocated for the heap just unmap it to free it + pr_devel("Freeing heap 0x%lx for process %s\n", reg->addr, + processGetName(addr->process)); + pageUnmap(reg->addr); + free(reg); + } else { + if(reg->res->ops){ + if(reg->res->ops->unmap) + reg->res->ops->unmap(reg, reg->addr, reg->size); + if(reg->res->ops->close) + reg->res->ops->close(reg); + } + free(reg); + } } return mmuContextUnref(addr->ctx); } @@ -387,7 +396,7 @@ int uAddrSpaceSolvePageFault(struct uAddrSpace *as, vaddr_t faultAddr, int isWri return -EFAULT; if (isWriteAccess && !(reg->right & PAGING_MEM_WRITE)) - return -EFAULT; + return -EACCES; if (isWriteAccess) rights |= PAGING_MEM_WRITE;