summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-02-06 01:25:32 +0100
committerAndreas Kling <kling@serenityos.org>2022-02-06 01:25:32 +0100
commit04539d4930733d5f2c293273f3c94290c41c4573 (patch)
treeb057939c79fd5e7164beb4c83c6bf0c669c7ac2f
parentc1c5444c14115cd0d0637383c92b806abb262f77 (diff)
downloadserenity-04539d4930733d5f2c293273f3c94290c41c4573.zip
Kernel: Propagate sys$profiling_enable() buffer allocation failure
Caught a kernel panic when enabling profiling of all threads when there was very little memory available.
-rw-r--r--Kernel/Syscalls/profiling.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/Kernel/Syscalls/profiling.cpp b/Kernel/Syscalls/profiling.cpp
index a244219ad1..251eee7a5c 100644
--- a/Kernel/Syscalls/profiling.cpp
+++ b/Kernel/Syscalls/profiling.cpp
@@ -26,10 +26,15 @@ ErrorOr<FlatPtr> Process::sys$profiling_enable(pid_t pid, u64 event_mask)
return EPERM;
ScopedCritical critical;
g_profiling_event_mask = PERF_EVENT_PROCESS_CREATE | PERF_EVENT_THREAD_CREATE | PERF_EVENT_MMAP;
- if (g_global_perf_events)
+ if (g_global_perf_events) {
g_global_perf_events->clear();
- else
+ } else {
g_global_perf_events = PerformanceEventBuffer::try_create_with_size(32 * MiB).leak_ptr();
+ if (!g_global_perf_events) {
+ g_profiling_event_mask = 0;
+ return ENOMEM;
+ }
+ }
SpinlockLocker lock(g_profiling_lock);
if (!TimeManagement::the().enable_profile_timer())