From ece29711120c372405a28c85e1dc1d160afa4623 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 22 Feb 2020 11:09:03 +0100 Subject: [PATCH] Kernel: Disable profiling during the critical section of sys$execve() Since we're gonna throw away these stacks at the end of exec anyway, we might as well disable profiling before starting to mess with the process page tables. One less weird situation to worry about in the sampling code. --- Kernel/Process.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index db9040e0f7..4eb4284c45 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -804,6 +804,10 @@ int Process::do_exec(NonnullRefPtr main_program_description, Ve return -ETXTBSY; } + // Disable profiling temporarily in case it's running on this process. + bool was_profiling = is_profiling(); + TemporaryChange profiling_disabler(m_profiling, false); + auto old_page_directory = move(m_page_directory); auto old_regions = move(m_regions); m_page_directory = PageDirectory::create_for_userspace(*this); @@ -1015,7 +1019,7 @@ int Process::do_exec(NonnullRefPtr main_program_description, Ve kprintf("Process %u (%s) exec'd %s @ %p\n", pid(), name().characters(), path.characters(), tss.eip); #endif - if (is_profiling()) + if (was_profiling) Profiling::did_exec(path); new_main_thread->set_state(Thread::State::Skip1SchedulerPass);