mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-08 20:32:56 +03:00
b0a2572577
AnonymousFile always allocates in multiples of a page size when created with anon_create. This is especially an issue if we use AnonymousFile shared memory to store a shared data structure that isn't exactly a multiple of a page in size. Therefore, we can just allow mmaps of AnonymousFile to map only an initial part of the shared memory. This makes SharedSingleProducerCircularQueue work when it's introduced later.
34 lines
883 B
C++
34 lines
883 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/FileSystem/AnonymousFile.h>
|
|
#include <Kernel/Memory/AnonymousVMObject.h>
|
|
#include <Kernel/Process.h>
|
|
|
|
namespace Kernel {
|
|
|
|
AnonymousFile::AnonymousFile(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
|
|
: m_vmobject(move(vmobject))
|
|
{
|
|
}
|
|
|
|
AnonymousFile::~AnonymousFile() = default;
|
|
|
|
ErrorOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
|
{
|
|
if (offset != 0)
|
|
return EINVAL;
|
|
|
|
return process.address_space().allocate_region_with_vmobject(range, m_vmobject, offset, {}, prot, shared);
|
|
}
|
|
|
|
ErrorOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(OpenFileDescription const&) const
|
|
{
|
|
return KString::try_create(":anonymous-file:"sv);
|
|
}
|
|
|
|
}
|