2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-08 11:33:14 +00:00
|
|
|
#include <AK/Memory.h>
|
2021-09-11 06:19:20 +00:00
|
|
|
#include <Kernel/Devices/DeviceManagement.h>
|
2021-06-22 15:40:16 +00:00
|
|
|
#include <Kernel/Devices/ZeroDevice.h>
|
|
|
|
#include <Kernel/Sections.h>
|
2018-10-14 00:59:22 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2022-08-19 18:53:40 +00:00
|
|
|
UNMAP_AFTER_INIT NonnullLockRefPtr<ZeroDevice> ZeroDevice::must_create()
|
2021-06-18 08:37:26 +00:00
|
|
|
{
|
2021-09-11 06:19:20 +00:00
|
|
|
auto zero_device_or_error = DeviceManagement::try_create_device<ZeroDevice>();
|
2021-09-10 11:44:46 +00:00
|
|
|
// FIXME: Find a way to propagate errors
|
|
|
|
VERIFY(!zero_device_or_error.is_error());
|
|
|
|
return zero_device_or_error.release_value();
|
2021-06-18 08:37:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-19 17:41:50 +00:00
|
|
|
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()
|
2018-10-30 12:59:29 +00:00
|
|
|
: CharacterDevice(1, 5)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-16 19:15:15 +00:00
|
|
|
UNMAP_AFTER_INIT ZeroDevice::~ZeroDevice() = default;
|
2018-10-14 00:59:22 +00:00
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
bool ZeroDevice::can_read(OpenFileDescription const&, u64) const
|
2018-10-25 11:07:59 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-07 23:51:39 +00:00
|
|
|
ErrorOr<size_t> ZeroDevice::read(OpenFileDescription&, u64, UserOrKernelBuffer& buffer, size_t size)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
2021-09-07 10:09:52 +00:00
|
|
|
TRY(buffer.memset(0, size));
|
2021-05-27 07:13:49 +00:00
|
|
|
return size;
|
2018-10-14 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
ErrorOr<size_t> ZeroDevice::write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t size)
|
2018-10-14 00:59:22 +00:00
|
|
|
{
|
2021-05-27 07:13:49 +00:00
|
|
|
return size;
|
2018-10-14 00:59:22 +00:00
|
|
|
}
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|