diff options
author | Gunnar Beutner <gunnar@beutner.name> | 2021-04-13 19:27:49 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-14 13:12:52 +0200 |
commit | 2d91761cf6fb79cdc587c90270455396a8170d37 (patch) | |
tree | 03c28108a5d9409416bc34f4c52a9b12372d6706 /Kernel | |
parent | 341b44b6f7dc0f4a0eb2166029d36315f17a4f85 (diff) | |
download | serenity-2d91761cf6fb79cdc587c90270455396a8170d37.zip |
Kernel: Make sure the offset stays the same when using mremap()
When using mmap() on a file with a non-zero offset subsequent
calls to mremap() would incorrectly reset the offset to zero.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Syscalls/mmap.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index db401a59c5..3e8ede3c8a 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -566,6 +566,7 @@ KResultOr<FlatPtr> Process::sys$mremap(Userspace<const Syscall::SC_mremap_params auto range = old_region->range(); auto old_name = old_region->name(); auto old_prot = region_access_flags_to_prot(old_region->access()); + auto old_offset = old_region->offset_in_vmobject(); NonnullRefPtr inode = static_cast<SharedInodeVMObject&>(old_region->vmobject()).inode(); // Unmap without deallocating the VM range since we're going to reuse it. @@ -575,7 +576,7 @@ KResultOr<FlatPtr> Process::sys$mremap(Userspace<const Syscall::SC_mremap_params auto new_vmobject = PrivateInodeVMObject::create_with_inode(inode); - auto new_region_or_error = space().allocate_region_with_vmobject(range, new_vmobject, 0, old_name, old_prot, false); + auto new_region_or_error = space().allocate_region_with_vmobject(range, new_vmobject, old_offset, old_name, old_prot, false); if (new_region_or_error.is_error()) return new_region_or_error.error().error(); auto& new_region = *new_region_or_error.value(); |