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