Kernel/Graphics: Protect the list of display connectors with a Spinlock

This list could be updated in runtime if an hotplug event occurs, so we
must protect it with a spin lock to avoid corruption of the list.
This commit is contained in:
Liav A 2022-05-06 14:46:58 +03:00 committed by Linus Groh
parent c246d86867
commit b8493bf70f
Notes: sideshowbarker 2024-07-17 11:14:30 +09:00
2 changed files with 15 additions and 9 deletions

View file

@ -86,24 +86,30 @@ void GraphicsManagement::set_vga_text_mode_cursor(size_t console_width, size_t x
void GraphicsManagement::deactivate_graphical_mode()
{
for (auto& connector : m_display_connector_nodes) {
connector.set_display_mode({}, DisplayConnector::DisplayMode::Console);
}
return m_display_connector_nodes.with([&](auto& display_connectors) {
for (auto& connector : display_connectors)
connector.set_display_mode({}, DisplayConnector::DisplayMode::Console);
});
}
void GraphicsManagement::activate_graphical_mode()
{
for (auto& connector : m_display_connector_nodes) {
connector.set_display_mode({}, DisplayConnector::DisplayMode::Graphical);
}
return m_display_connector_nodes.with([&](auto& display_connectors) {
for (auto& connector : display_connectors)
connector.set_display_mode({}, DisplayConnector::DisplayMode::Graphical);
});
}
void GraphicsManagement::attach_new_display_connector(Badge<DisplayConnector>, DisplayConnector& connector)
{
m_display_connector_nodes.append(connector);
return m_display_connector_nodes.with([&](auto& display_connectors) {
display_connectors.append(connector);
});
}
void GraphicsManagement::detach_display_connector(Badge<DisplayConnector>, DisplayConnector& connector)
{
m_display_connector_nodes.remove(connector);
return m_display_connector_nodes.with([&](auto& display_connectors) {
display_connectors.remove(connector);
});
}
static inline bool is_vga_compatible_pci_device(PCI::DeviceIdentifier const& device_identifier)

View file

@ -58,7 +58,7 @@ private:
RefPtr<VGACompatibleAdapter> m_vga_adapter;
unsigned m_current_minor_number { 0 };
IntrusiveList<&DisplayConnector::m_list_node> m_display_connector_nodes;
SpinlockProtected<IntrusiveList<&DisplayConnector::m_list_node>> m_display_connector_nodes;
RecursiveSpinlock m_main_vga_lock;
bool m_vga_access_is_disabled { false };