2021-01-15 07:28:07 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-15 07:28:07 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Kernel/FileSystem/AnonymousFile.h>
|
2021-08-06 05:45:34 -03:00
|
|
|
#include <Kernel/Memory/AnonymousVMObject.h>
|
2021-01-15 07:28:07 -03:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-08-06 08:49:36 -03:00
|
|
|
AnonymousFile::AnonymousFile(NonnullRefPtr<Memory::AnonymousVMObject> vmobject)
|
2021-01-15 07:28:07 -03:00
|
|
|
: m_vmobject(move(vmobject))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AnonymousFile::~AnonymousFile()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 08:39:11 -03:00
|
|
|
KResultOr<Memory::Region*> AnonymousFile::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
2021-01-15 07:28:07 -03:00
|
|
|
{
|
|
|
|
|
if (offset != 0)
|
2021-01-20 19:11:17 -03:00
|
|
|
return EINVAL;
|
2021-01-15 07:28:07 -03:00
|
|
|
|
2021-01-25 10:52:36 -03:00
|
|
|
if (range.size() != m_vmobject->size())
|
2021-01-20 19:11:17 -03:00
|
|
|
return EINVAL;
|
2021-01-15 07:28:07 -03:00
|
|
|
|
2021-08-06 08:59:22 -03:00
|
|
|
return process.address_space().allocate_region_with_vmobject(range, m_vmobject, offset, {}, prot, shared);
|
2021-01-15 07:28:07 -03:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 19:45:23 -03:00
|
|
|
KResultOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(const OpenFileDescription&) const
|
|
|
|
|
{
|
|
|
|
|
return KString::try_create(":anonymous-file:"sv);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 07:28:07 -03:00
|
|
|
}
|