From 19d3f8cab77a95b284e30f142521c6b483221324 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 20 Jan 2021 23:11:17 +0100 Subject: 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. --- Kernel/Ptrace.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'Kernel/Ptrace.cpp') 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 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 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 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 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(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(®s, (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 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(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 { (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 { (FlatPtr)params.addr }, params.data); default: - return KResult(-EINVAL); + return EINVAL; } return KSuccess; -- cgit v1.2.3