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/errno.h>
25 #include <linux/ptrace.h>
26 #include <linux/regset.h>
27 #include <linux/user.h>
28 #include <linux/security.h>
29 #include <linux/signal.h>
30 #include <linux/compat.h>
32 #include <linux/uaccess.h>
34 #include <asm/pgtable.h>
35 #include <asm/switch_to.h>
38 * does not yet catch signals sent when the child dies.
39 * in exit.c or in signal.c.
42 /* Macros to workout the correct index for the FPR in the thread struct */
43 #define FPRNUMBER(i) (((i) - PT_FPR0) >> 1)
44 #define FPRHALF(i) (((i) - PT_FPR0) & 1)
45 #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i)
47 long compat_arch_ptrace(struct task_struct
*child
, compat_long_t request
,
48 compat_ulong_t caddr
, compat_ulong_t cdata
)
50 unsigned long addr
= caddr
;
51 unsigned long data
= cdata
;
56 * Read 4 bytes of the other process' storage
57 * data is a pointer specifying where the user wants the
59 * addr is a pointer in the user's storage that contains an 8 byte
60 * address in the other process of the 4 bytes that is to be read
61 * (this is run in a 32-bit process looking at a 64-bit process)
62 * when I and D space are separate, these will need to be fixed.
64 case PPC_PTRACE_PEEKTEXT_3264
:
65 case PPC_PTRACE_PEEKDATA_3264
: {
68 u32 __user
* addrOthers
;
72 /* Get the addr in the other process that we want to read */
73 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
76 copied
= ptrace_access_vm(child
, (u64
)addrOthers
, &tmp
,
77 sizeof(tmp
), FOLL_FORCE
);
78 if (copied
!= sizeof(tmp
))
80 ret
= put_user(tmp
, (u32 __user
*)data
);
84 /* Read a register (specified by ADDR) out of the "user area" */
85 case PTRACE_PEEKUSR
: {
90 /* convert to index and check */
91 index
= (unsigned long) addr
>> 2;
92 if ((addr
& 3) || (index
> PT_FPSCR32
))
95 CHECK_FULL_REGS(child
->thread
.regs
);
96 if (index
< PT_FPR0
) {
97 ret
= ptrace_get_reg(child
, index
, &tmp
);
101 flush_fp_to_thread(child
);
103 * the user space code considers the floating point
104 * to be an array of unsigned int (32 bits) - the
105 * index passed in is based on this assumption.
107 tmp
= ((unsigned int *)child
->thread
.fp_state
.fpr
)
110 ret
= put_user((unsigned int)tmp
, (u32 __user
*)data
);
115 * Read 4 bytes out of the other process' pt_regs area
116 * data is a pointer specifying where the user wants the
117 * 4 bytes copied into
118 * addr is the offset into the other process' pt_regs structure
120 * (this is run in a 32-bit process looking at a 64-bit process)
122 case PPC_PTRACE_PEEKUSR_3264
: {
130 /* Determine which register the user wants */
131 index
= (u64
)addr
>> 2;
133 /* Determine which part of the register the user wants */
135 part
= 1; /* want the 2nd half of the register (right-most). */
137 part
= 0; /* want the 1st half of the register (left-most). */
139 /* Validate the input - check to see if address is on the wrong boundary
140 * or beyond the end of the user area
142 if ((addr
& 3) || numReg
> PT_FPSCR
)
145 CHECK_FULL_REGS(child
->thread
.regs
);
146 if (numReg
>= PT_FPR0
) {
147 flush_fp_to_thread(child
);
149 tmp
= child
->thread
.fp_state
.fpr
[numReg
- PT_FPR0
][0];
150 } else { /* register within PT_REGS struct */
152 ret
= ptrace_get_reg(child
, numReg
, &tmp2
);
157 reg32bits
= ((u32
*)&tmp
)[part
];
158 ret
= put_user(reg32bits
, (u32 __user
*)data
);
163 * Write 4 bytes into the other process' storage
164 * data is the 4 bytes that the user wants written
165 * addr is a pointer in the user's storage that contains an
166 * 8 byte address in the other process where the 4 bytes
167 * that is to be written
168 * (this is run in a 32-bit process looking at a 64-bit process)
169 * when I and D space are separate, these will need to be fixed.
171 case PPC_PTRACE_POKETEXT_3264
:
172 case PPC_PTRACE_POKEDATA_3264
: {
174 u32 __user
* addrOthers
;
176 /* Get the addr in the other process that we want to write into */
178 if (get_user(addrOthers
, (u32 __user
* __user
*)addr
) != 0)
181 if (ptrace_access_vm(child
, (u64
)addrOthers
, &tmp
,
183 FOLL_FORCE
| FOLL_WRITE
) == sizeof(tmp
))
189 /* write the word at location addr in the USER area */
190 case PTRACE_POKEUSR
: {
194 /* convert to index and check */
195 index
= (unsigned long) addr
>> 2;
196 if ((addr
& 3) || (index
> PT_FPSCR32
))
199 CHECK_FULL_REGS(child
->thread
.regs
);
200 if (index
< PT_FPR0
) {
201 ret
= ptrace_put_reg(child
, index
, data
);
203 flush_fp_to_thread(child
);
205 * the user space code considers the floating point
206 * to be an array of unsigned int (32 bits) - the
207 * index passed in is based on this assumption.
209 ((unsigned int *)child
->thread
.fp_state
.fpr
)
210 [FPRINDEX(index
)] = data
;
217 * Write 4 bytes into the other process' pt_regs area
218 * data is the 4 bytes that the user wants written
219 * addr is the offset into the other process' pt_regs structure
220 * that is to be written into
221 * (this is run in a 32-bit process looking at a 64-bit process)
223 case PPC_PTRACE_POKEUSR_3264
: {
228 /* Determine which register the user wants */
229 index
= (u64
)addr
>> 2;
233 * Validate the input - check to see if address is on the
234 * wrong boundary or beyond the end of the user area
236 if ((addr
& 3) || (numReg
> PT_FPSCR
))
238 CHECK_FULL_REGS(child
->thread
.regs
);
239 if (numReg
< PT_FPR0
) {
241 ret
= ptrace_get_reg(child
, numReg
, &freg
);
245 freg
= (freg
& ~0xfffffffful
) | (data
& 0xfffffffful
);
247 freg
= (freg
& 0xfffffffful
) | (data
<< 32);
248 ret
= ptrace_put_reg(child
, numReg
, freg
);
251 flush_fp_to_thread(child
);
252 /* get 64 bit FPR ... */
253 tmp
= &child
->thread
.fp_state
.fpr
[numReg
- PT_FPR0
][0];
254 /* ... write the 32 bit part we want */
255 ((u32
*)tmp
)[index
% 2] = data
;
261 case PTRACE_GET_DEBUGREG
: {
262 #ifndef CONFIG_PPC_ADV_DEBUG_REGS
263 unsigned long dabr_fake
;
266 /* We only support one DABR and no IABRS at the moment */
269 #ifdef CONFIG_PPC_ADV_DEBUG_REGS
270 ret
= put_user(child
->thread
.debug
.dac1
, (u32 __user
*)data
);
273 (child
->thread
.hw_brk
.address
& (~HW_BRK_TYPE_DABR
)) |
274 (child
->thread
.hw_brk
.type
& HW_BRK_TYPE_DABR
));
275 ret
= put_user(dabr_fake
, (u32 __user
*)data
);
280 case PTRACE_GETREGS
: /* Get all pt_regs from the child. */
281 return copy_regset_to_user(
282 child
, task_user_regset_view(current
), 0,
283 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
286 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
287 return copy_regset_from_user(
288 child
, task_user_regset_view(current
), 0,
289 0, PT_REGS_COUNT
* sizeof(compat_long_t
),
292 case PTRACE_GETFPREGS
:
293 case PTRACE_SETFPREGS
:
294 case PTRACE_GETVRREGS
:
295 case PTRACE_SETVRREGS
:
296 case PTRACE_GETVSRREGS
:
297 case PTRACE_SETVSRREGS
:
298 case PTRACE_GETREGS64
:
299 case PTRACE_SETREGS64
:
301 case PTRACE_SINGLESTEP
:
303 case PTRACE_SET_DEBUGREG
:
306 case PPC_PTRACE_GETHWDBGINFO
:
307 case PPC_PTRACE_SETHWDEBUG
:
308 case PPC_PTRACE_DELHWDEBUG
:
309 ret
= arch_ptrace(child
, request
, addr
, data
);
313 ret
= compat_ptrace_request(child
, request
, addr
, data
);