2 * linux/arch/ppc64/kernel/ptrace32.c
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@linuxcare.com.au).
15 * This file is subject to the terms and conditions of the GNU General
16 * Public License. See the file README.legal in the main directory of
17 * this archive for more details.
20 #include <linux/config.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/errno.h>
27 #include <linux/ptrace.h>
28 #include <linux/user.h>
29 #include <linux/security.h>
30 #include <linux/signal.h>
32 #include <asm/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/system.h>
36 #include <asm/ptrace-common.h>
39 * does not yet catch signals sent when the child dies.
40 * in exit.c or in signal.c.
43 int sys32_ptrace(long request
, long pid
, unsigned long addr
, unsigned long data
)
45 struct task_struct
*child
;
49 if (request
== PTRACE_TRACEME
) {
50 /* are we already being traced? */
51 if (current
->ptrace
& PT_PTRACED
)
53 ret
= security_ptrace(current
->parent
, current
);
56 /* set the ptrace bit in the process flags. */
57 current
->ptrace
|= PT_PTRACED
;
62 read_lock(&tasklist_lock
);
63 child
= find_task_by_pid(pid
);
65 get_task_struct(child
);
66 read_unlock(&tasklist_lock
);
71 if (pid
== 1) /* you may not mess with init */
74 if (request
== PTRACE_ATTACH
) {
75 ret
= ptrace_attach(child
);
79 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
84 /* when I and D space are separate, these will need to be fixed. */
85 case PTRACE_PEEKTEXT
: /* read word at location addr. */
86 case PTRACE_PEEKDATA
: {
90 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
92 if (copied
!= sizeof(tmp
))
94 ret
= put_user(tmp
, (u32 __user
*)data
);
99 * Read 4 bytes of the other process' storage
100 * data is a pointer specifying where the user wants the
101 * 4 bytes copied into
102 * addr is a pointer in the user's storage that contains an 8 byte
103 * address in the other process of the 4 bytes that is to be read
104 * (this is run in a 32-bit process looking at a 64-bit process)
105 * when I and D space are separate, these will need to be fixed.
107 case PPC_PTRACE_PEEKTEXT_3264
:
108 case PPC_PTRACE_PEEKDATA_3264
: {
111 u32 __user
* addrOthers
;
115 /* Get the addr in the other process that we want to read */
116 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
119 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
121 if (copied
!= sizeof(tmp
))
123 ret
= put_user(tmp
, (u32 __user
*)data
);
127 /* Read a register (specified by ADDR) out of the "user area" */
128 case PTRACE_PEEKUSR
: {
133 /* convert to index and check */
134 index
= (unsigned long) addr
>> 2;
135 if ((addr
& 3) || (index
> PT_FPSCR32
))
138 if (index
< PT_FPR0
) {
139 tmp
= get_reg(child
, index
);
141 flush_fp_to_thread(child
);
143 * the user space code considers the floating point
144 * to be an array of unsigned int (32 bits) - the
145 * index passed in is based on this assumption.
147 tmp
= ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
];
149 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
154 * Read 4 bytes out of the other process' pt_regs area
155 * data is a pointer specifying where the user wants the
156 * 4 bytes copied into
157 * addr is the offset into the other process' pt_regs structure
159 * (this is run in a 32-bit process looking at a 64-bit process)
161 case PPC_PTRACE_PEEKUSR_3264
: {
169 /* Determine which register the user wants */
170 index
= (u64
)addr
>> 2;
172 /* Determine which part of the register the user wants */
174 part
= 1; /* want the 2nd half of the register (right-most). */
176 part
= 0; /* want the 1st half of the register (left-most). */
178 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
179 if ((addr
& 3) || numReg
> PT_FPSCR
)
182 if (numReg
>= PT_FPR0
) {
183 flush_fp_to_thread(child
);
184 tmp
= ((unsigned long int *)child
->thread
.fpr
)[numReg
- PT_FPR0
];
185 } else { /* register within PT_REGS struct */
186 tmp
= get_reg(child
, numReg
);
188 reg32bits
= ((u32
*)&tmp
)[part
];
189 ret
= put_user(reg32bits
, (u32 __user
*)data
);
193 /* If I and D space are separate, this will have to be fixed. */
194 case PTRACE_POKETEXT
: /* write the word at location addr. */
195 case PTRACE_POKEDATA
: {
199 if (access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 1)
207 * Write 4 bytes into the other process' storage
208 * data is the 4 bytes that the user wants written
209 * addr is a pointer in the user's storage that contains an
210 * 8 byte address in the other process where the 4 bytes
211 * that is to be written
212 * (this is run in a 32-bit process looking at a 64-bit process)
213 * when I and D space are separate, these will need to be fixed.
215 case PPC_PTRACE_POKETEXT_3264
:
216 case PPC_PTRACE_POKEDATA_3264
: {
218 u32 __user
* addrOthers
;
220 /* Get the addr in the other process that we want to write into */
222 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
225 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
226 sizeof(tmp
), 1) == sizeof(tmp
))
232 /* write the word at location addr in the USER area */
233 case PTRACE_POKEUSR
: {
237 /* convert to index and check */
238 index
= (unsigned long) addr
>> 2;
239 if ((addr
& 3) || (index
> PT_FPSCR32
))
242 if (index
== PT_ORIG_R3
)
244 if (index
< PT_FPR0
) {
245 ret
= put_reg(child
, index
, data
);
247 flush_fp_to_thread(child
);
249 * the user space code considers the floating point
250 * to be an array of unsigned int (32 bits) - the
251 * index passed in is based on this assumption.
253 ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
260 * Write 4 bytes into the other process' pt_regs area
261 * data is the 4 bytes that the user wants written
262 * addr is the offset into the other process' pt_regs structure
263 * that is to be written into
264 * (this is run in a 32-bit process looking at a 64-bit process)
266 case PPC_PTRACE_POKEUSR_3264
: {
271 /* Determine which register the user wants */
272 index
= (u64
)addr
>> 2;
275 * Validate the input - check to see if address is on the
276 * wrong boundary or beyond the end of the user area
278 if ((addr
& 3) || (numReg
> PT_FPSCR
))
280 /* Insure it is a register we let them change */
281 if ((numReg
== PT_ORIG_R3
)
282 || ((numReg
> PT_CCR
) && (numReg
< PT_FPR0
)))
284 if (numReg
>= PT_FPR0
) {
285 flush_fp_to_thread(child
);
287 if (numReg
== PT_MSR
)
288 data
= (data
& MSR_DEBUGCHANGE
)
289 | (child
->thread
.regs
->msr
& ~MSR_DEBUGCHANGE
);
290 ((u32
*)child
->thread
.regs
)[index
] = data
;
295 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
296 case PTRACE_CONT
: { /* restart after signal. */
298 if (!valid_signal(data
))
300 if (request
== PTRACE_SYSCALL
)
301 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
303 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
304 child
->exit_code
= data
;
305 /* make sure the single step bit is not set. */
306 clear_single_step(child
);
307 wake_up_process(child
);
313 * make the child exit. Best I can do is send it a sigkill.
314 * perhaps it should be put in the status that it wants to
319 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
321 child
->exit_code
= SIGKILL
;
322 /* make sure the single step bit is not set. */
323 clear_single_step(child
);
324 wake_up_process(child
);
328 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
330 if (!valid_signal(data
))
332 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
333 set_single_step(child
);
334 child
->exit_code
= data
;
335 /* give it a chance to run. */
336 wake_up_process(child
);
341 case PTRACE_GET_DEBUGREG
: {
343 /* We only support one DABR and no IABRS at the moment */
346 ret
= put_user(child
->thread
.dabr
, (u32 __user
*)data
);
350 case PTRACE_SET_DEBUGREG
:
351 ret
= ptrace_set_debugreg(child
, addr
, data
);
355 ret
= ptrace_detach(child
, data
);
358 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
360 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
361 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
363 for (i
= 0; i
< 32; i
++) {
364 ret
= put_user(*reg
, tmp
);
373 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
375 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
376 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
378 for (i
= 0; i
< 32; i
++) {
379 ret
= get_user(*reg
, tmp
);
388 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
390 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
391 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
393 flush_fp_to_thread(child
);
395 for (i
= 0; i
< 32; i
++) {
396 ret
= put_user(*reg
, tmp
);
405 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
407 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
408 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
410 flush_fp_to_thread(child
);
412 for (i
= 0; i
< 32; i
++) {
413 ret
= get_user(*reg
, tmp
);
422 case PTRACE_GETEVENTMSG
:
423 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) data
);
426 #ifdef CONFIG_ALTIVEC
427 case PTRACE_GETVRREGS
:
428 /* Get the child altivec register state. */
429 flush_altivec_to_thread(child
);
430 ret
= get_vrregs((unsigned long __user
*)data
, child
);
433 case PTRACE_SETVRREGS
:
434 /* Set the child altivec register state. */
435 flush_altivec_to_thread(child
);
436 ret
= set_vrregs(child
, (unsigned long __user
*)data
);
441 ret
= ptrace_request(child
, request
, addr
, data
);
445 put_task_struct(child
);