aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k/kernel/ptrace.c
diff options
context:
space:
mode:
authorRoman Zippel <zippel@linux-m68k.org>2005-09-03 18:57:08 -0400
committerLinus Torvalds <torvalds@evo.osdl.org>2005-09-05 03:06:19 -0400
commit69f447cffb911bb2d9737fa905f6d983ec2aa5d3 (patch)
treeee1f932ab2ffb6ff923ef20c708787875f3862bb /arch/m68k/kernel/ptrace.c
parentb3319f50acbe3a26c258cdd899b9baa2e5e94efc (diff)
[PATCH] m68k: sys_ptrace cleanup
- create helper function singlestep_disable() - move variable definitions to the top of the function - use "out_eio" label as common error destination - don't clear failure value for PTRACE_SETREGS/PTRACE_GETREGS Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/m68k/kernel/ptrace.c')
-rw-r--r--arch/m68k/kernel/ptrace.c175
1 files changed, 64 insertions, 111 deletions
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c
index 9bb25ea78677..8ed1b01a6a87 100644
--- a/arch/m68k/kernel/ptrace.c
+++ b/arch/m68k/kernel/ptrace.c
@@ -103,48 +103,56 @@ static inline int put_reg(struct task_struct *task, int regno,
103} 103}
104 104
105/* 105/*
106 * Called by kernel/ptrace.c when detaching..
107 *
108 * Make sure the single step bit is not set. 106 * Make sure the single step bit is not set.
109 */ 107 */
110void ptrace_disable(struct task_struct *child) 108static inline void singlestep_disable(struct task_struct *child)
111{ 109{
112 unsigned long tmp; 110 unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
113 /* make sure the single step bit is not set. */
114 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
115 put_reg(child, PT_SR, tmp); 111 put_reg(child, PT_SR, tmp);
116 child->thread.work.delayed_trace = 0; 112 child->thread.work.delayed_trace = 0;
113}
114
115/*
116 * Called by kernel/ptrace.c when detaching..
117 */
118void ptrace_disable(struct task_struct *child)
119{
120 singlestep_disable(child);
117 child->thread.work.syscall_trace = 0; 121 child->thread.work.syscall_trace = 0;
118} 122}
119 123
120asmlinkage int sys_ptrace(long request, long pid, long addr, long data) 124asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
121{ 125{
122 struct task_struct *child; 126 struct task_struct *child;
123 int ret; 127 unsigned long tmp;
128 int i, ret = 0;
124 129
125 lock_kernel(); 130 lock_kernel();
126 ret = -EPERM;
127 if (request == PTRACE_TRACEME) { 131 if (request == PTRACE_TRACEME) {
128 /* are we already being traced? */ 132 /* are we already being traced? */
129 if (current->ptrace & PT_PTRACED) 133 if (current->ptrace & PT_PTRACED) {
134 ret = -EPERM;
130 goto out; 135 goto out;
136 }
131 /* set the ptrace bit in the process flags. */ 137 /* set the ptrace bit in the process flags. */
132 current->ptrace |= PT_PTRACED; 138 current->ptrace |= PT_PTRACED;
133 ret = 0;
134 goto out; 139 goto out;
135 } 140 }
136 ret = -ESRCH;
137 read_lock(&tasklist_lock); 141 read_lock(&tasklist_lock);
138 child = find_task_by_pid(pid); 142 child = find_task_by_pid(pid);
139 if (child) 143 if (child)
140 get_task_struct(child); 144 get_task_struct(child);
141 read_unlock(&tasklist_lock); 145 read_unlock(&tasklist_lock);
142 if (!child) 146 if (unlikely(!child)) {
147 ret = -ESRCH;
143 goto out; 148 goto out;
149 }
144 150
145 ret = -EPERM; 151 /* you may not mess with init */
146 if (pid == 1) /* you may not mess with init */ 152 if (unlikely(pid == 1)) {
153 ret = -EPERM;
147 goto out_tsk; 154 goto out_tsk;
155 }
148 156
149 if (request == PTRACE_ATTACH) { 157 if (request == PTRACE_ATTACH) {
150 ret = ptrace_attach(child); 158 ret = ptrace_attach(child);
@@ -152,86 +160,62 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
152 } 160 }
153 161
154 ret = ptrace_check_attach(child, request == PTRACE_KILL); 162 ret = ptrace_check_attach(child, request == PTRACE_KILL);
155 if (ret < 0) 163 if (ret)
156 goto out_tsk; 164 goto out_tsk;
157 165
158 switch (request) { 166 switch (request) {
159 /* when I and D space are separate, these will need to be fixed. */ 167 /* when I and D space are separate, these will need to be fixed. */
160 case PTRACE_PEEKTEXT: /* read word at location addr. */ 168 case PTRACE_PEEKTEXT: /* read word at location addr. */
161 case PTRACE_PEEKDATA: { 169 case PTRACE_PEEKDATA:
162 unsigned long tmp; 170 i = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
163 int copied; 171 if (i != sizeof(tmp))
164 172 goto out_eio;
165 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
166 ret = -EIO;
167 if (copied != sizeof(tmp))
168 break;
169 ret = put_user(tmp, (unsigned long *)data); 173 ret = put_user(tmp, (unsigned long *)data);
170 break; 174 break;
171 }
172 175
173 /* read the word at location addr in the USER area. */ 176 /* read the word at location addr in the USER area. */
174 case PTRACE_PEEKUSR: { 177 case PTRACE_PEEKUSR:
175 unsigned long tmp; 178 if (addr & 3)
176 179 goto out_eio;
177 ret = -EIO; 180 addr >>= 2; /* temporary hack. */
178 if ((addr & 3) || addr < 0 ||
179 addr > sizeof(struct user) - 3)
180 break;
181 181
182 tmp = 0; /* Default return condition */ 182 if (addr >= 0 && addr < 19) {
183 addr = addr >> 2; /* temporary hack. */
184 ret = -EIO;
185 if (addr < 19) {
186 tmp = get_reg(child, addr); 183 tmp = get_reg(child, addr);
187 if (addr == PT_SR) 184 if (addr == PT_SR)
188 tmp >>= 16; 185 tmp >>= 16;
189 } else if (addr >= 21 && addr < 49) { 186 } else if (addr >= 21 && addr < 49) {
190 tmp = child->thread.fp[addr - 21]; 187 tmp = child->thread.fp[addr - 21];
191#ifdef CONFIG_M68KFPU_EMU
192 /* Convert internal fpu reg representation 188 /* Convert internal fpu reg representation
193 * into long double format 189 * into long double format
194 */ 190 */
195 if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) 191 if (FPU_IS_EMU && (addr < 45) && !(addr % 3))
196 tmp = ((tmp & 0xffff0000) << 15) | 192 tmp = ((tmp & 0xffff0000) << 15) |
197 ((tmp & 0x0000ffff) << 16); 193 ((tmp & 0x0000ffff) << 16);
198#endif
199 } else 194 } else
200 break; 195 break;
201 ret = put_user(tmp, (unsigned long *)data); 196 ret = put_user(tmp, (unsigned long *)data);
202 break; 197 break;
203 }
204 198
205 /* when I and D space are separate, this will have to be fixed. */ 199 /* when I and D space are separate, this will have to be fixed. */
206 case PTRACE_POKETEXT: /* write the word at location addr. */ 200 case PTRACE_POKETEXT: /* write the word at location addr. */
207 case PTRACE_POKEDATA: 201 case PTRACE_POKEDATA:
208 ret = 0; 202 if (access_process_vm(child, addr, &data, sizeof(data), 1) != sizeof(data))
209 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data)) 203 goto out_eio;
210 break;
211 ret = -EIO;
212 break; 204 break;
213 205
214 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 206 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
215 ret = -EIO; 207 if (addr & 3)
216 if ((addr & 3) || addr < 0 || 208 goto out_eio;
217 addr > sizeof(struct user) - 3) 209 addr >>= 2; /* temporary hack. */
218 break;
219
220 addr = addr >> 2; /* temporary hack. */
221 210
222 if (addr == PT_SR) { 211 if (addr == PT_SR) {
223 data &= SR_MASK; 212 data &= SR_MASK;
224 data <<= 16; 213 data <<= 16;
225 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); 214 data |= get_reg(child, PT_SR) & ~(SR_MASK << 16);
226 } 215 } else if (addr >= 0 && addr < 19) {
227 if (addr < 19) {
228 if (put_reg(child, addr, data)) 216 if (put_reg(child, addr, data))
229 break; 217 goto out_eio;
230 ret = 0; 218 } else if (addr >= 21 && addr < 48) {
231 break;
232 }
233 if (addr >= 21 && addr < 48) {
234#ifdef CONFIG_M68KFPU_EMU
235 /* Convert long double format 219 /* Convert long double format
236 * into internal fpu reg representation 220 * into internal fpu reg representation
237 */ 221 */
@@ -240,60 +224,42 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
240 data = (data & 0xffff0000) | 224 data = (data & 0xffff0000) |
241 ((data & 0x0000ffff) >> 1); 225 ((data & 0x0000ffff) >> 1);
242 } 226 }
243#endif
244 child->thread.fp[addr - 21] = data; 227 child->thread.fp[addr - 21] = data;
245 ret = 0; 228 } else
246 } 229 goto out_eio;
247 break; 230 break;
248 231
249 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ 232 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
250 case PTRACE_CONT: { /* restart after signal. */ 233 case PTRACE_CONT: /* restart after signal. */
251 long tmp;
252
253 ret = -EIO;
254 if (!valid_signal(data)) 234 if (!valid_signal(data))
255 break; 235 goto out_eio;
256 if (request == PTRACE_SYSCALL) { 236
237 if (request == PTRACE_SYSCALL)
257 child->thread.work.syscall_trace = ~0; 238 child->thread.work.syscall_trace = ~0;
258 } else { 239 else
259 child->thread.work.syscall_trace = 0; 240 child->thread.work.syscall_trace = 0;
260 }
261 child->exit_code = data; 241 child->exit_code = data;
262 /* make sure the single step bit is not set. */ 242 singlestep_disable(child);
263 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
264 put_reg(child, PT_SR, tmp);
265 child->thread.work.delayed_trace = 0;
266 wake_up_process(child); 243 wake_up_process(child);
267 ret = 0;
268 break; 244 break;
269 }
270 245
271 /* 246 /*
272 * make the child exit. Best I can do is send it a sigkill. 247 * make the child exit. Best I can do is send it a sigkill.
273 * perhaps it should be put in the status that it wants to 248 * perhaps it should be put in the status that it wants to
274 * exit. 249 * exit.
275 */ 250 */
276 case PTRACE_KILL: { 251 case PTRACE_KILL:
277 long tmp;
278
279 ret = 0;
280 if (child->exit_state == EXIT_ZOMBIE) /* already dead */ 252 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
281 break; 253 break;
282 child->exit_code = SIGKILL; 254 child->exit_code = SIGKILL;
283 /* make sure the single step bit is not set. */ 255 singlestep_disable(child);
284 tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16);
285 put_reg(child, PT_SR, tmp);
286 child->thread.work.delayed_trace = 0;
287 wake_up_process(child); 256 wake_up_process(child);
288 break; 257 break;
289 }
290
291 case PTRACE_SINGLESTEP: { /* set the trap flag. */
292 long tmp;
293 258
294 ret = -EIO; 259 case PTRACE_SINGLESTEP: /* set the trap flag. */
295 if (!valid_signal(data)) 260 if (!valid_signal(data))
296 break; 261 goto out_eio;
262
297 child->thread.work.syscall_trace = 0; 263 child->thread.work.syscall_trace = 0;
298 tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16); 264 tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16);
299 put_reg(child, PT_SR, tmp); 265 put_reg(child, PT_SR, tmp);
@@ -302,39 +268,29 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
302 child->exit_code = data; 268 child->exit_code = data;
303 /* give it a chance to run. */ 269 /* give it a chance to run. */
304 wake_up_process(child); 270 wake_up_process(child);
305 ret = 0;
306 break; 271 break;
307 }
308 272
309 case PTRACE_DETACH: /* detach a process that was attached. */ 273 case PTRACE_DETACH: /* detach a process that was attached. */
310 ret = ptrace_detach(child, data); 274 ret = ptrace_detach(child, data);
311 break; 275 break;
312 276
313 case PTRACE_GETREGS: { /* Get all gp regs from the child. */ 277 case PTRACE_GETREGS: /* Get all gp regs from the child. */
314 int i;
315 unsigned long tmp;
316 for (i = 0; i < 19; i++) { 278 for (i = 0; i < 19; i++) {
317 tmp = get_reg(child, i); 279 tmp = get_reg(child, i);
318 if (i == PT_SR) 280 if (i == PT_SR)
319 tmp >>= 16; 281 tmp >>= 16;
320 if (put_user(tmp, (unsigned long *)data)) { 282 ret = put_user(tmp, (unsigned long *)data);
321 ret = -EFAULT; 283 if (ret)
322 break; 284 break;
323 }
324 data += sizeof(long); 285 data += sizeof(long);
325 } 286 }
326 ret = 0;
327 break; 287 break;
328 }
329 288
330 case PTRACE_SETREGS: { /* Set all gp regs in the child. */ 289 case PTRACE_SETREGS: /* Set all gp regs in the child. */
331 int i;
332 unsigned long tmp;
333 for (i = 0; i < 19; i++) { 290 for (i = 0; i < 19; i++) {
334 if (get_user(tmp, (unsigned long *)data)) { 291 ret = get_user(tmp, (unsigned long *)data);
335 ret = -EFAULT; 292 if (ret)
336 break; 293 break;
337 }
338 if (i == PT_SR) { 294 if (i == PT_SR) {
339 tmp &= SR_MASK; 295 tmp &= SR_MASK;
340 tmp <<= 16; 296 tmp <<= 16;
@@ -343,25 +299,19 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
343 put_reg(child, i, tmp); 299 put_reg(child, i, tmp);
344 data += sizeof(long); 300 data += sizeof(long);
345 } 301 }
346 ret = 0;
347 break; 302 break;
348 }
349 303
350 case PTRACE_GETFPREGS: { /* Get the child FPU state. */ 304 case PTRACE_GETFPREGS: /* Get the child FPU state. */
351 ret = 0;
352 if (copy_to_user((void *)data, &child->thread.fp, 305 if (copy_to_user((void *)data, &child->thread.fp,
353 sizeof(struct user_m68kfp_struct))) 306 sizeof(struct user_m68kfp_struct)))
354 ret = -EFAULT; 307 ret = -EFAULT;
355 break; 308 break;
356 }
357 309
358 case PTRACE_SETFPREGS: { /* Set the child FPU state. */ 310 case PTRACE_SETFPREGS: /* Set the child FPU state. */
359 ret = 0;
360 if (copy_from_user(&child->thread.fp, (void *)data, 311 if (copy_from_user(&child->thread.fp, (void *)data,
361 sizeof(struct user_m68kfp_struct))) 312 sizeof(struct user_m68kfp_struct)))
362 ret = -EFAULT; 313 ret = -EFAULT;
363 break; 314 break;
364 }
365 315
366 default: 316 default:
367 ret = ptrace_request(child, request, addr, data); 317 ret = ptrace_request(child, request, addr, data);
@@ -372,6 +322,9 @@ out_tsk:
372out: 322out:
373 unlock_kernel(); 323 unlock_kernel();
374 return ret; 324 return ret;
325out_eio:
326 ret = -EIO;
327 goto out_tsk;
375} 328}
376 329
377asmlinkage void syscall_trace(void) 330asmlinkage void syscall_trace(void)