kernel: Free the initial ramdisk memory after copying everything into the VFS
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-16 23:02:53 +01:00
parent 59838f1225
commit b9e8030aac
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 18 additions and 0 deletions

View File

@ -3,7 +3,9 @@
#include "arch/MMU.h" #include "arch/MMU.h"
#include "boot/bootboot.h" #include "boot/bootboot.h"
#include "fs/VFS.h" #include "fs/VFS.h"
#include "memory/MemoryManager.h"
#include <bits/modes.h> #include <bits/modes.h>
#include <luna/Alignment.h>
TarStream g_initrd; TarStream g_initrd;
extern const BOOTBOOT bootboot; extern const BOOTBOOT bootboot;
@ -43,5 +45,9 @@ Result<void> InitRD::populate_vfs()
TRY(vfs_create_dir_if_not_exists(entry.name, entry.mode)); TRY(vfs_create_dir_if_not_exists(entry.name, entry.mode));
} }
} }
// Now we don't need the original initrd anymore
MemoryManager::free_frames(bootboot.initrd_ptr, get_blocks_from_size(bootboot.initrd_size, ARCH_PAGE_SIZE));
return {}; return {};
} }

View File

@ -170,6 +170,17 @@ namespace MemoryManager
return {}; return {};
} }
Result<void> free_frames(u64 address, usize count)
{
while (count--)
{
TRY(free_frame(address));
address += ARCH_PAGE_SIZE;
}
return {};
}
Result<void> remap(u64 address, usize count, int flags) Result<void> remap(u64 address, usize count, int flags)
{ {
CHECK_PAGE_ALIGNED(address); CHECK_PAGE_ALIGNED(address);

View File

@ -11,6 +11,7 @@ namespace MemoryManager
Result<u64> alloc_frame(); Result<u64> alloc_frame();
Result<void> free_frame(u64 frame); Result<void> free_frame(u64 frame);
Result<void> free_frames(u64 address, usize count);
void lock_frame(u64 frame); void lock_frame(u64 frame);
void lock_frames(u64 frames, usize count); void lock_frames(u64 frames, usize count);