mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +00:00
Kernel: Simplify the File memory-mapping API
Before this change, we had File::mmap() which did all the work of setting up a VMObject, and then creating a Region in the current process's address space. This patch simplifies the interface by removing the region part. Files now only have to return a suitable VMObject from vmobject_for_mmap(), and then sys$mmap() itself will take care of actually mapping it into the address space. This fixes an issue where we'd try to block on I/O (for inode metadata lookup) while holding the address space spinlock. It also reduces time spent holding the address space lock.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
@@ -85,16 +85,11 @@ ErrorOr<void> InodeFile::ioctl(OpenFileDescription& description, unsigned reques
|
||||
}
|
||||
}
|
||||
|
||||
ErrorOr<Memory::Region*> InodeFile::mmap(Process&, Memory::AddressSpace& address_space, OpenFileDescription& description, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||
ErrorOr<NonnullLockRefPtr<Memory::VMObject>> InodeFile::vmobject_for_mmap(Process&, Memory::VirtualRange const&, u64&, bool shared)
|
||||
{
|
||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||
LockRefPtr<Memory::InodeVMObject> vmobject;
|
||||
if (shared)
|
||||
vmobject = TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode()));
|
||||
else
|
||||
vmobject = TRY(Memory::PrivateInodeVMObject::try_create_with_inode(inode()));
|
||||
auto path = TRY(description.pseudo_path());
|
||||
return address_space.allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, path->view(), prot, shared);
|
||||
return TRY(Memory::SharedInodeVMObject::try_create_with_inode(inode()));
|
||||
return TRY(Memory::PrivateInodeVMObject::try_create_with_inode(inode()));
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<KString>> InodeFile::pseudo_path(OpenFileDescription const&) const
|
||||
|
||||
Reference in New Issue
Block a user