1
2
3
4
5
6
7
8
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
14#include <linux/errno.h>
15#include <linux/ptrace.h>
16#include <linux/tracehook.h>
17#include <linux/user.h>
18#include <linux/personality.h>
19#include <linux/security.h>
20#include <linux/compat.h>
21#include <linux/signal.h>
22
23#include <asm/uaccess.h>
24#include <asm/pgtable.h>
25#include <asm/system.h>
26#include <asm/processor.h>
27#include <asm/asm-offsets.h>
28
29
30#define USER_PSW_BITS (PSW_N | PSW_V | PSW_CB)
31
32
33
34
35
36
37void ptrace_disable(struct task_struct *task)
38{
39 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
40 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
41
42
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
51
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{
60 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
61 set_tsk_thread_flag(task, TIF_SINGLESTEP);
62
63 if (pa_psw(task)->n) {
64 struct siginfo si;
65
66
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
77
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
84 return;
85 }
86
87
88
89
90
91
92
93
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{
103 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
104 set_tsk_thread_flag(task, TIF_BLOCKSTEP);
105
106
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
113long arch_ptrace(struct task_struct *child, long request,
114 unsigned long addr, unsigned long data)
115{
116 unsigned long tmp;
117 long ret = -EIO;
118
119 switch (request) {
120
121
122
123 case PTRACE_PEEKUSR:
124 if ((addr & (sizeof(unsigned long)-1)) ||
125 addr >= sizeof(struct pt_regs))
126 break;
127 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
128 ret = put_user(tmp, (unsigned long __user *) data);
129 break;
130
131
132
133
134
135
136
137 case PTRACE_POKEUSR:
138
139
140
141
142 if (addr == PT_PSW) {
143
144
145
146
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
155 if ((addr & (sizeof(unsigned long)-1)) ||
156 addr >= sizeof(struct pt_regs))
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
177
178
179
180
181
182
183
184
185
186
187
188
189static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
190{
191 if (offset < 0)
192 return sizeof(struct pt_regs);
193 else if (offset <= 32*4)
194 return offset * 2 + 4;
195 else if (offset <= 32*4+32*8)
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
200 return sizeof(struct pt_regs);
201}
202
203long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
204 compat_ulong_t addr, compat_ulong_t data)
205{
206 compat_uint_t tmp;
207 long ret = -EIO;
208
209 switch (request) {
210
211 case PTRACE_PEEKUSR:
212 if (addr & (sizeof(compat_uint_t)-1))
213 break;
214 addr = translate_usr_offset(addr);
215 if (addr >= sizeof(struct pt_regs))
216 break;
217
218 tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
219 ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
220 break;
221
222
223
224
225
226
227
228 case PTRACE_POKEUSR:
229
230
231
232
233 if (addr == PT_PSW) {
234
235
236
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);
242 if (addr >= sizeof(struct pt_regs))
243 break;
244 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
245
246 *(__u64 *) ((char *) task_regs(child) + addr) = data;
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
253 *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
254 *(__u32 *) ((char *) task_regs(child) + addr) = data;
255 ret = 0;
256 }
257 }
258 break;
259
260 default:
261 ret = compat_ptrace_request(child, request, addr, data);
262 break;
263 }
264
265 return ret;
266}
267#endif
268
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}
277
278void do_syscall_trace_exit(struct pt_regs *regs)
279{
280 int stepping = test_thread_flag(TIF_SINGLESTEP) ||
281 test_thread_flag(TIF_BLOCKSTEP);
282
283 if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
284 tracehook_report_syscall_exit(regs, stepping);
285}
286