From 86e30100437b57d6da66207fe860fb167d8278db Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sun, 23 May 2021 13:45:58 -0600 Subject: [PATCH] Kernel: Pass trampolines instead of lambdas to create_kernel_process With -Og, all calls to create_kernel_process were triggering -Wnonnull when creating these lambdas that get implicitly converted to function pointers. A different design of create_kernel_process to use AK::Function instead might avoid this awkward behavior. --- Kernel/Process.h | 17 +++++++++-------- Kernel/Tasks/FinalizerTask.cpp | 24 +++++++++++++----------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Kernel/Process.h b/Kernel/Process.h index 526a5c7f8e..bb3bb75ed9 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -151,17 +151,19 @@ public: return current_thread ? ¤t_thread->process() : nullptr; } + template + static void kernel_process_trampoline(void* data) + { + EntryFunction* func = reinterpret_cast(data); + (*func)(); + delete func; + } + template static RefPtr create_kernel_process(RefPtr& first_thread, String&& name, EntryFunction entry, u32 affinity = THREAD_AFFINITY_DEFAULT) { auto* entry_func = new EntryFunction(move(entry)); - return create_kernel_process( - first_thread, move(name), [](void* data) { - EntryFunction* func = reinterpret_cast(data); - (*func)(); - delete func; - }, - entry_func, affinity); + return create_kernel_process(first_thread, move(name), &Process::kernel_process_trampoline, entry_func, affinity); } static RefPtr create_kernel_process(RefPtr& first_thread, String&& name, void (*entry)(void*), void* entry_data = nullptr, u32 affinity = THREAD_AFFINITY_DEFAULT); @@ -805,7 +807,6 @@ inline ProcessID Thread::pid() const VERIFY_NOT_REACHED(); \ } \ } while (0) - } inline static String copy_string_from_user(const Kernel::Syscall::StringArgument& string) diff --git a/Kernel/Tasks/FinalizerTask.cpp b/Kernel/Tasks/FinalizerTask.cpp index 786b8f5ee8..8679c1fd3f 100644 --- a/Kernel/Tasks/FinalizerTask.cpp +++ b/Kernel/Tasks/FinalizerTask.cpp @@ -9,20 +9,22 @@ namespace Kernel { +static void finalizer_task(void*) +{ + Thread::current()->set_priority(THREAD_PRIORITY_LOW); + for (;;) { + g_finalizer_wait_queue->wait_forever("FinalizerTask"); + + if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true) + Thread::finalize_dying_threads(); + } +}; + void FinalizerTask::spawn() { RefPtr finalizer_thread; - Process::create_kernel_process( - finalizer_thread, "FinalizerTask", [](void*) { - Thread::current()->set_priority(THREAD_PRIORITY_LOW); - for (;;) { - g_finalizer_wait_queue->wait_forever("FinalizerTask"); - - if (g_finalizer_has_work.exchange(false, AK::MemoryOrder::memory_order_acq_rel) == true) - Thread::finalize_dying_threads(); - } - }, - nullptr); + auto finalizer_process = Process::create_kernel_process(finalizer_thread, "FinalizerTask", finalizer_task, nullptr); + VERIFY(finalizer_process); g_finalizer = finalizer_thread; }