Skip to content

Commit 11ba172

Browse files
FlyGoattsbogend
authored andcommitted
ptrace: Introduce exception_ip arch hook
On architectures with delay slot, architecture level instruction pointer (or program counter) in pt_regs may differ from where exception was triggered. Introduce exception_ip hook to invoke architecture code and determine actual instruction pointer to the exception. Link: https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/ Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent d55347b commit 11ba172

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

arch/mips/include/asm/ptrace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static inline long regs_return_value(struct pt_regs *regs)
154154
}
155155

156156
#define instruction_pointer(regs) ((regs)->cp0_epc)
157+
extern unsigned long exception_ip(struct pt_regs *regs);
158+
#define exception_ip(regs) exception_ip(regs)
157159
#define profile_pc(regs) instruction_pointer(regs)
158160

159161
extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall);

arch/mips/kernel/ptrace.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/seccomp.h>
3232
#include <linux/ftrace.h>
3333

34+
#include <asm/branch.h>
3435
#include <asm/byteorder.h>
3536
#include <asm/cpu.h>
3637
#include <asm/cpu-info.h>
@@ -48,6 +49,12 @@
4849
#define CREATE_TRACE_POINTS
4950
#include <trace/events/syscalls.h>
5051

52+
unsigned long exception_ip(struct pt_regs *regs)
53+
{
54+
return exception_epc(regs);
55+
}
56+
EXPORT_SYMBOL(exception_ip);
57+
5158
/*
5259
* Called by kernel/ptrace.c when detaching..
5360
*

include/linux/ptrace.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ static inline void user_single_step_report(struct pt_regs *regs)
393393
#define current_user_stack_pointer() user_stack_pointer(current_pt_regs())
394394
#endif
395395

396+
#ifndef exception_ip
397+
#define exception_ip(x) instruction_pointer(x)
398+
#endif
399+
396400
extern int task_current_syscall(struct task_struct *target, struct syscall_info *info);
397401

398402
extern void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact);

0 commit comments

Comments
 (0)