2 * ptrace for 32-bit processes running on a 64-bit kernel.
5 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
7 * Derived from "arch/m68k/kernel/ptrace.c"
8 * Copyright (C) 1994 by Hamish Macdonald
9 * Taken from linux/kernel/ptrace.c and modified for M680x0.
10 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
12 * Modified by Cort Dougan (cort@hq.fsmlabs.com)
13 * and Paul Mackerras (paulus@samba.org).
15 * This file is subject to the terms and conditions of the GNU General
16 * Public License. See the file COPYING in the main directory of
17 * this archive for more details.
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
23 #include <linux/smp.h>
24 #include <linux/smp_lock.h>
25 #include <linux/errno.h>
26 #include <linux/ptrace.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/signal.h>
31 #include <asm/uaccess.h>
33 #include <asm/pgtable.h>
34 #include <asm/system.h>
36 #include "ptrace-common.h"
39 * does not yet catch signals sent when the child dies.
40 * in exit.c or in signal.c.
43 long compat_sys_ptrace(int request
, int pid
, unsigned long addr
,
46 struct task_struct
*child
;
50 if (request
== PTRACE_TRACEME
) {
51 ret
= ptrace_traceme();
55 child
= ptrace_get_task_struct(pid
);
61 if (request
== PTRACE_ATTACH
) {
62 ret
= ptrace_attach(child
);
66 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
71 /* when I and D space are separate, these will need to be fixed. */
72 case PTRACE_PEEKTEXT
: /* read word at location addr. */
73 case PTRACE_PEEKDATA
: {
77 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
79 if (copied
!= sizeof(tmp
))
81 ret
= put_user(tmp
, (u32 __user
*)data
);
86 * Read 4 bytes of the other process' storage
87 * data is a pointer specifying where the user wants the
89 * addr is a pointer in the user's storage that contains an 8 byte
90 * address in the other process of the 4 bytes that is to be read
91 * (this is run in a 32-bit process looking at a 64-bit process)
92 * when I and D space are separate, these will need to be fixed.
94 case PPC_PTRACE_PEEKTEXT_3264
:
95 case PPC_PTRACE_PEEKDATA_3264
: {
98 u32 __user
* addrOthers
;
102 /* Get the addr in the other process that we want to read */
103 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
106 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
108 if (copied
!= sizeof(tmp
))
110 ret
= put_user(tmp
, (u32 __user
*)data
);
114 /* Read a register (specified by ADDR) out of the "user area" */
115 case PTRACE_PEEKUSR
: {
120 /* convert to index and check */
121 index
= (unsigned long) addr
>> 2;
122 if ((addr
& 3) || (index
> PT_FPSCR32
))
125 if (index
< PT_FPR0
) {
126 tmp
= get_reg(child
, index
);
128 flush_fp_to_thread(child
);
130 * the user space code considers the floating point
131 * to be an array of unsigned int (32 bits) - the
132 * index passed in is based on this assumption.
134 tmp
= ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
];
136 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
141 * Read 4 bytes out of the other process' pt_regs area
142 * data is a pointer specifying where the user wants the
143 * 4 bytes copied into
144 * addr is the offset into the other process' pt_regs structure
146 * (this is run in a 32-bit process looking at a 64-bit process)
148 case PPC_PTRACE_PEEKUSR_3264
: {
156 /* Determine which register the user wants */
157 index
= (u64
)addr
>> 2;
159 /* Determine which part of the register the user wants */
161 part
= 1; /* want the 2nd half of the register (right-most). */
163 part
= 0; /* want the 1st half of the register (left-most). */
165 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
166 if ((addr
& 3) || numReg
> PT_FPSCR
)
169 if (numReg
>= PT_FPR0
) {
170 flush_fp_to_thread(child
);
171 tmp
= ((unsigned long int *)child
->thread
.fpr
)[numReg
- PT_FPR0
];
172 } else { /* register within PT_REGS struct */
173 tmp
= get_reg(child
, numReg
);
175 reg32bits
= ((u32
*)&tmp
)[part
];
176 ret
= put_user(reg32bits
, (u32 __user
*)data
);
180 /* If I and D space are separate, this will have to be fixed. */
181 case PTRACE_POKETEXT
: /* write the word at location addr. */
182 case PTRACE_POKEDATA
: {
186 if (access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 1)
194 * Write 4 bytes into the other process' storage
195 * data is the 4 bytes that the user wants written
196 * addr is a pointer in the user's storage that contains an
197 * 8 byte address in the other process where the 4 bytes
198 * that is to be written
199 * (this is run in a 32-bit process looking at a 64-bit process)
200 * when I and D space are separate, these will need to be fixed.
202 case PPC_PTRACE_POKETEXT_3264
:
203 case PPC_PTRACE_POKEDATA_3264
: {
205 u32 __user
* addrOthers
;
207 /* Get the addr in the other process that we want to write into */
209 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
212 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
213 sizeof(tmp
), 1) == sizeof(tmp
))
219 /* write the word at location addr in the USER area */
220 case PTRACE_POKEUSR
: {
224 /* convert to index and check */
225 index
= (unsigned long) addr
>> 2;
226 if ((addr
& 3) || (index
> PT_FPSCR32
))
229 if (index
== PT_ORIG_R3
)
231 if (index
< PT_FPR0
) {
232 ret
= put_reg(child
, index
, data
);
234 flush_fp_to_thread(child
);
236 * the user space code considers the floating point
237 * to be an array of unsigned int (32 bits) - the
238 * index passed in is based on this assumption.
240 ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
247 * Write 4 bytes into the other process' pt_regs area
248 * data is the 4 bytes that the user wants written
249 * addr is the offset into the other process' pt_regs structure
250 * that is to be written into
251 * (this is run in a 32-bit process looking at a 64-bit process)
253 case PPC_PTRACE_POKEUSR_3264
: {
258 /* Determine which register the user wants */
259 index
= (u64
)addr
>> 2;
262 * Validate the input - check to see if address is on the
263 * wrong boundary or beyond the end of the user area
265 if ((addr
& 3) || (numReg
> PT_FPSCR
))
267 /* Insure it is a register we let them change */
268 if ((numReg
== PT_ORIG_R3
)
269 || ((numReg
> PT_CCR
) && (numReg
< PT_FPR0
)))
271 if (numReg
>= PT_FPR0
) {
272 flush_fp_to_thread(child
);
274 if (numReg
== PT_MSR
)
275 data
= (data
& MSR_DEBUGCHANGE
)
276 | (child
->thread
.regs
->msr
& ~MSR_DEBUGCHANGE
);
277 ((u32
*)child
->thread
.regs
)[index
] = data
;
282 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
283 case PTRACE_CONT
: { /* restart after signal. */
285 if (!valid_signal(data
))
287 if (request
== PTRACE_SYSCALL
)
288 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
290 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
291 child
->exit_code
= data
;
292 /* make sure the single step bit is not set. */
293 clear_single_step(child
);
294 wake_up_process(child
);
300 * make the child exit. Best I can do is send it a sigkill.
301 * perhaps it should be put in the status that it wants to
306 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
308 child
->exit_code
= SIGKILL
;
309 /* make sure the single step bit is not set. */
310 clear_single_step(child
);
311 wake_up_process(child
);
315 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
317 if (!valid_signal(data
))
319 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
320 set_single_step(child
);
321 child
->exit_code
= data
;
322 /* give it a chance to run. */
323 wake_up_process(child
);
328 case PTRACE_GET_DEBUGREG
: {
330 /* We only support one DABR and no IABRS at the moment */
333 ret
= put_user(child
->thread
.dabr
, (u32 __user
*)data
);
337 case PTRACE_SET_DEBUGREG
:
338 ret
= ptrace_set_debugreg(child
, addr
, data
);
342 ret
= ptrace_detach(child
, data
);
345 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
347 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
348 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
350 for (i
= 0; i
< 32; i
++) {
351 ret
= put_user(*reg
, tmp
);
360 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
362 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
363 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
365 for (i
= 0; i
< 32; i
++) {
366 ret
= get_user(*reg
, tmp
);
375 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
377 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
378 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
380 flush_fp_to_thread(child
);
382 for (i
= 0; i
< 32; i
++) {
383 ret
= put_user(*reg
, tmp
);
392 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
394 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
395 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
397 flush_fp_to_thread(child
);
399 for (i
= 0; i
< 32; i
++) {
400 ret
= get_user(*reg
, tmp
);
409 case PTRACE_GETEVENTMSG
:
410 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) data
);
413 #ifdef CONFIG_ALTIVEC
414 case PTRACE_GETVRREGS
:
415 /* Get the child altivec register state. */
416 flush_altivec_to_thread(child
);
417 ret
= get_vrregs((unsigned long __user
*)data
, child
);
420 case PTRACE_SETVRREGS
:
421 /* Set the child altivec register state. */
422 flush_altivec_to_thread(child
);
423 ret
= set_vrregs(child
, (unsigned long __user
*)data
);
428 ret
= ptrace_request(child
, request
, addr
, data
);
432 put_task_struct(child
);