mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
Kernel: Add a syscall to clear the profiling buffer
While profiling all processes the profile buffer lives forever. Once you have copied the profile to disk, there's no need to keep it in memory. This syscall surfaces the ability to clear that buffer.
This commit is contained in:
parent
cdd9faaf39
commit
4ed682aebc
4 changed files with 42 additions and 0 deletions
|
@ -67,6 +67,8 @@ KResultOr<int> Process::sys$profiling_enable(pid_t pid)
|
|||
|
||||
KResultOr<int> Process::sys$profiling_disable(pid_t pid)
|
||||
{
|
||||
REQUIRE_NO_PROMISES;
|
||||
|
||||
if (pid == -1) {
|
||||
if (!is_superuser())
|
||||
return EPERM;
|
||||
|
@ -87,4 +89,35 @@ KResultOr<int> Process::sys$profiling_disable(pid_t pid)
|
|||
return 0;
|
||||
}
|
||||
|
||||
KResultOr<int> Process::sys$profiling_free_buffer(pid_t pid)
|
||||
{
|
||||
REQUIRE_NO_PROMISES;
|
||||
|
||||
if (pid == -1) {
|
||||
if (!is_superuser())
|
||||
return EPERM;
|
||||
|
||||
OwnPtr<PerformanceEventBuffer> perf_events;
|
||||
|
||||
{
|
||||
ScopedCritical critical;
|
||||
|
||||
perf_events = g_global_perf_events;
|
||||
g_global_perf_events = nullptr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ScopedSpinLock lock(g_processes_lock);
|
||||
auto process = Process::from_pid(pid);
|
||||
if (!process)
|
||||
return ESRCH;
|
||||
if (!is_superuser() && process->uid() != euid())
|
||||
return EPERM;
|
||||
if (process->is_profiling())
|
||||
return EINVAL;
|
||||
process->delete_perf_events_buffer();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue