From aa4d5817afcf7f8455396c01435331ed6d9637d4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 5 Sep 2021 16:11:42 +0200 Subject: [PATCH] Kernel: Use TRY() in sys$ptrace() --- Kernel/Syscalls/ptrace.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Kernel/Syscalls/ptrace.cpp b/Kernel/Syscalls/ptrace.cpp index d7be01114e8..8a671378bd5 100644 --- a/Kernel/Syscalls/ptrace.cpp +++ b/Kernel/Syscalls/ptrace.cpp @@ -52,9 +52,7 @@ static KResultOr handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par if (peer_process.tracer()) { return EBUSY; } - auto result = peer_process.start_tracing_from(caller.pid()); - if (result.is_error()) - return result.error(); + TRY(peer_process.start_tracing_from(caller.pid())); SpinlockLocker lock(peer->get_lock()); if (peer->state() != Thread::State::Stopped) { peer->send_signal(SIGSTOP, &caller); @@ -123,10 +121,8 @@ static KResultOr handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par return EFAULT; if (!Memory::is_user_address(VirtualAddress { peek_params.address })) 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())) + auto data = TRY(peer->process().peek_user_data(Userspace { (FlatPtr)peek_params.address })); + if (!copy_to_user(peek_params.out_data, &data)) return EFAULT; break; } @@ -140,10 +136,8 @@ static KResultOr handle_ptrace(const Kernel::Syscall::SC_ptrace_params& par Kernel::Syscall::SC_ptrace_peek_params peek_params {}; if (!copy_from_user(&peek_params, reinterpret_cast(params.addr))) return EFAULT; - auto result = peer->peek_debug_register(reinterpret_cast(peek_params.address)); - if (result.is_error()) - return result.error(); - if (!copy_to_user(peek_params.out_data, &result.value())) + auto data = TRY(peer->peek_debug_register(reinterpret_cast(peek_params.address))); + if (!copy_to_user(peek_params.out_data, &data)) return EFAULT; break; }