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/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>
30 #include <asm/uaccess.h>
32 #include <asm/pgtable.h>
33 #include <asm/system.h>
34 #include <asm/ptrace-common.h>
37 * does not yet catch signals sent when the child dies.
38 * in exit.c or in signal.c.
41 int sys32_ptrace(long request
, long pid
, unsigned long addr
, unsigned long data
)
43 struct task_struct
*child
;
47 if (request
== PTRACE_TRACEME
) {
48 /* are we already being traced? */
49 if (current
->ptrace
& PT_PTRACED
)
51 ret
= security_ptrace(current
->parent
, current
);
54 /* set the ptrace bit in the process flags. */
55 current
->ptrace
|= PT_PTRACED
;
60 read_lock(&tasklist_lock
);
61 child
= find_task_by_pid(pid
);
63 get_task_struct(child
);
64 read_unlock(&tasklist_lock
);
69 if (pid
== 1) /* you may not mess with init */
72 if (request
== PTRACE_ATTACH
) {
73 ret
= ptrace_attach(child
);
77 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
82 /* when I and D space are separate, these will need to be fixed. */
83 case PTRACE_PEEKTEXT
: /* read word at location addr. */
84 case PTRACE_PEEKDATA
: {
88 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
90 if (copied
!= sizeof(tmp
))
92 ret
= put_user(tmp
, (u32 __user
*)data
);
97 * Read 4 bytes of the other process' storage
98 * data is a pointer specifying where the user wants the
100 * addr is a pointer in the user's storage that contains an 8 byte
101 * address in the other process of the 4 bytes that is to be read
102 * (this is run in a 32-bit process looking at a 64-bit process)
103 * when I and D space are separate, these will need to be fixed.
105 case PPC_PTRACE_PEEKTEXT_3264
:
106 case PPC_PTRACE_PEEKDATA_3264
: {
109 u32 __user
* addrOthers
;
113 /* Get the addr in the other process that we want to read */
114 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
117 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
119 if (copied
!= sizeof(tmp
))
121 ret
= put_user(tmp
, (u32 __user
*)data
);
125 /* Read a register (specified by ADDR) out of the "user area" */
126 case PTRACE_PEEKUSR
: {
131 /* convert to index and check */
132 index
= (unsigned long) addr
>> 2;
133 if ((addr
& 3) || (index
> PT_FPSCR32
))
136 if (index
< PT_FPR0
) {
137 tmp
= get_reg(child
, index
);
139 flush_fp_to_thread(child
);
141 * the user space code considers the floating point
142 * to be an array of unsigned int (32 bits) - the
143 * index passed in is based on this assumption.
145 tmp
= ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
];
147 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
152 * Read 4 bytes out of the other process' pt_regs area
153 * data is a pointer specifying where the user wants the
154 * 4 bytes copied into
155 * addr is the offset into the other process' pt_regs structure
157 * (this is run in a 32-bit process looking at a 64-bit process)
159 case PPC_PTRACE_PEEKUSR_3264
: {
167 /* Determine which register the user wants */
168 index
= (u64
)addr
>> 2;
170 /* Determine which part of the register the user wants */
172 part
= 1; /* want the 2nd half of the register (right-most). */
174 part
= 0; /* want the 1st half of the register (left-most). */
176 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
177 if ((addr
& 3) || numReg
> PT_FPSCR
)
180 if (numReg
>= PT_FPR0
) {
181 flush_fp_to_thread(child
);
182 tmp
= ((unsigned long int *)child
->thread
.fpr
)[numReg
- PT_FPR0
];
183 } else { /* register within PT_REGS struct */
184 tmp
= get_reg(child
, numReg
);
186 reg32bits
= ((u32
*)&tmp
)[part
];
187 ret
= put_user(reg32bits
, (u32 __user
*)data
);
191 /* If I and D space are separate, this will have to be fixed. */
192 case PTRACE_POKETEXT
: /* write the word at location addr. */
193 case PTRACE_POKEDATA
: {
197 if (access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 1)
205 * Write 4 bytes into the other process' storage
206 * data is the 4 bytes that the user wants written
207 * addr is a pointer in the user's storage that contains an
208 * 8 byte address in the other process where the 4 bytes
209 * that is to be written
210 * (this is run in a 32-bit process looking at a 64-bit process)
211 * when I and D space are separate, these will need to be fixed.
213 case PPC_PTRACE_POKETEXT_3264
:
214 case PPC_PTRACE_POKEDATA_3264
: {
216 u32 __user
* addrOthers
;
218 /* Get the addr in the other process that we want to write into */
220 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
223 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
224 sizeof(tmp
), 1) == sizeof(tmp
))
230 /* write the word at location addr in the USER area */
231 case PTRACE_POKEUSR
: {
235 /* convert to index and check */
236 index
= (unsigned long) addr
>> 2;
237 if ((addr
& 3) || (index
> PT_FPSCR32
))
240 if (index
== PT_ORIG_R3
)
242 if (index
< PT_FPR0
) {
243 ret
= put_reg(child
, index
, data
);
245 flush_fp_to_thread(child
);
247 * the user space code considers the floating point
248 * to be an array of unsigned int (32 bits) - the
249 * index passed in is based on this assumption.
251 ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
258 * Write 4 bytes into the other process' pt_regs area
259 * data is the 4 bytes that the user wants written
260 * addr is the offset into the other process' pt_regs structure
261 * that is to be written into
262 * (this is run in a 32-bit process looking at a 64-bit process)
264 case PPC_PTRACE_POKEUSR_3264
: {
269 /* Determine which register the user wants */
270 index
= (u64
)addr
>> 2;
273 * Validate the input - check to see if address is on the
274 * wrong boundary or beyond the end of the user area
276 if ((addr
& 3) || (numReg
> PT_FPSCR
))
278 /* Insure it is a register we let them change */
279 if ((numReg
== PT_ORIG_R3
)
280 || ((numReg
> PT_CCR
) && (numReg
< PT_FPR0
)))
282 if (numReg
>= PT_FPR0
) {
283 flush_fp_to_thread(child
);
285 if (numReg
== PT_MSR
)
286 data
= (data
& MSR_DEBUGCHANGE
)
287 | (child
->thread
.regs
->msr
& ~MSR_DEBUGCHANGE
);
288 ((u32
*)child
->thread
.regs
)[index
] = data
;
293 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
294 case PTRACE_CONT
: { /* restart after signal. */
296 if ((unsigned long) data
> _NSIG
)
298 if (request
== PTRACE_SYSCALL
)
299 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
301 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
302 child
->exit_code
= data
;
303 /* make sure the single step bit is not set. */
304 clear_single_step(child
);
305 wake_up_process(child
);
311 * make the child exit. Best I can do is send it a sigkill.
312 * perhaps it should be put in the status that it wants to
317 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
319 child
->exit_code
= SIGKILL
;
320 /* make sure the single step bit is not set. */
321 clear_single_step(child
);
322 wake_up_process(child
);
326 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
328 if ((unsigned long) data
> _NSIG
)
330 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
331 set_single_step(child
);
332 child
->exit_code
= data
;
333 /* give it a chance to run. */
334 wake_up_process(child
);
340 ret
= ptrace_detach(child
, data
);
343 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
345 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
346 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
348 for (i
= 0; i
< 32; i
++) {
349 ret
= put_user(*reg
, tmp
);
358 case PPC_PTRACE_SETREGS
: { /* Set 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
= get_user(*reg
, tmp
);
373 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
375 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
376 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
378 flush_fp_to_thread(child
);
380 for (i
= 0; i
< 32; i
++) {
381 ret
= put_user(*reg
, tmp
);
390 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
392 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
393 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
395 flush_fp_to_thread(child
);
397 for (i
= 0; i
< 32; i
++) {
398 ret
= get_user(*reg
, tmp
);
407 case PTRACE_GETEVENTMSG
:
408 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) data
);
412 ret
= ptrace_request(child
, request
, addr
, data
);
416 put_task_struct(child
);