2021-01-29 14:03:25 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-29 14:03:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
|
|
|
|
#include <Kernel/PhysicalAddress.h>
|
|
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
|
|
class MemoryDevice final : public CharacterDevice {
|
2021-09-11 09:19:20 +03:00
|
|
|
friend class DeviceManagement;
|
|
|
|
|
|
2021-01-29 14:03:25 +02:00
|
|
|
public:
|
2022-08-19 20:53:40 +02:00
|
|
|
static NonnullLockRefPtr<MemoryDevice> must_create();
|
2021-01-29 14:03:25 +02:00
|
|
|
~MemoryDevice();
|
|
|
|
|
|
2022-08-23 17:58:05 +02:00
|
|
|
virtual ErrorOr<Memory::Region*> mmap(Process&, Memory::AddressSpace&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
2021-01-29 14:03:25 +02:00
|
|
|
|
2021-09-11 09:19:20 +03:00
|
|
|
private:
|
2021-06-18 11:37:26 +03:00
|
|
|
MemoryDevice();
|
2021-09-10 14:44:46 +03:00
|
|
|
|
2021-10-02 15:24:00 -07:00
|
|
|
virtual StringView class_name() const override { return "MemoryDevice"sv; }
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
|
|
|
|
|
virtual bool can_write(OpenFileDescription const&, u64) const override { return false; }
|
2021-06-24 14:04:41 +02:00
|
|
|
virtual bool is_seekable() const override { return true; }
|
2021-11-08 00:51:39 +01:00
|
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
2022-04-01 20:58:27 +03:00
|
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return EINVAL; }
|
2021-01-29 14:03:25 +02:00
|
|
|
|
2021-08-06 13:54:48 +02:00
|
|
|
bool is_allowed_range(PhysicalAddress, Memory::VirtualRange const&) const;
|
2021-01-29 14:03:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|