Skip to content

Commit 741a900

Browse files
ruanjinjie-engwilldeacon
authored andcommitted
arm64/ptrace: Split report_syscall()
The generic syscall entry code has the form: | syscall_trace_enter() | { | ptrace_report_syscall_entry() | } | | syscall_exit_work() | { | ptrace_report_syscall_exit() | } In preparation for moving arm64 over to the generic entry code, split report_syscall() to two separate enter and exit functions to align the structure of the arm64 code with syscall_trace_enter() and syscall_exit_work() from the generic entry code. No functional changes. Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Suggested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Will Deacon <will@kernel.org>
1 parent e7e7afd commit 741a900

1 file changed

Lines changed: 29 additions & 12 deletions

File tree

arch/arm64/kernel/ptrace.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,9 +2343,10 @@ enum ptrace_syscall_dir {
23432343
PTRACE_SYSCALL_EXIT,
23442344
};
23452345

2346-
static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
2346+
static __always_inline unsigned long ptrace_save_reg(struct pt_regs *regs,
2347+
enum ptrace_syscall_dir dir,
2348+
int *regno)
23472349
{
2348-
int regno;
23492350
unsigned long saved_reg;
23502351

23512352
/*
@@ -2364,15 +2365,31 @@ static void report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir)
23642365
* - Syscall stops behave differently to seccomp and pseudo-step traps
23652366
* (the latter do not nobble any registers).
23662367
*/
2367-
regno = (is_compat_task() ? 12 : 7);
2368-
saved_reg = regs->regs[regno];
2369-
regs->regs[regno] = dir;
2368+
*regno = (is_compat_task() ? 12 : 7);
2369+
saved_reg = regs->regs[*regno];
2370+
regs->regs[*regno] = dir;
23702371

2371-
if (dir == PTRACE_SYSCALL_ENTER) {
2372-
if (ptrace_report_syscall_entry(regs))
2373-
forget_syscall(regs);
2374-
regs->regs[regno] = saved_reg;
2375-
} else if (!test_thread_flag(TIF_SINGLESTEP)) {
2372+
return saved_reg;
2373+
}
2374+
2375+
static void report_syscall_entry(struct pt_regs *regs)
2376+
{
2377+
unsigned long saved_reg;
2378+
int regno;
2379+
2380+
saved_reg = ptrace_save_reg(regs, PTRACE_SYSCALL_ENTER, &regno);
2381+
if (ptrace_report_syscall_entry(regs))
2382+
forget_syscall(regs);
2383+
regs->regs[regno] = saved_reg;
2384+
}
2385+
2386+
static void report_syscall_exit(struct pt_regs *regs)
2387+
{
2388+
unsigned long saved_reg;
2389+
int regno;
2390+
2391+
saved_reg = ptrace_save_reg(regs, PTRACE_SYSCALL_EXIT, &regno);
2392+
if (!test_thread_flag(TIF_SINGLESTEP)) {
23762393
ptrace_report_syscall_exit(regs, 0);
23772394
regs->regs[regno] = saved_reg;
23782395
} else {
@@ -2392,7 +2409,7 @@ int syscall_trace_enter(struct pt_regs *regs)
23922409
unsigned long flags = read_thread_flags();
23932410

23942411
if (flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) {
2395-
report_syscall(regs, PTRACE_SYSCALL_ENTER);
2412+
report_syscall_entry(regs);
23962413
if (flags & _TIF_SYSCALL_EMU)
23972414
return NO_SYSCALL;
23982415
}
@@ -2420,7 +2437,7 @@ void syscall_trace_exit(struct pt_regs *regs)
24202437
trace_sys_exit(regs, syscall_get_return_value(current, regs));
24212438

24222439
if (flags & (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP))
2423-
report_syscall(regs, PTRACE_SYSCALL_EXIT);
2440+
report_syscall_exit(regs);
24242441

24252442
rseq_syscall(regs);
24262443
}

0 commit comments

Comments
 (0)