Compare commits

..

2 Commits

Author SHA1 Message Date
b9e8030aac
kernel: Free the initial ramdisk memory after copying everything into the VFS
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-16 23:02:53 +01:00
59838f1225
kernel: Replace some raw divisions with get_blocks_from_size() 2023-03-16 23:01:35 +01:00
4 changed files with 22 additions and 4 deletions

View File

@ -3,7 +3,9 @@
#include "arch/MMU.h"
#include "boot/bootboot.h"
#include "fs/VFS.h"
#include "memory/MemoryManager.h"
#include <bits/modes.h>
#include <luna/Alignment.h>
TarStream g_initrd;
extern const BOOTBOOT bootboot;
@ -43,5 +45,9 @@ Result<void> InitRD::populate_vfs()
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 {};
}

View File

@ -170,6 +170,17 @@ namespace MemoryManager
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)
{
CHECK_PAGE_ALIGNED(address);

View File

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

View File

@ -37,7 +37,7 @@ Result<u64> sys_mmap(Registers*, SyscallArgs args)
Thread* current = Scheduler::current();
u64 address;
if (!addr) address = TRY(current->vm_allocator->alloc_several_pages(len / ARCH_PAGE_SIZE));
if (!addr) address = TRY(current->vm_allocator->alloc_several_pages(get_blocks_from_size(len, ARCH_PAGE_SIZE)));
else
{
kwarnln("mmap: FIXME: tried to mmap at a given address, instead of letting us choose");
@ -51,7 +51,7 @@ Result<u64> sys_mmap(Registers*, SyscallArgs args)
kdbgln("mmap: mapping memory at %#lx, size=%zu", address, len);
return MemoryManager::alloc_at(address, len / ARCH_PAGE_SIZE, mmu_flags);
return MemoryManager::alloc_at(address, get_blocks_from_size(len, ARCH_PAGE_SIZE), mmu_flags);
}
Result<u64> sys_munmap(Registers*, SyscallArgs args)
@ -64,14 +64,14 @@ Result<u64> sys_munmap(Registers*, SyscallArgs args)
Thread* current = Scheduler::current();
bool ok = TRY(current->vm_allocator->free_several_pages(address, size / ARCH_PAGE_SIZE));
bool ok = TRY(current->vm_allocator->free_several_pages(address, get_blocks_from_size(size, ARCH_PAGE_SIZE)));
// POSIX says munmap should silently do nothing if the memory was not already mapped.
if (!ok) return 0;
kdbgln("munmap: unmapping memory at %#lx, size=%zu", address, size);
TRY(MemoryManager::unmap_owned(address, size / ARCH_PAGE_SIZE));
TRY(MemoryManager::unmap_owned(address, get_blocks_from_size(size, ARCH_PAGE_SIZE)));
return { 0 };
}