1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/unicore32/kernel/ptrace.c
5 * Code specific to PKUnity SoC and UniCore ISA
7 * Copyright (C) 2001-2010 GUAN Xue-tao
11 #include <linux/kernel.h>
12 #include <linux/ptrace.h>
13 #include <linux/signal.h>
14 #include <linux/uaccess.h>
15 #include <linux/sched/task_stack.h>
18 * this routine will get a word off of the processes privileged stack.
19 * the offset is how far from the base addr as stored in the THREAD.
20 * this routine assumes that all the privileged stacks are in our
23 static inline long get_user_reg(struct task_struct *task, int offset)
25 return task_pt_regs(task)->uregs[offset];
29 * this routine will put a word on the processes privileged stack.
30 * the offset is how far from the base addr as stored in the THREAD.
31 * this routine assumes that all the privileged stacks are in our
35 put_user_reg(struct task_struct *task, int offset, long data)
37 struct pt_regs newregs, *regs = task_pt_regs(task);
41 newregs.uregs[offset] = data;
43 if (valid_user_regs(&newregs)) {
44 regs->uregs[offset] = data;
52 * Called by kernel/ptrace.c when detaching..
54 void ptrace_disable(struct task_struct *child)
59 * We actually access the pt_regs stored on the kernel stack.
61 static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
62 unsigned long __user *ret)
67 if (off < sizeof(struct pt_regs))
68 tmp = get_user_reg(tsk, off >> 2);
70 return put_user(tmp, ret);
74 * We actually access the pt_regs stored on the kernel stack.
76 static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
79 if (off >= sizeof(struct pt_regs))
82 return put_user_reg(tsk, off >> 2, val);
85 long arch_ptrace(struct task_struct *child, long request,
86 unsigned long addr, unsigned long data)
89 unsigned long __user *datap = (unsigned long __user *) data;
93 ret = ptrace_read_user(child, addr, datap);
97 ret = ptrace_write_user(child, addr, data);
100 case PTRACE_GET_THREAD_AREA:
101 ret = put_user(task_pt_regs(child)->UCreg_16,
106 ret = ptrace_request(child, request, addr, data);
113 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
117 if (!test_thread_flag(TIF_SYSCALL_TRACE))
119 if (!(current->ptrace & PT_PTRACED))
123 * Save IP. IP is used to denote syscall entry/exit:
124 * IP = 0 -> entry, = 1 -> exit
127 regs->UCreg_ip = why;
129 current_thread_info()->syscall = scno;
131 /* the 0x80 provides a way for the tracing parent to distinguish
132 between a syscall stop and SIGTRAP delivery */
133 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
136 * this isn't the same as continuing with a signal, but it will do
137 * for normal use. strace only continues with a signal if the
138 * stopping signal is not SIGTRAP. -brl
140 if (current->exit_code) {
141 send_sig(current->exit_code, current, 1);
142 current->exit_code = 0;
146 return current_thread_info()->syscall;