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