summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-11-29 21:19:58 +0200
committerIdan Horowitz <idan.horowitz@gmail.com>2021-12-01 21:44:11 +0200
commit4ca39c71104084be36b672fbe10952ba88326fba (patch)
tree4b3360e11db62a05da3216d336423c4b70a6e272 /Kernel/Syscalls
parentff6b43734c9750b1319e62f60bae170df5313771 (diff)
downloadserenity-4ca39c71104084be36b672fbe10952ba88326fba.zip
Kernel: Move the expand_range_to_page_boundaries helper to MemoryManager
This helper can (and will) be used in more parts of the kernel besides the mmap-family of syscalls.
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/mmap.cpp25
1 files changed, 4 insertions, 21 deletions
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp
index 9660c8b1c2..4d2856fab8 100644
--- a/Kernel/Syscalls/mmap.cpp
+++ b/Kernel/Syscalls/mmap.cpp
@@ -250,23 +250,6 @@ ErrorOr<FlatPtr> Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> use
return region->vaddr().get();
}
-static ErrorOr<Memory::VirtualRange> expand_range_to_page_boundaries(FlatPtr address, size_t size)
-{
- if (Memory::page_round_up_would_wrap(size))
- return EINVAL;
-
- if ((address + size) < address)
- return EINVAL;
-
- if (Memory::page_round_up_would_wrap(address + size))
- return EINVAL;
-
- auto base = VirtualAddress { address }.page_base();
- auto end = Memory::page_round_up(address + size);
-
- return Memory::VirtualRange { base, end - base.get() };
-}
-
ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int prot)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
@@ -276,7 +259,7 @@ ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int p
REQUIRE_PROMISE(prot_exec);
}
- auto range_to_mprotect = TRY(expand_range_to_page_boundaries(addr.ptr(), size));
+ auto range_to_mprotect = TRY(Memory::expand_range_to_page_boundaries(addr.ptr(), size));
if (!range_to_mprotect.size())
return EINVAL;
@@ -411,7 +394,7 @@ ErrorOr<FlatPtr> Process::sys$madvise(Userspace<void*> address, size_t size, int
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(stdio);
- auto range_to_madvise = TRY(expand_range_to_page_boundaries(address.ptr(), size));
+ auto range_to_madvise = TRY(Memory::expand_range_to_page_boundaries(address.ptr(), size));
if (!range_to_madvise.size())
return EINVAL;
@@ -447,7 +430,7 @@ ErrorOr<FlatPtr> Process::sys$set_mmap_name(Userspace<const Syscall::SC_set_mmap
return ENAMETOOLONG;
auto name = TRY(try_copy_kstring_from_user(params.name));
- auto range = TRY(expand_range_to_page_boundaries((FlatPtr)params.addr, params.size));
+ auto range = TRY(Memory::expand_range_to_page_boundaries((FlatPtr)params.addr, params.size));
auto* region = address_space().find_region_from_range(range);
if (!region)
@@ -475,7 +458,7 @@ ErrorOr<FlatPtr> Process::sys$mremap(Userspace<const Syscall::SC_mremap_params*>
REQUIRE_PROMISE(stdio);
auto params = TRY(copy_typed_from_user(user_params));
- auto old_range = TRY(expand_range_to_page_boundaries((FlatPtr)params.old_address, params.old_size));
+ auto old_range = TRY(Memory::expand_range_to_page_boundaries((FlatPtr)params.old_address, params.old_size));
auto* old_region = address_space().find_region_from_range(old_range);
if (!old_region)