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 if (child->thread.regs->msr & MSR_FP)
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 if (child->thread.regs->msr & MSR_FP)
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 if (child->thread.regs->msr & MSR_FP)
250 * the user space code considers the floating point
251 * to be an array of unsigned int (32 bits) - the
252 * index passed in is based on this assumption.
254 ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data;
261 * Write 4 bytes into the other process' pt_regs area
262 * data is the 4 bytes that the user wants written
263 * addr is the offset into the other process' pt_regs structure
264 * that is to be written into
265 * (this is run in a 32-bit process looking at a 64-bit process)
267 case PPC_PTRACE_POKEUSR_3264: {
272 /* Determine which register the user wants */
273 index = (u64)addr >> 2;
276 * Validate the input - check to see if address is on the
277 * wrong boundary or beyond the end of the user area
279 if ((addr & 3) || (numReg > PT_FPSCR))
281 /* Insure it is a register we let them change */
282 if ((numReg == PT_ORIG_R3)
283 || ((numReg > PT_CCR) && (numReg < PT_FPR0)))
285 if (numReg >= PT_FPR0) {
286 if (child->thread.regs->msr & MSR_FP)
289 if (numReg == PT_MSR)
290 data = (data & MSR_DEBUGCHANGE)
291 | (child->thread.regs->msr & ~MSR_DEBUGCHANGE);
292 ((u32*)child->thread.regs)[index] = data;
297 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
298 case PTRACE_CONT: { /* restart after signal. */
300 if ((unsigned long) data > _NSIG)
302 if (request == PTRACE_SYSCALL)
303 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
305 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
306 child->exit_code = data;
307 /* make sure the single step bit is not set. */
308 clear_single_step(child);
309 wake_up_process(child);
315 * make the child exit. Best I can do is send it a sigkill.
316 * perhaps it should be put in the status that it wants to
321 if (child->state == TASK_ZOMBIE) /* already dead */
323 child->exit_code = SIGKILL;
324 /* make sure the single step bit is not set. */
325 clear_single_step(child);
326 wake_up_process(child);
330 case PTRACE_SINGLESTEP: { /* set the trap flag. */
332 if ((unsigned long) data > _NSIG)
334 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
335 set_single_step(child);
336 child->exit_code = data;
337 /* give it a chance to run. */
338 wake_up_process(child);
344 ret = ptrace_detach(child, data);
347 case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */
349 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
350 unsigned int __user *tmp = (unsigned int __user *)addr;
352 for (i = 0; i < 32; i++) {
353 ret = put_user(*reg, tmp);
362 case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */
364 unsigned long *reg = &((unsigned long *)child->thread.regs)[0];
365 unsigned int __user *tmp = (unsigned int __user *)addr;
367 for (i = 0; i < 32; i++) {
368 ret = get_user(*reg, tmp);
377 case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */
379 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
380 unsigned int __user *tmp = (unsigned int __user *)addr;
382 if (child->thread.regs->msr & MSR_FP)
385 for (i = 0; i < 32; i++) {
386 ret = put_user(*reg, tmp);
395 case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */
397 unsigned long *reg = &((unsigned long *)child->thread.fpr)[0];
398 unsigned int __user *tmp = (unsigned int __user *)addr;
400 if (child->thread.regs->msr & MSR_FP)
403 for (i = 0; i < 32; i++) {
404 ret = get_user(*reg, tmp);
416 ret = ptrace_request(child, request, addr, data);
420 put_task_struct(child);