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/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>
37 #include "ptrace-common.h"
40 * does not yet catch signals sent when the child dies.
41 * in exit.c or in signal.c.
44 long compat_sys_ptrace(int request, int pid, unsigned long addr,
47 struct task_struct *child;
51 if (request == PTRACE_TRACEME) {
52 ret = ptrace_traceme();
56 child = ptrace_get_task_struct(pid);
62 if (request == PTRACE_ATTACH) {
63 ret = ptrace_attach(child);
67 ret = ptrace_check_attach(child, request == PTRACE_KILL);
72 /* when I and D space are separate, these will need to be fixed. */
73 case PTRACE_PEEKTEXT: /* read word at location addr. */
74 case PTRACE_PEEKDATA: {
78 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
80 if (copied != sizeof(tmp))
82 ret = put_user(tmp, (u32 __user *)data);
87 * Read 4 bytes of the other process' storage
88 * data is a pointer specifying where the user wants the
90 * addr is a pointer in the user's storage that contains an 8 byte
91 * address in the other process of the 4 bytes that is to be read
92 * (this is run in a 32-bit process looking at a 64-bit process)
93 * when I and D space are separate, these will need to be fixed.
95 case PPC_PTRACE_PEEKTEXT_3264:
96 case PPC_PTRACE_PEEKDATA_3264: {
99 u32 __user * addrOthers;
103 /* Get the addr in the other process that we want to read */
104 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
107 copied = access_process_vm(child, (u64)addrOthers, &tmp,
109 if (copied != sizeof(tmp))
111 ret = put_user(tmp, (u32 __user *)data);
115 /* Read a register (specified by ADDR) out of the "user area" */
116 case PTRACE_PEEKUSR: {
121 /* convert to index and check */
122 index = (unsigned long) addr >> 2;
123 if ((addr & 3) || (index > PT_FPSCR32))
126 if (index < PT_FPR0) {
127 tmp = get_reg(child, index);
129 flush_fp_to_thread(child);
131 * the user space code considers the floating point
132 * to be an array of unsigned int (32 bits) - the
133 * index passed in is based on this assumption.
135 tmp = ((unsigned int *)child->thread.fpr)[index - PT_FPR0];
137 ret = put_user((unsigned int)tmp, (u32 __user *)data);
142 * Read 4 bytes out of the other process' pt_regs area
143 * data is a pointer specifying where the user wants the
144 * 4 bytes copied into
145 * addr is the offset into the other process' pt_regs structure
147 * (this is run in a 32-bit process looking at a 64-bit process)
149 case PPC_PTRACE_PEEKUSR_3264: {
157 /* Determine which register the user wants */
158 index = (u64)addr >> 2;
160 /* Determine which part of the register the user wants */
162 part = 1; /* want the 2nd half of the register (right-most). */
164 part = 0; /* want the 1st half of the register (left-most). */
166 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
167 if ((addr & 3) || numReg > PT_FPSCR)
170 if (numReg >= PT_FPR0) {
171 flush_fp_to_thread(child);
172 tmp = ((unsigned long int *)child->thread.fpr)[numReg - PT_FPR0];
173 } else { /* register within PT_REGS struct */
174 tmp = get_reg(child, numReg);
176 reg32bits = ((u32*)&tmp)[part];
177 ret = put_user(reg32bits, (u32 __user *)data);
181 /* If I and D space are separate, this will have to be fixed. */
182 case PTRACE_POKETEXT: /* write the word at location addr. */
183 case PTRACE_POKEDATA: {
187 if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1)
195 * Write 4 bytes into the other process' storage
196 * data is the 4 bytes that the user wants written
197 * addr is a pointer in the user's storage that contains an
198 * 8 byte address in the other process where the 4 bytes
199 * that is to be written
200 * (this is run in a 32-bit process looking at a 64-bit process)
201 * when I and D space are separate, these will need to be fixed.
203 case PPC_PTRACE_POKETEXT_3264:
204 case PPC_PTRACE_POKEDATA_3264: {
206 u32 __user * addrOthers;
208 /* Get the addr in the other process that we want to write into */
210 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
213 if (access_process_vm(child, (u64)addrOthers, &tmp,
214 sizeof(tmp), 1) == sizeof(tmp))
220 /* write the word at location addr in the USER area */
221 case PTRACE_POKEUSR: {
225 /* convert to index and check */
226 index = (unsigned long) addr >> 2;
227 if ((addr & 3) || (index > PT_FPSCR32))
230 if (index == PT_ORIG_R3)
232 if (index < PT_FPR0) {
233 ret = put_reg(child, index, data);
235 flush_fp_to_thread(child);
237 * the user space code considers the floating point
238 * to be an array of unsigned int (32 bits) - the
239 * index passed in is based on this assumption.
241 ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data;
248 * Write 4 bytes into the other process' pt_regs area
249 * data is the 4 bytes that the user wants written
250 * addr is the offset into the other process' pt_regs structure
251 * that is to be written into
252 * (this is run in a 32-bit process looking at a 64-bit process)
254 case PPC_PTRACE_POKEUSR_3264: {
259 /* Determine which register the user wants */
260 index = (u64)addr >> 2;
263 * Validate the input - check to see if address is on the
264 * wrong boundary or beyond the end of the user area
266 if ((addr & 3) || (numReg > PT_FPSCR))
268 /* Insure it is a register we let them change */
269 if ((numReg == PT_ORIG_R3)
270 || ((numReg > PT_CCR) && (numReg < PT_FPR0)))
272 if (numReg >= PT_FPR0) {
273 flush_fp_to_thread(child);
275 if (numReg == PT_MSR)
276 data = (data & MSR_DEBUGCHANGE)
277 | (child->thread.regs->msr & ~MSR_DEBUGCHANGE);
278 ((u32*)child->thread.regs)[index] = data;
283 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
284 case PTRACE_CONT: { /* restart after signal. */
286 if (!valid_signal(data))
288 if (request == PTRACE_SYSCALL)
289 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
291 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
292 child->exit_code = data;
293 /* make sure the single step bit is not set. */
294 clear_single_step(child);
295 wake_up_process(child);
301 * make the child exit. Best I can do is send it a sigkill.
302 * perhaps it should be put in the status that it wants to
307 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
309 child->exit_code = SIGKILL;
310 /* make sure the single step bit is not set. */
311 clear_single_step(child);
312 wake_up_process(child);
316 case PTRACE_SINGLESTEP: { /* set the trap flag. */
318 if (!valid_signal(data))
320 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
321 set_single_step(child);
322 child->exit_code = data;
323 /* give it a chance to run. */
324 wake_up_process(child);
329 case PTRACE_GET_DEBUGREG: {
331 /* We only support one DABR and no IABRS at the moment */
334 ret = put_user(child->thread.dabr, (u32 __user *)data);
338 case PTRACE_SET_DEBUGREG:
339 ret = ptrace_set_debugreg(child, addr, data);
343 ret = ptrace_detach(child, data);
346 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
348 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
349 unsigned int __user *tmp = (unsigned int __user *)addr;
351 for (i = 0; i < 32; i++) {
352 ret = put_user(*reg, tmp);
361 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
363 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
364 unsigned int __user *tmp = (unsigned int __user *)addr;
366 for (i = 0; i < 32; i++) {
367 ret = get_user(*reg, tmp);
376 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
378 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
379 unsigned int __user *tmp = (unsigned int __user *)addr;
381 flush_fp_to_thread(child);
383 for (i = 0; i < 32; i++) {
384 ret = put_user(*reg, tmp);
393 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
395 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
396 unsigned int __user *tmp = (unsigned int __user *)addr;
398 flush_fp_to_thread(child);
400 for (i = 0; i < 32; i++) {
401 ret = get_user(*reg, tmp);
410 case PTRACE_GETEVENTMSG:
411 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
414 #ifdef CONFIG_ALTIVEC
415 case PTRACE_GETVRREGS:
416 /* Get the child altivec register state. */
417 flush_altivec_to_thread(child);
418 ret = get_vrregs((unsigned long __user *)data, child);
421 case PTRACE_SETVRREGS:
422 /* Set the child altivec register state. */
423 flush_altivec_to_thread(child);
424 ret = set_vrregs(child, (unsigned long __user *)data);
429 ret = ptrace_request(child, request, addr, data);
433 put_task_struct(child);