2 * linux/arch/h8300/kernel/ptrace.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
7 * linux/arch/m68k/kernel/ptrace.c
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
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.
18 #include <linux/kernel.h>
19 #include <linux/sched.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>
26 #include <linux/config.h>
28 #include <asm/uaccess.h>
30 #include <asm/pgtable.h>
31 #include <asm/system.h>
32 #include <asm/processor.h>
33 #include <asm/signal.h>
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);
42 * does not yet catch signals sent when the child dies.
43 * in exit.c or in signal.c.
47 static int read_long(struct task_struct * tsk, unsigned long addr,
48 unsigned long * result)
50 *result = *(unsigned long *)addr;
54 void ptrace_disable(struct task_struct *child)
56 h8300_disable_trace(child);
59 asmlinkage int sys_ptrace(long request, long pid, long addr, long data)
61 struct task_struct *child;
66 if (request == PTRACE_TRACEME) {
67 /* are we already being traced? */
68 if (current->ptrace & PT_PTRACED)
70 /* set the ptrace bit in the process flags. */
71 current->ptrace |= PT_PTRACED;
76 read_lock(&tasklist_lock);
77 child = find_task_by_pid(pid);
79 get_task_struct(child);
80 read_unlock(&tasklist_lock);
85 if (pid == 1) /* you may not mess with init */
88 if (request == PTRACE_ATTACH) {
89 ret = ptrace_attach(child);
93 if (!(child->ptrace & PT_PTRACED))
95 if (child->state != TASK_STOPPED) {
96 if (request != PTRACE_KILL)
99 ret = ptrace_check_attach(child, request == PTRACE_KILL);
104 case PTRACE_PEEKTEXT: /* read word at location addr. */
105 case PTRACE_PEEKDATA: {
108 ret = read_long(child, addr, &tmp);
111 ret = put_user(tmp, (unsigned long *) data);
115 /* read the word at location addr in the USER area. */
116 case PTRACE_PEEKUSR: {
119 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user))
122 tmp = 0; /* Default return condition */
123 addr = addr >> 2; /* temporary hack. */
124 if (addr < H8300_REGS_NO)
125 tmp = h8300_get_reg(child, addr);
130 ret = put_user(tmp,(unsigned long *) data);
134 /* when I and D space are separate, this will have to be fixed. */
135 case PTRACE_POKETEXT: /* write the word at location addr. */
136 case PTRACE_POKEDATA:
138 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
143 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
144 if ((addr & 3) || addr < 0 || addr >= sizeof(struct user)) {
148 addr = addr >> 2; /* temporary hack. */
150 if (addr == PT_ORIG_ER0) {
154 if (addr < H8300_REGS_NO) {
155 ret = h8300_put_reg(child, addr, data);
160 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
161 case PTRACE_CONT: { /* restart after signal. */
163 if ((unsigned long) data >= _NSIG)
165 if (request == PTRACE_SYSCALL)
166 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
168 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
169 child->exit_code = data;
170 wake_up_process(child);
171 /* make sure the single step bit is not set. */
172 h8300_disable_trace(child);
177 * make the child exit. Best I can do is send it a sigkill.
178 * perhaps it should be put in the status that it wants to
184 if (child->state == TASK_ZOMBIE) /* already dead */
186 child->exit_code = SIGKILL;
187 h8300_disable_trace(child);
188 wake_up_process(child);
192 case PTRACE_SINGLESTEP: { /* set the trap flag. */
194 if ((unsigned long) data > _NSIG)
196 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
197 child->exit_code = data;
198 h8300_enable_trace(child);
199 wake_up_process(child);
204 case PTRACE_DETACH: /* detach a process that was attached. */
205 ret = ptrace_detach(child, data);
208 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
211 for (i = 0; i < H8300_REGS_NO; i++) {
212 tmp = h8300_get_reg(child, i);
213 if (put_user(tmp, (unsigned long *) data)) {
217 data += sizeof(long);
223 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
226 for (i = 0; i < H8300_REGS_NO; i++) {
227 if (get_user(tmp, (unsigned long *) data)) {
231 h8300_put_reg(child, i, tmp);
232 data += sizeof(long);
243 put_task_struct(child);
249 asmlinkage void syscall_trace(void)
251 if (!test_thread_flag(TIF_SYSCALL_TRACE))
253 if (!(current->ptrace & PT_PTRACED))
255 current->exit_code = SIGTRAP;
256 current->state = TASK_STOPPED;
257 notify_parent(current, SIGCHLD);
260 * this isn't the same as continuing with a signal, but it will do
261 * for normal use. strace only continues with a signal if the
262 * stopping signal is not SIGTRAP. -brl
264 if (current->exit_code) {
265 send_sig(current->exit_code, current, 1);
266 current->exit_code = 0;