2021-01-15 13:28:07 +03:00
|
|
|
/*
|
2022-08-23 19:51:18 +03:00
|
|
|
* Copyright (c) 2021-2022, Andreas Kling <kling@serenityos.org>
|
2021-01-15 13:28:07 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-15 13:28:07 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Kernel/FileSystem/File.h>
|
2021-08-06 11:45:34 +03:00
|
|
|
#include <Kernel/Memory/AnonymousVMObject.h>
|
2021-01-15 13:28:07 +03:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class AnonymousFile final : public File {
|
|
|
|
public:
|
2023-03-10 09:53:02 +03:00
|
|
|
static ErrorOr<NonnullRefPtr<AnonymousFile>> try_create(NonnullLockRefPtr<Memory::AnonymousVMObject> vmobject)
|
2021-01-15 13:28:07 +03:00
|
|
|
{
|
2023-03-10 09:53:02 +03:00
|
|
|
return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject)));
|
2021-01-15 13:28:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~AnonymousFile() override;
|
|
|
|
|
2022-08-23 19:51:18 +03:00
|
|
|
virtual ErrorOr<NonnullLockRefPtr<Memory::VMObject>> vmobject_for_mmap(Process&, Memory::VirtualRange const&, u64& offset, bool shared) override;
|
2021-01-15 13:28:07 +03:00
|
|
|
|
|
|
|
private:
|
2021-10-03 01:24:00 +03:00
|
|
|
virtual StringView class_name() const override { return "AnonymousFile"sv; }
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
|
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override { return false; }
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override { return false; }
|
2021-11-08 02:51:39 +03:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return ENOTSUP; }
|
2021-01-15 13:28:07 +03:00
|
|
|
|
2022-08-19 21:53:40 +03:00
|
|
|
explicit AnonymousFile(NonnullLockRefPtr<Memory::AnonymousVMObject>);
|
2021-01-15 13:28:07 +03:00
|
|
|
|
2022-08-19 21:53:40 +03:00
|
|
|
NonnullLockRefPtr<Memory::AnonymousVMObject> m_vmobject;
|
2021-01-15 13:28:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|