From 3ac977f50bfd8dc9be2fe6e92211c67d7958a5ef Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 12 Jan 2019 23:23:35 +0100 Subject: [PATCH] Paper over a race in DoubleBuffer. I'm still somewhat okay throwing InterruptDisabler at races as they screw me. Eventually I'm gonna have to devise a different strategy though. --- Kernel/DoubleBuffer.cpp | 6 +++++- Kernel/kmalloc.cpp | 2 +- Kernel/kmalloc.h | 10 +++++++++- Widgets/EventLoop.cpp | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 30c125bd22975b..ab85c1b6ab3e3d 100644 --- a/Kernel/DoubleBuffer.cpp +++ b/Kernel/DoubleBuffer.cpp @@ -2,9 +2,13 @@ void DoubleBuffer::flip() { + InterruptDisabler disabler; ASSERT(m_read_buffer_index == m_read_buffer->size()); swap(m_read_buffer, m_write_buffer); - m_write_buffer->clear(); + if (m_write_buffer->capacity() < 32) + m_write_buffer->clear_with_capacity(); + else + m_write_buffer->clear(); m_read_buffer_index = 0; } diff --git a/Kernel/kmalloc.cpp b/Kernel/kmalloc.cpp index fd837e03d0a278..d297d28e2d67d7 100644 --- a/Kernel/kmalloc.cpp +++ b/Kernel/kmalloc.cpp @@ -90,7 +90,7 @@ void* kmalloc_page_aligned(size_t size) return ptr; } -void* kmalloc(dword size) +void* kmalloc_impl(dword size) { InterruptDisabler disabler; diff --git a/Kernel/kmalloc.h b/Kernel/kmalloc.h index afbaa2e5a1da0a..1aeae01099f6bd 100644 --- a/Kernel/kmalloc.h +++ b/Kernel/kmalloc.h @@ -1,7 +1,7 @@ #pragma once void kmalloc_init(); -void *kmalloc(dword size) __attribute__ ((malloc)); +void* kmalloc_impl(dword size) __attribute__ ((malloc)); void* kmalloc_eternal(size_t) __attribute__ ((malloc)); void* kmalloc_page_aligned(size_t) __attribute__ ((malloc)); void* kmalloc_aligned(size_t, size_t alignment) __attribute__ ((malloc)); @@ -17,3 +17,11 @@ extern volatile size_t kmalloc_sum_page_aligned; inline void* operator new(size_t, void* p) { return p; } inline void* operator new[](size_t, void* p) { return p; } + +ALWAYS_INLINE void* kmalloc(size_t size) +{ + // Any kernel allocation >= 32K is very suspicious, catch them. + if (size >= 0x8000) + asm volatile("cli;hlt"); + return kmalloc_impl(size); +} diff --git a/Widgets/EventLoop.cpp b/Widgets/EventLoop.cpp index d4c026cebc21b0..22b94cdd03e3ba 100644 --- a/Widgets/EventLoop.cpp +++ b/Widgets/EventLoop.cpp @@ -36,7 +36,11 @@ int EventLoop::exec() for (;;) { if (m_queuedEvents.is_empty()) waitForEvent(); - auto events = move(m_queuedEvents); + Vector events; + { + InterruptDisabler disabler; + events = move(m_queuedEvents); + } for (auto& queuedEvent : events) { auto* receiver = queuedEvent.receiver; auto& event = *queuedEvent.event;