Kernel: Fix spinlock bugs found by the new spinlock security

This commit is contained in:
Bananymous 2025-05-30 22:02:17 +03:00
parent 6542a037df
commit 692ba43182
2 changed files with 14 additions and 11 deletions

View File

@ -281,10 +281,11 @@ namespace Kernel
if (!is_streaming()) if (!is_streaming())
m_packet_sizes.push(packet.size()); m_packet_sizes.push(packet.size());
epoll_notify(EPOLLIN);
m_packet_thread_blocker.unblock(); m_packet_thread_blocker.unblock();
m_packet_lock.unlock(state); m_packet_lock.unlock(state);
epoll_notify(EPOLLIN);
return {}; return {};
} }

View File

@ -88,18 +88,20 @@ namespace Kernel
bool PseudoTerminalMaster::putchar(uint8_t ch) bool PseudoTerminalMaster::putchar(uint8_t ch)
{ {
SpinLockGuard _(m_buffer_lock); {
SpinLockGuard _(m_buffer_lock);
if (m_buffer_size >= m_buffer->size()) if (m_buffer_size >= m_buffer->size())
return false; return false;
reinterpret_cast<uint8_t*>(m_buffer->vaddr())[(m_buffer_tail + m_buffer_size) % m_buffer->size()] = ch; reinterpret_cast<uint8_t*>(m_buffer->vaddr())[(m_buffer_tail + m_buffer_size) % m_buffer->size()] = ch;
m_buffer_size++; m_buffer_size++;
m_buffer_blocker.unblock();
}
epoll_notify(EPOLLIN); epoll_notify(EPOLLIN);
m_buffer_blocker.unblock();
return true; return true;
} }
@ -130,10 +132,10 @@ namespace Kernel
m_buffer_size -= to_copy; m_buffer_size -= to_copy;
m_buffer_tail = (m_buffer_tail + to_copy) % m_buffer->size(); m_buffer_tail = (m_buffer_tail + to_copy) % m_buffer->size();
epoll_notify(EPOLLOUT);
m_buffer_lock.unlock(state); m_buffer_lock.unlock(state);
epoll_notify(EPOLLOUT);
return to_copy; return to_copy;
} }