Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
b123923d | 2 | * ptrace for 32-bit processes running on a 64-bit kernel. |
1da177e4 LT |
3 | * |
4 | * PowerPC version | |
5 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | |
6 | * | |
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 | |
11 | * | |
12 | * Modified by Cort Dougan (cort@hq.fsmlabs.com) | |
b123923d | 13 | * and Paul Mackerras (paulus@samba.org). |
1da177e4 LT |
14 | * |
15 | * This file is subject to the terms and conditions of the GNU General | |
b123923d | 16 | * Public License. See the file COPYING in the main directory of |
1da177e4 LT |
17 | * this archive for more details. |
18 | */ | |
19 | ||
20 | #include <linux/kernel.h> | |
21 | #include <linux/sched.h> | |
22 | #include <linux/mm.h> | |
23 | #include <linux/smp.h> | |
24 | #include <linux/smp_lock.h> | |
25 | #include <linux/errno.h> | |
26 | #include <linux/ptrace.h> | |
0deef2c7 | 27 | #include <linux/regset.h> |
1da177e4 LT |
28 | #include <linux/user.h> |
29 | #include <linux/security.h> | |
7ed20e1a | 30 | #include <linux/signal.h> |
1d48d71c | 31 | #include <linux/compat.h> |
1da177e4 LT |
32 | |
33 | #include <asm/uaccess.h> | |
34 | #include <asm/page.h> | |
35 | #include <asm/pgtable.h> | |
36 | #include <asm/system.h> | |
21a62902 | 37 | |
1da177e4 LT |
38 | /* |
39 | * does not yet catch signals sent when the child dies. | |
40 | * in exit.c or in signal.c. | |
41 | */ | |
42 | ||
e17666ba BH |
43 | /* |
44 | * Here are the old "legacy" powerpc specific getregs/setregs ptrace calls, | |
45 | * we mark them as obsolete now, they will be removed in a future version | |
46 | */ | |
47 | static long compat_ptrace_old(struct task_struct *child, long request, | |
48 | long addr, long data) | |
49 | { | |
0deef2c7 RM |
50 | switch (request) { |
51 | case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */ | |
52 | return copy_regset_to_user(child, | |
53 | task_user_regset_view(current), 0, | |
54 | 0, 32 * sizeof(compat_long_t), | |
55 | compat_ptr(data)); | |
56 | ||
57 | case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */ | |
58 | return copy_regset_from_user(child, | |
59 | task_user_regset_view(current), 0, | |
60 | 0, 32 * sizeof(compat_long_t), | |
61 | compat_ptr(data)); | |
e17666ba BH |
62 | } |
63 | ||
0deef2c7 | 64 | return -EPERM; |
e17666ba BH |
65 | } |
66 | ||
81e695c0 RM |
67 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
68 | compat_ulong_t caddr, compat_ulong_t cdata) | |
1da177e4 | 69 | { |
81e695c0 RM |
70 | unsigned long addr = caddr; |
71 | unsigned long data = cdata; | |
6b9c7ed8 | 72 | int ret; |
1da177e4 | 73 | |
1da177e4 | 74 | switch (request) { |
1da177e4 LT |
75 | /* |
76 | * Read 4 bytes of the other process' storage | |
77 | * data is a pointer specifying where the user wants the | |
78 | * 4 bytes copied into | |
79 | * addr is a pointer in the user's storage that contains an 8 byte | |
80 | * address in the other process of the 4 bytes that is to be read | |
81 | * (this is run in a 32-bit process looking at a 64-bit process) | |
82 | * when I and D space are separate, these will need to be fixed. | |
83 | */ | |
84 | case PPC_PTRACE_PEEKTEXT_3264: | |
85 | case PPC_PTRACE_PEEKDATA_3264: { | |
86 | u32 tmp; | |
87 | int copied; | |
88 | u32 __user * addrOthers; | |
89 | ||
90 | ret = -EIO; | |
91 | ||
92 | /* Get the addr in the other process that we want to read */ | |
93 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) | |
94 | break; | |
95 | ||
96 | copied = access_process_vm(child, (u64)addrOthers, &tmp, | |
97 | sizeof(tmp), 0); | |
98 | if (copied != sizeof(tmp)) | |
99 | break; | |
100 | ret = put_user(tmp, (u32 __user *)data); | |
101 | break; | |
102 | } | |
103 | ||
104 | /* Read a register (specified by ADDR) out of the "user area" */ | |
105 | case PTRACE_PEEKUSR: { | |
106 | int index; | |
107 | unsigned long tmp; | |
108 | ||
109 | ret = -EIO; | |
110 | /* convert to index and check */ | |
111 | index = (unsigned long) addr >> 2; | |
112 | if ((addr & 3) || (index > PT_FPSCR32)) | |
113 | break; | |
114 | ||
fabca2c0 | 115 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 | 116 | if (index < PT_FPR0) { |
865418d8 | 117 | tmp = ptrace_get_reg(child, index); |
1da177e4 LT |
118 | } else { |
119 | flush_fp_to_thread(child); | |
120 | /* | |
121 | * the user space code considers the floating point | |
122 | * to be an array of unsigned int (32 bits) - the | |
123 | * index passed in is based on this assumption. | |
124 | */ | |
125 | tmp = ((unsigned int *)child->thread.fpr)[index - PT_FPR0]; | |
126 | } | |
127 | ret = put_user((unsigned int)tmp, (u32 __user *)data); | |
128 | break; | |
129 | } | |
130 | ||
131 | /* | |
132 | * Read 4 bytes out of the other process' pt_regs area | |
133 | * data is a pointer specifying where the user wants the | |
134 | * 4 bytes copied into | |
135 | * addr is the offset into the other process' pt_regs structure | |
136 | * that is to be read | |
137 | * (this is run in a 32-bit process looking at a 64-bit process) | |
138 | */ | |
139 | case PPC_PTRACE_PEEKUSR_3264: { | |
140 | u32 index; | |
141 | u32 reg32bits; | |
142 | u64 tmp; | |
143 | u32 numReg; | |
144 | u32 part; | |
145 | ||
146 | ret = -EIO; | |
147 | /* Determine which register the user wants */ | |
148 | index = (u64)addr >> 2; | |
149 | numReg = index / 2; | |
150 | /* Determine which part of the register the user wants */ | |
151 | if (index % 2) | |
152 | part = 1; /* want the 2nd half of the register (right-most). */ | |
153 | else | |
154 | part = 0; /* want the 1st half of the register (left-most). */ | |
155 | ||
912000e7 BH |
156 | /* Validate the input - check to see if address is on the wrong boundary |
157 | * or beyond the end of the user area | |
158 | */ | |
1da177e4 LT |
159 | if ((addr & 3) || numReg > PT_FPSCR) |
160 | break; | |
161 | ||
fabca2c0 | 162 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 LT |
163 | if (numReg >= PT_FPR0) { |
164 | flush_fp_to_thread(child); | |
165 | tmp = ((unsigned long int *)child->thread.fpr)[numReg - PT_FPR0]; | |
166 | } else { /* register within PT_REGS struct */ | |
865418d8 | 167 | tmp = ptrace_get_reg(child, numReg); |
1da177e4 LT |
168 | } |
169 | reg32bits = ((u32*)&tmp)[part]; | |
170 | ret = put_user(reg32bits, (u32 __user *)data); | |
171 | break; | |
172 | } | |
173 | ||
1da177e4 LT |
174 | /* |
175 | * Write 4 bytes into the other process' storage | |
176 | * data is the 4 bytes that the user wants written | |
177 | * addr is a pointer in the user's storage that contains an | |
178 | * 8 byte address in the other process where the 4 bytes | |
179 | * that is to be written | |
180 | * (this is run in a 32-bit process looking at a 64-bit process) | |
181 | * when I and D space are separate, these will need to be fixed. | |
182 | */ | |
183 | case PPC_PTRACE_POKETEXT_3264: | |
184 | case PPC_PTRACE_POKEDATA_3264: { | |
185 | u32 tmp = data; | |
186 | u32 __user * addrOthers; | |
187 | ||
188 | /* Get the addr in the other process that we want to write into */ | |
189 | ret = -EIO; | |
190 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) | |
191 | break; | |
192 | ret = 0; | |
193 | if (access_process_vm(child, (u64)addrOthers, &tmp, | |
194 | sizeof(tmp), 1) == sizeof(tmp)) | |
195 | break; | |
196 | ret = -EIO; | |
197 | break; | |
198 | } | |
199 | ||
200 | /* write the word at location addr in the USER area */ | |
201 | case PTRACE_POKEUSR: { | |
202 | unsigned long index; | |
203 | ||
204 | ret = -EIO; | |
205 | /* convert to index and check */ | |
206 | index = (unsigned long) addr >> 2; | |
207 | if ((addr & 3) || (index > PT_FPSCR32)) | |
208 | break; | |
209 | ||
fabca2c0 | 210 | CHECK_FULL_REGS(child->thread.regs); |
1da177e4 | 211 | if (index < PT_FPR0) { |
865418d8 | 212 | ret = ptrace_put_reg(child, index, data); |
1da177e4 LT |
213 | } else { |
214 | flush_fp_to_thread(child); | |
215 | /* | |
216 | * the user space code considers the floating point | |
217 | * to be an array of unsigned int (32 bits) - the | |
218 | * index passed in is based on this assumption. | |
219 | */ | |
220 | ((unsigned int *)child->thread.fpr)[index - PT_FPR0] = data; | |
221 | ret = 0; | |
222 | } | |
223 | break; | |
224 | } | |
225 | ||
226 | /* | |
227 | * Write 4 bytes into the other process' pt_regs area | |
228 | * data is the 4 bytes that the user wants written | |
229 | * addr is the offset into the other process' pt_regs structure | |
230 | * that is to be written into | |
231 | * (this is run in a 32-bit process looking at a 64-bit process) | |
232 | */ | |
233 | case PPC_PTRACE_POKEUSR_3264: { | |
234 | u32 index; | |
235 | u32 numReg; | |
236 | ||
237 | ret = -EIO; | |
238 | /* Determine which register the user wants */ | |
239 | index = (u64)addr >> 2; | |
240 | numReg = index / 2; | |
912000e7 | 241 | |
1da177e4 LT |
242 | /* |
243 | * Validate the input - check to see if address is on the | |
244 | * wrong boundary or beyond the end of the user area | |
245 | */ | |
246 | if ((addr & 3) || (numReg > PT_FPSCR)) | |
247 | break; | |
fabca2c0 | 248 | CHECK_FULL_REGS(child->thread.regs); |
912000e7 BH |
249 | if (numReg < PT_FPR0) { |
250 | unsigned long freg = ptrace_get_reg(child, numReg); | |
251 | if (index % 2) | |
252 | freg = (freg & ~0xfffffffful) | (data & 0xfffffffful); | |
253 | else | |
254 | freg = (freg & 0xfffffffful) | (data << 32); | |
255 | ret = ptrace_put_reg(child, numReg, freg); | |
256 | } else { | |
1da177e4 | 257 | flush_fp_to_thread(child); |
912000e7 BH |
258 | ((unsigned int *)child->thread.regs)[index] = data; |
259 | ret = 0; | |
1da177e4 | 260 | } |
1da177e4 LT |
261 | break; |
262 | } | |
263 | ||
fd9648df AB |
264 | case PTRACE_GET_DEBUGREG: { |
265 | ret = -EINVAL; | |
266 | /* We only support one DABR and no IABRS at the moment */ | |
267 | if (addr > 0) | |
268 | break; | |
269 | ret = put_user(child->thread.dabr, (u32 __user *)data); | |
270 | break; | |
271 | } | |
272 | ||
0deef2c7 RM |
273 | case PTRACE_GETREGS: /* Get all pt_regs from the child. */ |
274 | return copy_regset_to_user( | |
275 | child, task_user_regset_view(current), 0, | |
276 | 0, PT_REGS_COUNT * sizeof(compat_long_t), | |
277 | compat_ptr(data)); | |
278 | ||
279 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ | |
280 | return copy_regset_from_user( | |
281 | child, task_user_regset_view(current), 0, | |
282 | 0, PT_REGS_COUNT * sizeof(compat_long_t), | |
283 | compat_ptr(data)); | |
1da177e4 | 284 | |
e17666ba BH |
285 | case PTRACE_GETFPREGS: |
286 | case PTRACE_SETFPREGS: | |
962bca7f | 287 | case PTRACE_GETVRREGS: |
e17666ba BH |
288 | case PTRACE_SETVRREGS: |
289 | case PTRACE_GETREGS64: | |
290 | case PTRACE_SETREGS64: | |
291 | case PPC_PTRACE_GETFPREGS: | |
292 | case PPC_PTRACE_SETFPREGS: | |
293 | case PTRACE_KILL: | |
294 | case PTRACE_SINGLESTEP: | |
295 | case PTRACE_DETACH: | |
296 | case PTRACE_SET_DEBUGREG: | |
297 | case PTRACE_SYSCALL: | |
298 | case PTRACE_CONT: | |
299 | ret = arch_ptrace(child, request, addr, data); | |
962bca7f RJ |
300 | break; |
301 | ||
e17666ba BH |
302 | /* Old reverse args ptrace callss */ |
303 | case PPC_PTRACE_GETREGS: /* Get GPRs 0 - 31. */ | |
304 | case PPC_PTRACE_SETREGS: /* Set GPRs 0 - 31. */ | |
305 | ret = compat_ptrace_old(child, request, addr, data); | |
962bca7f | 306 | break; |
962bca7f | 307 | |
1da177e4 | 308 | default: |
1d48d71c | 309 | ret = compat_ptrace_request(child, request, addr, data); |
1da177e4 LT |
310 | break; |
311 | } | |
81e695c0 | 312 | |
1da177e4 LT |
313 | return ret; |
314 | } |