diff options
Diffstat (limited to 'arch/m68k/kernel/ptrace.c')
-rw-r--r-- | arch/m68k/kernel/ptrace.c | 370 |
1 files changed, 161 insertions, 209 deletions
diff --git a/arch/m68k/kernel/ptrace.c b/arch/m68k/kernel/ptrace.c index f4e1e5eb8e12..8ed1b01a6a87 100644 --- a/arch/m68k/kernel/ptrace.c +++ b/arch/m68k/kernel/ptrace.c | |||
@@ -95,7 +95,7 @@ static inline int put_reg(struct task_struct *task, int regno, | |||
95 | if (regno == PT_USP) | 95 | if (regno == PT_USP) |
96 | addr = &task->thread.usp; | 96 | addr = &task->thread.usp; |
97 | else if (regno < sizeof(regoff)/sizeof(regoff[0])) | 97 | else if (regno < sizeof(regoff)/sizeof(regoff[0])) |
98 | addr = (unsigned long *) (task->thread.esp0 + regoff[regno]); | 98 | addr = (unsigned long *)(task->thread.esp0 + regoff[regno]); |
99 | else | 99 | else |
100 | return -1; | 100 | return -1; |
101 | *addr = data; | 101 | *addr = data; |
@@ -103,48 +103,56 @@ static inline int put_reg(struct task_struct *task, int regno, | |||
103 | } | 103 | } |
104 | 104 | ||
105 | /* | 105 | /* |
106 | * Called by kernel/ptrace.c when detaching.. | ||
107 | * | ||
108 | * Make sure the single step bit is not set. | 106 | * Make sure the single step bit is not set. |
109 | */ | 107 | */ |
110 | void ptrace_disable(struct task_struct *child) | 108 | static inline void singlestep_disable(struct task_struct *child) |
111 | { | 109 | { |
112 | unsigned long tmp; | 110 | unsigned long tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); |
113 | /* make sure the single step bit is not set. */ | ||
114 | tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); | ||
115 | put_reg(child, PT_SR, tmp); | 111 | put_reg(child, PT_SR, tmp); |
116 | child->thread.work.delayed_trace = 0; | 112 | child->thread.work.delayed_trace = 0; |
113 | } | ||
114 | |||
115 | /* | ||
116 | * Called by kernel/ptrace.c when detaching.. | ||
117 | */ | ||
118 | void ptrace_disable(struct task_struct *child) | ||
119 | { | ||
120 | singlestep_disable(child); | ||
117 | child->thread.work.syscall_trace = 0; | 121 | child->thread.work.syscall_trace = 0; |
118 | } | 122 | } |
119 | 123 | ||
120 | asmlinkage int sys_ptrace(long request, long pid, long addr, long data) | 124 | asmlinkage int sys_ptrace(long request, long pid, long addr, long data) |
121 | { | 125 | { |
122 | struct task_struct *child; | 126 | struct task_struct *child; |
123 | int ret; | 127 | unsigned long tmp; |
128 | int i, ret = 0; | ||
124 | 129 | ||
125 | lock_kernel(); | 130 | lock_kernel(); |
126 | ret = -EPERM; | ||
127 | if (request == PTRACE_TRACEME) { | 131 | if (request == PTRACE_TRACEME) { |
128 | /* are we already being traced? */ | 132 | /* are we already being traced? */ |
129 | if (current->ptrace & PT_PTRACED) | 133 | if (current->ptrace & PT_PTRACED) { |
134 | ret = -EPERM; | ||
130 | goto out; | 135 | goto out; |
136 | } | ||
131 | /* set the ptrace bit in the process flags. */ | 137 | /* set the ptrace bit in the process flags. */ |
132 | current->ptrace |= PT_PTRACED; | 138 | current->ptrace |= PT_PTRACED; |
133 | ret = 0; | ||
134 | goto out; | 139 | goto out; |
135 | } | 140 | } |
136 | ret = -ESRCH; | ||
137 | read_lock(&tasklist_lock); | 141 | read_lock(&tasklist_lock); |
138 | child = find_task_by_pid(pid); | 142 | child = find_task_by_pid(pid); |
139 | if (child) | 143 | if (child) |
140 | get_task_struct(child); | 144 | get_task_struct(child); |
141 | read_unlock(&tasklist_lock); | 145 | read_unlock(&tasklist_lock); |
142 | if (!child) | 146 | if (unlikely(!child)) { |
147 | ret = -ESRCH; | ||
143 | goto out; | 148 | goto out; |
149 | } | ||
144 | 150 | ||
145 | ret = -EPERM; | 151 | /* you may not mess with init */ |
146 | if (pid == 1) /* you may not mess with init */ | 152 | if (unlikely(pid == 1)) { |
153 | ret = -EPERM; | ||
147 | goto out_tsk; | 154 | goto out_tsk; |
155 | } | ||
148 | 156 | ||
149 | if (request == PTRACE_ATTACH) { | 157 | if (request == PTRACE_ATTACH) { |
150 | ret = ptrace_attach(child); | 158 | ret = ptrace_attach(child); |
@@ -152,227 +160,171 @@ asmlinkage int sys_ptrace(long request, long pid, long addr, long data) | |||
152 | } | 160 | } |
153 | 161 | ||
154 | ret = ptrace_check_attach(child, request == PTRACE_KILL); | 162 | ret = ptrace_check_attach(child, request == PTRACE_KILL); |
155 | if (ret < 0) | 163 | if (ret) |
156 | goto out_tsk; | 164 | goto out_tsk; |
157 | 165 | ||
158 | switch (request) { | 166 | switch (request) { |
159 | /* when I and D space are separate, these will need to be fixed. */ | 167 | /* when I and D space are separate, these will need to be fixed. */ |
160 | case PTRACE_PEEKTEXT: /* read word at location addr. */ | 168 | case PTRACE_PEEKTEXT: /* read word at location addr. */ |
161 | case PTRACE_PEEKDATA: { | 169 | case PTRACE_PEEKDATA: |
162 | unsigned long tmp; | 170 | i = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); |
163 | int copied; | 171 | if (i != sizeof(tmp)) |
164 | 172 | goto out_eio; | |
165 | copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); | 173 | ret = put_user(tmp, (unsigned long *)data); |
166 | ret = -EIO; | 174 | break; |
167 | if (copied != sizeof(tmp)) | ||
168 | break; | ||
169 | ret = put_user(tmp,(unsigned long *) data); | ||
170 | break; | ||
171 | } | ||
172 | 175 | ||
173 | /* read the word at location addr in the USER area. */ | 176 | /* read the word at location addr in the USER area. */ |
174 | case PTRACE_PEEKUSR: { | 177 | case PTRACE_PEEKUSR: |
175 | unsigned long tmp; | 178 | if (addr & 3) |
176 | 179 | goto out_eio; | |
177 | ret = -EIO; | 180 | addr >>= 2; /* temporary hack. */ |
178 | if ((addr & 3) || addr < 0 || | 181 | |
179 | addr > sizeof(struct user) - 3) | 182 | if (addr >= 0 && addr < 19) { |
180 | break; | 183 | tmp = get_reg(child, addr); |
181 | 184 | if (addr == PT_SR) | |
182 | tmp = 0; /* Default return condition */ | 185 | tmp >>= 16; |
183 | addr = addr >> 2; /* temporary hack. */ | 186 | } else if (addr >= 21 && addr < 49) { |
184 | ret = -EIO; | 187 | tmp = child->thread.fp[addr - 21]; |
185 | if (addr < 19) { | 188 | /* Convert internal fpu reg representation |
186 | tmp = get_reg(child, addr); | 189 | * into long double format |
187 | if (addr == PT_SR) | 190 | */ |
188 | tmp >>= 16; | 191 | if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) |
189 | } else if (addr >= 21 && addr < 49) { | 192 | tmp = ((tmp & 0xffff0000) << 15) | |
190 | tmp = child->thread.fp[addr - 21]; | 193 | ((tmp & 0x0000ffff) << 16); |
191 | #ifdef CONFIG_M68KFPU_EMU | 194 | } else |
192 | /* Convert internal fpu reg representation | ||
193 | * into long double format | ||
194 | */ | ||
195 | if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) | ||
196 | tmp = ((tmp & 0xffff0000) << 15) | | ||
197 | ((tmp & 0x0000ffff) << 16); | ||
198 | #endif | ||
199 | } else | ||
200 | break; | ||
201 | ret = put_user(tmp,(unsigned long *) data); | ||
202 | break; | ||
203 | } | ||
204 | |||
205 | /* when I and D space are separate, this will have to be fixed. */ | ||
206 | case PTRACE_POKETEXT: /* write the word at location addr. */ | ||
207 | case PTRACE_POKEDATA: | ||
208 | ret = 0; | ||
209 | if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data)) | ||
210 | break; | ||
211 | ret = -EIO; | ||
212 | break; | ||
213 | |||
214 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ | ||
215 | ret = -EIO; | ||
216 | if ((addr & 3) || addr < 0 || | ||
217 | addr > sizeof(struct user) - 3) | ||
218 | break; | ||
219 | |||
220 | addr = addr >> 2; /* temporary hack. */ | ||
221 | |||
222 | if (addr == PT_SR) { | ||
223 | data &= SR_MASK; | ||
224 | data <<= 16; | ||
225 | data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); | ||
226 | } | ||
227 | if (addr < 19) { | ||
228 | if (put_reg(child, addr, data)) | ||
229 | break; | ||
230 | ret = 0; | ||
231 | break; | ||
232 | } | ||
233 | if (addr >= 21 && addr < 48) | ||
234 | { | ||
235 | #ifdef CONFIG_M68KFPU_EMU | ||
236 | /* Convert long double format | ||
237 | * into internal fpu reg representation | ||
238 | */ | ||
239 | if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) { | ||
240 | data = (unsigned long)data << 15; | ||
241 | data = (data & 0xffff0000) | | ||
242 | ((data & 0x0000ffff) >> 1); | ||
243 | } | ||
244 | #endif | ||
245 | child->thread.fp[addr - 21] = data; | ||
246 | ret = 0; | ||
247 | } | ||
248 | break; | 195 | break; |
249 | 196 | ret = put_user(tmp, (unsigned long *)data); | |
250 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ | 197 | break; |
251 | case PTRACE_CONT: { /* restart after signal. */ | 198 | |
252 | long tmp; | 199 | /* when I and D space are separate, this will have to be fixed. */ |
253 | 200 | case PTRACE_POKETEXT: /* write the word at location addr. */ | |
254 | ret = -EIO; | 201 | case PTRACE_POKEDATA: |
255 | if (!valid_signal(data)) | 202 | if (access_process_vm(child, addr, &data, sizeof(data), 1) != sizeof(data)) |
256 | break; | 203 | goto out_eio; |
257 | if (request == PTRACE_SYSCALL) { | 204 | break; |
258 | child->thread.work.syscall_trace = ~0; | 205 | |
259 | } else { | 206 | case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ |
260 | child->thread.work.syscall_trace = 0; | 207 | if (addr & 3) |
208 | goto out_eio; | ||
209 | addr >>= 2; /* temporary hack. */ | ||
210 | |||
211 | if (addr == PT_SR) { | ||
212 | data &= SR_MASK; | ||
213 | data <<= 16; | ||
214 | data |= get_reg(child, PT_SR) & ~(SR_MASK << 16); | ||
215 | } else if (addr >= 0 && addr < 19) { | ||
216 | if (put_reg(child, addr, data)) | ||
217 | goto out_eio; | ||
218 | } else if (addr >= 21 && addr < 48) { | ||
219 | /* Convert long double format | ||
220 | * into internal fpu reg representation | ||
221 | */ | ||
222 | if (FPU_IS_EMU && (addr < 45) && !(addr % 3)) { | ||
223 | data = (unsigned long)data << 15; | ||
224 | data = (data & 0xffff0000) | | ||
225 | ((data & 0x0000ffff) >> 1); | ||
261 | } | 226 | } |
262 | child->exit_code = data; | 227 | child->thread.fp[addr - 21] = data; |
263 | /* make sure the single step bit is not set. */ | 228 | } else |
264 | tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); | 229 | goto out_eio; |
265 | put_reg(child, PT_SR, tmp); | 230 | break; |
266 | child->thread.work.delayed_trace = 0; | 231 | |
267 | wake_up_process(child); | 232 | case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ |
268 | ret = 0; | 233 | case PTRACE_CONT: /* restart after signal. */ |
269 | break; | 234 | if (!valid_signal(data)) |
270 | } | 235 | goto out_eio; |
271 | 236 | ||
272 | /* | 237 | if (request == PTRACE_SYSCALL) |
273 | * make the child exit. Best I can do is send it a sigkill. | 238 | child->thread.work.syscall_trace = ~0; |
274 | * perhaps it should be put in the status that it wants to | 239 | else |
275 | * exit. | ||
276 | */ | ||
277 | case PTRACE_KILL: { | ||
278 | long tmp; | ||
279 | |||
280 | ret = 0; | ||
281 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | ||
282 | break; | ||
283 | child->exit_code = SIGKILL; | ||
284 | /* make sure the single step bit is not set. */ | ||
285 | tmp = get_reg(child, PT_SR) & ~(TRACE_BITS << 16); | ||
286 | put_reg(child, PT_SR, tmp); | ||
287 | child->thread.work.delayed_trace = 0; | ||
288 | wake_up_process(child); | ||
289 | break; | ||
290 | } | ||
291 | |||
292 | case PTRACE_SINGLESTEP: { /* set the trap flag. */ | ||
293 | long tmp; | ||
294 | |||
295 | ret = -EIO; | ||
296 | if (!valid_signal(data)) | ||
297 | break; | ||
298 | child->thread.work.syscall_trace = 0; | 240 | child->thread.work.syscall_trace = 0; |
299 | tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16); | 241 | child->exit_code = data; |
300 | put_reg(child, PT_SR, tmp); | 242 | singlestep_disable(child); |
301 | child->thread.work.delayed_trace = 1; | 243 | wake_up_process(child); |
302 | 244 | break; | |
303 | child->exit_code = data; | ||
304 | /* give it a chance to run. */ | ||
305 | wake_up_process(child); | ||
306 | ret = 0; | ||
307 | break; | ||
308 | } | ||
309 | 245 | ||
310 | case PTRACE_DETACH: /* detach a process that was attached. */ | 246 | /* |
311 | ret = ptrace_detach(child, data); | 247 | * make the child exit. Best I can do is send it a sigkill. |
248 | * perhaps it should be put in the status that it wants to | ||
249 | * exit. | ||
250 | */ | ||
251 | case PTRACE_KILL: | ||
252 | if (child->exit_state == EXIT_ZOMBIE) /* already dead */ | ||
312 | break; | 253 | break; |
313 | 254 | child->exit_code = SIGKILL; | |
314 | case PTRACE_GETREGS: { /* Get all gp regs from the child. */ | 255 | singlestep_disable(child); |
315 | int i; | 256 | wake_up_process(child); |
316 | unsigned long tmp; | 257 | break; |
317 | for (i = 0; i < 19; i++) { | 258 | |
318 | tmp = get_reg(child, i); | 259 | case PTRACE_SINGLESTEP: /* set the trap flag. */ |
319 | if (i == PT_SR) | 260 | if (!valid_signal(data)) |
261 | goto out_eio; | ||
262 | |||
263 | child->thread.work.syscall_trace = 0; | ||
264 | tmp = get_reg(child, PT_SR) | (TRACE_BITS << 16); | ||
265 | put_reg(child, PT_SR, tmp); | ||
266 | child->thread.work.delayed_trace = 1; | ||
267 | |||
268 | child->exit_code = data; | ||
269 | /* give it a chance to run. */ | ||
270 | wake_up_process(child); | ||
271 | break; | ||
272 | |||
273 | case PTRACE_DETACH: /* detach a process that was attached. */ | ||
274 | ret = ptrace_detach(child, data); | ||
275 | break; | ||
276 | |||
277 | case PTRACE_GETREGS: /* Get all gp regs from the child. */ | ||
278 | for (i = 0; i < 19; i++) { | ||
279 | tmp = get_reg(child, i); | ||
280 | if (i == PT_SR) | ||
320 | tmp >>= 16; | 281 | tmp >>= 16; |
321 | if (put_user(tmp, (unsigned long *) data)) { | 282 | ret = put_user(tmp, (unsigned long *)data); |
322 | ret = -EFAULT; | 283 | if (ret) |
323 | break; | 284 | break; |
324 | } | 285 | data += sizeof(long); |
325 | data += sizeof(long); | ||
326 | } | ||
327 | ret = 0; | ||
328 | break; | ||
329 | } | 286 | } |
287 | break; | ||
330 | 288 | ||
331 | case PTRACE_SETREGS: { /* Set all gp regs in the child. */ | 289 | case PTRACE_SETREGS: /* Set all gp regs in the child. */ |
332 | int i; | 290 | for (i = 0; i < 19; i++) { |
333 | unsigned long tmp; | 291 | ret = get_user(tmp, (unsigned long *)data); |
334 | for (i = 0; i < 19; i++) { | 292 | if (ret) |
335 | if (get_user(tmp, (unsigned long *) data)) { | ||
336 | ret = -EFAULT; | ||
337 | break; | 293 | break; |
338 | } | 294 | if (i == PT_SR) { |
339 | if (i == PT_SR) { | ||
340 | tmp &= SR_MASK; | 295 | tmp &= SR_MASK; |
341 | tmp <<= 16; | 296 | tmp <<= 16; |
342 | tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16); | 297 | tmp |= get_reg(child, PT_SR) & ~(SR_MASK << 16); |
343 | } | ||
344 | put_reg(child, i, tmp); | ||
345 | data += sizeof(long); | ||
346 | } | 298 | } |
347 | ret = 0; | 299 | put_reg(child, i, tmp); |
348 | break; | 300 | data += sizeof(long); |
349 | } | 301 | } |
350 | 302 | break; | |
351 | case PTRACE_GETFPREGS: { /* Get the child FPU state. */ | 303 | |
352 | ret = 0; | 304 | case PTRACE_GETFPREGS: /* Get the child FPU state. */ |
353 | if (copy_to_user((void *)data, &child->thread.fp, | 305 | if (copy_to_user((void *)data, &child->thread.fp, |
354 | sizeof(struct user_m68kfp_struct))) | 306 | sizeof(struct user_m68kfp_struct))) |
355 | ret = -EFAULT; | 307 | ret = -EFAULT; |
356 | break; | 308 | break; |
357 | } | 309 | |
358 | 310 | case PTRACE_SETFPREGS: /* Set the child FPU state. */ | |
359 | case PTRACE_SETFPREGS: { /* Set the child FPU state. */ | 311 | if (copy_from_user(&child->thread.fp, (void *)data, |
360 | ret = 0; | 312 | sizeof(struct user_m68kfp_struct))) |
361 | if (copy_from_user(&child->thread.fp, (void *)data, | 313 | ret = -EFAULT; |
362 | sizeof(struct user_m68kfp_struct))) | 314 | break; |
363 | ret = -EFAULT; | 315 | |
364 | break; | 316 | default: |
365 | } | 317 | ret = ptrace_request(child, request, addr, data); |
366 | 318 | break; | |
367 | default: | ||
368 | ret = ptrace_request(child, request, addr, data); | ||
369 | break; | ||
370 | } | 319 | } |
371 | out_tsk: | 320 | out_tsk: |
372 | put_task_struct(child); | 321 | put_task_struct(child); |
373 | out: | 322 | out: |
374 | unlock_kernel(); | 323 | unlock_kernel(); |
375 | return ret; | 324 | return ret; |
325 | out_eio: | ||
326 | ret = -EIO; | ||
327 | goto out_tsk; | ||
376 | } | 328 | } |
377 | 329 | ||
378 | asmlinkage void syscall_trace(void) | 330 | asmlinkage void syscall_trace(void) |