Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 2 | * SuperH process tracing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 4 | * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 5 | * Copyright (C) 2002 - 2009 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 7 | * Audit support by Yuichi Nakamura <ynakam@hitachisoft.jp> |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General Public |
| 10 | * License. See the file "COPYING" in the main directory of this archive |
| 11 | * for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/errno.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/user.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/security.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 22 | #include <linux/signal.h> |
Stuart Menefy | 9432f96 | 2007-02-23 13:22:17 +0900 | [diff] [blame] | 23 | #include <linux/io.h> |
Yuichi Nakamura | 1322b9d | 2007-11-10 19:21:34 +0900 | [diff] [blame] | 24 | #include <linux/audit.h> |
Paul Mundt | c4637d4 | 2008-07-30 15:30:52 +0900 | [diff] [blame] | 25 | #include <linux/seccomp.h> |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 26 | #include <linux/tracehook.h> |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 27 | #include <linux/elf.h> |
| 28 | #include <linux/regset.h> |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 29 | #include <linux/hw_breakpoint.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/uaccess.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/processor.h> |
| 34 | #include <asm/mmu_context.h> |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 35 | #include <asm/syscalls.h> |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 36 | #include <asm/fpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Paul Mundt | a74f7e0 | 2009-09-16 14:30:34 +0900 | [diff] [blame] | 38 | #define CREATE_TRACE_POINTS |
| 39 | #include <trace/events/syscalls.h> |
Matt Fleming | c652d78 | 2009-07-06 20:16:33 +0900 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | * This routine will get a word off of the process kernel stack. |
| 43 | */ |
| 44 | static inline int get_stack_long(struct task_struct *task, int offset) |
| 45 | { |
| 46 | unsigned char *stack; |
| 47 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 48 | stack = (unsigned char *)task_pt_regs(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | stack += offset; |
| 50 | return (*((int *)stack)); |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * This routine will put a word on the process kernel stack. |
| 55 | */ |
| 56 | static inline int put_stack_long(struct task_struct *task, int offset, |
| 57 | unsigned long data) |
| 58 | { |
| 59 | unsigned char *stack; |
| 60 | |
Al Viro | 3cf0f4e | 2006-01-12 01:05:44 -0800 | [diff] [blame] | 61 | stack = (unsigned char *)task_pt_regs(task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | stack += offset; |
| 63 | *(unsigned long *) stack = data; |
| 64 | return 0; |
| 65 | } |
| 66 | |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 67 | void ptrace_triggered(struct perf_event *bp, int nmi, |
| 68 | struct perf_sample_data *data, struct pt_regs *regs) |
| 69 | { |
| 70 | struct perf_event_attr attr; |
| 71 | |
| 72 | /* |
| 73 | * Disable the breakpoint request here since ptrace has defined a |
| 74 | * one-shot behaviour for breakpoint exceptions. |
| 75 | */ |
| 76 | attr = bp->attr; |
| 77 | attr.disabled = true; |
| 78 | modify_user_hw_breakpoint(bp, &attr); |
| 79 | } |
| 80 | |
| 81 | static int set_single_step(struct task_struct *tsk, unsigned long addr) |
| 82 | { |
| 83 | struct thread_struct *thread = &tsk->thread; |
| 84 | struct perf_event *bp; |
| 85 | struct perf_event_attr attr; |
| 86 | |
| 87 | bp = thread->ptrace_bps[0]; |
| 88 | if (!bp) { |
| 89 | hw_breakpoint_init(&attr); |
| 90 | |
| 91 | attr.bp_addr = addr; |
| 92 | attr.bp_len = HW_BREAKPOINT_LEN_2; |
| 93 | attr.bp_type = HW_BREAKPOINT_R; |
| 94 | |
| 95 | bp = register_user_hw_breakpoint(&attr, ptrace_triggered, tsk); |
| 96 | if (IS_ERR(bp)) |
| 97 | return PTR_ERR(bp); |
| 98 | |
| 99 | thread->ptrace_bps[0] = bp; |
| 100 | } else { |
| 101 | int err; |
| 102 | |
| 103 | attr = bp->attr; |
| 104 | attr.bp_addr = addr; |
| 105 | err = modify_user_hw_breakpoint(bp, &attr); |
| 106 | if (unlikely(err)) |
| 107 | return err; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 113 | void user_enable_single_step(struct task_struct *child) |
| 114 | { |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 115 | unsigned long pc = get_stack_long(child, offsetof(struct pt_regs, pc)); |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 116 | |
| 117 | set_tsk_thread_flag(child, TIF_SINGLESTEP); |
Paul Mundt | 34d0b5a | 2009-12-28 17:53:47 +0900 | [diff] [blame] | 118 | |
| 119 | set_single_step(child, pc); |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | void user_disable_single_step(struct task_struct *child) |
Stuart Menefy | 9432f96 | 2007-02-23 13:22:17 +0900 | [diff] [blame] | 123 | { |
| 124 | clear_tsk_thread_flag(child, TIF_SINGLESTEP); |
Stuart Menefy | 9432f96 | 2007-02-23 13:22:17 +0900 | [diff] [blame] | 125 | } |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
| 128 | * Called by kernel/ptrace.c when detaching.. |
| 129 | * |
| 130 | * Make sure single step bits etc are not set. |
| 131 | */ |
| 132 | void ptrace_disable(struct task_struct *child) |
| 133 | { |
Paul Mundt | c459dbf | 2008-07-30 19:09:31 +0900 | [diff] [blame] | 134 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 137 | static int genregs_get(struct task_struct *target, |
| 138 | const struct user_regset *regset, |
| 139 | unsigned int pos, unsigned int count, |
| 140 | void *kbuf, void __user *ubuf) |
| 141 | { |
| 142 | const struct pt_regs *regs = task_pt_regs(target); |
| 143 | int ret; |
| 144 | |
| 145 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 146 | regs->regs, |
| 147 | 0, 16 * sizeof(unsigned long)); |
| 148 | if (!ret) |
| 149 | /* PC, PR, SR, GBR, MACH, MACL, TRA */ |
| 150 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
| 151 | ®s->pc, |
| 152 | offsetof(struct pt_regs, pc), |
| 153 | sizeof(struct pt_regs)); |
| 154 | if (!ret) |
| 155 | ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 156 | sizeof(struct pt_regs), -1); |
| 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int genregs_set(struct task_struct *target, |
| 162 | const struct user_regset *regset, |
| 163 | unsigned int pos, unsigned int count, |
| 164 | const void *kbuf, const void __user *ubuf) |
| 165 | { |
| 166 | struct pt_regs *regs = task_pt_regs(target); |
| 167 | int ret; |
| 168 | |
| 169 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 170 | regs->regs, |
| 171 | 0, 16 * sizeof(unsigned long)); |
| 172 | if (!ret && count > 0) |
| 173 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
| 174 | ®s->pc, |
| 175 | offsetof(struct pt_regs, pc), |
| 176 | sizeof(struct pt_regs)); |
| 177 | if (!ret) |
| 178 | ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, |
| 179 | sizeof(struct pt_regs), -1); |
| 180 | |
| 181 | return ret; |
| 182 | } |
| 183 | |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 184 | #ifdef CONFIG_SH_FPU |
| 185 | int fpregs_get(struct task_struct *target, |
| 186 | const struct user_regset *regset, |
| 187 | unsigned int pos, unsigned int count, |
| 188 | void *kbuf, void __user *ubuf) |
| 189 | { |
| 190 | int ret; |
| 191 | |
| 192 | ret = init_fpu(target); |
| 193 | if (ret) |
| 194 | return ret; |
| 195 | |
| 196 | if ((boot_cpu_data.flags & CPU_HAS_FPU)) |
| 197 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 198 | &target->thread.xstate->hardfpu, 0, -1); |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 199 | |
| 200 | return user_regset_copyout(&pos, &count, &kbuf, &ubuf, |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 201 | &target->thread.xstate->softfpu, 0, -1); |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static int fpregs_set(struct task_struct *target, |
| 205 | const struct user_regset *regset, |
| 206 | unsigned int pos, unsigned int count, |
| 207 | const void *kbuf, const void __user *ubuf) |
| 208 | { |
| 209 | int ret; |
| 210 | |
| 211 | ret = init_fpu(target); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | set_stopped_child_used_math(target); |
| 216 | |
| 217 | if ((boot_cpu_data.flags & CPU_HAS_FPU)) |
| 218 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 219 | &target->thread.xstate->hardfpu, 0, -1); |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 220 | |
| 221 | return user_regset_copyin(&pos, &count, &kbuf, &ubuf, |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 222 | &target->thread.xstate->softfpu, 0, -1); |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static int fpregs_active(struct task_struct *target, |
| 226 | const struct user_regset *regset) |
| 227 | { |
| 228 | return tsk_used_math(target) ? regset->n : 0; |
| 229 | } |
| 230 | #endif |
| 231 | |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 232 | #ifdef CONFIG_SH_DSP |
| 233 | static int dspregs_get(struct task_struct *target, |
| 234 | const struct user_regset *regset, |
| 235 | unsigned int pos, unsigned int count, |
| 236 | void *kbuf, void __user *ubuf) |
| 237 | { |
Michael Trimarchi | 01ab103 | 2009-04-03 17:32:33 +0000 | [diff] [blame] | 238 | const struct pt_dspregs *regs = |
| 239 | (struct pt_dspregs *)&target->thread.dsp_status.dsp_regs; |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 240 | int ret; |
| 241 | |
| 242 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, regs, |
| 243 | 0, sizeof(struct pt_dspregs)); |
| 244 | if (!ret) |
| 245 | ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, |
| 246 | sizeof(struct pt_dspregs), -1); |
| 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static int dspregs_set(struct task_struct *target, |
| 252 | const struct user_regset *regset, |
| 253 | unsigned int pos, unsigned int count, |
| 254 | const void *kbuf, const void __user *ubuf) |
| 255 | { |
Michael Trimarchi | 01ab103 | 2009-04-03 17:32:33 +0000 | [diff] [blame] | 256 | struct pt_dspregs *regs = |
| 257 | (struct pt_dspregs *)&target->thread.dsp_status.dsp_regs; |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 258 | int ret; |
| 259 | |
| 260 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, regs, |
| 261 | 0, sizeof(struct pt_dspregs)); |
| 262 | if (!ret) |
| 263 | ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, |
| 264 | sizeof(struct pt_dspregs), -1); |
| 265 | |
| 266 | return ret; |
| 267 | } |
Paul Mundt | 7246199 | 2008-09-12 22:56:35 +0900 | [diff] [blame] | 268 | |
| 269 | static int dspregs_active(struct task_struct *target, |
| 270 | const struct user_regset *regset) |
| 271 | { |
| 272 | struct pt_regs *regs = task_pt_regs(target); |
| 273 | |
| 274 | return regs->sr & SR_DSP ? regset->n : 0; |
| 275 | } |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 276 | #endif |
| 277 | |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 278 | /* |
| 279 | * These are our native regset flavours. |
| 280 | */ |
| 281 | enum sh_regset { |
| 282 | REGSET_GENERAL, |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 283 | #ifdef CONFIG_SH_FPU |
| 284 | REGSET_FPU, |
| 285 | #endif |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 286 | #ifdef CONFIG_SH_DSP |
| 287 | REGSET_DSP, |
| 288 | #endif |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | static const struct user_regset sh_regsets[] = { |
| 292 | /* |
| 293 | * Format is: |
| 294 | * R0 --> R15 |
| 295 | * PC, PR, SR, GBR, MACH, MACL, TRA |
| 296 | */ |
| 297 | [REGSET_GENERAL] = { |
| 298 | .core_note_type = NT_PRSTATUS, |
| 299 | .n = ELF_NGREG, |
| 300 | .size = sizeof(long), |
| 301 | .align = sizeof(long), |
| 302 | .get = genregs_get, |
| 303 | .set = genregs_set, |
| 304 | }, |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 305 | |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 306 | #ifdef CONFIG_SH_FPU |
| 307 | [REGSET_FPU] = { |
| 308 | .core_note_type = NT_PRFPREG, |
| 309 | .n = sizeof(struct user_fpu_struct) / sizeof(long), |
| 310 | .size = sizeof(long), |
| 311 | .align = sizeof(long), |
| 312 | .get = fpregs_get, |
| 313 | .set = fpregs_set, |
| 314 | .active = fpregs_active, |
| 315 | }, |
| 316 | #endif |
| 317 | |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 318 | #ifdef CONFIG_SH_DSP |
| 319 | [REGSET_DSP] = { |
| 320 | .n = sizeof(struct pt_dspregs) / sizeof(long), |
| 321 | .size = sizeof(long), |
| 322 | .align = sizeof(long), |
| 323 | .get = dspregs_get, |
| 324 | .set = dspregs_set, |
Paul Mundt | 7246199 | 2008-09-12 22:56:35 +0900 | [diff] [blame] | 325 | .active = dspregs_active, |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 326 | }, |
| 327 | #endif |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | static const struct user_regset_view user_sh_native_view = { |
| 331 | .name = "sh", |
| 332 | .e_machine = EM_SH, |
| 333 | .regsets = sh_regsets, |
| 334 | .n = ARRAY_SIZE(sh_regsets), |
| 335 | }; |
| 336 | |
Paul Mundt | f9540ec | 2008-09-12 22:42:43 +0900 | [diff] [blame] | 337 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) |
| 338 | { |
| 339 | return &user_sh_native_view; |
| 340 | } |
| 341 | |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 342 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | struct user * dummy = NULL; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 345 | unsigned long __user *datap = (unsigned long __user *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | int ret; |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* read the word at location addr in the USER area. */ |
| 350 | case PTRACE_PEEKUSR: { |
| 351 | unsigned long tmp; |
| 352 | |
| 353 | ret = -EIO; |
Stuart Menefy | 9432f96 | 2007-02-23 13:22:17 +0900 | [diff] [blame] | 354 | if ((addr & 3) || addr < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | addr > sizeof(struct user) - 3) |
| 356 | break; |
| 357 | |
| 358 | if (addr < sizeof(struct pt_regs)) |
| 359 | tmp = get_stack_long(child, addr); |
| 360 | else if (addr >= (long) &dummy->fpu && |
| 361 | addr < (long) &dummy->u_fpvalid) { |
| 362 | if (!tsk_used_math(child)) { |
| 363 | if (addr == (long)&dummy->fpu.fpscr) |
| 364 | tmp = FPSCR_INIT; |
| 365 | else |
| 366 | tmp = 0; |
| 367 | } else |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 368 | tmp = ((long *)child->thread.xstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | [(addr - (long)&dummy->fpu) >> 2]; |
| 370 | } else if (addr == (long) &dummy->u_fpvalid) |
| 371 | tmp = !!tsk_used_math(child); |
Peter Griffin | ba0d474 | 2009-05-08 15:50:54 +0100 | [diff] [blame] | 372 | else if (addr == PT_TEXT_ADDR) |
| 373 | tmp = child->mm->start_code; |
| 374 | else if (addr == PT_DATA_ADDR) |
| 375 | tmp = child->mm->start_data; |
| 376 | else if (addr == PT_TEXT_END_ADDR) |
| 377 | tmp = child->mm->end_code; |
| 378 | else if (addr == PT_TEXT_LEN) |
| 379 | tmp = child->mm->end_code - child->mm->start_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | else |
| 381 | tmp = 0; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 382 | ret = put_user(tmp, datap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | } |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
| 387 | ret = -EIO; |
Stuart Menefy | 9432f96 | 2007-02-23 13:22:17 +0900 | [diff] [blame] | 388 | if ((addr & 3) || addr < 0 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | addr > sizeof(struct user) - 3) |
| 390 | break; |
| 391 | |
| 392 | if (addr < sizeof(struct pt_regs)) |
| 393 | ret = put_stack_long(child, addr, data); |
| 394 | else if (addr >= (long) &dummy->fpu && |
| 395 | addr < (long) &dummy->u_fpvalid) { |
| 396 | set_stopped_child_used_math(child); |
Paul Mundt | 0ea820c | 2010-01-13 12:51:40 +0900 | [diff] [blame] | 397 | ((long *)child->thread.xstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | [(addr - (long)&dummy->fpu) >> 2] = data; |
| 399 | ret = 0; |
| 400 | } else if (addr == (long) &dummy->u_fpvalid) { |
| 401 | conditional_stopped_child_used_math(data, child); |
| 402 | ret = 0; |
| 403 | } |
| 404 | break; |
| 405 | |
Paul Mundt | 934135c | 2008-09-12 19:52:36 +0900 | [diff] [blame] | 406 | case PTRACE_GETREGS: |
| 407 | return copy_regset_to_user(child, &user_sh_native_view, |
| 408 | REGSET_GENERAL, |
| 409 | 0, sizeof(struct pt_regs), |
| 410 | (void __user *)data); |
| 411 | case PTRACE_SETREGS: |
| 412 | return copy_regset_from_user(child, &user_sh_native_view, |
| 413 | REGSET_GENERAL, |
| 414 | 0, sizeof(struct pt_regs), |
| 415 | (const void __user *)data); |
Paul Mundt | e7ab3cd | 2008-09-21 19:04:55 +0900 | [diff] [blame] | 416 | #ifdef CONFIG_SH_FPU |
| 417 | case PTRACE_GETFPREGS: |
| 418 | return copy_regset_to_user(child, &user_sh_native_view, |
| 419 | REGSET_FPU, |
| 420 | 0, sizeof(struct user_fpu_struct), |
| 421 | (void __user *)data); |
| 422 | case PTRACE_SETFPREGS: |
| 423 | return copy_regset_from_user(child, &user_sh_native_view, |
| 424 | REGSET_FPU, |
| 425 | 0, sizeof(struct user_fpu_struct), |
| 426 | (const void __user *)data); |
| 427 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | #ifdef CONFIG_SH_DSP |
Paul Mundt | 5dadb34 | 2008-09-12 22:42:10 +0900 | [diff] [blame] | 429 | case PTRACE_GETDSPREGS: |
| 430 | return copy_regset_to_user(child, &user_sh_native_view, |
| 431 | REGSET_DSP, |
| 432 | 0, sizeof(struct pt_dspregs), |
| 433 | (void __user *)data); |
| 434 | case PTRACE_SETDSPREGS: |
| 435 | return copy_regset_from_user(child, &user_sh_native_view, |
| 436 | REGSET_DSP, |
| 437 | 0, sizeof(struct pt_dspregs), |
| 438 | (const void __user *)data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | #endif |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 440 | #ifdef CONFIG_BINFMT_ELF_FDPIC |
| 441 | case PTRACE_GETFDPIC: { |
| 442 | unsigned long tmp = 0; |
| 443 | |
| 444 | switch (addr) { |
| 445 | case PTRACE_GETFDPIC_EXEC: |
| 446 | tmp = child->mm->context.exec_fdpic_loadmap; |
| 447 | break; |
| 448 | case PTRACE_GETFDPIC_INTERP: |
| 449 | tmp = child->mm->context.interp_fdpic_loadmap; |
| 450 | break; |
| 451 | default: |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | ret = 0; |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 456 | if (put_user(tmp, datap)) { |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 457 | ret = -EFAULT; |
| 458 | break; |
| 459 | } |
| 460 | break; |
| 461 | } |
| 462 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | default: |
| 464 | ret = ptrace_request(child, request, addr, data); |
| 465 | break; |
| 466 | } |
Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return ret; |
| 469 | } |
| 470 | |
Paul Mundt | 9e5e211 | 2008-07-30 20:05:35 +0900 | [diff] [blame] | 471 | static inline int audit_arch(void) |
| 472 | { |
| 473 | int arch = EM_SH; |
| 474 | |
| 475 | #ifdef CONFIG_CPU_LITTLE_ENDIAN |
| 476 | arch |= __AUDIT_ARCH_LE; |
| 477 | #endif |
| 478 | |
| 479 | return arch; |
| 480 | } |
| 481 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 482 | asmlinkage long do_syscall_trace_enter(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | { |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 484 | long ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Paul Mundt | c4637d4 | 2008-07-30 15:30:52 +0900 | [diff] [blame] | 486 | secure_computing(regs->regs[0]); |
| 487 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 488 | if (test_thread_flag(TIF_SYSCALL_TRACE) && |
| 489 | tracehook_report_syscall_entry(regs)) |
| 490 | /* |
| 491 | * Tracing decided this syscall should not happen. |
| 492 | * We'll return a bogus call number to get an ENOSYS |
| 493 | * error, but leave the original number in regs->regs[0]. |
| 494 | */ |
| 495 | ret = -1L; |
Yuichi Nakamura | 1322b9d | 2007-11-10 19:21:34 +0900 | [diff] [blame] | 496 | |
Paul Mundt | a74f7e0 | 2009-09-16 14:30:34 +0900 | [diff] [blame] | 497 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 498 | trace_sys_enter(regs, regs->regs[0]); |
Matt Fleming | c652d78 | 2009-07-06 20:16:33 +0900 | [diff] [blame] | 499 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 500 | if (unlikely(current->audit_context)) |
Paul Mundt | 9e5e211 | 2008-07-30 20:05:35 +0900 | [diff] [blame] | 501 | audit_syscall_entry(audit_arch(), regs->regs[3], |
Yuichi Nakamura | 1322b9d | 2007-11-10 19:21:34 +0900 | [diff] [blame] | 502 | regs->regs[4], regs->regs[5], |
| 503 | regs->regs[6], regs->regs[7]); |
| 504 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 505 | return ret ?: regs->regs[0]; |
| 506 | } |
| 507 | |
| 508 | asmlinkage void do_syscall_trace_leave(struct pt_regs *regs) |
| 509 | { |
| 510 | int step; |
| 511 | |
| 512 | if (unlikely(current->audit_context)) |
| 513 | audit_syscall_exit(AUDITSC_RESULT(regs->regs[0]), |
| 514 | regs->regs[0]); |
| 515 | |
Paul Mundt | a74f7e0 | 2009-09-16 14:30:34 +0900 | [diff] [blame] | 516 | if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) |
| 517 | trace_sys_exit(regs, regs->regs[0]); |
Matt Fleming | c652d78 | 2009-07-06 20:16:33 +0900 | [diff] [blame] | 518 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 519 | step = test_thread_flag(TIF_SINGLESTEP); |
| 520 | if (step || test_thread_flag(TIF_SYSCALL_TRACE)) |
| 521 | tracehook_report_syscall_exit(regs, step); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |