]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
22 | #include <linux/smp_lock.h> | |
23 | #include <linux/errno.h> | |
24 | #include <linux/ptrace.h> | |
25 | #include <linux/user.h> | |
7ed20e1a | 26 | #include <linux/signal.h> |
1da177e4 LT |
27 | |
28 | #include <asm/uaccess.h> | |
29 | #include <asm/page.h> | |
30 | #include <asm/pgtable.h> | |
31 | #include <asm/system.h> | |
32 | #include <asm/processor.h> | |
33 | #include <asm/signal.h> | |
34 | ||
35 | /* cpu depend functions */ | |
36 | extern long h8300_get_reg(struct task_struct *task, int regno); | |
37 | extern int h8300_put_reg(struct task_struct *task, int regno, unsigned long data); | |
38 | extern void h8300_disable_trace(struct task_struct *child); | |
39 | extern void h8300_enable_trace(struct task_struct *child); | |
40 | ||
41 | /* | |
42 | * does not yet catch signals sent when the child dies. | |
43 | * in exit.c or in signal.c. | |
44 | */ | |
45 | ||
46 | inline | |
47 | static int read_long(struct task_struct * tsk, unsigned long addr, | |
48 | unsigned long * result) | |
49 | { | |
50 | *result = *(unsigned long *)addr; | |
51 | return 0; | |
52 | } | |
53 | ||
54 | void ptrace_disable(struct task_struct *child) | |
55 | { | |
56 | h8300_disable_trace(child); | |
57 | } | |
58 | ||
481bed45 | 59 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) |
1da177e4 | 60 | { |
1da177e4 LT |
61 | int ret; |
62 | ||
1da177e4 LT |
63 | switch (request) { |
64 | case PTRACE_PEEKTEXT: /* read word at location addr. */ | |
65 | case PTRACE_PEEKDATA: { | |
66 | unsigned long tmp; | |
67 | ||
68 | ret = read_long(child, addr, &tmp); | |
69 | if (ret < 0) | |
70 | break ; | |
71 | ret = put_user(tmp, (unsigned long *) data); | |
72 | break ; | |
73 | } | |
74 | ||
75 | /* read the word at location addr in the USER area. */ | |
76 | case PTRACE_PEEKUSR: { | |
77 | unsigned long tmp = 0; | |
78 | ||
79 | if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { | |
80 | ret = -EIO; | |
81 | break ; | |
82 | } | |
83 | ||
84 | ret = 0; /* Default return condition */ | |
85 | addr = addr >> 2; /* temporary hack. */ | |
86 | ||
87 | if (addr < H8300_REGS_NO) | |
88 | tmp = h8300_get_reg(child, addr); | |
89 | else { | |
90 | switch(addr) { | |
91 | case 49: | |
92 | tmp = child->mm->start_code; | |
93 | break ; | |
94 | case 50: | |
95 | tmp = child->mm->start_data; | |
96 | break ; | |
97 | case 51: | |
98 | tmp = child->mm->end_code; | |
99 | break ; | |
100 | case 52: | |
101 | tmp = child->mm->end_data; | |
102 | break ; | |
103 | default: | |
104 | ret = -EIO; | |
105 | } | |
106 | } | |
107 | if (!ret) | |
108 | ret = put_user(tmp,(unsigned long *) data); | |
109 | break ; | |
110 | } | |
111 | ||
112 | /* when I and D space are separate, this will have to be fixed. */ | |
113 | case PTRACE_POKETEXT: /* write the word at location addr. */ | |
114 | case PTRACE_POKEDATA: | |
115 | ret = 0; | |
116 | if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data)) | |
117 | break; | |
118 | ret = -EIO; | |
119 | break; | |
120 | ||
121 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ | |
122 | if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) { | |
123 | ret = -EIO; | |
124 | break ; | |
125 | } | |
126 | addr = addr >> 2; /* temporary hack. */ | |
127 | ||
128 | if (addr == PT_ORIG_ER0) { | |
129 | ret = -EIO; | |
130 | break ; | |
131 | } | |
132 | if (addr < H8300_REGS_NO) { | |
133 | ret = h8300_put_reg(child, addr, data); | |
134 | break ; | |
135 | } | |
136 | ret = -EIO; | |
137 | break ; | |
138 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ | |
139 | case PTRACE_CONT: { /* restart after signal. */ | |
140 | ret = -EIO; | |
7ed20e1a | 141 | if (!valid_signal(data)) |
1da177e4 LT |
142 | break ; |
143 | if (request == PTRACE_SYSCALL) | |
144 | set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
145 | else | |
146 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
147 | child->exit_code = data; | |
148 | wake_up_process(child); | |
149 | /* make sure the single step bit is not set. */ | |
150 | h8300_disable_trace(child); | |
151 | ret = 0; | |
152 | } | |
153 | ||
154 | /* | |
155 | * make the child exit. Best I can do is send it a sigkill. | |
156 | * perhaps it should be put in the status that it wants to | |
157 | * exit. | |
158 | */ | |
159 | case PTRACE_KILL: { | |
160 | ||
161 | ret = 0; | |
162 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | |
163 | break; | |
164 | child->exit_code = SIGKILL; | |
165 | h8300_disable_trace(child); | |
166 | wake_up_process(child); | |
167 | break; | |
168 | } | |
169 | ||
170 | case PTRACE_SINGLESTEP: { /* set the trap flag. */ | |
171 | ret = -EIO; | |
7ed20e1a | 172 | if (!valid_signal(data)) |
1da177e4 LT |
173 | break; |
174 | clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | |
175 | child->exit_code = data; | |
176 | h8300_enable_trace(child); | |
177 | wake_up_process(child); | |
178 | ret = 0; | |
179 | break; | |
180 | } | |
181 | ||
182 | case PTRACE_DETACH: /* detach a process that was attached. */ | |
183 | ret = ptrace_detach(child, data); | |
184 | break; | |
185 | ||
186 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ | |
187 | int i; | |
188 | unsigned long tmp; | |
189 | for (i = 0; i < H8300_REGS_NO; i++) { | |
190 | tmp = h8300_get_reg(child, i); | |
191 | if (put_user(tmp, (unsigned long *) data)) { | |
192 | ret = -EFAULT; | |
193 | break; | |
194 | } | |
195 | data += sizeof(long); | |
196 | } | |
197 | ret = 0; | |
198 | break; | |
199 | } | |
200 | ||
201 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ | |
202 | int i; | |
203 | unsigned long tmp; | |
204 | for (i = 0; i < H8300_REGS_NO; i++) { | |
205 | if (get_user(tmp, (unsigned long *) data)) { | |
206 | ret = -EFAULT; | |
207 | break; | |
208 | } | |
209 | h8300_put_reg(child, i, tmp); | |
210 | data += sizeof(long); | |
211 | } | |
212 | ret = 0; | |
213 | break; | |
214 | } | |
215 | ||
216 | default: | |
217 | ret = -EIO; | |
218 | break; | |
219 | } | |
1da177e4 LT |
220 | return ret; |
221 | } | |
222 | ||
223 | asmlinkage void syscall_trace(void) | |
224 | { | |
225 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | |
226 | return; | |
227 | if (!(current->ptrace & PT_PTRACED)) | |
228 | return; | |
229 | ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) | |
230 | ? 0x80 : 0)); | |
231 | /* | |
232 | * this isn't the same as continuing with a signal, but it will do | |
233 | * for normal use. strace only continues with a signal if the | |
234 | * stopping signal is not SIGTRAP. -brl | |
235 | */ | |
236 | if (current->exit_code) { | |
237 | send_sig(current->exit_code, current, 1); | |
238 | current->exit_code = 0; | |
239 | } | |
240 | } |