summaryrefslogtreecommitdiff
path: root/Kernel/Ptrace.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-20 23:11:17 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-20 23:20:02 +0100
commit19d3f8cab77a95b284e30f142521c6b483221324 (patch)
tree8df3f585e91113215b52d10a9a0032c9998dc1b5 /Kernel/Ptrace.cpp
parente279b45aed5509efc537fc8c831f40733d7b1028 (diff)
downloadserenity-19d3f8cab77a95b284e30f142521c6b483221324.zip
Kernel+LibC: Turn errno codes into a strongly typed enum
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
Diffstat (limited to 'Kernel/Ptrace.cpp')
-rw-r--r--Kernel/Ptrace.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/Kernel/Ptrace.cpp b/Kernel/Ptrace.cpp
index 90b65e0370..e39b3de21b 100644
--- a/Kernel/Ptrace.cpp
+++ b/Kernel/Ptrace.cpp
@@ -38,7 +38,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 (Process::current()->tracer())
- return KResult(-EBUSY);
+ return EBUSY;
caller.set_wait_for_tracer_at_next_execve(true);
return KSuccess;
@@ -49,23 +49,23 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
// long it is not the main thread. Alternatively, if this is desired, then the
// bug is that this prevents PT_ATTACH to the main thread from another thread.
if (params.tid == caller.pid().value())
- return KResult(-EINVAL);
+ return EINVAL;
auto peer = Thread::from_tid(params.tid);
if (!peer)
- return KResult(-ESRCH);
+ return ESRCH;
if ((peer->process().uid() != caller.euid())
|| (peer->process().uid() != peer->process().euid())) // Disallow tracing setuid processes
- return KResult(-EACCES);
+ return EACCES;
if (!peer->process().is_dumpable())
- return KResult(-EACCES);
+ return EACCES;
auto& peer_process = peer->process();
if (params.request == PT_ATTACH) {
if (peer_process.tracer()) {
- return KResult(-EBUSY);
+ return EBUSY;
}
peer_process.start_tracing_from(caller.pid());
ScopedSpinLock lock(peer->get_lock());
@@ -78,13 +78,13 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
auto* tracer = peer_process.tracer();
if (!tracer)
- return KResult(-EPERM);
+ return EPERM;
if (tracer->tracer_pid() != caller.pid())
- return KResult(-EBUSY);
+ return EBUSY;
if (peer->state() == Thread::State::Running)
- return KResult(-EBUSY);
+ return EBUSY;
scheduler_lock.unlock();
@@ -105,25 +105,25 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
case PT_GETREGS: {
if (!tracer->has_regs())
- return KResult(-EINVAL);
+ return EINVAL;
auto* regs = reinterpret_cast<PtraceRegisters*>(params.addr);
if (!copy_to_user(regs, &tracer->regs()))
- return KResult(-EFAULT);
+ return EFAULT;
break;
}
case PT_SETREGS: {
if (!tracer->has_regs())
- return KResult(-EINVAL);
+ return EINVAL;
PtraceRegisters regs;
if (!copy_from_user(&regs, (const PtraceRegisters*)params.addr))
- return KResult(-EFAULT);
+ return EFAULT;
auto& peer_saved_registers = peer->get_register_dump_from_stack();
// Verify that the saved registers are in usermode context
if ((peer_saved_registers.cs & 0x03) != 3)
- return KResult(-EFAULT);
+ return EFAULT;
tracer->set_regs(regs);
copy_ptrace_registers_into_kernel_registers(peer_saved_registers, regs);
@@ -133,24 +133,24 @@ KResultOr<u32> handle_syscall(const Kernel::Syscall::SC_ptrace_params& params, P
case PT_PEEK: {
Kernel::Syscall::SC_ptrace_peek_params peek_params;
if (!copy_from_user(&peek_params, reinterpret_cast<Kernel::Syscall::SC_ptrace_peek_params*>(params.addr)))
- return KResult(-EFAULT);
+ return EFAULT;
if (!is_user_address(VirtualAddress { peek_params.address }))
- return KResult(-EFAULT);
+ return EFAULT;
auto result = peer->process().peek_user_data(Userspace<const u32*> { (FlatPtr)peek_params.address });
if (result.is_error())
return result.error();
if (!copy_to_user(peek_params.out_data, &result.value()))
- return KResult(-EFAULT);
+ return EFAULT;
break;
}
case PT_POKE:
if (!is_user_address(VirtualAddress { params.addr }))
- return KResult(-EFAULT);
+ return EFAULT;
return peer->process().poke_user_data(Userspace<u32*> { (FlatPtr)params.addr }, params.data);
default:
- return KResult(-EINVAL);
+ return EINVAL;
}
return KSuccess;