kernel: Replace some raw divisions with get_blocks_from_size()

This commit is contained in:
apio 2023-03-16 23:00:44 +01:00
parent 8c72e9a49a
commit 59838f1225
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -37,7 +37,7 @@ Result<u64> sys_mmap(Registers*, SyscallArgs args)
Thread* current = Scheduler::current(); Thread* current = Scheduler::current();
u64 address; 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 else
{ {
kwarnln("mmap: FIXME: tried to mmap at a given address, instead of letting us choose"); 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); 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) Result<u64> sys_munmap(Registers*, SyscallArgs args)
@ -64,14 +64,14 @@ Result<u64> sys_munmap(Registers*, SyscallArgs args)
Thread* current = Scheduler::current(); 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. // POSIX says munmap should silently do nothing if the memory was not already mapped.
if (!ok) return 0; if (!ok) return 0;
kdbgln("munmap: unmapping memory at %#lx, size=%zu", address, size); 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 }; return { 0 };
} }