Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: arch/blackfin/kernel/ptrace.c |
| 3 | * Based on: Taken from linux/kernel/ptrace.c |
| 4 | * Author: linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds |
| 5 | * |
| 6 | * Created: 1/23/92 |
| 7 | * Description: |
| 8 | * |
| 9 | * Modified: |
| 10 | * Copyright 2004-2006 Analog Devices Inc. |
| 11 | * |
| 12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, see the file COPYING, or write |
| 26 | * to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | */ |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/sched.h> |
| 32 | #include <linux/mm.h> |
| 33 | #include <linux/smp.h> |
| 34 | #include <linux/smp_lock.h> |
| 35 | #include <linux/errno.h> |
| 36 | #include <linux/ptrace.h> |
| 37 | #include <linux/user.h> |
| 38 | #include <linux/signal.h> |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 39 | #include <linux/uaccess.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 40 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 41 | #include <asm/page.h> |
| 42 | #include <asm/pgtable.h> |
| 43 | #include <asm/system.h> |
| 44 | #include <asm/processor.h> |
| 45 | #include <asm/asm-offsets.h> |
| 46 | #include <asm/dma.h> |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 47 | #include <asm/fixed_code.h> |
Jie Zhang | 7786ce8 | 2009-03-05 18:50:26 +0800 | [diff] [blame] | 48 | #include <asm/cacheflush.h> |
Graf Yang | dbc895f | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 49 | #include <asm/mem_map.h> |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 50 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 51 | #define TEXT_OFFSET 0 |
| 52 | /* |
| 53 | * does not yet catch signals sent when the child dies. |
| 54 | * in exit.c or in signal.c. |
| 55 | */ |
| 56 | |
| 57 | /* determines which bits in the SYSCFG reg the user has access to. */ |
| 58 | /* 1 = access 0 = no access */ |
| 59 | #define SYSCFG_MASK 0x0007 /* SYSCFG reg */ |
| 60 | /* sets the trace bits. */ |
| 61 | #define TRACE_BITS 0x0001 |
| 62 | |
| 63 | /* Find the stack offset for a register, relative to thread.esp0. */ |
| 64 | #define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg) |
| 65 | |
| 66 | /* |
| 67 | * Get the address of the live pt_regs for the specified task. |
| 68 | * These are saved onto the top kernel stack when the process |
| 69 | * is not running. |
| 70 | * |
| 71 | * Note: if a user thread is execve'd from kernel space, the |
| 72 | * kernel stack will not be empty on entry to the kernel, so |
| 73 | * ptracing these tasks will fail. |
| 74 | */ |
| 75 | static inline struct pt_regs *get_user_regs(struct task_struct *task) |
| 76 | { |
| 77 | return (struct pt_regs *) |
Roman Zippel | f7e4217 | 2007-05-09 02:35:17 -0700 | [diff] [blame] | 78 | ((unsigned long)task_stack_page(task) + |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 79 | (THREAD_SIZE - sizeof(struct pt_regs))); |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Get all user integer registers. |
| 84 | */ |
Mike Frysinger | 8a86176 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 85 | static inline int ptrace_getregs(struct task_struct *tsk, void __user *uregs) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 86 | { |
Mike Frysinger | 8a86176 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 87 | struct pt_regs regs; |
| 88 | memcpy(®s, get_user_regs(tsk), sizeof(regs)); |
| 89 | regs.usp = tsk->thread.usp; |
| 90 | return copy_to_user(uregs, ®s, sizeof(struct pt_regs)) ? -EFAULT : 0; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* Mapping from PT_xxx to the stack offset at which the register is |
| 94 | * saved. Notice that usp has no stack-slot and needs to be treated |
| 95 | * specially (see get_reg/put_reg below). |
| 96 | */ |
| 97 | |
| 98 | /* |
| 99 | * Get contents of register REGNO in task TASK. |
| 100 | */ |
| 101 | static inline long get_reg(struct task_struct *task, int regno) |
| 102 | { |
| 103 | unsigned char *reg_ptr; |
| 104 | |
| 105 | struct pt_regs *regs = |
Roman Zippel | f7e4217 | 2007-05-09 02:35:17 -0700 | [diff] [blame] | 106 | (struct pt_regs *)((unsigned long)task_stack_page(task) + |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 107 | (THREAD_SIZE - sizeof(struct pt_regs))); |
| 108 | reg_ptr = (char *)regs; |
| 109 | |
| 110 | switch (regno) { |
| 111 | case PT_USP: |
| 112 | return task->thread.usp; |
| 113 | default: |
| 114 | if (regno <= 216) |
| 115 | return *(long *)(reg_ptr + regno); |
| 116 | } |
| 117 | /* slight mystery ... never seems to come here but kernel misbehaves without this code! */ |
| 118 | |
| 119 | printk(KERN_WARNING "Request to get for unknown register %d\n", regno); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * Write contents of register REGNO in task TASK. |
| 125 | */ |
| 126 | static inline int |
| 127 | put_reg(struct task_struct *task, int regno, unsigned long data) |
| 128 | { |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 129 | char *reg_ptr; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 130 | |
| 131 | struct pt_regs *regs = |
Roman Zippel | f7e4217 | 2007-05-09 02:35:17 -0700 | [diff] [blame] | 132 | (struct pt_regs *)((unsigned long)task_stack_page(task) + |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 133 | (THREAD_SIZE - sizeof(struct pt_regs))); |
| 134 | reg_ptr = (char *)regs; |
| 135 | |
| 136 | switch (regno) { |
| 137 | case PT_PC: |
| 138 | /*********************************************************************/ |
| 139 | /* At this point the kernel is most likely in exception. */ |
| 140 | /* The RETX register will be used to populate the pc of the process. */ |
| 141 | /*********************************************************************/ |
| 142 | regs->retx = data; |
| 143 | regs->pc = data; |
| 144 | break; |
| 145 | case PT_RETX: |
| 146 | break; /* regs->retx = data; break; */ |
| 147 | case PT_USP: |
| 148 | regs->usp = data; |
| 149 | task->thread.usp = data; |
| 150 | break; |
| 151 | default: |
| 152 | if (regno <= 216) |
Mike Frysinger | 1f83b8f | 2007-07-12 22:58:21 +0800 | [diff] [blame] | 153 | *(long *)(reg_ptr + regno) = data; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * check that an address falls within the bounds of the target process's memory mappings |
| 160 | */ |
| 161 | static inline int is_user_addr_valid(struct task_struct *child, |
| 162 | unsigned long start, unsigned long len) |
| 163 | { |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 164 | struct vm_area_struct *vma; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 165 | struct sram_list_struct *sraml; |
| 166 | |
Mike Frysinger | 3c08f1d | 2008-10-10 17:12:51 +0800 | [diff] [blame] | 167 | /* overflow */ |
| 168 | if (start + len < start) |
| 169 | return -EIO; |
| 170 | |
David Howells | 8feae13 | 2009-01-08 12:04:47 +0000 | [diff] [blame] | 171 | vma = find_vma(child->mm, start); |
| 172 | if (vma && start >= vma->vm_start && start + len <= vma->vm_end) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 173 | return 0; |
| 174 | |
| 175 | for (sraml = child->mm->context.sram_list; sraml; sraml = sraml->next) |
| 176 | if (start >= (unsigned long)sraml->addr |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 177 | && start + len < (unsigned long)sraml->addr + sraml->length) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 178 | return 0; |
| 179 | |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 180 | if (start >= FIXED_CODE_START && start + len < FIXED_CODE_END) |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 181 | return 0; |
| 182 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 183 | return -EIO; |
| 184 | } |
| 185 | |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 186 | void ptrace_enable(struct task_struct *child) |
| 187 | { |
| 188 | unsigned long tmp; |
| 189 | tmp = get_reg(child, PT_SYSCFG) | (TRACE_BITS); |
| 190 | put_reg(child, PT_SYSCFG, tmp); |
| 191 | } |
| 192 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 193 | /* |
| 194 | * Called by kernel/ptrace.c when detaching.. |
| 195 | * |
| 196 | * Make sure the single step bit is not set. |
| 197 | */ |
| 198 | void ptrace_disable(struct task_struct *child) |
| 199 | { |
| 200 | unsigned long tmp; |
| 201 | /* make sure the single step bit is not set. */ |
Bernd Schmidt | 7d39270 | 2008-05-07 11:41:26 +0800 | [diff] [blame] | 202 | tmp = get_reg(child, PT_SYSCFG) & ~TRACE_BITS; |
| 203 | put_reg(child, PT_SYSCFG, tmp); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
| 207 | { |
| 208 | int ret; |
Mike Frysinger | 0ddeeca | 2008-03-07 02:37:41 +0800 | [diff] [blame] | 209 | unsigned long __user *datap = (unsigned long __user *)data; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 210 | |
| 211 | switch (request) { |
| 212 | /* when I and D space are separate, these will need to be fixed. */ |
| 213 | case PTRACE_PEEKDATA: |
| 214 | pr_debug("ptrace: PEEKDATA\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 215 | /* fall through */ |
| 216 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
| 217 | { |
| 218 | unsigned long tmp = 0; |
| 219 | int copied; |
| 220 | |
| 221 | ret = -EIO; |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 222 | pr_debug("ptrace: PEEKTEXT at addr 0x%08lx + %ld\n", addr, sizeof(data)); |
| 223 | if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 224 | break; |
| 225 | pr_debug("ptrace: user address is valid\n"); |
| 226 | |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 227 | if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start() |
| 228 | && addr + sizeof(tmp) <= get_l1_code_start() + L1_CODE_LENGTH) { |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 229 | safe_dma_memcpy (&tmp, (const void *)(addr), sizeof(tmp)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 230 | copied = sizeof(tmp); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 231 | |
| 232 | } else if (L1_DATA_A_LENGTH != 0 && addr >= L1_DATA_A_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 233 | && addr + sizeof(tmp) <= L1_DATA_A_START + L1_DATA_A_LENGTH) { |
| 234 | memcpy(&tmp, (const void *)(addr), sizeof(tmp)); |
Jie Zhang | 6546eae | 2008-07-15 16:15:40 +0800 | [diff] [blame] | 235 | copied = sizeof(tmp); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 236 | |
| 237 | } else if (L1_DATA_B_LENGTH != 0 && addr >= L1_DATA_B_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 238 | && addr + sizeof(tmp) <= L1_DATA_B_START + L1_DATA_B_LENGTH) { |
| 239 | memcpy(&tmp, (const void *)(addr), sizeof(tmp)); |
Jie Zhang | 6546eae | 2008-07-15 16:15:40 +0800 | [diff] [blame] | 240 | copied = sizeof(tmp); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 241 | |
| 242 | } else if (addr >= FIXED_CODE_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 243 | && addr + sizeof(tmp) <= FIXED_CODE_END) { |
Jie Zhang | 7786ce8 | 2009-03-05 18:50:26 +0800 | [diff] [blame] | 244 | copy_from_user_page(0, 0, 0, &tmp, (const void *)(addr), sizeof(tmp)); |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 245 | copied = sizeof(tmp); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 246 | |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 247 | } else |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 248 | copied = access_process_vm(child, addr, &tmp, |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 249 | sizeof(tmp), 0); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 250 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 251 | pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp); |
| 252 | if (copied != sizeof(tmp)) |
| 253 | break; |
Mike Frysinger | 0ddeeca | 2008-03-07 02:37:41 +0800 | [diff] [blame] | 254 | ret = put_user(tmp, datap); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 255 | break; |
| 256 | } |
| 257 | |
| 258 | /* read the word at location addr in the USER area. */ |
| 259 | case PTRACE_PEEKUSR: |
| 260 | { |
| 261 | unsigned long tmp; |
| 262 | ret = -EIO; |
| 263 | tmp = 0; |
| 264 | if ((addr & 3) || (addr > (sizeof(struct pt_regs) + 16))) { |
| 265 | printk(KERN_WARNING "ptrace error : PEEKUSR : temporarily returning " |
| 266 | "0 - %x sizeof(pt_regs) is %lx\n", |
| 267 | (int)addr, sizeof(struct pt_regs)); |
| 268 | break; |
| 269 | } |
| 270 | if (addr == sizeof(struct pt_regs)) { |
| 271 | /* PT_TEXT_ADDR */ |
| 272 | tmp = child->mm->start_code + TEXT_OFFSET; |
| 273 | } else if (addr == (sizeof(struct pt_regs) + 4)) { |
| 274 | /* PT_TEXT_END_ADDR */ |
| 275 | tmp = child->mm->end_code; |
| 276 | } else if (addr == (sizeof(struct pt_regs) + 8)) { |
| 277 | /* PT_DATA_ADDR */ |
| 278 | tmp = child->mm->start_data; |
| 279 | #ifdef CONFIG_BINFMT_ELF_FDPIC |
| 280 | } else if (addr == (sizeof(struct pt_regs) + 12)) { |
| 281 | tmp = child->mm->context.exec_fdpic_loadmap; |
| 282 | } else if (addr == (sizeof(struct pt_regs) + 16)) { |
| 283 | tmp = child->mm->context.interp_fdpic_loadmap; |
| 284 | #endif |
| 285 | } else { |
| 286 | tmp = get_reg(child, addr); |
| 287 | } |
Mike Frysinger | 0ddeeca | 2008-03-07 02:37:41 +0800 | [diff] [blame] | 288 | ret = put_user(tmp, datap); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 289 | break; |
| 290 | } |
| 291 | |
| 292 | /* when I and D space are separate, this will have to be fixed. */ |
| 293 | case PTRACE_POKEDATA: |
Mike Frysinger | d3ab3a6 | 2008-10-09 15:19:50 +0800 | [diff] [blame] | 294 | pr_debug("ptrace: PTRACE_PEEKDATA\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 295 | /* fall through */ |
| 296 | case PTRACE_POKETEXT: /* write the word at location addr. */ |
| 297 | { |
| 298 | int copied; |
| 299 | |
| 300 | ret = -EIO; |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 301 | pr_debug("ptrace: POKETEXT at addr 0x%08lx + %ld bytes %lx\n", |
| 302 | addr, sizeof(data), data); |
| 303 | if (is_user_addr_valid(child, addr, sizeof(data)) < 0) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 304 | break; |
| 305 | pr_debug("ptrace: user address is valid\n"); |
| 306 | |
Graf Yang | 8f65873 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 307 | if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start() |
| 308 | && addr + sizeof(data) <= get_l1_code_start() + L1_CODE_LENGTH) { |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 309 | safe_dma_memcpy ((void *)(addr), &data, sizeof(data)); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 310 | copied = sizeof(data); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 311 | |
| 312 | } else if (L1_DATA_A_LENGTH != 0 && addr >= L1_DATA_A_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 313 | && addr + sizeof(data) <= L1_DATA_A_START + L1_DATA_A_LENGTH) { |
| 314 | memcpy((void *)(addr), &data, sizeof(data)); |
Jie Zhang | 6546eae | 2008-07-15 16:15:40 +0800 | [diff] [blame] | 315 | copied = sizeof(data); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 316 | |
| 317 | } else if (L1_DATA_B_LENGTH != 0 && addr >= L1_DATA_B_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 318 | && addr + sizeof(data) <= L1_DATA_B_START + L1_DATA_B_LENGTH) { |
| 319 | memcpy((void *)(addr), &data, sizeof(data)); |
Jie Zhang | 6546eae | 2008-07-15 16:15:40 +0800 | [diff] [blame] | 320 | copied = sizeof(data); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 321 | |
| 322 | } else if (addr >= FIXED_CODE_START |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 323 | && addr + sizeof(data) <= FIXED_CODE_END) { |
Jie Zhang | 7786ce8 | 2009-03-05 18:50:26 +0800 | [diff] [blame] | 324 | copy_to_user_page(0, 0, 0, (void *)(addr), &data, sizeof(data)); |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 325 | copied = sizeof(data); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 326 | |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 327 | } else |
Mike Frysinger | dabaad5 | 2008-10-09 15:17:36 +0800 | [diff] [blame] | 328 | copied = access_process_vm(child, addr, &data, |
Jie Zhang | 2615639 | 2007-08-05 16:25:23 +0800 | [diff] [blame] | 329 | sizeof(data), 1); |
Mike Frysinger | d207a8c | 2008-10-10 17:26:57 +0800 | [diff] [blame] | 330 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 331 | pr_debug("ptrace: copied size %d\n", copied); |
| 332 | if (copied != sizeof(data)) |
| 333 | break; |
| 334 | ret = 0; |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
| 339 | ret = -EIO; |
| 340 | if ((addr & 3) || (addr > (sizeof(struct pt_regs) + 16))) { |
| 341 | printk(KERN_WARNING "ptrace error : POKEUSR: temporarily returning 0\n"); |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | if (addr >= (sizeof(struct pt_regs))) { |
| 346 | ret = 0; |
| 347 | break; |
| 348 | } |
| 349 | if (addr == PT_SYSCFG) { |
| 350 | data &= SYSCFG_MASK; |
| 351 | data |= get_reg(child, PT_SYSCFG); |
| 352 | } |
| 353 | ret = put_reg(child, addr, data); |
| 354 | break; |
| 355 | |
| 356 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 357 | case PTRACE_CONT: /* restart after signal. */ |
| 358 | pr_debug("ptrace: syscall/cont\n"); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 359 | |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 360 | ret = -EIO; |
| 361 | if (!valid_signal(data)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 362 | break; |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 363 | if (request == PTRACE_SYSCALL) |
| 364 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 365 | else |
| 366 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 367 | child->exit_code = data; |
| 368 | ptrace_disable(child); |
| 369 | pr_debug("ptrace: before wake_up_process\n"); |
| 370 | wake_up_process(child); |
| 371 | ret = 0; |
| 372 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * make the child exit. Best I can do is send it a sigkill. |
| 376 | * perhaps it should be put in the status that it wants to |
| 377 | * exit. |
| 378 | */ |
| 379 | case PTRACE_KILL: |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 380 | ret = 0; |
| 381 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 382 | break; |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 383 | child->exit_code = SIGKILL; |
| 384 | ptrace_disable(child); |
| 385 | wake_up_process(child); |
| 386 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 387 | |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 388 | case PTRACE_SINGLESTEP: /* set the trap flag. */ |
| 389 | pr_debug("ptrace: single step\n"); |
| 390 | ret = -EIO; |
| 391 | if (!valid_signal(data)) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 392 | break; |
Mike Frysinger | cb4c173 | 2008-10-09 15:21:05 +0800 | [diff] [blame] | 393 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); |
| 394 | ptrace_enable(child); |
| 395 | child->exit_code = data; |
| 396 | wake_up_process(child); |
| 397 | ret = 0; |
| 398 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 399 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 400 | case PTRACE_GETREGS: |
Mike Frysinger | d3ab3a6 | 2008-10-09 15:19:50 +0800 | [diff] [blame] | 401 | /* Get all gp regs from the child. */ |
| 402 | ret = ptrace_getregs(child, datap); |
| 403 | break; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 404 | |
| 405 | case PTRACE_SETREGS: |
Mike Frysinger | d3ab3a6 | 2008-10-09 15:19:50 +0800 | [diff] [blame] | 406 | printk(KERN_WARNING "ptrace: SETREGS: **** NOT IMPLEMENTED ***\n"); |
| 407 | /* Set all gp regs in the child. */ |
| 408 | ret = 0; |
| 409 | break; |
| 410 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 411 | default: |
| 412 | ret = ptrace_request(child, request, addr, data); |
| 413 | break; |
| 414 | } |
| 415 | |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | asmlinkage void syscall_trace(void) |
| 420 | { |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 421 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
| 422 | return; |
| 423 | |
| 424 | if (!(current->ptrace & PT_PTRACED)) |
| 425 | return; |
| 426 | |
| 427 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 428 | * between a syscall stop and SIGTRAP delivery |
| 429 | */ |
| 430 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
| 431 | ? 0x80 : 0)); |
| 432 | |
| 433 | /* |
| 434 | * this isn't the same as continuing with a signal, but it will do |
| 435 | * for normal use. strace only continues with a signal if the |
| 436 | * stopping signal is not SIGTRAP. -brl |
| 437 | */ |
| 438 | if (current->exit_code) { |
| 439 | send_sig(current->exit_code, current, 1); |
| 440 | current->exit_code = 0; |
| 441 | } |
| 442 | } |