From 59838f12252eca85da533f557e2697e9928fb200 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 16 Mar 2023 23:00:44 +0100 Subject: [PATCH] kernel: Replace some raw divisions with get_blocks_from_size() --- kernel/src/sys/mmap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/src/sys/mmap.cpp b/kernel/src/sys/mmap.cpp index 7a111ecf..7eb9b6a7 100644 --- a/kernel/src/sys/mmap.cpp +++ b/kernel/src/sys/mmap.cpp @@ -37,7 +37,7 @@ Result 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 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 sys_munmap(Registers*, SyscallArgs args) @@ -64,14 +64,14 @@ Result 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 }; }