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))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-16 16:15:15 -03:00
|
|
|
AnonymousFile::~AnonymousFile() = default;
|
2021-01-15 07:28:07 -03:00
|
|
|
|
2021-11-07 20:51:39 -03:00
|
|
|
ErrorOr<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-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
|
|
|
}
|
|
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
ErrorOr<NonnullOwnPtr<KString>> AnonymousFile::pseudo_path(OpenFileDescription const&) const
|
2021-10-29 19:45:23 -03:00
|
|
|
{
|
|
|
|
|
return KString::try_create(":anonymous-file:"sv);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 07:28:07 -03:00
|
|
|
}
|