1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Free the initrd after extraction.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-03-12 17:40:33 +01:00
parent 54da838c79
commit dc4924585e
3 changed files with 24 additions and 1 deletions

View file

@ -344,5 +344,25 @@ bool ExtractFromPhysicalInto(addr_t physaddr, size_t size, Ref<Descriptor> desc)
return ExtractInto(desc);
}
void Delete()
{
size_t size = initrdsize;
initrd = NULL;
initrdsize = 0;
// Unmap the pages and return the physical frames for reallocation.
addr_t mapat = initrd_addr_alloc.from;
for ( size_t i = 0; i < size; i += Page::Size() )
{
addr_t addr = Memory::Unmap(mapat + i);
Page::Put(addr);
}
Memory::Flush();
// Free the used virtual address space.
FreeKernelAddress(&initrd_addr_alloc);
}
} // namespace InitRD
} // namespace Sortix

View file

@ -35,6 +35,7 @@ namespace InitRD {
bool ExtractInto(Ref<Descriptor> desc);
bool ExtractFromPhysicalInto(addr_t physaddr, size_t size, Ref<Descriptor> desc);
void Delete();
} // namespace InitRD

View file

@ -361,7 +361,9 @@ static void BootThread(void* /*user*/)
// Install the initrd into our fresh RAM filesystem.
if ( !InitRD::ExtractFromPhysicalInto(initrd, initrdsize, droot) )
Panic("Unable to extract initrd into RAM root filesystem.");
// TODO: It's safe to free the original initrd now.
// We no longer need the initrd, so free its resources.
InitRD::Delete();
// Get a descriptor for the /dev directory so we can populate it.
if ( droot->mkdir(&ctx, "dev", 0775) != 0 && errno != EEXIST )