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-ppc64.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.
45 * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls,
46 * we mark them as obsolete now, they will be removed in a future version
48 static long compat_ptrace_old(struct task_struct *child, long request,
54 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
56 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
57 unsigned int __user *tmp = (unsigned int __user *)addr;
59 for (i = 0; i < 32; i++) {
60 ret = put_user(*reg, tmp);
69 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
71 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
72 unsigned int __user *tmp = (unsigned int __user *)addr;
74 for (i = 0; i < 32; i++) {
75 ret = get_user(*reg, tmp);
88 long compat_sys_ptrace(int request, int pid, unsigned long addr,
91 struct task_struct *child;
95 if (request == PTRACE_TRACEME) {
96 ret = ptrace_traceme();
100 child = ptrace_get_task_struct(pid);
102 ret = PTR_ERR(child);
106 if (request == PTRACE_ATTACH) {
107 ret = ptrace_attach(child);
111 ret = ptrace_check_attach(child, request == PTRACE_KILL);
116 /* when I and D space are separate, these will need to be fixed. */
117 case PTRACE_PEEKTEXT: /* read word at location addr. */
118 case PTRACE_PEEKDATA: {
122 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
124 if (copied != sizeof(tmp))
126 ret = put_user(tmp, (u32 __user *)data);
131 * Read 4 bytes of the other process' storage
132 * data is a pointer specifying where the user wants the
133 * 4 bytes copied into
134 * addr is a pointer in the user's storage that contains an 8 byte
135 * address in the other process of the 4 bytes that is to be read
136 * (this is run in a 32-bit process looking at a 64-bit process)
137 * when I and D space are separate, these will need to be fixed.
139 case PPC_PTRACE_PEEKTEXT_3264:
140 case PPC_PTRACE_PEEKDATA_3264: {
143 u32 __user * addrOthers;
147 /* Get the addr in the other process that we want to read */
148 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
151 copied = access_process_vm(child, (u64)addrOthers, &tmp,
153 if (copied != sizeof(tmp))
155 ret = put_user(tmp, (u32 __user *)data);
159 /* Read a register (specified by ADDR) out of the "user area" */
160 case PTRACE_PEEKUSR: {
165 /* convert to index and check */
166 index = (unsigned long) addr >> 2;
167 if ((addr & 3) || (index > PT_FPSCR32))
170 if (index < PT_FPR0) {
171 tmp = get_reg(child, index);
173 flush_fp_to_thread(child);
175 * the user space code considers the floating point
176 * to be an array of unsigned int (32 bits) - the
177 * index passed in is based on this assumption.
179 tmp = ((unsigned int *)child->thread.fpr)[index - PT_FPR0];
181 ret = put_user((unsigned int)tmp, (u32 __user *)data);
186 * Read 4 bytes out of the other process' pt_regs area
187 * data is a pointer specifying where the user wants the
188 * 4 bytes copied into
189 * addr is the offset into the other process' pt_regs structure
191 * (this is run in a 32-bit process looking at a 64-bit process)
193 case PPC_PTRACE_PEEKUSR_3264: {
201 /* Determine which register the user wants */
202 index = (u64)addr >> 2;
204 /* Determine which part of the register the user wants */
206 part = 1; /* want the 2nd half of the register (right-most). */
208 part = 0; /* want the 1st half of the register (left-most). */
210 /* Validate the input - check to see if address is on the wrong boundary or beyond the end of the user area */
211 if ((addr & 3) || numReg > PT_FPSCR)
214 if (numReg >= PT_FPR0) {
215 flush_fp_to_thread(child);
216 tmp = ((unsigned long int *)child->thread.fpr)[numReg - PT_FPR0];
217 } else { /* register within PT_REGS struct */
218 tmp = get_reg(child, numReg);
220 reg32bits = ((u32*)&tmp)[part];
221 ret = put_user(reg32bits, (u32 __user *)data);
225 /* If I and D space are separate, this will have to be fixed. */
226 case PTRACE_POKETEXT: /* write the word at location addr. */
227 case PTRACE_POKEDATA: {
231 if (access_process_vm(child, addr, &tmp, sizeof(tmp), 1)
239 * Write 4 bytes into the other process' storage
240 * data is the 4 bytes that the user wants written
241 * addr is a pointer in the user's storage that contains an
242 * 8 byte address in the other process where the 4 bytes
243 * that is to be written
244 * (this is run in a 32-bit process looking at a 64-bit process)
245 * when I and D space are separate, these will need to be fixed.
247 case PPC_PTRACE_POKETEXT_3264:
248 case PPC_PTRACE_POKEDATA_3264: {
250 u32 __user * addrOthers;
252 /* Get the addr in the other process that we want to write into */
254 if (get_user(addrOthers, (u32 __user * __user *)addr) != 0)
257 if (access_process_vm(child, (u64)addrOthers, &tmp,
258 sizeof(tmp), 1) == sizeof(tmp))
264 /* write the word at location addr in the USER area */
265 case PTRACE_POKEUSR: {
269 /* convert to index and check */
270 index = (unsigned long) addr >> 2;
271 if ((addr & 3) || (index > PT_FPSCR32))
274 if (index == PT_ORIG_R3)
276 if (index < PT_FPR0) {
277 ret = put_reg(child, index, data);
279 flush_fp_to_thread(child);
281 * the user space code considers the floating point
282 * to be an array of unsigned int (32 bits) - the
283 * index passed in is based on this assumption.
285 ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data;
292 * Write 4 bytes into the other process' pt_regs area
293 * data is the 4 bytes that the user wants written
294 * addr is the offset into the other process' pt_regs structure
295 * that is to be written into
296 * (this is run in a 32-bit process looking at a 64-bit process)
298 case PPC_PTRACE_POKEUSR_3264: {
303 /* Determine which register the user wants */
304 index = (u64)addr >> 2;
307 * Validate the input - check to see if address is on the
308 * wrong boundary or beyond the end of the user area
310 if ((addr & 3) || (numReg > PT_FPSCR))
312 /* Insure it is a register we let them change */
313 if ((numReg == PT_ORIG_R3)
314 || ((numReg > PT_CCR) && (numReg < PT_FPR0)))
316 if (numReg >= PT_FPR0) {
317 flush_fp_to_thread(child);
319 if (numReg == PT_MSR)
320 data = (data & MSR_DEBUGCHANGE)
321 | (child->thread.regs->msr & ~MSR_DEBUGCHANGE);
322 ((u32*)child->thread.regs)[index] = data;
327 case PTRACE_GET_DEBUGREG: {
329 /* We only support one DABR and no IABRS at the moment */
332 ret = put_user(child->thread.dabr, (u32 __user *)data);
336 case PTRACE_GETEVENTMSG:
337 ret = put_user(child->ptrace_message, (unsigned int __user *) data);
340 case PTRACE_GETREGS: { /* Get all pt_regs from the child. */
342 if (!access_ok(VERIFY_WRITE, (void __user *)data,
343 PT_REGS_COUNT * sizeof(int))) {
348 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
349 ret |= __put_user(get_reg(child, ui),
350 (unsigned int __user *) data);
356 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
359 if (!access_ok(VERIFY_READ, (void __user *)data,
360 PT_REGS_COUNT * sizeof(int))) {
365 for (ui = 0; ui < PT_REGS_COUNT; ui ++) {
366 ret = __get_user(tmp, (unsigned int __user *) data);
369 put_reg(child, ui, tmp);
375 case PTRACE_GETFPREGS:
376 case PTRACE_SETFPREGS:
377 case PTRACE_GETVRREGS:
378 case PTRACE_SETVRREGS:
379 case PTRACE_GETREGS64:
380 case PTRACE_SETREGS64:
381 case PPC_PTRACE_GETFPREGS:
382 case PPC_PTRACE_SETFPREGS:
384 case PTRACE_SINGLESTEP:
386 case PTRACE_SET_DEBUGREG:
389 ret = arch_ptrace(child, request, addr, data);
392 /* Old reverse args ptrace callss */
393 case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */
394 case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */
395 ret = compat_ptrace_old(child, request, addr, data);
399 ret = ptrace_request(child, request, addr, data);
403 put_task_struct(child);