[NETFILTER]: PPTP conntrack: simplify expectation handling
[hh.org.git] / arch / xtensa / kernel / ptrace.c
blob9aea23cc0dc5aee76324d6c74b29bca72afe0e5d
1 // TODO some minor issues
2 /*
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
5 * for more details.
7 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
10 * Chris Zankel <chris@zankel.net>
11 * Scott Foehner<sfoehner@yahoo.com>,
12 * Kevin Chea
13 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/mm.h>
19 #include <linux/errno.h>
20 #include <linux/ptrace.h>
21 #include <linux/smp.h>
22 #include <linux/smp_lock.h>
23 #include <linux/security.h>
24 #include <linux/signal.h>
26 #include <asm/pgtable.h>
27 #include <asm/page.h>
28 #include <asm/system.h>
29 #include <asm/uaccess.h>
30 #include <asm/ptrace.h>
31 #include <asm/elf.h>
33 #define TEST_KERNEL // verify kernel operations FIXME: remove
37 * Called by kernel/ptrace.c when detaching..
39 * Make sure single step bits etc are not set.
42 void ptrace_disable(struct task_struct *child)
44 /* Nothing to do.. */
47 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
49 int ret = -EPERM;
51 switch (request) {
52 case PTRACE_PEEKTEXT: /* read word at location addr. */
53 case PTRACE_PEEKDATA:
55 unsigned long tmp;
56 int copied;
58 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
59 ret = -EIO;
60 if (copied != sizeof(tmp))
61 break;
62 ret = put_user(tmp,(unsigned long *) data);
64 goto out;
67 /* Read the word at location addr in the USER area. */
69 case PTRACE_PEEKUSR:
71 struct pt_regs *regs;
72 unsigned long tmp;
74 regs = task_pt_regs(child);
75 tmp = 0; /* Default return value. */
77 switch(addr) {
79 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
81 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
82 ar &= (XCHAL_NUM_AREGS - 1);
83 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
84 tmp = regs->areg[ar];
85 else
86 ret = -EIO;
87 break;
89 case REG_A_BASE ... REG_A_BASE + 15:
90 tmp = regs->areg[addr - REG_A_BASE];
91 break;
92 case REG_PC:
93 tmp = regs->pc;
94 break;
95 case REG_PS:
96 /* Note: PS.EXCM is not set while user task is running;
97 * its being set in regs is for exception handling
98 * convenience. */
99 tmp = (regs->ps & ~XCHAL_PS_EXCM_MASK);
100 break;
101 case REG_WB:
102 tmp = regs->windowbase;
103 break;
104 case REG_WS:
105 tmp = regs->windowstart;
106 break;
107 case REG_LBEG:
108 tmp = regs->lbeg;
109 break;
110 case REG_LEND:
111 tmp = regs->lend;
112 break;
113 case REG_LCOUNT:
114 tmp = regs->lcount;
115 break;
116 case REG_SAR:
117 tmp = regs->sar;
118 break;
119 case REG_DEPC:
120 tmp = regs->depc;
121 break;
122 case REG_EXCCAUSE:
123 tmp = regs->exccause;
124 break;
125 case REG_EXCVADDR:
126 tmp = regs->excvaddr;
127 break;
128 case SYSCALL_NR:
129 tmp = regs->syscall;
130 break;
131 default:
132 tmp = 0;
133 ret = -EIO;
134 goto out;
136 ret = put_user(tmp, (unsigned long *) data);
137 goto out;
140 case PTRACE_POKETEXT: /* write the word at location addr. */
141 case PTRACE_POKEDATA:
142 if (access_process_vm(child, addr, &data, sizeof(data), 1)
143 == sizeof(data))
144 break;
145 ret = -EIO;
146 goto out;
148 case PTRACE_POKEUSR:
150 struct pt_regs *regs;
151 regs = task_pt_regs(child);
153 switch (addr) {
154 case REG_AR_BASE ... REG_AR_BASE + XCHAL_NUM_AREGS - 1:
156 int ar = addr - REG_AR_BASE - regs->windowbase * 4;
157 if (ar < 16 && ar + (regs->wmask >> 4) * 4 >= 0)
158 regs->areg[ar & (XCHAL_NUM_AREGS - 1)] = data;
159 else
160 ret = -EIO;
161 break;
163 case REG_A_BASE ... REG_A_BASE + 15:
164 regs->areg[addr - REG_A_BASE] = data;
165 break;
166 case REG_PC:
167 regs->pc = data;
168 break;
169 case SYSCALL_NR:
170 regs->syscall = data;
171 break;
172 #ifdef TEST_KERNEL
173 case REG_WB:
174 regs->windowbase = data;
175 break;
176 case REG_WS:
177 regs->windowstart = data;
178 break;
179 #endif
181 default:
182 /* The rest are not allowed. */
183 ret = -EIO;
184 break;
186 break;
189 /* continue and stop at next (return from) syscall */
190 case PTRACE_SYSCALL:
191 case PTRACE_CONT: /* restart after signal. */
193 ret = -EIO;
194 if (!valid_signal(data))
195 break;
196 if (request == PTRACE_SYSCALL)
197 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
198 else
199 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
200 child->exit_code = data;
201 /* Make sure the single step bit is not set. */
202 child->ptrace &= ~PT_SINGLESTEP;
203 wake_up_process(child);
204 ret = 0;
205 break;
209 * make the child exit. Best I can do is send it a sigkill.
210 * perhaps it should be put in the status that it wants to
211 * exit.
213 case PTRACE_KILL:
214 ret = 0;
215 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
216 break;
217 child->exit_code = SIGKILL;
218 child->ptrace &= ~PT_SINGLESTEP;
219 wake_up_process(child);
220 break;
222 case PTRACE_SINGLESTEP:
223 ret = -EIO;
224 if (!valid_signal(data))
225 break;
226 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
227 child->ptrace |= PT_SINGLESTEP;
228 child->exit_code = data;
229 wake_up_process(child);
230 ret = 0;
231 break;
233 case PTRACE_GETREGS:
235 /* 'data' points to user memory in which to write.
236 * Mainly due to the non-live register values, we
237 * reformat the register values into something more
238 * standard. For convenience, we use the handy
239 * elf_gregset_t format. */
241 xtensa_gregset_t format;
242 struct pt_regs *regs = task_pt_regs(child);
244 do_copy_regs (&format, regs, child);
246 /* Now, copy to user space nice and easy... */
247 ret = 0;
248 if (copy_to_user((void *)data, &format, sizeof(elf_gregset_t)))
249 ret = -EFAULT;
250 break;
253 case PTRACE_SETREGS:
255 /* 'data' points to user memory that contains the new
256 * values in the elf_gregset_t format. */
258 xtensa_gregset_t format;
259 struct pt_regs *regs = task_pt_regs(child);
261 if (copy_from_user(&format,(void *)data,sizeof(elf_gregset_t))){
262 ret = -EFAULT;
263 break;
266 /* FIXME: Perhaps we want some sanity checks on
267 * these user-space values? See ARM version. Are
268 * debuggers a security concern? */
270 do_restore_regs (&format, regs, child);
272 ret = 0;
273 break;
276 case PTRACE_GETFPREGS:
278 /* 'data' points to user memory in which to write.
279 * For convenience, we use the handy
280 * elf_fpregset_t format. */
282 elf_fpregset_t fpregs;
283 struct pt_regs *regs = task_pt_regs(child);
285 do_save_fpregs (&fpregs, regs, child);
287 /* Now, copy to user space nice and easy... */
288 ret = 0;
289 if (copy_to_user((void *)data, &fpregs, sizeof(elf_fpregset_t)))
290 ret = -EFAULT;
292 break;
295 case PTRACE_SETFPREGS:
297 /* 'data' points to user memory that contains the new
298 * values in the elf_fpregset_t format.
300 elf_fpregset_t fpregs;
301 struct pt_regs *regs = task_pt_regs(child);
303 ret = 0;
304 if (copy_from_user(&fpregs, (void *)data, sizeof(elf_fpregset_t))) {
305 ret = -EFAULT;
306 break;
309 if (do_restore_fpregs (&fpregs, regs, child))
310 ret = -EIO;
311 break;
314 case PTRACE_GETFPREGSIZE:
315 /* 'data' points to 'unsigned long' set to the size
316 * of elf_fpregset_t
318 ret = put_user(sizeof(elf_fpregset_t), (unsigned long *) data);
319 break;
321 case PTRACE_DETACH: /* detach a process that was attached. */
322 ret = ptrace_detach(child, data);
323 break;
325 default:
326 ret = ptrace_request(child, request, addr, data);
327 goto out;
329 out:
330 return ret;
333 void do_syscall_trace(void)
335 if (!test_thread_flag(TIF_SYSCALL_TRACE))
336 return;
338 if (!(current->ptrace & PT_PTRACED))
339 return;
342 * The 0x80 provides a way for the tracing parent to distinguish
343 * between a syscall stop and SIGTRAP delivery
345 ptrace_notify(SIGTRAP|((current->ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
348 * this isn't the same as continuing with a signal, but it will do
349 * for normal use. strace only continues with a signal if the
350 * stopping signal is not SIGTRAP. -brl
352 if (current->exit_code) {
353 send_sig(current->exit_code, current, 1);
354 current->exit_code = 0;