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