]> bbs.cooldavid.org Git - net-next-2.6.git/blob - arch/um/kernel/ptrace.c
ptrace: change signature of arch_ptrace()
[net-next-2.6.git] / arch / um / kernel / ptrace.c
1 /*
2  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/audit.h"
7 #include "linux/ptrace.h"
8 #include "linux/sched.h"
9 #include "asm/uaccess.h"
10 #include "skas_ptrace.h"
11
12
13
14 void user_enable_single_step(struct task_struct *child)
15 {
16         child->ptrace |= PT_DTRACE;
17         child->thread.singlestep_syscall = 0;
18
19 #ifdef SUBARCH_SET_SINGLESTEPPING
20         SUBARCH_SET_SINGLESTEPPING(child, 1);
21 #endif
22 }
23
24 void user_disable_single_step(struct task_struct *child)
25 {
26         child->ptrace &= ~PT_DTRACE;
27         child->thread.singlestep_syscall = 0;
28
29 #ifdef SUBARCH_SET_SINGLESTEPPING
30         SUBARCH_SET_SINGLESTEPPING(child, 0);
31 #endif
32 }
33
34 /*
35  * Called by kernel/ptrace.c when detaching..
36  */
37 void ptrace_disable(struct task_struct *child)
38 {
39         user_disable_single_step(child);
40 }
41
42 extern int peek_user(struct task_struct * child, long addr, long data);
43 extern int poke_user(struct task_struct * child, long addr, long data);
44
45 long arch_ptrace(struct task_struct *child, long request,
46                  unsigned long addr, unsigned long data)
47 {
48         int i, ret;
49         unsigned long __user *p = (void __user *)data;
50
51         switch (request) {
52         /* read word at location addr. */
53         case PTRACE_PEEKTEXT:
54         case PTRACE_PEEKDATA:
55                 ret = generic_ptrace_peekdata(child, addr, data);
56                 break;
57
58         /* read the word at location addr in the USER area. */
59         case PTRACE_PEEKUSR:
60                 ret = peek_user(child, addr, data);
61                 break;
62
63         /* write the word at location addr. */
64         case PTRACE_POKETEXT:
65         case PTRACE_POKEDATA:
66                 ret = generic_ptrace_pokedata(child, addr, data);
67                 break;
68
69         /* write the word at location addr in the USER area */
70         case PTRACE_POKEUSR:
71                 ret = poke_user(child, addr, data);
72                 break;
73
74         case PTRACE_SYSEMU:
75         case PTRACE_SYSEMU_SINGLESTEP:
76                 ret = -EIO;
77                 break;
78
79 #ifdef PTRACE_GETREGS
80         case PTRACE_GETREGS: { /* Get all gp regs from the child. */
81                 if (!access_ok(VERIFY_WRITE, p, MAX_REG_OFFSET)) {
82                         ret = -EIO;
83                         break;
84                 }
85                 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
86                         __put_user(getreg(child, i), p);
87                         p++;
88                 }
89                 ret = 0;
90                 break;
91         }
92 #endif
93 #ifdef PTRACE_SETREGS
94         case PTRACE_SETREGS: { /* Set all gp regs in the child. */
95                 unsigned long tmp = 0;
96                 if (!access_ok(VERIFY_READ, p, MAX_REG_OFFSET)) {
97                         ret = -EIO;
98                         break;
99                 }
100                 for ( i = 0; i < MAX_REG_OFFSET; i += sizeof(long) ) {
101                         __get_user(tmp, p);
102                         putreg(child, i, tmp);
103                         p++;
104                 }
105                 ret = 0;
106                 break;
107         }
108 #endif
109 #ifdef PTRACE_GETFPREGS
110         case PTRACE_GETFPREGS: /* Get the child FPU state. */
111                 ret = get_fpregs((struct user_i387_struct __user *) data,
112                                  child);
113                 break;
114 #endif
115 #ifdef PTRACE_SETFPREGS
116         case PTRACE_SETFPREGS: /* Set the child FPU state. */
117                 ret = set_fpregs((struct user_i387_struct __user *) data,
118                                  child);
119                 break;
120 #endif
121         case PTRACE_GET_THREAD_AREA:
122                 ret = ptrace_get_thread_area(child, addr,
123                                              (struct user_desc __user *) data);
124                 break;
125
126         case PTRACE_SET_THREAD_AREA:
127                 ret = ptrace_set_thread_area(child, addr,
128                                              (struct user_desc __user *) data);
129                 break;
130
131         case PTRACE_FAULTINFO: {
132                 /*
133                  * Take the info from thread->arch->faultinfo,
134                  * but transfer max. sizeof(struct ptrace_faultinfo).
135                  * On i386, ptrace_faultinfo is smaller!
136                  */
137                 ret = copy_to_user(p, &child->thread.arch.faultinfo,
138                                    sizeof(struct ptrace_faultinfo));
139                 break;
140         }
141
142 #ifdef PTRACE_LDT
143         case PTRACE_LDT: {
144                 struct ptrace_ldt ldt;
145
146                 if (copy_from_user(&ldt, p, sizeof(ldt))) {
147                         ret = -EIO;
148                         break;
149                 }
150
151                 /*
152                  * This one is confusing, so just punt and return -EIO for
153                  * now
154                  */
155                 ret = -EIO;
156                 break;
157         }
158 #endif
159 #ifdef PTRACE_ARCH_PRCTL
160         case PTRACE_ARCH_PRCTL:
161                 /* XXX Calls ptrace on the host - needs some SMP thinking */
162                 ret = arch_prctl(child, data, (void *) addr);
163                 break;
164 #endif
165         default:
166                 ret = ptrace_request(child, request, addr, data);
167                 if (ret == -EIO)
168                         ret = subarch_ptrace(child, request, addr, data);
169                 break;
170         }
171
172         return ret;
173 }
174
175 static void send_sigtrap(struct task_struct *tsk, struct uml_pt_regs *regs,
176                   int error_code)
177 {
178         struct siginfo info;
179
180         memset(&info, 0, sizeof(info));
181         info.si_signo = SIGTRAP;
182         info.si_code = TRAP_BRKPT;
183
184         /* User-mode eip? */
185         info.si_addr = UPT_IS_USER(regs) ? (void __user *) UPT_IP(regs) : NULL;
186
187         /* Send us the fake SIGTRAP */
188         force_sig_info(SIGTRAP, &info, tsk);
189 }
190
191 /*
192  * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and
193  * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
194  */
195 void syscall_trace(struct uml_pt_regs *regs, int entryexit)
196 {
197         int is_singlestep = (current->ptrace & PT_DTRACE) && entryexit;
198         int tracesysgood;
199
200         if (unlikely(current->audit_context)) {
201                 if (!entryexit)
202                         audit_syscall_entry(HOST_AUDIT_ARCH,
203                                             UPT_SYSCALL_NR(regs),
204                                             UPT_SYSCALL_ARG1(regs),
205                                             UPT_SYSCALL_ARG2(regs),
206                                             UPT_SYSCALL_ARG3(regs),
207                                             UPT_SYSCALL_ARG4(regs));
208                 else audit_syscall_exit(AUDITSC_RESULT(UPT_SYSCALL_RET(regs)),
209                                         UPT_SYSCALL_RET(regs));
210         }
211
212         /* Fake a debug trap */
213         if (is_singlestep)
214                 send_sigtrap(current, regs, 0);
215
216         if (!test_thread_flag(TIF_SYSCALL_TRACE))
217                 return;
218
219         if (!(current->ptrace & PT_PTRACED))
220                 return;
221
222         /*
223          * the 0x80 provides a way for the tracing parent to distinguish
224          * between a syscall stop and SIGTRAP delivery
225          */
226         tracesysgood = (current->ptrace & PT_TRACESYSGOOD);
227         ptrace_notify(SIGTRAP | (tracesysgood ? 0x80 : 0));
228
229         if (entryexit) /* force do_signal() --> is_syscall() */
230                 set_thread_flag(TIF_SIGPENDING);
231
232         /*
233          * this isn't the same as continuing with a signal, but it will do
234          * for normal use.  strace only continues with a signal if the
235          * stopping signal is not SIGTRAP.  -brl
236          */
237         if (current->exit_code) {
238                 send_sig(current->exit_code, current, 1);
239                 current->exit_code = 0;
240         }
241 }