Kernel: Ensure proper locking when mutating boot console cursor

The BootFramebufferConsole highly depends on using the m_lock spinlock,
therefore setting and changing the cursor state should be done under
that spinlock too to avoid crashing.
This commit is contained in:
Liav A 2022-09-20 21:41:52 +03:00 committed by Linus Groh
parent 0a5416a87a
commit 37ed1b28fa
2 changed files with 30 additions and 0 deletions

View file

@ -71,6 +71,31 @@ void BootFramebufferConsole::write(size_t x, size_t y, char ch, Color background
GenericFramebufferConsoleImpl::write(x, y, ch, background, foreground, critical);
}
void BootFramebufferConsole::set_cursor(size_t x, size_t y)
{
// Note: To ensure we don't trigger a deadlock, let's assert in
// case we already locked the spinlock, so we know there's a bug
// in the call path.
VERIFY(!m_lock.is_locked());
SpinlockLocker lock(m_lock);
hide_cursor();
m_x = x;
m_y = y;
show_cursor();
}
void BootFramebufferConsole::hide_cursor()
{
VERIFY(m_lock.is_locked());
GenericFramebufferConsoleImpl::hide_cursor();
}
void BootFramebufferConsole::show_cursor()
{
VERIFY(m_lock.is_locked());
GenericFramebufferConsoleImpl::show_cursor();
}
u8* BootFramebufferConsole::framebuffer_data()
{
VERIFY(m_lock.is_locked());

View file

@ -30,6 +30,11 @@ public:
BootFramebufferConsole(PhysicalAddress framebuffer_addr, size_t width, size_t height, size_t pitch);
#endif
private:
virtual void set_cursor(size_t x, size_t y) override;
virtual void hide_cursor() override;
virtual void show_cursor() override;
protected:
virtual void clear_glyph(size_t x, size_t y) override;