2 * linux/arch/unicore32/kernel/ptrace.c
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/ptrace.h>
16 #include <linux/signal.h>
17 #include <linux/uaccess.h>
18 #include <linux/sched/task_stack.h>
21 * this routine will get a word off of the processes privileged stack.
22 * the offset is how far from the base addr as stored in the THREAD.
23 * this routine assumes that all the privileged stacks are in our
26 static inline long get_user_reg(struct task_struct *task, int offset)
28 return task_pt_regs(task)->uregs[offset];
32 * this routine will put a word on the processes privileged stack.
33 * the offset is how far from the base addr as stored in the THREAD.
34 * this routine assumes that all the privileged stacks are in our
38 put_user_reg(struct task_struct *task, int offset, long data)
40 struct pt_regs newregs, *regs = task_pt_regs(task);
44 newregs.uregs[offset] = data;
46 if (valid_user_regs(&newregs)) {
47 regs->uregs[offset] = data;
55 * Called by kernel/ptrace.c when detaching..
57 void ptrace_disable(struct task_struct *child)
62 * We actually access the pt_regs stored on the kernel stack.
64 static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
65 unsigned long __user *ret)
70 if (off < sizeof(struct pt_regs))
71 tmp = get_user_reg(tsk, off >> 2);
73 return put_user(tmp, ret);
77 * We actually access the pt_regs stored on the kernel stack.
79 static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
82 if (off >= sizeof(struct pt_regs))
85 return put_user_reg(tsk, off >> 2, val);
88 long arch_ptrace(struct task_struct *child, long request,
89 unsigned long addr, unsigned long data)
92 unsigned long __user *datap = (unsigned long __user *) data;
96 ret = ptrace_read_user(child, addr, datap);
100 ret = ptrace_write_user(child, addr, data);
103 case PTRACE_GET_THREAD_AREA:
104 ret = put_user(task_pt_regs(child)->UCreg_16,
109 ret = ptrace_request(child, request, addr, data);
116 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
120 if (!test_thread_flag(TIF_SYSCALL_TRACE))
122 if (!(current->ptrace & PT_PTRACED))
126 * Save IP. IP is used to denote syscall entry/exit:
127 * IP = 0 -> entry, = 1 -> exit
130 regs->UCreg_ip = why;
132 current_thread_info()->syscall = scno;
134 /* the 0x80 provides a way for the tracing parent to distinguish
135 between a syscall stop and SIGTRAP delivery */
136 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
139 * this isn't the same as continuing with a signal, but it will do
140 * for normal use. strace only continues with a signal if the
141 * stopping signal is not SIGTRAP. -brl
143 if (current->exit_code) {
144 send_sig(current->exit_code, current, 1);
145 current->exit_code = 0;
149 return current_thread_info()->syscall;