mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
Kernel/VirtIO: Defer initialization of device out of the constructor
This ensures we safely handle interrupts (which can call virtual functions), so they don't happen in the constructor - this pattern can lead to a crash, if we are still in the constructor context because not all methods are available for usage (some are pure virtual, so it's possible to call __cxa_pure_virtual). Also, under some conditions like adding a PCI device via PCI-passthrough mechanism in QEMU, it became exposed to the eye that the code asserts on RNG::handle_device_config_change(). That device has no configuration but if the hypervisor still misbehaves and tries to configure it, we should simply return false to indicate nothing happened.
This commit is contained in:
parent
e490c17bde
commit
ed6c1f53af
9 changed files with 47 additions and 17 deletions
|
@ -17,10 +17,9 @@ UNMAP_AFTER_INIT NonnullRefPtr<Console> Console::must_create(PCI::Address addres
|
|||
return adopt_ref_if_nonnull(new Console(address)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
, m_device_id(next_device_id++)
|
||||
UNMAP_AFTER_INIT void Console::initialize()
|
||||
{
|
||||
Device::initialize();
|
||||
if (auto cfg = get_config(ConfigurationType::Device)) {
|
||||
bool success = negotiate_features([&](u64 supported_features) {
|
||||
u64 negotiated = 0;
|
||||
|
@ -58,6 +57,12 @@ UNMAP_AFTER_INIT Console::Console(PCI::Address address)
|
|||
}
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::Address address)
|
||||
: VirtIO::Device(address)
|
||||
, m_device_id(next_device_id++)
|
||||
{
|
||||
}
|
||||
|
||||
bool Console::handle_device_config_change()
|
||||
{
|
||||
dbgln("VirtIO::Console: Handle device config change");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue