summaryrefslogtreecommitdiff
path: root/Kernel/Ptrace.cpp
diff options
context:
space:
mode:
authorTom <tomut@yahoo.com>2020-12-08 21:18:45 -0700
committerAndreas Kling <kling@serenityos.org>2020-12-12 21:28:12 +0100
commitc455fc203055f88908a77f390398b16eccb903ae (patch)
treee5703bcebf8c320a813fb36dd6360b321e654a32 /Kernel/Ptrace.cpp
parent47ede74326d980c0c14abc77025794b105fdcb07 (diff)
downloadserenity-c455fc203055f88908a77f390398b16eccb903ae.zip
Kernel: Change wait blocking to Process-only blocking
This prevents zombies created by multi-threaded applications and brings our model back to closer to what other OSs do. This also means that SIGSTOP needs to halt all threads, and SIGCONT needs to resume those threads.
Diffstat (limited to 'Kernel/Ptrace.cpp')
-rw-r--r--Kernel/Ptrace.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/Kernel/Ptrace.cpp b/Kernel/Ptrace.cpp
index 39953effb8..97066bf86a 100644
--- a/Kernel/Ptrace.cpp
+++ b/Kernel/Ptrace.cpp
@@ -37,7 +37,7 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
{
ScopedSpinLock scheduler_lock(g_scheduler_lock);
if (params.request == PT_TRACE_ME) {
- if (Thread::current()->tracer())
+ if (Process::current()->tracer())
return KResult(-EBUSY);
caller.set_wait_for_tracer_at_next_execve(true);
@@ -59,11 +59,12 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
|| (peer->process().uid() != peer->process().euid())) // Disallow tracing setuid processes
return KResult(-EACCES);
+ auto& peer_process = peer->process();
if (params.request == PT_ATTACH) {
- if (peer->tracer()) {
+ if (peer_process.tracer()) {
return KResult(-EBUSY);
}
- peer->start_tracing_from(caller.pid());
+ peer_process.start_tracing_from(caller.pid());
ScopedSpinLock lock(peer->get_lock());
if (peer->state() != Thread::State::Stopped) {
peer->send_signal(SIGSTOP, &caller);
@@ -71,7 +72,7 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
return KSuccess;
}
- auto* tracer = peer->tracer();
+ auto* tracer = peer_process.tracer();
if (!tracer)
return KResult(-EPERM);
@@ -88,7 +89,7 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
break;
case PT_DETACH:
- peer->stop_tracing();
+ peer_process.stop_tracing();
peer->send_signal(SIGCONT, &caller);
break;