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