summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-02 16:55:54 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-02 22:38:06 +0100
commitb425c2602c6dd10b5509fcd8d81c765b9c76993a (patch)
tree2bf74d65414324093a011cd026daa72adf8df049 /Kernel/Syscalls
parente7ef729db308d3372a129f4313a5c3e9fc0b36ae (diff)
downloadserenity-b425c2602c6dd10b5509fcd8d81c765b9c76993a.zip
Kernel: Better handling of allocation failure in profiling
If we can't allocate a PerformanceEventBuffer to store the profiling events, we now fail sys$profiling_enable() and sys$perf_event() with ENOMEM instead of carrying on with a broken buffer.
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/perf_event.cpp4
-rw-r--r--Kernel/Syscalls/profiling.cpp3
2 files changed, 5 insertions, 2 deletions
diff --git a/Kernel/Syscalls/perf_event.cpp b/Kernel/Syscalls/perf_event.cpp
index 36229bc232..3e90b95a77 100644
--- a/Kernel/Syscalls/perf_event.cpp
+++ b/Kernel/Syscalls/perf_event.cpp
@@ -31,7 +31,9 @@ namespace Kernel {
KResultOr<int> Process::sys$perf_event(int type, FlatPtr arg1, FlatPtr arg2)
{
- return ensure_perf_events().append(type, arg1, arg2);
+ if (!create_perf_events_buffer_if_needed())
+ return ENOMEM;
+ return perf_events()->append(type, arg1, arg2);
}
}
diff --git a/Kernel/Syscalls/profiling.cpp b/Kernel/Syscalls/profiling.cpp
index c02cf73215..42e1381697 100644
--- a/Kernel/Syscalls/profiling.cpp
+++ b/Kernel/Syscalls/profiling.cpp
@@ -43,7 +43,8 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
return ESRCH;
if (!is_superuser() && process->uid() != m_euid)
return EPERM;
- process->ensure_perf_events();
+ if (!process->create_perf_events_buffer_if_needed())
+ return ENOMEM;
process->set_profiling(true);
return 0;
}