ladybird/Kernel/Devices/ZeroDevice.h
Liav A 29f9a38f76 Kernel: Don't use naked new statements in init process
Instead, try to create the device objects in separate static methods,
and if we fail for some odd reason to allocate memory for such devices,
just panic with that reason.
2021-06-19 09:30:43 +02:00

33 lines
998 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "CharacterDevice.h"
namespace Kernel {
class ZeroDevice final : public CharacterDevice {
AK_MAKE_ETERNAL
public:
static NonnullRefPtr<ZeroDevice> must_create();
virtual ~ZeroDevice() override;
// ^Device
virtual mode_t required_mode() const override { return 0666; }
virtual String device_name() const override { return "zero"; }
private:
ZeroDevice();
// ^CharacterDevice
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
virtual bool can_read(const FileDescription&, size_t) const override;
virtual bool can_write(const FileDescription&, size_t) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; }
};
}