aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/x86/ptrace_syscall.c
diff options
context:
space:
mode:
authorChang S. Bae <chang.seok.bae@intel.com>2025-02-25 17:07:21 -0800
committerIngo Molnar <mingo@kernel.org>2025-02-26 13:05:28 +0100
commitdbd6b649e7d5b66c7fa95a65d67b59cf5b45f0ac (patch)
treed2869469913beefa4d2cd5272bb5760727c900e7 /tools/testing/selftests/x86/ptrace_syscall.c
parentMerge tag 'v6.14-rc4' into x86/fpu, to pick up fixes and refresh the branch (diff)
downloadlinux-dbd6b649e7d5b66c7fa95a65d67b59cf5b45f0ac.tar.gz
linux-dbd6b649e7d5b66c7fa95a65d67b59cf5b45f0ac.zip
selftests/x86: Consolidate redundant signal helper functions
The x86 selftests frequently register and clean up signal handlers, but the sethandler() and clearhandler() functions have been redundantly copied across multiple .c files. Move these functions to helpers.h to enable reuse across tests, eliminating around 250 lines of duplicate code. Converge the error handling by using ksft_exit_fail_msg(), which is functionally equivalent with err() within the selftest framework. This change is a prerequisite for the upcoming xstate selftest, which requires signal handling for registering and cleaning up handlers. Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20250226010731.2456-2-chang.seok.bae@intel.com
Diffstat (limited to 'tools/testing/selftests/x86/ptrace_syscall.c')
-rw-r--r--tools/testing/selftests/x86/ptrace_syscall.c24
1 files changed, 2 insertions, 22 deletions
diff --git a/tools/testing/selftests/x86/ptrace_syscall.c b/tools/testing/selftests/x86/ptrace_syscall.c
index 12aaa063196e..360ec88d5432 100644
--- a/tools/testing/selftests/x86/ptrace_syscall.c
+++ b/tools/testing/selftests/x86/ptrace_syscall.c
@@ -15,6 +15,8 @@
#include <asm/ptrace-abi.h>
#include <sys/auxv.h>
+#include "helpers.h"
+
/* Bitness-agnostic defines for user_regs_struct fields. */
#ifdef __x86_64__
# define user_syscall_nr orig_rax
@@ -93,18 +95,6 @@ static siginfo_t wait_trap(pid_t chld)
return si;
}
-static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
- int flags)
-{
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_sigaction = handler;
- sa.sa_flags = SA_SIGINFO | flags;
- sigemptyset(&sa.sa_mask);
- if (sigaction(sig, &sa, 0))
- err(1, "sigaction");
-}
-
static void setsigign(int sig, int flags)
{
struct sigaction sa;
@@ -116,16 +106,6 @@ static void setsigign(int sig, int flags)
err(1, "sigaction");
}
-static void clearhandler(int sig)
-{
- struct sigaction sa;
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_DFL;
- sigemptyset(&sa.sa_mask);
- if (sigaction(sig, &sa, 0))
- err(1, "sigaction");
-}
-
#ifdef __x86_64__
# define REG_BP REG_RBP
#else