diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-01-12 23:23:35 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-01-12 23:23:35 +0100 |
commit | 3ac977f50bfd8dc9be2fe6e92211c67d7958a5ef (patch) | |
tree | 6f421eafb11fb8cf09da4f9356b895c455b66678 | |
parent | 2e2d883c09c179acccf020d27adf16b5b82850bf (diff) | |
download | serenity-3ac977f50bfd8dc9be2fe6e92211c67d7958a5ef.zip |
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.
-rw-r--r-- | Kernel/DoubleBuffer.cpp | 6 | ||||
-rw-r--r-- | Kernel/kmalloc.cpp | 2 | ||||
-rw-r--r-- | Kernel/kmalloc.h | 10 | ||||
-rw-r--r-- | Widgets/EventLoop.cpp | 6 |
4 files changed, 20 insertions, 4 deletions
diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp index 30c125bd22..ab85c1b6ab 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 fd837e03d0..d297d28e2d 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 afbaa2e5a1..1aeae01099 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 d4c026cebc..22b94cdd03 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<QueuedEvent> events; + { + InterruptDisabler disabler; + events = move(m_queuedEvents); + } for (auto& queuedEvent : events) { auto* receiver = queuedEvent.receiver; auto& event = *queuedEvent.event; |