Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/h8300/kernel/ptrace.c |
| 3 | * |
| 4 | * Yoshinori Sato <ysato@users.sourceforge.jp> |
| 5 | * |
| 6 | * Based on: |
| 7 | * linux/arch/m68k/kernel/ptrace.c |
| 8 | * |
| 9 | * Copyright (C) 1994 by Hamish Macdonald |
| 10 | * Taken from linux/kernel/ptrace.c and modified for M680x0. |
| 11 | * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds |
| 12 | * |
| 13 | * This file is subject to the terms and conditions of the GNU General |
| 14 | * Public License. See the file COPYING in the main directory of |
| 15 | * this archive for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/sched.h> |
| 20 | #include <linux/mm.h> |
| 21 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/errno.h> |
| 23 | #include <linux/ptrace.h> |
| 24 | #include <linux/user.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 25 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include <asm/uaccess.h> |
| 28 | #include <asm/page.h> |
| 29 | #include <asm/pgtable.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <asm/processor.h> |
| 31 | #include <asm/signal.h> |
| 32 | |
| 33 | /* cpu depend functions */ |
| 34 | extern long h8300_get_reg(struct task_struct *task, int regno); |
| 35 | extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data); |
Christoph Hellwig | 857fb25 | 2010-03-10 15:22:52 -0800 | [diff] [blame] | 36 | |
| 37 | |
| 38 | void user_disable_single_step(struct task_struct *child) |
| 39 | { |
| 40 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * does not yet catch signals sent when the child dies. |
| 44 | * in exit.c or in signal.c. |
| 45 | */ |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | void ptrace_disable(struct task_struct *child) |
| 48 | { |
Christoph Hellwig | 857fb25 | 2010-03-10 15:22:52 -0800 | [diff] [blame] | 49 | user_disable_single_step(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Namhyung Kim | 9b05a69 | 2010-10-27 15:33:47 -0700 | [diff] [blame] | 52 | long arch_ptrace(struct task_struct *child, long request, |
| 53 | unsigned long addr, unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | int ret; |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 56 | int regno = addr >> 2; |
| 57 | unsigned long __user *datap = (unsigned long __user *) data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | switch (request) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* read the word at location addr in the USER area. */ |
| 61 | case PTRACE_PEEKUSR: { |
| 62 | unsigned long tmp = 0; |
| 63 | |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 64 | if ((addr & 3) || addr >= sizeof(struct user)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | ret = -EIO; |
| 66 | break ; |
| 67 | } |
| 68 | |
| 69 | ret = 0; /* Default return condition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 71 | if (regno < H8300_REGS_NO) |
| 72 | tmp = h8300_get_reg(child, regno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | else { |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 74 | switch (regno) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | case 49: |
| 76 | tmp = child->mm->start_code; |
| 77 | break ; |
| 78 | case 50: |
| 79 | tmp = child->mm->start_data; |
| 80 | break ; |
| 81 | case 51: |
| 82 | tmp = child->mm->end_code; |
| 83 | break ; |
| 84 | case 52: |
| 85 | tmp = child->mm->end_data; |
| 86 | break ; |
| 87 | default: |
| 88 | ret = -EIO; |
| 89 | } |
| 90 | } |
| 91 | if (!ret) |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 92 | ret = put_user(tmp, datap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | break ; |
| 94 | } |
| 95 | |
| 96 | /* when I and D space are separate, this will have to be fixed. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 98 | if ((addr & 3) || addr >= sizeof(struct user)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | ret = -EIO; |
| 100 | break ; |
| 101 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 103 | if (regno == PT_ORIG_ER0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | ret = -EIO; |
| 105 | break ; |
| 106 | } |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 107 | if (regno < H8300_REGS_NO) { |
| 108 | ret = h8300_put_reg(child, regno, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | break ; |
| 110 | } |
| 111 | ret = -EIO; |
| 112 | break ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ |
| 115 | int i; |
| 116 | unsigned long tmp; |
| 117 | for (i = 0; i < H8300_REGS_NO; i++) { |
| 118 | tmp = h8300_get_reg(child, i); |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 119 | if (put_user(tmp, datap)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | ret = -EFAULT; |
| 121 | break; |
| 122 | } |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 123 | datap++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | ret = 0; |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ |
| 130 | int i; |
| 131 | unsigned long tmp; |
| 132 | for (i = 0; i < H8300_REGS_NO; i++) { |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 133 | if (get_user(tmp, datap)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | ret = -EFAULT; |
| 135 | break; |
| 136 | } |
| 137 | h8300_put_reg(child, i, tmp); |
Namhyung Kim | 05fabda | 2010-10-27 15:33:53 -0700 | [diff] [blame] | 138 | datap++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | ret = 0; |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | default: |
Christoph Hellwig | b3c1e01 | 2010-03-10 15:22:44 -0800 | [diff] [blame] | 145 | ret = ptrace_request(child, request, addr, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | break; |
| 147 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | return ret; |
| 149 | } |
| 150 | |
Yoshinori Sato | 2fea299 | 2007-07-15 23:38:36 -0700 | [diff] [blame] | 151 | asmlinkage void do_syscall_trace(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
| 154 | return; |
| 155 | if (!(current->ptrace & PT_PTRACED)) |
| 156 | return; |
| 157 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) |
| 158 | ? 0x80 : 0)); |
| 159 | /* |
| 160 | * this isn't the same as continuing with a signal, but it will do |
| 161 | * for normal use. strace only continues with a signal if the |
| 162 | * stopping signal is not SIGTRAP. -brl |
| 163 | */ |
| 164 | if (current->exit_code) { |
| 165 | send_sig(current->exit_code, current, 1); |
| 166 | current->exit_code = 0; |
| 167 | } |
| 168 | } |