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>
29 #include <linux/signal.h>
31 #include <asm/uaccess.h>
33 #include <asm/pgtable.h>
34 #include <asm/system.h>
35 #include <asm/ptrace-common.h>
38 * does not yet catch signals sent when the child dies.
39 * in exit.c or in signal.c.
42 int sys32_ptrace(long request
, long pid
, unsigned long addr
, unsigned long data
)
44 struct task_struct
*child
;
48 if (request
== PTRACE_TRACEME
) {
49 /* are we already being traced? */
50 if (current
->ptrace
& PT_PTRACED
)
52 ret
= security_ptrace(current
->parent
, current
);
55 /* set the ptrace bit in the process flags. */
56 current
->ptrace
|= PT_PTRACED
;
61 read_lock(&tasklist_lock
);
62 child
= find_task_by_pid(pid
);
64 get_task_struct(child
);
65 read_unlock(&tasklist_lock
);
70 if (pid
== 1) /* you may not mess with init */
73 if (request
== PTRACE_ATTACH
) {
74 ret
= ptrace_attach(child
);
78 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
83 /* when I and D space are separate, these will need to be fixed. */
84 case PTRACE_PEEKTEXT
: /* read word at location addr. */
85 case PTRACE_PEEKDATA
: {
89 copied
= access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 0);
91 if (copied
!= sizeof(tmp
))
93 ret
= put_user(tmp
, (u32 __user
*)data
);
98 * Read 4 bytes of the other process' storage
99 * data is a pointer specifying where the user wants the
100 * 4 bytes copied into
101 * addr is a pointer in the user's storage that contains an 8 byte
102 * address in the other process of the 4 bytes that is to be read
103 * (this is run in a 32-bit process looking at a 64-bit process)
104 * when I and D space are separate, these will need to be fixed.
106 case PPC_PTRACE_PEEKTEXT_3264
:
107 case PPC_PTRACE_PEEKDATA_3264
: {
110 u32 __user
* addrOthers
;
114 /* Get the addr in the other process that we want to read */
115 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
118 copied
= access_process_vm(child
, (u64
)addrOthers
, &tmp
,
120 if (copied
!= sizeof(tmp
))
122 ret
= put_user(tmp
, (u32 __user
*)data
);
126 /* Read a register (specified by ADDR) out of the "user area" */
127 case PTRACE_PEEKUSR
: {
132 /* convert to index and check */
133 index
= (unsigned long) addr
>> 2;
134 if ((addr
& 3) || (index
> PT_FPSCR32
))
137 if (index
< PT_FPR0
) {
138 tmp
= get_reg(child
, index
);
140 flush_fp_to_thread(child
);
142 * the user space code considers the floating point
143 * to be an array of unsigned int (32 bits) - the
144 * index passed in is based on this assumption.
146 tmp
= ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
];
148 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
153 * Read 4 bytes out of the other process' pt_regs area
154 * data is a pointer specifying where the user wants the
155 * 4 bytes copied into
156 * addr is the offset into the other process' pt_regs structure
158 * (this is run in a 32-bit process looking at a 64-bit process)
160 case PPC_PTRACE_PEEKUSR_3264
: {
168 /* Determine which register the user wants */
169 index
= (u64
)addr
>> 2;
171 /* Determine which part of the register the user wants */
173 part
= 1; /* want the 2nd half of the register (right-most). */
175 part
= 0; /* want the 1st half of the register (left-most). */
177 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
178 if ((addr
& 3) || numReg
> PT_FPSCR
)
181 if (numReg
>= PT_FPR0
) {
182 flush_fp_to_thread(child
);
183 tmp
= ((unsigned long int *)child
->thread
.fpr
)[numReg
- PT_FPR0
];
184 } else { /* register within PT_REGS struct */
185 tmp
= get_reg(child
, numReg
);
187 reg32bits
= ((u32
*)&tmp
)[part
];
188 ret
= put_user(reg32bits
, (u32 __user
*)data
);
192 /* If I and D space are separate, this will have to be fixed. */
193 case PTRACE_POKETEXT
: /* write the word at location addr. */
194 case PTRACE_POKEDATA
: {
198 if (access_process_vm(child
, addr
, &tmp
, sizeof(tmp
), 1)
206 * Write 4 bytes into the other process' storage
207 * data is the 4 bytes that the user wants written
208 * addr is a pointer in the user's storage that contains an
209 * 8 byte address in the other process where the 4 bytes
210 * that is to be written
211 * (this is run in a 32-bit process looking at a 64-bit process)
212 * when I and D space are separate, these will need to be fixed.
214 case PPC_PTRACE_POKETEXT_3264
:
215 case PPC_PTRACE_POKEDATA_3264
: {
217 u32 __user
* addrOthers
;
219 /* Get the addr in the other process that we want to write into */
221 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
224 if (access_process_vm(child
, (u64
)addrOthers
, &tmp
,
225 sizeof(tmp
), 1) == sizeof(tmp
))
231 /* write the word at location addr in the USER area */
232 case PTRACE_POKEUSR
: {
236 /* convert to index and check */
237 index
= (unsigned long) addr
>> 2;
238 if ((addr
& 3) || (index
> PT_FPSCR32
))
241 if (index
== PT_ORIG_R3
)
243 if (index
< PT_FPR0
) {
244 ret
= put_reg(child
, index
, data
);
246 flush_fp_to_thread(child
);
248 * the user space code considers the floating point
249 * to be an array of unsigned int (32 bits) - the
250 * index passed in is based on this assumption.
252 ((unsigned int *)child
->thread
.fpr
)[index
- PT_FPR0
] = data
;
259 * Write 4 bytes into the other process' pt_regs area
260 * data is the 4 bytes that the user wants written
261 * addr is the offset into the other process' pt_regs structure
262 * that is to be written into
263 * (this is run in a 32-bit process looking at a 64-bit process)
265 case PPC_PTRACE_POKEUSR_3264
: {
270 /* Determine which register the user wants */
271 index
= (u64
)addr
>> 2;
274 * Validate the input - check to see if address is on the
275 * wrong boundary or beyond the end of the user area
277 if ((addr
& 3) || (numReg
> PT_FPSCR
))
279 /* Insure it is a register we let them change */
280 if ((numReg
== PT_ORIG_R3
)
281 || ((numReg
> PT_CCR
) && (numReg
< PT_FPR0
)))
283 if (numReg
>= PT_FPR0
) {
284 flush_fp_to_thread(child
);
286 if (numReg
== PT_MSR
)
287 data
= (data
& MSR_DEBUGCHANGE
)
288 | (child
->thread
.regs
->msr
& ~MSR_DEBUGCHANGE
);
289 ((u32
*)child
->thread
.regs
)[index
] = data
;
294 case PTRACE_SYSCALL
: /* continue and stop at next (return from) syscall */
295 case PTRACE_CONT
: { /* restart after signal. */
297 if (!valid_signal(data
))
299 if (request
== PTRACE_SYSCALL
)
300 set_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
302 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
303 child
->exit_code
= data
;
304 /* make sure the single step bit is not set. */
305 clear_single_step(child
);
306 wake_up_process(child
);
312 * make the child exit. Best I can do is send it a sigkill.
313 * perhaps it should be put in the status that it wants to
318 if (child
->exit_state
== EXIT_ZOMBIE
) /* already dead */
320 child
->exit_code
= SIGKILL
;
321 /* make sure the single step bit is not set. */
322 clear_single_step(child
);
323 wake_up_process(child
);
327 case PTRACE_SINGLESTEP
: { /* set the trap flag. */
329 if (!valid_signal(data
))
331 clear_tsk_thread_flag(child
, TIF_SYSCALL_TRACE
);
332 set_single_step(child
);
333 child
->exit_code
= data
;
334 /* give it a chance to run. */
335 wake_up_process(child
);
341 ret
= ptrace_detach(child
, data
);
344 case PPC_PTRACE_GETREGS
: { /* Get GPRs 0 - 31. */
346 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
347 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
349 for (i
= 0; i
< 32; i
++) {
350 ret
= put_user(*reg
, tmp
);
359 case PPC_PTRACE_SETREGS
: { /* Set GPRs 0 - 31. */
361 unsigned long *reg
= &((unsigned long *)child
->thread
.regs
)[0];
362 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
364 for (i
= 0; i
< 32; i
++) {
365 ret
= get_user(*reg
, tmp
);
374 case PPC_PTRACE_GETFPREGS
: { /* Get FPRs 0 - 31. */
376 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
377 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
379 flush_fp_to_thread(child
);
381 for (i
= 0; i
< 32; i
++) {
382 ret
= put_user(*reg
, tmp
);
391 case PPC_PTRACE_SETFPREGS
: { /* Get FPRs 0 - 31. */
393 unsigned long *reg
= &((unsigned long *)child
->thread
.fpr
)[0];
394 unsigned int __user
*tmp
= (unsigned int __user
*)addr
;
396 flush_fp_to_thread(child
);
398 for (i
= 0; i
< 32; i
++) {
399 ret
= get_user(*reg
, tmp
);
408 case PTRACE_GETEVENTMSG
:
409 ret
= put_user(child
->ptrace_message
, (unsigned int __user
*) data
);
413 ret
= ptrace_request(child
, request
, addr
, data
);
417 put_task_struct(child
);