From: Ben Gras Date: Thu, 10 Feb 2011 15:39:56 +0000 (+0000) Subject: memory driver: munmap() imgrd after first close. X-Git-Tag: v3.2.0~678 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/named.html?a=commitdiff_plain;h=3beb81a5d0b12a2c1cd61d061f76e8a9827ef6fa;p=minix.git memory driver: munmap() imgrd after first close. (that munmap() range not supported yet by vm.) --- diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index a3e60e469..4ad14e8e3 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "kernel/const.h" #include "kernel/config.h" @@ -393,6 +394,28 @@ message *m_ptr; } openct[m_device]--; + /* Special case: free initial ramdisk after it's been unmounted once. */ + if(m_device == IMGRD_DEV && openct[m_device] == 0 && m_vaddrs[IMGRD_DEV]) { + vir_bytes vaddr, vlen; + vaddr = m_vaddrs[IMGRD_DEV]; + vlen = imgrd_size; + /* Align `inwards' so as to not unmap more than the initial + * ramdisk image. + */ + if(vaddr % PAGE_SIZE) { + vir_bytes o = PAGE_SIZE - (vaddr % PAGE_SIZE); + vlen -= o; + vaddr += o; + } + if(vlen % PAGE_SIZE) { + vlen -= vlen % PAGE_SIZE; + } + munmap((void *) vaddr, vlen); + m_geom[IMGRD_DEV].dv_base= cvul64(0); + m_geom[IMGRD_DEV].dv_size= cvul64(0); + m_vaddrs[IMGRD_DEV] = 0; + } + return(OK); }