Free the initrd after extraction.
This commit is contained in:
parent
54da838c79
commit
dc4924585e
|
@ -344,5 +344,25 @@ bool ExtractFromPhysicalInto(addr_t physaddr, size_t size, Ref<Descriptor> desc)
|
||||||
return ExtractInto(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 InitRD
|
||||||
} // namespace Sortix
|
} // namespace Sortix
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace InitRD {
|
||||||
|
|
||||||
bool ExtractInto(Ref<Descriptor> desc);
|
bool ExtractInto(Ref<Descriptor> desc);
|
||||||
bool ExtractFromPhysicalInto(addr_t physaddr, size_t size, Ref<Descriptor> desc);
|
bool ExtractFromPhysicalInto(addr_t physaddr, size_t size, Ref<Descriptor> desc);
|
||||||
|
void Delete();
|
||||||
|
|
||||||
} // namespace InitRD
|
} // namespace InitRD
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,9 @@ static void BootThread(void* /*user*/)
|
||||||
// Install the initrd into our fresh RAM filesystem.
|
// Install the initrd into our fresh RAM filesystem.
|
||||||
if ( !InitRD::ExtractFromPhysicalInto(initrd, initrdsize, droot) )
|
if ( !InitRD::ExtractFromPhysicalInto(initrd, initrdsize, droot) )
|
||||||
Panic("Unable to extract initrd into RAM root filesystem.");
|
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.
|
// Get a descriptor for the /dev directory so we can populate it.
|
||||||
if ( droot->mkdir(&ctx, "dev", 0775) != 0 && errno != EEXIST )
|
if ( droot->mkdir(&ctx, "dev", 0775) != 0 && errno != EEXIST )
|
||||||
|
|
Loading…
Reference in New Issue