mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 16:55:09 +00:00
Kernel/Devices: Defer creation of SysFS component after the constructor
Instead of doing so in the constructor, let's do immediately after the constructor, so we can safely pass a reference of a Device, so the SysFSDeviceComponent constructor can use that object to identify whether it's a block device or a character device. This allows to us to not hold a device in SysFSDeviceComponent with a RefPtr. Also, we also call the before_removing method in both SlavePTY::unref and File::unref, so because Device has that method being overrided, it can ensure the device is removed always cleanly.
This commit is contained in:
parent
c545d4ffcb
commit
f5de4f24b2
41 changed files with 142 additions and 57 deletions
|
@ -20,6 +20,7 @@ static Kernel::Spinlock g_console_lock;
|
||||||
UNMAP_AFTER_INIT void ConsoleDevice::initialize()
|
UNMAP_AFTER_INIT void ConsoleDevice::initialize()
|
||||||
{
|
{
|
||||||
s_the.ensure_instance();
|
s_the.ensure_instance();
|
||||||
|
s_the->after_inserting();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsoleDevice& ConsoleDevice::the()
|
ConsoleDevice& ConsoleDevice::the()
|
||||||
|
|
|
@ -26,8 +26,9 @@ NonnullRefPtr<SysFSDeviceComponent> SysFSDeviceComponent::must_create(Device con
|
||||||
}
|
}
|
||||||
SysFSDeviceComponent::SysFSDeviceComponent(Device const& device)
|
SysFSDeviceComponent::SysFSDeviceComponent(Device const& device)
|
||||||
: SysFSComponent(String::formatted("{}:{}", device.major(), device.minor()))
|
: SysFSComponent(String::formatted("{}:{}", device.major(), device.minor()))
|
||||||
, m_associated_device(device)
|
, m_block_device(device.is_block_device())
|
||||||
{
|
{
|
||||||
|
VERIFY(device.is_block_device() || device.is_character_device());
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<SysFSDevicesDirectory> SysFSDevicesDirectory::must_create(SysFSRootDirectory const& root_directory)
|
UNMAP_AFTER_INIT NonnullRefPtr<SysFSDevicesDirectory> SysFSDevicesDirectory::must_create(SysFSRootDirectory const& root_directory)
|
||||||
|
@ -58,7 +59,7 @@ KResult SysFSBlockDevicesDirectory::traverse_as_directory(unsigned fsid, Functio
|
||||||
|
|
||||||
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
||||||
for (auto& exposed_device : list) {
|
for (auto& exposed_device : list) {
|
||||||
if (!exposed_device.device().is_block_device())
|
if (!exposed_device.is_block_device())
|
||||||
continue;
|
continue;
|
||||||
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
|
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
|
||||||
}
|
}
|
||||||
|
@ -69,7 +70,7 @@ RefPtr<SysFSComponent> SysFSBlockDevicesDirectory::lookup(StringView name)
|
||||||
{
|
{
|
||||||
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
|
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
|
||||||
for (auto& exposed_device : list) {
|
for (auto& exposed_device : list) {
|
||||||
if (!exposed_device.device().is_block_device())
|
if (!exposed_device.is_block_device())
|
||||||
continue;
|
continue;
|
||||||
if (exposed_device.name() == name)
|
if (exposed_device.name() == name)
|
||||||
return exposed_device;
|
return exposed_device;
|
||||||
|
@ -94,7 +95,7 @@ KResult SysFSCharacterDevicesDirectory::traverse_as_directory(unsigned fsid, Fun
|
||||||
|
|
||||||
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
||||||
for (auto& exposed_device : list) {
|
for (auto& exposed_device : list) {
|
||||||
if (!exposed_device.device().is_character_device())
|
if (exposed_device.is_block_device())
|
||||||
continue;
|
continue;
|
||||||
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
|
callback({ exposed_device.name(), { fsid, exposed_device.component_index() }, 0 });
|
||||||
}
|
}
|
||||||
|
@ -105,7 +106,7 @@ RefPtr<SysFSComponent> SysFSCharacterDevicesDirectory::lookup(StringView name)
|
||||||
{
|
{
|
||||||
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
|
return SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> RefPtr<SysFSComponent> {
|
||||||
for (auto& exposed_device : list) {
|
for (auto& exposed_device : list) {
|
||||||
if (!exposed_device.device().is_character_device())
|
if (exposed_device.is_block_device())
|
||||||
continue;
|
continue;
|
||||||
if (exposed_device.name() == name)
|
if (exposed_device.name() == name)
|
||||||
return exposed_device;
|
return exposed_device;
|
||||||
|
@ -145,6 +146,11 @@ Device::Device(unsigned major, unsigned minor)
|
||||||
VERIFY(!map.contains(device_id));
|
VERIFY(!map.contains(device_id));
|
||||||
map.set(device_id, this);
|
map.set(device_id, this);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Device::after_inserting()
|
||||||
|
{
|
||||||
|
VERIFY(!m_sysfs_component);
|
||||||
auto sys_fs_component = SysFSDeviceComponent::must_create(*this);
|
auto sys_fs_component = SysFSDeviceComponent::must_create(*this);
|
||||||
m_sysfs_component = sys_fs_component;
|
m_sysfs_component = sys_fs_component;
|
||||||
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
||||||
|
@ -154,12 +160,11 @@ Device::Device(unsigned major, unsigned minor)
|
||||||
|
|
||||||
void Device::before_removing()
|
void Device::before_removing()
|
||||||
{
|
{
|
||||||
auto sys_fs_component = m_sysfs_component.strong_ref();
|
|
||||||
VERIFY(sys_fs_component);
|
|
||||||
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
|
||||||
list.remove(*sys_fs_component);
|
|
||||||
});
|
|
||||||
m_state = State::BeingRemoved;
|
m_state = State::BeingRemoved;
|
||||||
|
VERIFY(m_sysfs_component);
|
||||||
|
SysFSComponentRegistry::the().devices_list().with_exclusive([&](auto& list) -> void {
|
||||||
|
list.remove(*m_sysfs_component);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Device::~Device()
|
Device::~Device()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <AK/Function.h>
|
#include <AK/Function.h>
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
#include <AK/RefPtr.h>
|
#include <AK/RefPtr.h>
|
||||||
|
#include <Kernel/API/KResult.h>
|
||||||
#include <Kernel/Devices/AsyncDeviceRequest.h>
|
#include <Kernel/Devices/AsyncDeviceRequest.h>
|
||||||
#include <Kernel/FileSystem/File.h>
|
#include <Kernel/FileSystem/File.h>
|
||||||
#include <Kernel/FileSystem/SysFS.h>
|
#include <Kernel/FileSystem/SysFS.h>
|
||||||
|
@ -26,6 +27,14 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
|
template<typename DeviceType, typename... Args>
|
||||||
|
inline KResultOr<NonnullRefPtr<DeviceType>> try_create_device(Args&&... args)
|
||||||
|
{
|
||||||
|
auto device = TRY(adopt_nonnull_ref_or_enomem(new DeviceType(forward<Args>(args)...)));
|
||||||
|
device->after_inserting();
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
class Device : public File {
|
class Device : public File {
|
||||||
protected:
|
protected:
|
||||||
enum class State {
|
enum class State {
|
||||||
|
@ -46,7 +55,8 @@ public:
|
||||||
GroupID gid() const { return m_gid; }
|
GroupID gid() const { return m_gid; }
|
||||||
|
|
||||||
virtual bool is_device() const override { return true; }
|
virtual bool is_device() const override { return true; }
|
||||||
virtual void before_removing();
|
virtual void before_removing() override;
|
||||||
|
virtual void after_inserting();
|
||||||
|
|
||||||
static void for_each(Function<void(Device&)>);
|
static void for_each(Function<void(Device&)>);
|
||||||
static Device* get_device(unsigned major, unsigned minor);
|
static Device* get_device(unsigned major, unsigned minor);
|
||||||
|
@ -82,7 +92,7 @@ private:
|
||||||
|
|
||||||
Spinlock m_requests_lock;
|
Spinlock m_requests_lock;
|
||||||
DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests;
|
DoublyLinkedList<RefPtr<AsyncDeviceRequest>> m_requests;
|
||||||
WeakPtr<SysFSDeviceComponent> m_sysfs_component;
|
RefPtr<SysFSDeviceComponent> m_sysfs_component;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,10 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<FullDevice> FullDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new FullDevice);
|
auto full_device_or_error = try_create_device<FullDevice>();
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!full_device_or_error.is_error());
|
||||||
|
return full_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT FullDevice::FullDevice()
|
UNMAP_AFTER_INIT FullDevice::FullDevice()
|
||||||
|
|
|
@ -16,9 +16,10 @@ public:
|
||||||
static NonnullRefPtr<FullDevice> must_create();
|
static NonnullRefPtr<FullDevice> must_create();
|
||||||
virtual ~FullDevice() override;
|
virtual ~FullDevice() override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
FullDevice();
|
FullDevice();
|
||||||
|
|
||||||
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||||
|
|
|
@ -112,6 +112,7 @@ UNMAP_AFTER_INIT void HIDManagement::enumerate()
|
||||||
m_i8042_controller->detect_devices();
|
m_i8042_controller->detect_devices();
|
||||||
if (m_i8042_controller->mouse())
|
if (m_i8042_controller->mouse())
|
||||||
m_hid_devices.append(m_i8042_controller->mouse().release_nonnull());
|
m_hid_devices.append(m_i8042_controller->mouse().release_nonnull());
|
||||||
|
|
||||||
if (m_i8042_controller->keyboard())
|
if (m_i8042_controller->keyboard())
|
||||||
m_hid_devices.append(m_i8042_controller->keyboard().release_nonnull());
|
m_hid_devices.append(m_i8042_controller->keyboard().release_nonnull());
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,9 +83,11 @@ bool PS2KeyboardDevice::handle_irq(const RegisterState&)
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
UNMAP_AFTER_INIT RefPtr<PS2KeyboardDevice> PS2KeyboardDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
||||||
{
|
{
|
||||||
auto device = adopt_ref(*new PS2KeyboardDevice(ps2_controller));
|
auto keyboard_device_or_error = try_create_device<PS2KeyboardDevice>(ps2_controller);
|
||||||
if (device->initialize())
|
// FIXME: Find a way to propagate errors
|
||||||
return device;
|
VERIFY(!keyboard_device_or_error.is_error());
|
||||||
|
if (keyboard_device_or_error.value()->initialize())
|
||||||
|
return keyboard_device_or_error.release_value();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,10 @@ public:
|
||||||
enable_irq();
|
enable_irq();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
explicit PS2KeyboardDevice(const I8042Controller&);
|
explicit PS2KeyboardDevice(const I8042Controller&);
|
||||||
|
|
||||||
|
private:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
|
|
||||||
|
|
|
@ -174,9 +174,11 @@ void PS2MouseDevice::set_sample_rate(u8 rate)
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RefPtr<PS2MouseDevice> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
UNMAP_AFTER_INIT RefPtr<PS2MouseDevice> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
||||||
{
|
{
|
||||||
auto device = adopt_ref(*new PS2MouseDevice(ps2_controller));
|
auto mouse_device_or_error = try_create_device<PS2MouseDevice>(ps2_controller);
|
||||||
if (device->initialize())
|
// FIXME: Find a way to propagate errors
|
||||||
return device;
|
VERIFY(!mouse_device_or_error.is_error());
|
||||||
|
if (mouse_device_or_error.value()->initialize())
|
||||||
|
return mouse_device_or_error.release_value();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,10 @@ public:
|
||||||
enable_irq();
|
enable_irq();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
explicit PS2MouseDevice(const I8042Controller&);
|
explicit PS2MouseDevice(const I8042Controller&);
|
||||||
|
|
||||||
|
protected:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
virtual bool handle_irq(const RegisterState&) override;
|
virtual bool handle_irq(const RegisterState&) override;
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,11 @@ UNMAP_AFTER_INIT RefPtr<VMWareMouseDevice> VMWareMouseDevice::try_to_initialize(
|
||||||
return {};
|
return {};
|
||||||
if (!VMWareBackdoor::the()->vmmouse_is_absolute())
|
if (!VMWareBackdoor::the()->vmmouse_is_absolute())
|
||||||
return {};
|
return {};
|
||||||
auto device = adopt_ref(*new VMWareMouseDevice(ps2_controller));
|
auto mouse_device_or_error = try_create_device<VMWareMouseDevice>(ps2_controller);
|
||||||
if (device->initialize())
|
// FIXME: Find a way to propagate errors
|
||||||
return device;
|
VERIFY(!mouse_device_or_error.is_error());
|
||||||
|
if (mouse_device_or_error.value()->initialize())
|
||||||
|
return mouse_device_or_error.release_value();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
// ^I8042Device
|
// ^I8042Device
|
||||||
virtual void irq_handle_byte_read(u8 byte) override;
|
virtual void irq_handle_byte_read(u8 byte) override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
explicit VMWareMouseDevice(const I8042Controller&);
|
explicit VMWareMouseDevice(const I8042Controller&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,10 @@ HashMap<ThreadID, KCOVInstance*>* KCOVDevice::thread_instance;
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<KCOVDevice> KCOVDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<KCOVDevice> KCOVDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new KCOVDevice);
|
auto kcov_device_or_error = try_create_device<KCOVDevice>();
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!kcov_device_or_error.is_error());
|
||||||
|
return kcov_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT KCOVDevice::KCOVDevice()
|
UNMAP_AFTER_INIT KCOVDevice::KCOVDevice()
|
||||||
|
|
|
@ -25,6 +25,9 @@ public:
|
||||||
KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||||
KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options) override;
|
||||||
|
|
||||||
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
|
KCOVDevice();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual StringView class_name() const override { return "KCOVDevice"; }
|
virtual StringView class_name() const override { return "KCOVDevice"; }
|
||||||
|
|
||||||
|
@ -34,9 +37,6 @@ protected:
|
||||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||||
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
||||||
|
|
||||||
private:
|
|
||||||
KCOVDevice();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<MemoryDevice> MemoryDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<MemoryDevice> MemoryDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new MemoryDevice);
|
auto memory_device_or_error = try_create_device<MemoryDevice>();
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!memory_device_or_error.is_error());
|
||||||
|
return memory_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT MemoryDevice::MemoryDevice()
|
UNMAP_AFTER_INIT MemoryDevice::MemoryDevice()
|
||||||
|
|
|
@ -21,8 +21,10 @@ public:
|
||||||
|
|
||||||
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
MemoryDevice();
|
MemoryDevice();
|
||||||
|
|
||||||
|
private:
|
||||||
virtual StringView class_name() const override { return "MemoryDevice"; }
|
virtual StringView class_name() const override { return "MemoryDevice"; }
|
||||||
virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; }
|
virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; }
|
||||||
virtual bool can_write(const OpenFileDescription&, size_t) const override { return false; }
|
virtual bool can_write(const OpenFileDescription&, size_t) const override { return false; }
|
||||||
|
|
|
@ -15,6 +15,7 @@ static Singleton<NullDevice> s_the;
|
||||||
UNMAP_AFTER_INIT void NullDevice::initialize()
|
UNMAP_AFTER_INIT void NullDevice::initialize()
|
||||||
{
|
{
|
||||||
s_the.ensure_instance();
|
s_the.ensure_instance();
|
||||||
|
s_the->after_inserting();
|
||||||
}
|
}
|
||||||
|
|
||||||
NullDevice& NullDevice::the()
|
NullDevice& NullDevice::the()
|
||||||
|
|
|
@ -12,7 +12,10 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<RandomDevice> RandomDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<RandomDevice> RandomDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new RandomDevice);
|
auto random_device_or_error = try_create_device<RandomDevice>();
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!random_device_or_error.is_error());
|
||||||
|
return random_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT RandomDevice::RandomDevice()
|
UNMAP_AFTER_INIT RandomDevice::RandomDevice()
|
||||||
|
|
|
@ -16,9 +16,10 @@ public:
|
||||||
static NonnullRefPtr<RandomDevice> must_create();
|
static NonnullRefPtr<RandomDevice> must_create();
|
||||||
virtual ~RandomDevice() override;
|
virtual ~RandomDevice() override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
RandomDevice();
|
RandomDevice();
|
||||||
|
|
||||||
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||||
|
|
|
@ -89,6 +89,7 @@ UNMAP_AFTER_INIT void SB16::detect()
|
||||||
UNMAP_AFTER_INIT void SB16::create()
|
UNMAP_AFTER_INIT void SB16::create()
|
||||||
{
|
{
|
||||||
s_the.ensure_instance();
|
s_the.ensure_instance();
|
||||||
|
s_the->after_inserting();
|
||||||
}
|
}
|
||||||
|
|
||||||
SB16& SB16::the()
|
SB16& SB16::the()
|
||||||
|
|
|
@ -12,7 +12,10 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<ZeroDevice> ZeroDevice::must_create()
|
UNMAP_AFTER_INIT NonnullRefPtr<ZeroDevice> ZeroDevice::must_create()
|
||||||
{
|
{
|
||||||
return adopt_ref(*new ZeroDevice);
|
auto zero_device_or_error = try_create_device<ZeroDevice>();
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!zero_device_or_error.is_error());
|
||||||
|
return zero_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()
|
UNMAP_AFTER_INIT ZeroDevice::ZeroDevice()
|
||||||
|
|
|
@ -16,8 +16,10 @@ public:
|
||||||
static NonnullRefPtr<ZeroDevice> must_create();
|
static NonnullRefPtr<ZeroDevice> must_create();
|
||||||
virtual ~ZeroDevice() override;
|
virtual ~ZeroDevice() override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
ZeroDevice();
|
ZeroDevice();
|
||||||
|
|
||||||
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||||
|
|
|
@ -24,6 +24,7 @@ bool File::unref() const
|
||||||
{
|
{
|
||||||
if (deref_base())
|
if (deref_base())
|
||||||
return false;
|
return false;
|
||||||
|
const_cast<File&>(*this).before_removing();
|
||||||
delete this;
|
delete this;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ class File
|
||||||
, public Weakable<File> {
|
, public Weakable<File> {
|
||||||
public:
|
public:
|
||||||
virtual bool unref() const;
|
virtual bool unref() const;
|
||||||
|
virtual void before_removing() { }
|
||||||
virtual ~File();
|
virtual ~File();
|
||||||
|
|
||||||
virtual KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options);
|
virtual KResultOr<NonnullRefPtr<OpenFileDescription>> open(int options);
|
||||||
|
|
|
@ -34,12 +34,12 @@ class SysFSDeviceComponent final
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<SysFSDeviceComponent> must_create(Device const&);
|
static NonnullRefPtr<SysFSDeviceComponent> must_create(Device const&);
|
||||||
|
|
||||||
Device const& device() const { return *m_associated_device; }
|
bool is_block_device() { return m_block_device; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit SysFSDeviceComponent(Device const&);
|
explicit SysFSDeviceComponent(Device const&);
|
||||||
IntrusiveListNode<SysFSDeviceComponent, NonnullRefPtr<SysFSDeviceComponent>> m_list_node;
|
IntrusiveListNode<SysFSDeviceComponent, NonnullRefPtr<SysFSDeviceComponent>> m_list_node;
|
||||||
RefPtr<Device> m_associated_device;
|
bool m_block_device;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SysFSDevicesDirectory final : public SysFSDirectory {
|
class SysFSDevicesDirectory final : public SysFSDirectory {
|
||||||
|
|
|
@ -22,7 +22,10 @@ namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<FramebufferDevice> FramebufferDevice::create(const GraphicsDevice& adapter, size_t output_port_index, PhysicalAddress paddr, size_t width, size_t height, size_t pitch)
|
NonnullRefPtr<FramebufferDevice> FramebufferDevice::create(const GraphicsDevice& adapter, size_t output_port_index, PhysicalAddress paddr, size_t width, size_t height, size_t pitch)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new FramebufferDevice(adapter, output_port_index, paddr, width, height, pitch));
|
auto framebuffer_device_or_error = try_create_device<FramebufferDevice>(adapter, output_port_index, paddr, width, height, pitch);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!framebuffer_device_or_error.is_error());
|
||||||
|
return framebuffer_device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
KResultOr<Memory::Region*> FramebufferDevice::mmap(Process& process, OpenFileDescription&, Memory::VirtualRange const& range, u64 offset, int prot, bool shared)
|
||||||
|
|
|
@ -32,6 +32,9 @@ public:
|
||||||
virtual ~FramebufferDevice() {};
|
virtual ~FramebufferDevice() {};
|
||||||
KResult initialize();
|
KResult initialize();
|
||||||
|
|
||||||
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
|
FramebufferDevice(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^File
|
// ^File
|
||||||
virtual StringView class_name() const override { return "FramebufferDevice"; }
|
virtual StringView class_name() const override { return "FramebufferDevice"; }
|
||||||
|
@ -42,8 +45,6 @@ private:
|
||||||
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||||
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
||||||
|
|
||||||
FramebufferDevice(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
|
|
||||||
|
|
||||||
PhysicalAddress m_framebuffer_address;
|
PhysicalAddress m_framebuffer_address;
|
||||||
size_t m_framebuffer_pitch { 0 };
|
size_t m_framebuffer_pitch { 0 };
|
||||||
size_t m_framebuffer_width { 0 };
|
size_t m_framebuffer_width { 0 };
|
||||||
|
|
|
@ -64,6 +64,7 @@ void GPU::create_framebuffer_devices()
|
||||||
for (size_t i = 0; i < min(m_num_scanouts, VIRTIO_GPU_MAX_SCANOUTS); i++) {
|
for (size_t i = 0; i < min(m_num_scanouts, VIRTIO_GPU_MAX_SCANOUTS); i++) {
|
||||||
auto& scanout = m_scanouts[i];
|
auto& scanout = m_scanouts[i];
|
||||||
scanout.framebuffer = adopt_ref(*new VirtIOGPU::FrameBufferDevice(*this, i));
|
scanout.framebuffer = adopt_ref(*new VirtIOGPU::FrameBufferDevice(*this, i));
|
||||||
|
scanout.framebuffer->after_inserting();
|
||||||
scanout.console = Kernel::Graphics::VirtIOGPU::Console::initialize(scanout.framebuffer);
|
scanout.console = Kernel::Graphics::VirtIOGPU::Console::initialize(scanout.framebuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,10 @@ namespace Kernel {
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
|
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new PATADiskDevice(controller, channel, type, interface_type, capabilities, max_addressable_block));
|
auto device_or_error = try_create_device<PATADiskDevice>(controller, channel, type, interface_type, capabilities, max_addressable_block);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!device_or_error.is_error());
|
||||||
|
return device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
|
UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
|
||||||
|
|
|
@ -44,9 +44,10 @@ public:
|
||||||
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
||||||
virtual String storage_name() const override;
|
virtual String storage_name() const override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
|
PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
|
||||||
|
|
||||||
|
private:
|
||||||
// ^DiskDevice
|
// ^DiskDevice
|
||||||
virtual StringView class_name() const override;
|
virtual StringView class_name() const override;
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,10 @@ namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
|
NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new DiskPartition(device, minor_number, metadata));
|
auto partition_or_error = try_create_device<DiskPartition>(device, minor_number, metadata);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!partition_or_error.is_error());
|
||||||
|
return partition_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskPartition::DiskPartition(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
|
DiskPartition::DiskPartition(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
|
||||||
|
|
|
@ -28,11 +28,12 @@ public:
|
||||||
|
|
||||||
const DiskPartitionMetadata& metadata() const;
|
const DiskPartitionMetadata& metadata() const;
|
||||||
|
|
||||||
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
|
DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual StringView class_name() const override;
|
virtual StringView class_name() const override;
|
||||||
|
|
||||||
DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
|
|
||||||
|
|
||||||
WeakPtr<BlockDevice> m_device;
|
WeakPtr<BlockDevice> m_device;
|
||||||
DiskPartitionMetadata m_metadata;
|
DiskPartitionMetadata m_metadata;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,10 @@ namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new RamdiskDevice(controller, move(region), major, minor));
|
auto device_or_error = try_create_device<RamdiskDevice>(controller, move(region), major, minor);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!device_or_error.is_error());
|
||||||
|
return device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||||
|
|
|
@ -14,7 +14,10 @@ namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
|
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new SATADiskDevice(controller, port, sector_size, max_addressable_block));
|
auto device_or_error = try_create_device<SATADiskDevice>(controller, port, sector_size, max_addressable_block);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!device_or_error.is_error());
|
||||||
|
return device_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
|
SATADiskDevice::SATADiskDevice(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
|
||||||
|
|
|
@ -32,9 +32,10 @@ public:
|
||||||
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
||||||
virtual String storage_name() const override;
|
virtual String storage_name() const override;
|
||||||
|
|
||||||
private:
|
// FIXME: We expose this constructor to make try_create_device helper to work
|
||||||
SATADiskDevice(const AHCIController&, const AHCIPort&, size_t sector_size, u64 max_addressable_block);
|
SATADiskDevice(const AHCIController&, const AHCIPort&, size_t sector_size, u64 max_addressable_block);
|
||||||
|
|
||||||
|
private:
|
||||||
// ^DiskDevice
|
// ^DiskDevice
|
||||||
virtual StringView class_name() const override;
|
virtual StringView class_name() const override;
|
||||||
WeakPtr<AHCIPort> m_port;
|
WeakPtr<AHCIPort> m_port;
|
||||||
|
|
|
@ -22,6 +22,8 @@ KResultOr<NonnullRefPtr<MasterPTY>> MasterPTY::try_create(unsigned int index)
|
||||||
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer))));
|
auto master_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MasterPTY(index, move(buffer))));
|
||||||
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index)));
|
auto slave_pty = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SlavePTY(*master_pty, index)));
|
||||||
master_pty->m_slave = slave_pty;
|
master_pty->m_slave = slave_pty;
|
||||||
|
master_pty->after_inserting();
|
||||||
|
slave_pty->after_inserting();
|
||||||
return master_pty;
|
return master_pty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,11 @@ UNMAP_AFTER_INIT PTYMultiplexer::~PTYMultiplexer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PTYMultiplexer::initialize()
|
||||||
|
{
|
||||||
|
the().after_inserting();
|
||||||
|
}
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
KResultOr<NonnullRefPtr<OpenFileDescription>> PTYMultiplexer::open(int options)
|
||||||
{
|
{
|
||||||
return m_freelist.with_exclusive([&](auto& freelist) -> KResultOr<NonnullRefPtr<OpenFileDescription>> {
|
return m_freelist.with_exclusive([&](auto& freelist) -> KResultOr<NonnullRefPtr<OpenFileDescription>> {
|
||||||
|
|
|
@ -20,10 +20,7 @@ public:
|
||||||
PTYMultiplexer();
|
PTYMultiplexer();
|
||||||
virtual ~PTYMultiplexer() override;
|
virtual ~PTYMultiplexer() override;
|
||||||
|
|
||||||
static void initialize()
|
static void initialize();
|
||||||
{
|
|
||||||
the();
|
|
||||||
}
|
|
||||||
static PTYMultiplexer& the();
|
static PTYMultiplexer& the();
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
|
|
|
@ -28,8 +28,10 @@ bool SlavePTY::unref() const
|
||||||
m_list_node.remove();
|
m_list_node.remove();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (did_hit_zero)
|
if (did_hit_zero) {
|
||||||
|
const_cast<SlavePTY&>(*this).before_removing();
|
||||||
delete this;
|
delete this;
|
||||||
|
}
|
||||||
return did_hit_zero;
|
return did_hit_zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,12 +103,18 @@ void VirtualConsole::set_graphical(bool graphical)
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create(size_t index)
|
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create(size_t index)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new VirtualConsole(index));
|
auto virtual_console_or_error = try_create_device<VirtualConsole>(index);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!virtual_console_or_error.is_error());
|
||||||
|
return virtual_console_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create_with_preset_log(size_t index, const CircularQueue<char, 16384>& log)
|
UNMAP_AFTER_INIT NonnullRefPtr<VirtualConsole> VirtualConsole::create_with_preset_log(size_t index, const CircularQueue<char, 16384>& log)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new VirtualConsole(index, log));
|
auto virtual_console_or_error = try_create_device<VirtualConsole>(index, log);
|
||||||
|
// FIXME: Find a way to propagate errors
|
||||||
|
VERIFY(!virtual_console_or_error.is_error());
|
||||||
|
return virtual_console_or_error.release_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void VirtualConsole::initialize()
|
UNMAP_AFTER_INIT void VirtualConsole::initialize()
|
||||||
|
|
|
@ -84,9 +84,11 @@ public:
|
||||||
|
|
||||||
void emit_char(char);
|
void emit_char(char);
|
||||||
|
|
||||||
private:
|
// FIXME: We expose these constructors to make try_create_device helper to work
|
||||||
explicit VirtualConsole(const unsigned index);
|
explicit VirtualConsole(const unsigned index);
|
||||||
VirtualConsole(const unsigned index, const CircularQueue<char, 16384>&);
|
VirtualConsole(const unsigned index, const CircularQueue<char, 16384>&);
|
||||||
|
|
||||||
|
private:
|
||||||
// ^KeyboardClient
|
// ^KeyboardClient
|
||||||
virtual void on_key_pressed(KeyEvent) override;
|
virtual void on_key_pressed(KeyEvent) override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue