Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 2 | * ptrace for 32-bit processes running on a 64-bit kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 13 | * and Paul Mackerras (paulus@samba.org). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
| 15 | * This file is subject to the terms and conditions of the GNU General |
Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 16 | * Public License. See the file COPYING in the main directory of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/ptrace.h> |
Roland McGrath | 0deef2c | 2007-12-20 03:59:04 -0800 | [diff] [blame] | 26 | #include <linux/regset.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/user.h> |
| 28 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 29 | #include <linux/signal.h> |
Roland McGrath | 1d48d71 | 2007-12-20 03:58:49 -0800 | [diff] [blame] | 30 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/uaccess.h> |
| 33 | #include <asm/page.h> |
| 34 | #include <asm/pgtable.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 35 | #include <asm/switch_to.h> |
Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | /* |
| 38 | * does not yet catch signals sent when the child dies. |
| 39 | * in exit.c or in signal.c. |
| 40 | */ |
| 41 | |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 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) |
Michael Neuling | bc82666 | 2009-04-05 20:59:39 +0000 | [diff] [blame] | 45 | #define FPRINDEX(i) TS_FPRWIDTH * FPRNUMBER(i) * 2 + FPRHALF(i) |
| 46 | #define FPRINDEX_3264(i) (TS_FPRWIDTH * ((i) - PT_FPR0)) |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 47 | |
Roland McGrath | 81e695c | 2007-12-20 03:58:55 -0800 | [diff] [blame] | 48 | long compat_arch_ptrace(struct task_struct *child, compat_long_t request, |
| 49 | compat_ulong_t caddr, compat_ulong_t cdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Roland McGrath | 81e695c | 2007-12-20 03:58:55 -0800 | [diff] [blame] | 51 | unsigned long addr = caddr; |
| 52 | unsigned long data = cdata; |
Christoph Hellwig | 6b9c7ed8 | 2006-01-08 01:02:33 -0800 | [diff] [blame] | 53 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Read 4 bytes of the other process' storage |
| 58 | * data is a pointer specifying where the user wants the |
| 59 | * 4 bytes copied into |
| 60 | * addr is a pointer in the user's storage that contains an 8 byte |
| 61 | * address in the other process of the 4 bytes that is to be read |
| 62 | * (this is run in a 32-bit process looking at a 64-bit process) |
| 63 | * when I and D space are separate, these will need to be fixed. |
| 64 | */ |
| 65 | case PPC_PTRACE_PEEKTEXT_3264: |
| 66 | case PPC_PTRACE_PEEKDATA_3264: { |
| 67 | u32 tmp; |
| 68 | int copied; |
| 69 | u32 __user * addrOthers; |
| 70 | |
| 71 | ret = -EIO; |
| 72 | |
| 73 | /* Get the addr in the other process that we want to read */ |
| 74 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) |
| 75 | break; |
| 76 | |
| 77 | copied = access_process_vm(child, (u64)addrOthers, &tmp, |
| 78 | sizeof(tmp), 0); |
| 79 | if (copied != sizeof(tmp)) |
| 80 | break; |
| 81 | ret = put_user(tmp, (u32 __user *)data); |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | /* Read a register (specified by ADDR) out of the "user area" */ |
| 86 | case PTRACE_PEEKUSR: { |
| 87 | int index; |
| 88 | unsigned long tmp; |
| 89 | |
| 90 | ret = -EIO; |
| 91 | /* convert to index and check */ |
| 92 | index = (unsigned long) addr >> 2; |
| 93 | if ((addr & 3) || (index > PT_FPSCR32)) |
| 94 | break; |
| 95 | |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 96 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 98 | tmp = ptrace_get_reg(child, index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } else { |
| 100 | flush_fp_to_thread(child); |
| 101 | /* |
| 102 | * the user space code considers the floating point |
| 103 | * to be an array of unsigned int (32 bits) - the |
| 104 | * index passed in is based on this assumption. |
| 105 | */ |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 106 | tmp = ((unsigned int *)child->thread.fpr) |
| 107 | [FPRINDEX(index)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | ret = put_user((unsigned int)tmp, (u32 __user *)data); |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * Read 4 bytes out of the other process' pt_regs area |
| 115 | * data is a pointer specifying where the user wants the |
| 116 | * 4 bytes copied into |
| 117 | * addr is the offset into the other process' pt_regs structure |
| 118 | * that is to be read |
| 119 | * (this is run in a 32-bit process looking at a 64-bit process) |
| 120 | */ |
| 121 | case PPC_PTRACE_PEEKUSR_3264: { |
| 122 | u32 index; |
| 123 | u32 reg32bits; |
| 124 | u64 tmp; |
| 125 | u32 numReg; |
| 126 | u32 part; |
| 127 | |
| 128 | ret = -EIO; |
| 129 | /* Determine which register the user wants */ |
| 130 | index = (u64)addr >> 2; |
| 131 | numReg = index / 2; |
| 132 | /* Determine which part of the register the user wants */ |
| 133 | if (index % 2) |
| 134 | part = 1; /* want the 2nd half of the register (right-most). */ |
| 135 | else |
| 136 | part = 0; /* want the 1st half of the register (left-most). */ |
| 137 | |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 138 | /* Validate the input - check to see if address is on the wrong boundary |
| 139 | * or beyond the end of the user area |
| 140 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if ((addr & 3) || numReg > PT_FPSCR) |
| 142 | break; |
| 143 | |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 144 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | if (numReg >= PT_FPR0) { |
| 146 | flush_fp_to_thread(child); |
Michael Neuling | bc82666 | 2009-04-05 20:59:39 +0000 | [diff] [blame] | 147 | /* get 64 bit FPR */ |
| 148 | tmp = ((u64 *)child->thread.fpr) |
| 149 | [FPRINDEX_3264(numReg)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } else { /* register within PT_REGS struct */ |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 151 | tmp = ptrace_get_reg(child, numReg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | reg32bits = ((u32*)&tmp)[part]; |
| 154 | ret = put_user(reg32bits, (u32 __user *)data); |
| 155 | break; |
| 156 | } |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | /* |
| 159 | * Write 4 bytes into the other process' storage |
| 160 | * data is the 4 bytes that the user wants written |
| 161 | * addr is a pointer in the user's storage that contains an |
| 162 | * 8 byte address in the other process where the 4 bytes |
| 163 | * that is to be written |
| 164 | * (this is run in a 32-bit process looking at a 64-bit process) |
| 165 | * when I and D space are separate, these will need to be fixed. |
| 166 | */ |
| 167 | case PPC_PTRACE_POKETEXT_3264: |
| 168 | case PPC_PTRACE_POKEDATA_3264: { |
| 169 | u32 tmp = data; |
| 170 | u32 __user * addrOthers; |
| 171 | |
| 172 | /* Get the addr in the other process that we want to write into */ |
| 173 | ret = -EIO; |
| 174 | if (get_user(addrOthers, (u32 __user * __user *)addr) != 0) |
| 175 | break; |
| 176 | ret = 0; |
| 177 | if (access_process_vm(child, (u64)addrOthers, &tmp, |
| 178 | sizeof(tmp), 1) == sizeof(tmp)) |
| 179 | break; |
| 180 | ret = -EIO; |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | /* write the word at location addr in the USER area */ |
| 185 | case PTRACE_POKEUSR: { |
| 186 | unsigned long index; |
| 187 | |
| 188 | ret = -EIO; |
| 189 | /* convert to index and check */ |
| 190 | index = (unsigned long) addr >> 2; |
| 191 | if ((addr & 3) || (index > PT_FPSCR32)) |
| 192 | break; |
| 193 | |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 194 | CHECK_FULL_REGS(child->thread.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (index < PT_FPR0) { |
Benjamin Herrenschmidt | 865418d | 2007-06-04 15:15:44 +1000 | [diff] [blame] | 196 | ret = ptrace_put_reg(child, index, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } else { |
| 198 | flush_fp_to_thread(child); |
| 199 | /* |
| 200 | * the user space code considers the floating point |
| 201 | * to be an array of unsigned int (32 bits) - the |
| 202 | * index passed in is based on this assumption. |
| 203 | */ |
Michael Neuling | 9c75a31 | 2008-06-26 17:07:48 +1000 | [diff] [blame] | 204 | ((unsigned int *)child->thread.fpr) |
| 205 | [FPRINDEX(index)] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | ret = 0; |
| 207 | } |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * Write 4 bytes into the other process' pt_regs area |
| 213 | * data is the 4 bytes that the user wants written |
| 214 | * addr is the offset into the other process' pt_regs structure |
| 215 | * that is to be written into |
| 216 | * (this is run in a 32-bit process looking at a 64-bit process) |
| 217 | */ |
| 218 | case PPC_PTRACE_POKEUSR_3264: { |
| 219 | u32 index; |
| 220 | u32 numReg; |
| 221 | |
| 222 | ret = -EIO; |
| 223 | /* Determine which register the user wants */ |
| 224 | index = (u64)addr >> 2; |
| 225 | numReg = index / 2; |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* |
| 228 | * Validate the input - check to see if address is on the |
| 229 | * wrong boundary or beyond the end of the user area |
| 230 | */ |
| 231 | if ((addr & 3) || (numReg > PT_FPSCR)) |
| 232 | break; |
Roland McGrath | fabca2c | 2007-09-25 09:50:52 +1000 | [diff] [blame] | 233 | CHECK_FULL_REGS(child->thread.regs); |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 234 | if (numReg < PT_FPR0) { |
| 235 | unsigned long freg = ptrace_get_reg(child, numReg); |
| 236 | if (index % 2) |
| 237 | freg = (freg & ~0xfffffffful) | (data & 0xfffffffful); |
| 238 | else |
| 239 | freg = (freg & 0xfffffffful) | (data << 32); |
| 240 | ret = ptrace_put_reg(child, numReg, freg); |
| 241 | } else { |
Michael Neuling | bc82666 | 2009-04-05 20:59:39 +0000 | [diff] [blame] | 242 | u64 *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | flush_fp_to_thread(child); |
Michael Neuling | bc82666 | 2009-04-05 20:59:39 +0000 | [diff] [blame] | 244 | /* get 64 bit FPR ... */ |
| 245 | tmp = &(((u64 *)child->thread.fpr) |
| 246 | [FPRINDEX_3264(numReg)]); |
| 247 | /* ... write the 32 bit part we want */ |
| 248 | ((u32 *)tmp)[index % 2] = data; |
Benjamin Herrenschmidt | 912000e | 2007-06-04 15:15:46 +1000 | [diff] [blame] | 249 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | |
Anton Blanchard | fd9648d | 2005-09-10 16:01:11 +1000 | [diff] [blame] | 254 | case PTRACE_GET_DEBUGREG: { |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame^] | 255 | #ifndef CONFIG_PPC_ADV_DEBUG_REGS |
| 256 | unsigned long dabr_fake; |
| 257 | #endif |
Anton Blanchard | fd9648d | 2005-09-10 16:01:11 +1000 | [diff] [blame] | 258 | ret = -EINVAL; |
| 259 | /* We only support one DABR and no IABRS at the moment */ |
| 260 | if (addr > 0) |
| 261 | break; |
Andreas Schwab | bb2c458b | 2010-11-28 06:33:14 +0000 | [diff] [blame] | 262 | #ifdef CONFIG_PPC_ADV_DEBUG_REGS |
| 263 | ret = put_user(child->thread.dac1, (u32 __user *)data); |
| 264 | #else |
Michael Neuling | 9422de3 | 2012-12-20 14:06:44 +0000 | [diff] [blame^] | 265 | dabr_fake = ( |
| 266 | (child->thread.hw_brk.address & (~HW_BRK_TYPE_DABR)) | |
| 267 | (child->thread.hw_brk.type & HW_BRK_TYPE_DABR)); |
| 268 | ret = put_user(dabr_fake, (u32 __user *)data); |
Andreas Schwab | bb2c458b | 2010-11-28 06:33:14 +0000 | [diff] [blame] | 269 | #endif |
Anton Blanchard | fd9648d | 2005-09-10 16:01:11 +1000 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | |
Roland McGrath | 0deef2c | 2007-12-20 03:59:04 -0800 | [diff] [blame] | 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)); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 278 | |
Roland McGrath | 0deef2c | 2007-12-20 03:59:04 -0800 | [diff] [blame] | 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)); |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 284 | |
| 285 | case PTRACE_GETFPREGS: |
| 286 | case PTRACE_SETFPREGS: |
Robert Jennings | 962bca7 | 2005-09-10 16:01:07 +1000 | [diff] [blame] | 287 | case PTRACE_GETVRREGS: |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 288 | case PTRACE_SETVRREGS: |
Michael Neuling | 33b3f03 | 2008-07-29 01:13:14 +1000 | [diff] [blame] | 289 | case PTRACE_GETVSRREGS: |
| 290 | case PTRACE_SETVSRREGS: |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 291 | case PTRACE_GETREGS64: |
| 292 | case PTRACE_SETREGS64: |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 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: |
Andreas Schwab | bb2c458b | 2010-11-28 06:33:14 +0000 | [diff] [blame] | 299 | case PPC_PTRACE_GETHWDBGINFO: |
| 300 | case PPC_PTRACE_SETHWDEBUG: |
| 301 | case PPC_PTRACE_DELHWDEBUG: |
Benjamin Herrenschmidt | e17666b | 2007-06-04 15:15:43 +1000 | [diff] [blame] | 302 | ret = arch_ptrace(child, request, addr, data); |
Robert Jennings | 962bca7 | 2005-09-10 16:01:07 +1000 | [diff] [blame] | 303 | break; |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | default: |
Roland McGrath | 1d48d71 | 2007-12-20 03:58:49 -0800 | [diff] [blame] | 306 | ret = compat_ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | } |
Roland McGrath | 81e695c | 2007-12-20 03:58:55 -0800 | [diff] [blame] | 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return ret; |
| 311 | } |