]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/parisc/kernel/ptrace.c
ptrace: change signature of arch_ptrace()
[net-next-2.6.git] / arch / parisc / kernel / ptrace.c
CommitLineData
1da177e4
LT
1/*
2 * Kernel support for the ptrace() and syscall tracing interfaces.
3 *
4 * Copyright (C) 2000 Hewlett-Packard Co, Linuxcare Inc.
5 * Copyright (C) 2000 Matthew Wilcox <matthew@wil.cx>
6 * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
81e192d6 7 * Copyright (C) 2008 Helge Deller <deller@gmx.de>
1da177e4
LT
8 */
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
1da177e4
LT
14#include <linux/errno.h>
15#include <linux/ptrace.h>
d6b58772 16#include <linux/tracehook.h>
1da177e4
LT
17#include <linux/user.h>
18#include <linux/personality.h>
19#include <linux/security.h>
20#include <linux/compat.h>
7ed20e1a 21#include <linux/signal.h>
1da177e4
LT
22
23#include <asm/uaccess.h>
24#include <asm/pgtable.h>
25#include <asm/system.h>
26#include <asm/processor.h>
0013a854 27#include <asm/asm-offsets.h>
1da177e4
LT
28
29/* PSW bits we allow the debugger to modify */
30#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB)
31
81e192d6
HD
32/*
33 * Called by kernel/ptrace.c when detaching..
34 *
35 * Make sure single step bits etc are not set.
36 */
37void ptrace_disable(struct task_struct *task)
38{
ecd3d4bc
KM
39 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
40 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
1da177e4 41
81e192d6
HD
42 /* make sure the trap bits are not set */
43 pa_psw(task)->r = 0;
44 pa_psw(task)->t = 0;
45 pa_psw(task)->h = 0;
46 pa_psw(task)->l = 0;
47}
48
49/*
50 * The following functions are called by ptrace_resume() when
51 * enabling or disabling single/block tracing.
52 */
53void user_disable_single_step(struct task_struct *task)
54{
55 ptrace_disable(task);
56}
57
58void user_enable_single_step(struct task_struct *task)
59{
ecd3d4bc
KM
60 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
61 set_tsk_thread_flag(task, TIF_SINGLESTEP);
81e192d6
HD
62
63 if (pa_psw(task)->n) {
64 struct siginfo si;
65
66 /* Nullified, just crank over the queue. */
67 task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
68 task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
69 task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
70 pa_psw(task)->n = 0;
71 pa_psw(task)->x = 0;
72 pa_psw(task)->y = 0;
73 pa_psw(task)->z = 0;
74 pa_psw(task)->b = 0;
75 ptrace_disable(task);
76 /* Don't wake up the task, but let the
77 parent know something happened. */
78 si.si_code = TRAP_TRACE;
79 si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
80 si.si_signo = SIGTRAP;
81 si.si_errno = 0;
82 force_sig_info(SIGTRAP, &si, task);
83 /* notify_parent(task, SIGCHLD); */
84 return;
85 }
86
87 /* Enable recovery counter traps. The recovery counter
88 * itself will be set to zero on a task switch. If the
89 * task is suspended on a syscall then the syscall return
90 * path will overwrite the recovery counter with a suitable
91 * value such that it traps once back in user space. We
92 * disable interrupts in the tasks PSW here also, to avoid
93 * interrupts while the recovery counter is decrementing.
94 */
95 pa_psw(task)->r = 1;
96 pa_psw(task)->t = 0;
97 pa_psw(task)->h = 0;
98 pa_psw(task)->l = 0;
99}
100
101void user_enable_block_step(struct task_struct *task)
102{
ecd3d4bc
KM
103 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
104 set_tsk_thread_flag(task, TIF_BLOCKSTEP);
81e192d6
HD
105
106 /* Enable taken branch trap. */
107 pa_psw(task)->r = 0;
108 pa_psw(task)->t = 1;
109 pa_psw(task)->h = 0;
110 pa_psw(task)->l = 0;
111}
112
9b05a69e
NK
113long arch_ptrace(struct task_struct *child, long request,
114 unsigned long addr, unsigned long data)
81e192d6
HD
115{
116 unsigned long tmp;
117 long ret = -EIO;
1da177e4 118
81e192d6
HD
119 switch (request) {
120
121 /* Read the word at location addr in the USER area. For ptraced
122 processes, the kernel saves all regs on a syscall. */
123 case PTRACE_PEEKUSR:
9b05a69e
NK
124 if ((addr & (sizeof(unsigned long)-1)) ||
125 addr >= sizeof(struct pt_regs))
81e192d6
HD
126 break;
127 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
128 ret = put_user(tmp, (unsigned long *) data);
129 break;
130
131 /* Write the word at location addr in the USER area. This will need
132 to change when the kernel no longer saves all regs on a syscall.
133 FIXME. There is a problem at the moment in that r3-r18 are only
134 saved if the process is ptraced on syscall entry, and even then
135 those values are overwritten by actual register values on syscall
136 exit. */
137 case PTRACE_POKEUSR:
138 /* Some register values written here may be ignored in
139 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
140 * r31/r31+4, and not with the values in pt_regs.
141 */
142 if (addr == PT_PSW) {
143 /* Allow writing to Nullify, Divide-step-correction,
144 * and carry/borrow bits.
145 * BEWARE, if you set N, and then single step, it won't
146 * stop on the nullified instruction.
147 */
148 data &= USER_PSW_BITS;
149 task_regs(child)->gr[0] &= ~USER_PSW_BITS;
150 task_regs(child)->gr[0] |= data;
151 ret = 0;
152 break;
153 }
154
9b05a69e
NK
155 if ((addr & (sizeof(unsigned long)-1)) ||
156 addr >= sizeof(struct pt_regs))
81e192d6
HD
157 break;
158 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
159 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
160 (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
161 addr == PT_SAR) {
162 *(unsigned long *) ((char *) task_regs(child) + addr) = data;
163 ret = 0;
164 }
165 break;
166
167 default:
168 ret = ptrace_request(child, request, addr, data);
169 break;
170 }
171
172 return ret;
173}
174
175
176#ifdef CONFIG_COMPAT
1da177e4
LT
177
178/* This function is needed to translate 32 bit pt_regs offsets in to
179 * 64 bit pt_regs offsets. For example, a 32 bit gdb under a 64 bit kernel
180 * will request offset 12 if it wants gr3, but the lower 32 bits of
181 * the 64 bit kernels view of gr3 will be at offset 28 (3*8 + 4).
182 * This code relies on a 32 bit pt_regs being comprised of 32 bit values
183 * except for the fp registers which (a) are 64 bits, and (b) follow
184 * the gr registers at the start of pt_regs. The 32 bit pt_regs should
185 * be half the size of the 64 bit pt_regs, plus 32*4 to allow for fr[]
186 * being 64 bit in both cases.
187 */
188
ed79b86d 189static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
1da177e4
LT
190{
191 if (offset < 0)
ed79b86d 192 return sizeof(struct pt_regs);
1da177e4
LT
193 else if (offset <= 32*4) /* gr[0..31] */
194 return offset * 2 + 4;
195 else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */
196 return offset + 32*4;
197 else if (offset < sizeof(struct pt_regs)/2 + 32*4)
198 return offset * 2 + 4 - 32*8;
199 else
ed79b86d 200 return sizeof(struct pt_regs);
1da177e4 201}
1da177e4 202
81e192d6
HD
203long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
204 compat_ulong_t addr, compat_ulong_t data)
1da177e4 205{
81e192d6
HD
206 compat_uint_t tmp;
207 long ret = -EIO;
1da177e4 208
1da177e4 209 switch (request) {
1da177e4 210
81e192d6
HD
211 case PTRACE_PEEKUSR:
212 if (addr & (sizeof(compat_uint_t)-1))
213 break;
214 addr = translate_usr_offset(addr);
ed79b86d 215 if (addr >= sizeof(struct pt_regs))
81e192d6 216 break;
1da177e4 217
81e192d6
HD
218 tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
219 ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
220 break;
1da177e4
LT
221
222 /* Write the word at location addr in the USER area. This will need
223 to change when the kernel no longer saves all regs on a syscall.
224 FIXME. There is a problem at the moment in that r3-r18 are only
225 saved if the process is ptraced on syscall entry, and even then
226 those values are overwritten by actual register values on syscall
227 exit. */
228 case PTRACE_POKEUSR:
1da177e4
LT
229 /* Some register values written here may be ignored in
230 * entry.S:syscall_restore_rfi; e.g. iaoq is written with
231 * r31/r31+4, and not with the values in pt_regs.
232 */
1da177e4 233 if (addr == PT_PSW) {
81e192d6
HD
234 /* Since PT_PSW==0, it is valid for 32 bit processes
235 * under 64 bit kernels as well.
1da177e4 236 */
81e192d6
HD
237 ret = arch_ptrace(child, request, addr, data);
238 } else {
239 if (addr & (sizeof(compat_uint_t)-1))
240 break;
241 addr = translate_usr_offset(addr);
ed79b86d 242 if (addr >= sizeof(struct pt_regs))
81e192d6 243 break;
1da177e4
LT
244 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
245 /* Special case, fp regs are 64 bits anyway */
81e192d6 246 *(__u64 *) ((char *) task_regs(child) + addr) = data;
1da177e4
LT
247 ret = 0;
248 }
249 else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
250 addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
251 addr == PT_SAR+4) {
252 /* Zero the top 32 bits */
81e192d6
HD
253 *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
254 *(__u32 *) ((char *) task_regs(child) + addr) = data;
1da177e4
LT
255 ret = 0;
256 }
1da177e4 257 }
81e192d6 258 break;
1da177e4
LT
259
260 default:
81e192d6
HD
261 ret = compat_ptrace_request(child, request, addr, data);
262 break;
1da177e4
LT
263 }
264
1da177e4
LT
265 return ret;
266}
81e192d6
HD
267#endif
268
2798af1a
KM
269long do_syscall_trace_enter(struct pt_regs *regs)
270{
271 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
272 tracehook_report_syscall_entry(regs))
273 return -1L;
274
275 return regs->gr[20];
276}
1da177e4 277
2798af1a 278void do_syscall_trace_exit(struct pt_regs *regs)
1da177e4 279{
ecd3d4bc
KM
280 int stepping = test_thread_flag(TIF_SINGLESTEP) ||
281 test_thread_flag(TIF_BLOCKSTEP);
d6b58772 282
2798af1a
KM
283 if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
284 tracehook_report_syscall_exit(regs, stepping);
1da177e4 285}