Truly independent web browser
LibWeb: Forbid heap access on pool and clock threads
Andreas Kling97f227aba613
diff --git a/Libraries/LibWeb/Compositor/RenderClock.cpp b/Libraries/LibWeb/Compositor/RenderClock.cppindex becfa3d342f..3fa04400d3d 100644--- a/Libraries/LibWeb/Compositor/RenderClock.cpp+++ b/Libraries/LibWeb/Compositor/RenderClock.cpp@@ -9,6 +9,7 @@#include <Compositor/RenderClockServerEndpoint.h>#include <LibCore/EventLoop.h>#include <LibCore/ThreadEventQueue.h>+#include <LibGC/HeapAccess.h>#include <LibIPC/ConnectionToServer.h>#include <LibIPC/Transport.h>#include <LibThreading/Thread.h>@@ -113,6 +114,8 @@ RenderClock::RenderClock()intptr_t RenderClock::thread_main(){+ GC::forbid_heap_access_on_this_thread();+Core::EventLoop event_loop;{MutexLocker locker(m_mutex);diff --git a/Libraries/LibWeb/Platform/ThreadPoolWork.h b/Libraries/LibWeb/Platform/ThreadPoolWork.hindex 4abf1483fbb..8330bca38e6 100644--- a/Libraries/LibWeb/Platform/ThreadPoolWork.h+++ b/Libraries/LibWeb/Platform/ThreadPoolWork.h@@ -9,6 +9,7 @@#include <AK/Function.h>#include <AK/Types.h>#include <LibCore/EventLoop.h>+#include <LibGC/HeapAccess.h>#include <LibThreading/ThreadPool.h>#include <LibWeb/Export.h>@@ -35,6 +36,7 @@ void run_on_thread_pool(Work work, Function<void(Result)> on_complete)});Threading::ThreadPool::the().submit([work = move(work), completion_id, event_loop = Core::EventLoop::current_weak()]() mutable {+ GC::forbid_heap_access_on_this_thread();Result result = work();auto origin_event_loop = event_loop->take();diff --git a/Libraries/LibWeb/Rust/src/stage_thread.rs b/Libraries/LibWeb/Rust/src/stage_thread.rsindex e9481329d8f..217c5fc99b5 100644--- a/Libraries/LibWeb/Rust/src/stage_thread.rs+++ b/Libraries/LibWeb/Rust/src/stage_thread.rs@@ -101,6 +101,13 @@ thread_local! {static THREAD_SETUP: OnceLock<extern "C" fn()> = OnceLock::new();+/// Runs the setup `stage_thread_set_thread_setup` installed, on a thread that serves the same purpose as a stage thread.+pub(crate) fn run_thread_setup() {+ if let Some(setup) = THREAD_SETUP.get() {+ setup();+ }+}+/// Makes each stage thread run `setup` first thing once it starts. Call it before any is handed a job; the first setup/// installed stays.#[unsafe(no_mangle)]@@ -137,9 +144,7 @@ impl StageThread {.name(name.into()).stack_size(STAGE_THREAD_STACK_SIZE).spawn(move || {- if let Some(setup) = THREAD_SETUP.get() {- setup();- }+ run_thread_setup();let mut release_memory_at = None;loop {let last = loop {diff --git a/Libraries/LibWeb/Rust/src/style_layout_pool.rs b/Libraries/LibWeb/Rust/src/style_layout_pool.rsindex c101bef3ee7..d0a19263f0d 100644--- a/Libraries/LibWeb/Rust/src/style_layout_pool.rs+++ b/Libraries/LibWeb/Rust/src/style_layout_pool.rs@@ -103,6 +103,7 @@ fn start_threads(workers: usize) -> rayon::ThreadPool {.num_threads(workers).stack_size(crate::stage_thread::STAGE_THREAD_STACK_SIZE).thread_name(|index| format!("StyleLayout {index}"))+ .start_handler(|_| crate::stage_thread::run_thread_setup()).build().expect("the style and layout thread pool starts")}