summaryrefslogtreecommitdiff
path: root/Kernel/Bus/VirtIO
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2022-01-26 22:03:48 +0200
committerLinus Groh <mail@linusgroh.de>2022-01-26 22:07:01 +0000
commitac4583660b2c7da33ac13b4733f993767bb08644 (patch)
tree0571cdcdb26b1ca5987339616be32425b24d500f /Kernel/Bus/VirtIO
parent94a39db31d94bb60e257a5649b6cf2a873c820fc (diff)
downloadserenity-ac4583660b2c7da33ac13b4733f993767bb08644.zip
Kernel: Make VirtIO::ConsolePort construction OOM-fallible
Diffstat (limited to 'Kernel/Bus/VirtIO')
-rw-r--r--Kernel/Bus/VirtIO/ConsolePort.cpp13
-rw-r--r--Kernel/Bus/VirtIO/ConsolePort.h9
2 files changed, 16 insertions, 6 deletions
diff --git a/Kernel/Bus/VirtIO/ConsolePort.cpp b/Kernel/Bus/VirtIO/ConsolePort.cpp
index c484879da9..b13729d8ec 100644
--- a/Kernel/Bus/VirtIO/ConsolePort.cpp
+++ b/Kernel/Bus/VirtIO/ConsolePort.cpp
@@ -12,13 +12,20 @@ namespace Kernel::VirtIO {
unsigned ConsolePort::next_device_id = 0;
-ConsolePort::ConsolePort(unsigned port, VirtIO::Console& console)
+ErrorOr<NonnullRefPtr<ConsolePort>> ConsolePort::try_create(unsigned port, Console& console)
+{
+ auto receive_buffer = TRY(Memory::RingBuffer::try_create("VirtIO::ConsolePort Receive"sv, RINGBUFFER_SIZE));
+ auto transmit_buffer = TRY(Memory::RingBuffer::try_create("VirtIO::ConsolePort Transmit"sv, RINGBUFFER_SIZE));
+ return adopt_nonnull_ref_or_enomem(new (nothrow) ConsolePort(port, console, move(receive_buffer), move(transmit_buffer)));
+}
+
+ConsolePort::ConsolePort(unsigned port, VirtIO::Console& console, NonnullOwnPtr<Memory::RingBuffer> receive_buffer, NonnullOwnPtr<Memory::RingBuffer> transmit_buffer)
: CharacterDevice(229, next_device_id++)
+ , m_receive_buffer(move(receive_buffer))
+ , m_transmit_buffer(move(transmit_buffer))
, m_console(console)
, m_port(port)
{
- m_receive_buffer = Memory::RingBuffer::try_create("VirtIO::ConsolePort Receive"sv, RINGBUFFER_SIZE).release_value_but_fixme_should_propagate_errors();
- m_transmit_buffer = Memory::RingBuffer::try_create("VirtIO::ConsolePort Transmit"sv, RINGBUFFER_SIZE).release_value_but_fixme_should_propagate_errors();
m_receive_queue = m_port == 0 ? 0 : m_port * 2 + 2;
m_transmit_queue = m_port == 0 ? 1 : m_port * 2 + 3;
}
diff --git a/Kernel/Bus/VirtIO/ConsolePort.h b/Kernel/Bus/VirtIO/ConsolePort.h
index 40797ab397..beed06e1a2 100644
--- a/Kernel/Bus/VirtIO/ConsolePort.h
+++ b/Kernel/Bus/VirtIO/ConsolePort.h
@@ -24,7 +24,8 @@ class Console;
class ConsolePort
: public CharacterDevice {
public:
- explicit ConsolePort(unsigned port, VirtIO::Console&);
+ static ErrorOr<NonnullRefPtr<ConsolePort>> try_create(unsigned port, VirtIO::Console&);
+
void handle_queue_update(Badge<VirtIO::Console>, u16 queue_index);
void set_open(Badge<VirtIO::Console>, bool state) { m_open = state; }
@@ -35,6 +36,8 @@ public:
private:
constexpr static size_t RINGBUFFER_SIZE = 2 * PAGE_SIZE;
+ ConsolePort(unsigned port, VirtIO::Console& console, NonnullOwnPtr<Memory::RingBuffer> receive_buffer, NonnullOwnPtr<Memory::RingBuffer> transmit_buffer);
+
virtual StringView class_name() const override { return "VirtIOConsolePort"sv; }
virtual bool can_read(const OpenFileDescription&, u64) const override;
@@ -47,8 +50,8 @@ private:
u16 m_receive_queue {};
u16 m_transmit_queue {};
- OwnPtr<Memory::RingBuffer> m_receive_buffer;
- OwnPtr<Memory::RingBuffer> m_transmit_buffer;
+ NonnullOwnPtr<Memory::RingBuffer> m_receive_buffer;
+ NonnullOwnPtr<Memory::RingBuffer> m_transmit_buffer;
VirtIO::Console& m_console;
unsigned m_port;