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/processor.h>
26#include <asm/asm-offsets.h>
27
28
29#define USER_PSW_BITS (PSW_N | PSW_B | PSW_V | PSW_CB)
30
31
32
33
34
35
36void ptrace_disable(struct task_struct *task)
37{
38 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
39 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
40
41
42 pa_psw(task)->r = 0;
43 pa_psw(task)->t = 0;
44 pa_psw(task)->h = 0;
45 pa_psw(task)->l = 0;
46}
47
48
49
50
51
52void user_disable_single_step(struct task_struct *task)
53{
54 ptrace_disable(task);
55}
56
57void user_enable_single_step(struct task_struct *task)
58{
59 clear_tsk_thread_flag(task, TIF_BLOCKSTEP);
60 set_tsk_thread_flag(task, TIF_SINGLESTEP);
61
62 if (pa_psw(task)->n) {
63 struct siginfo si;
64
65
66 task_regs(task)->iaoq[0] = task_regs(task)->iaoq[1];
67 task_regs(task)->iasq[0] = task_regs(task)->iasq[1];
68 task_regs(task)->iaoq[1] = task_regs(task)->iaoq[0] + 4;
69 pa_psw(task)->n = 0;
70 pa_psw(task)->x = 0;
71 pa_psw(task)->y = 0;
72 pa_psw(task)->z = 0;
73 pa_psw(task)->b = 0;
74 ptrace_disable(task);
75
76
77 si.si_code = TRAP_TRACE;
78 si.si_addr = (void __user *) (task_regs(task)->iaoq[0] & ~3);
79 si.si_signo = SIGTRAP;
80 si.si_errno = 0;
81 force_sig_info(SIGTRAP, &si, task);
82
83 return;
84 }
85
86
87
88
89
90
91
92
93
94 pa_psw(task)->r = 1;
95 pa_psw(task)->t = 0;
96 pa_psw(task)->h = 0;
97 pa_psw(task)->l = 0;
98}
99
100void user_enable_block_step(struct task_struct *task)
101{
102 clear_tsk_thread_flag(task, TIF_SINGLESTEP);
103 set_tsk_thread_flag(task, TIF_BLOCKSTEP);
104
105
106 pa_psw(task)->r = 0;
107 pa_psw(task)->t = 1;
108 pa_psw(task)->h = 0;
109 pa_psw(task)->l = 0;
110}
111
112long arch_ptrace(struct task_struct *child, long request,
113 unsigned long addr, unsigned long data)
114{
115 unsigned long tmp;
116 long ret = -EIO;
117
118 switch (request) {
119
120
121
122 case PTRACE_PEEKUSR:
123 if ((addr & (sizeof(unsigned long)-1)) ||
124 addr >= sizeof(struct pt_regs))
125 break;
126 tmp = *(unsigned long *) ((char *) task_regs(child) + addr);
127 ret = put_user(tmp, (unsigned long __user *) data);
128 break;
129
130
131
132
133
134
135
136 case PTRACE_POKEUSR:
137
138
139
140
141 if (addr == PT_PSW) {
142
143
144
145
146
147 data &= USER_PSW_BITS;
148 task_regs(child)->gr[0] &= ~USER_PSW_BITS;
149 task_regs(child)->gr[0] |= data;
150 ret = 0;
151 break;
152 }
153
154 if ((addr & (sizeof(unsigned long)-1)) ||
155 addr >= sizeof(struct pt_regs))
156 break;
157 if ((addr >= PT_GR1 && addr <= PT_GR31) ||
158 addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
159 (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
160 addr == PT_SAR) {
161 *(unsigned long *) ((char *) task_regs(child) + addr) = data;
162 ret = 0;
163 }
164 break;
165
166 default:
167 ret = ptrace_request(child, request, addr, data);
168 break;
169 }
170
171 return ret;
172}
173
174
175#ifdef CONFIG_COMPAT
176
177
178
179
180
181
182
183
184
185
186
187
188static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
189{
190 if (offset < 0)
191 return sizeof(struct pt_regs);
192 else if (offset <= 32*4)
193 return offset * 2 + 4;
194 else if (offset <= 32*4+32*8)
195 return offset + 32*4;
196 else if (offset < sizeof(struct pt_regs)/2 + 32*4)
197 return offset * 2 + 4 - 32*8;
198 else
199 return sizeof(struct pt_regs);
200}
201
202long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
203 compat_ulong_t addr, compat_ulong_t data)
204{
205 compat_uint_t tmp;
206 long ret = -EIO;
207
208 switch (request) {
209
210 case PTRACE_PEEKUSR:
211 if (addr & (sizeof(compat_uint_t)-1))
212 break;
213 addr = translate_usr_offset(addr);
214 if (addr >= sizeof(struct pt_regs))
215 break;
216
217 tmp = *(compat_uint_t *) ((char *) task_regs(child) + addr);
218 ret = put_user(tmp, (compat_uint_t *) (unsigned long) data);
219 break;
220
221
222
223
224
225
226
227 case PTRACE_POKEUSR:
228
229
230
231
232 if (addr == PT_PSW) {
233
234
235
236 ret = arch_ptrace(child, request, addr, data);
237 } else {
238 if (addr & (sizeof(compat_uint_t)-1))
239 break;
240 addr = translate_usr_offset(addr);
241 if (addr >= sizeof(struct pt_regs))
242 break;
243 if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
244
245 *(__u64 *) ((char *) task_regs(child) + addr) = data;
246 ret = 0;
247 }
248 else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
249 addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4 ||
250 addr == PT_SAR+4) {
251
252 *(__u32 *) ((char *) task_regs(child) + addr - 4) = 0;
253 *(__u32 *) ((char *) task_regs(child) + addr) = data;
254 ret = 0;
255 }
256 }
257 break;
258
259 default:
260 ret = compat_ptrace_request(child, request, addr, data);
261 break;
262 }
263
264 return ret;
265}
266#endif
267
268long do_syscall_trace_enter(struct pt_regs *regs)
269{
270 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
271 tracehook_report_syscall_entry(regs))
272 return -1L;
273
274 return regs->gr[20];
275}
276
277void do_syscall_trace_exit(struct pt_regs *regs)
278{
279 int stepping = test_thread_flag(TIF_SINGLESTEP) ||
280 test_thread_flag(TIF_BLOCKSTEP);
281
282 if (stepping || test_thread_flag(TIF_SYSCALL_TRACE))
283 tracehook_report_syscall_exit(regs, stepping);
284}
285