mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:27:35 +00:00
Kernel: Hoist VM range allocation up to sys$mmap() itself
Instead of letting each File subclass do range allocation in their mmap() override, do it up front in sys$mmap(). This makes us honor alignment requests for file-backed memory mappings and simplifies the code somwhat.
This commit is contained in:
parent
adcc1c1eff
commit
ab14b0ac64
13 changed files with 26 additions and 36 deletions
|
@ -39,15 +39,15 @@ AnonymousFile::~AnonymousFile()
|
|||
{
|
||||
}
|
||||
|
||||
KResultOr<Region*> AnonymousFile::mmap(Process& process, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared)
|
||||
KResultOr<Region*> AnonymousFile::mmap(Process& process, FileDescription&, const Range& range, size_t offset, int prot, bool shared)
|
||||
{
|
||||
if (offset != 0)
|
||||
return EINVAL;
|
||||
|
||||
if (size != m_vmobject->size())
|
||||
if (range.size() != m_vmobject->size())
|
||||
return EINVAL;
|
||||
|
||||
return process.allocate_region_with_vmobject(preferred_vaddr, size, m_vmobject, offset, {}, prot, shared);
|
||||
return process.allocate_region_with_vmobject(range, m_vmobject, offset, {}, prot, shared);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
virtual ~AnonymousFile() override;
|
||||
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared) override;
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, size_t offset, int prot, bool shared) override;
|
||||
|
||||
private:
|
||||
virtual const char* class_name() const override { return "AnonymousFile"; }
|
||||
|
|
|
@ -59,7 +59,7 @@ int File::ioctl(FileDescription&, unsigned, FlatPtr)
|
|||
return -ENOTTY;
|
||||
}
|
||||
|
||||
KResultOr<Region*> File::mmap(Process&, FileDescription&, VirtualAddress, size_t, size_t, int, bool)
|
||||
KResultOr<Region*> File::mmap(Process&, FileDescription&, const Range&, size_t, int, bool)
|
||||
{
|
||||
return ENODEV;
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public:
|
|||
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) = 0;
|
||||
virtual KResultOr<size_t> write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) = 0;
|
||||
virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg);
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared);
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, size_t offset, int prot, bool shared);
|
||||
virtual KResult stat(::stat&) const { return EBADF; }
|
||||
|
||||
virtual String absolute_path(const FileDescription&) const = 0;
|
||||
|
|
|
@ -328,10 +328,10 @@ InodeMetadata FileDescription::metadata() const
|
|||
return {};
|
||||
}
|
||||
|
||||
KResultOr<Region*> FileDescription::mmap(Process& process, VirtualAddress vaddr, size_t offset, size_t size, int prot, bool shared)
|
||||
KResultOr<Region*> FileDescription::mmap(Process& process, const Range& range, size_t offset, int prot, bool shared)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
return m_file->mmap(process, *this, vaddr, offset, size, prot, shared);
|
||||
return m_file->mmap(process, *this, range, offset, prot, shared);
|
||||
}
|
||||
|
||||
KResult FileDescription::truncate(u64 length)
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
Custody* custody() { return m_custody.ptr(); }
|
||||
const Custody* custody() const { return m_custody.ptr(); }
|
||||
|
||||
KResultOr<Region*> mmap(Process&, VirtualAddress, size_t offset, size_t, int prot, bool shared);
|
||||
KResultOr<Region*> mmap(Process&, const Range&, size_t offset, int prot, bool shared);
|
||||
|
||||
bool is_blocking() const { return m_is_blocking; }
|
||||
void set_blocking(bool b) { m_is_blocking = b; }
|
||||
|
|
|
@ -69,7 +69,7 @@ KResultOr<size_t> InodeFile::write(FileDescription& description, size_t offset,
|
|||
return nwritten;
|
||||
}
|
||||
|
||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& description, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared)
|
||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& description, const Range& range, size_t offset, int prot, bool shared)
|
||||
{
|
||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||
RefPtr<InodeVMObject> vmobject;
|
||||
|
@ -79,7 +79,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptio
|
|||
vmobject = PrivateInodeVMObject::create_with_inode(inode());
|
||||
if (!vmobject)
|
||||
return ENOMEM;
|
||||
return process.allocate_region_with_vmobject(preferred_vaddr, size, *vmobject, offset, description.absolute_path(), prot, shared);
|
||||
return process.allocate_region_with_vmobject(range, vmobject.release_nonnull(), offset, description.absolute_path(), prot, shared);
|
||||
}
|
||||
|
||||
String InodeFile::absolute_path(const FileDescription& description) const
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
|
||||
virtual KResultOr<size_t> read(FileDescription&, size_t, UserOrKernelBuffer&, size_t) override;
|
||||
virtual KResultOr<size_t> write(FileDescription&, size_t, const UserOrKernelBuffer&, size_t) override;
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, VirtualAddress preferred_vaddr, size_t offset, size_t size, int prot, bool shared) override;
|
||||
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, size_t offset, int prot, bool shared) override;
|
||||
|
||||
virtual String absolute_path(const FileDescription&) const override;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue