blob: 607085f3f08a3359526df4ff6cfe745a1e92fa98 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* By Ross Biro 1/23/92 */
2/*
3 * Pentium III FXSR, SSE support
4 * Gareth Hughes <gareth@valinux.com>, May 2000
5 *
6 * x86-64 port 2000-2002 Andi Kleen
7 */
8
9#include <linux/kernel.h>
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/errno.h>
14#include <linux/ptrace.h>
15#include <linux/user.h>
16#include <linux/security.h>
17#include <linux/audit.h>
18#include <linux/seccomp.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070019#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/uaccess.h>
22#include <asm/pgtable.h>
23#include <asm/system.h>
24#include <asm/processor.h>
25#include <asm/i387.h>
26#include <asm/debugreg.h>
27#include <asm/ldt.h>
28#include <asm/desc.h>
29#include <asm/proto.h>
30#include <asm/ia32.h>
31
32/*
33 * does not yet catch signals sent when the child dies.
34 * in exit.c or in signal.c.
35 */
36
Chuck Ebbert60923df2006-01-11 22:46:03 +010037/*
38 * Determines which flags the user has access to [1 = access, 0 = no access].
39 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
40 * Also masks reserved bits (63-22, 15, 5, 3, 1).
41 */
42#define FLAG_MASK 0x54dd5UL
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44/* set's the trap flag. */
45#define TRAP_FLAG 0x100UL
46
47/*
48 * eflags and offset of eflags on child stack..
49 */
50#define EFLAGS offsetof(struct pt_regs, eflags)
51#define EFL_OFFSET ((int)(EFLAGS-sizeof(struct pt_regs)))
52
53/*
54 * this routine will get a word off of the processes privileged stack.
55 * the offset is how far from the base addr as stored in the TSS.
56 * this routine assumes that all the privileged stacks are in our
57 * data space.
58 */
59static inline unsigned long get_stack_long(struct task_struct *task, int offset)
60{
61 unsigned char *stack;
62
63 stack = (unsigned char *)task->thread.rsp0;
64 stack += offset;
65 return (*((unsigned long *)stack));
66}
67
68/*
69 * this routine will put a word on the processes privileged stack.
70 * the offset is how far from the base addr as stored in the TSS.
71 * this routine assumes that all the privileged stacks are in our
72 * data space.
73 */
74static inline long put_stack_long(struct task_struct *task, int offset,
75 unsigned long data)
76{
77 unsigned char * stack;
78
79 stack = (unsigned char *) task->thread.rsp0;
80 stack += offset;
81 *(unsigned long *) stack = data;
82 return 0;
83}
84
Andi Kleene502cdd2005-04-16 15:24:58 -070085#define LDT_SEGMENT 4
86
87unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs)
88{
89 unsigned long addr, seg;
90
91 addr = regs->rip;
92 seg = regs->cs & 0xffff;
93
94 /*
95 * We'll assume that the code segments in the GDT
96 * are all zero-based. That is largely true: the
97 * TLS segments are used for data, and the PNPBIOS
98 * and APM bios ones we just ignore here.
99 */
100 if (seg & LDT_SEGMENT) {
101 u32 *desc;
102 unsigned long base;
103
Roland McGrath29eb5112007-07-16 01:03:16 -0700104 seg &= ~7UL;
Andi Kleene502cdd2005-04-16 15:24:58 -0700105
Luiz Fernando N. Capitulinoc7537ab22007-10-17 18:04:41 +0200106 mutex_lock(&child->mm->context.lock);
Roland McGrath29eb5112007-07-16 01:03:16 -0700107 if (unlikely((seg >> 3) >= child->mm->context.size))
108 addr = -1L; /* bogus selector, access would fault */
109 else {
110 desc = child->mm->context.ldt + seg;
111 base = ((desc[0] >> 16) |
112 ((desc[1] & 0xff) << 16) |
113 (desc[1] & 0xff000000));
114
115 /* 16-bit code segment? */
116 if (!((desc[1] >> 22) & 1))
117 addr &= 0xffff;
118 addr += base;
119 }
Luiz Fernando N. Capitulinoc7537ab22007-10-17 18:04:41 +0200120 mutex_unlock(&child->mm->context.lock);
Andi Kleene502cdd2005-04-16 15:24:58 -0700121 }
Roland McGrath29eb5112007-07-16 01:03:16 -0700122
Andi Kleene502cdd2005-04-16 15:24:58 -0700123 return addr;
124}
125
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200126static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
Andi Kleene502cdd2005-04-16 15:24:58 -0700127{
128 int i, copied;
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200129 unsigned char opcode[15];
Andi Kleene502cdd2005-04-16 15:24:58 -0700130 unsigned long addr = convert_rip_to_linear(child, regs);
131
132 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
133 for (i = 0; i < copied; i++) {
134 switch (opcode[i]) {
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200135 /* popf and iret */
136 case 0x9d: case 0xcf:
Andi Kleene502cdd2005-04-16 15:24:58 -0700137 return 1;
138
139 /* CHECKME: 64 65 */
140
141 /* opcode and address size prefixes */
142 case 0x66: case 0x67:
143 continue;
144 /* irrelevant prefixes (segment overrides and repeats) */
145 case 0x26: case 0x2e:
146 case 0x36: case 0x3e:
147 case 0x64: case 0x65:
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200148 case 0xf2: case 0xf3:
Andi Kleene502cdd2005-04-16 15:24:58 -0700149 continue;
150
Andi Kleene502cdd2005-04-16 15:24:58 -0700151 case 0x40 ... 0x4f:
Chuck Ebberta752d712006-09-26 10:52:32 +0200152 if (regs->cs != __USER_CS)
153 /* 32-bit mode: register increment */
154 return 0;
155 /* 64-bit mode: REX prefix */
Andi Kleene502cdd2005-04-16 15:24:58 -0700156 continue;
157
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200158 /* CHECKME: f2, f3 */
Andi Kleene502cdd2005-04-16 15:24:58 -0700159
160 /*
161 * pushf: NOTE! We should probably not let
162 * the user see the TF bit being set. But
163 * it's more pain than it's worth to avoid
164 * it, and a debugger could emulate this
165 * all in user space if it _really_ cares.
166 */
167 case 0x9c:
168 default:
169 return 0;
170 }
171 }
172 return 0;
173}
174
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700175static void set_singlestep(struct task_struct *child)
176{
Al Virobb049232006-01-12 01:05:38 -0800177 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700178
179 /*
180 * Always set TIF_SINGLESTEP - this guarantees that
181 * we single-step system calls etc.. This will also
182 * cause us to set TF when returning to user mode.
183 */
184 set_tsk_thread_flag(child, TIF_SINGLESTEP);
185
186 /*
187 * If TF was already set, don't do anything else
188 */
189 if (regs->eflags & TRAP_FLAG)
190 return;
191
192 /* Set TF on the kernel stack.. */
193 regs->eflags |= TRAP_FLAG;
194
Andi Kleene502cdd2005-04-16 15:24:58 -0700195 /*
196 * ..but if TF is changed by the instruction we will trace,
197 * don't mark it as being "us" that set it, so that we
198 * won't clear it by hand later.
Andi Kleene502cdd2005-04-16 15:24:58 -0700199 */
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200200 if (is_setting_trap_flag(child, regs))
Andi Kleene502cdd2005-04-16 15:24:58 -0700201 return;
202
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700203 child->ptrace |= PT_DTRACE;
204}
205
206static void clear_singlestep(struct task_struct *child)
207{
208 /* Always clear TIF_SINGLESTEP... */
209 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
210
211 /* But touch TF only if it was set by us.. */
212 if (child->ptrace & PT_DTRACE) {
Al Virobb049232006-01-12 01:05:38 -0800213 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700214 regs->eflags &= ~TRAP_FLAG;
215 child->ptrace &= ~PT_DTRACE;
216 }
217}
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/*
220 * Called by kernel/ptrace.c when detaching..
221 *
222 * Make sure the single step bit is not set.
223 */
224void ptrace_disable(struct task_struct *child)
225{
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700226 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static int putreg(struct task_struct *child,
230 unsigned long regno, unsigned long value)
231{
232 unsigned long tmp;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 switch (regno) {
235 case offsetof(struct user_regs_struct,fs):
236 if (value && (value & 3) != 3)
237 return -EIO;
238 child->thread.fsindex = value & 0xffff;
239 return 0;
240 case offsetof(struct user_regs_struct,gs):
241 if (value && (value & 3) != 3)
242 return -EIO;
243 child->thread.gsindex = value & 0xffff;
244 return 0;
245 case offsetof(struct user_regs_struct,ds):
246 if (value && (value & 3) != 3)
247 return -EIO;
248 child->thread.ds = value & 0xffff;
249 return 0;
250 case offsetof(struct user_regs_struct,es):
251 if (value && (value & 3) != 3)
252 return -EIO;
253 child->thread.es = value & 0xffff;
254 return 0;
255 case offsetof(struct user_regs_struct,ss):
256 if ((value & 3) != 3)
257 return -EIO;
258 value &= 0xffff;
259 return 0;
260 case offsetof(struct user_regs_struct,fs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700261 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700262 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 child->thread.fs = value;
264 return 0;
265 case offsetof(struct user_regs_struct,gs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700266 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700267 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 child->thread.gs = value;
269 return 0;
270 case offsetof(struct user_regs_struct, eflags):
271 value &= FLAG_MASK;
272 tmp = get_stack_long(child, EFL_OFFSET);
273 tmp &= ~FLAG_MASK;
274 value |= tmp;
275 break;
276 case offsetof(struct user_regs_struct,cs):
277 if ((value & 3) != 3)
278 return -EIO;
279 value &= 0xffff;
280 break;
281 }
282 put_stack_long(child, regno - sizeof(struct pt_regs), value);
283 return 0;
284}
285
286static unsigned long getreg(struct task_struct *child, unsigned long regno)
287{
288 unsigned long val;
289 switch (regno) {
290 case offsetof(struct user_regs_struct, fs):
291 return child->thread.fsindex;
292 case offsetof(struct user_regs_struct, gs):
293 return child->thread.gsindex;
294 case offsetof(struct user_regs_struct, ds):
295 return child->thread.ds;
296 case offsetof(struct user_regs_struct, es):
297 return child->thread.es;
298 case offsetof(struct user_regs_struct, fs_base):
299 return child->thread.fs;
300 case offsetof(struct user_regs_struct, gs_base):
301 return child->thread.gs;
302 default:
303 regno = regno - sizeof(struct pt_regs);
304 val = get_stack_long(child, regno);
305 if (test_tsk_thread_flag(child, TIF_IA32))
306 val &= 0xffffffff;
307 return val;
308 }
309
310}
311
Christoph Hellwig481bed42005-11-07 00:59:47 -0800312long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 long i, ret;
315 unsigned ui;
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 switch (request) {
318 /* when I and D space are separate, these will need to be fixed. */
319 case PTRACE_PEEKTEXT: /* read word at location addr. */
Alexey Dobriyan76647322007-07-17 04:03:43 -0700320 case PTRACE_PEEKDATA:
321 ret = generic_ptrace_peekdata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* read the word at location addr in the USER area. */
325 case PTRACE_PEEKUSR: {
326 unsigned long tmp;
327
328 ret = -EIO;
329 if ((addr & 7) ||
330 addr > sizeof(struct user) - 7)
331 break;
332
333 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700334 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 tmp = getreg(child, addr);
336 break;
337 case offsetof(struct user, u_debugreg[0]):
338 tmp = child->thread.debugreg0;
339 break;
340 case offsetof(struct user, u_debugreg[1]):
341 tmp = child->thread.debugreg1;
342 break;
343 case offsetof(struct user, u_debugreg[2]):
344 tmp = child->thread.debugreg2;
345 break;
346 case offsetof(struct user, u_debugreg[3]):
347 tmp = child->thread.debugreg3;
348 break;
349 case offsetof(struct user, u_debugreg[6]):
350 tmp = child->thread.debugreg6;
351 break;
352 case offsetof(struct user, u_debugreg[7]):
353 tmp = child->thread.debugreg7;
354 break;
355 default:
356 tmp = 0;
357 break;
358 }
359 ret = put_user(tmp,(unsigned long __user *) data);
360 break;
361 }
362
363 /* when I and D space are separate, this will have to be fixed. */
364 case PTRACE_POKETEXT: /* write the word at location addr. */
365 case PTRACE_POKEDATA:
Alexey Dobriyanf284ce72007-07-17 04:03:44 -0700366 ret = generic_ptrace_pokedata(child, addr, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 break;
368
369 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
Suresh Siddha84929802005-06-21 17:14:32 -0700370 {
371 int dsize = test_tsk_thread_flag(child, TIF_IA32) ? 3 : 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 ret = -EIO;
373 if ((addr & 7) ||
374 addr > sizeof(struct user) - 7)
375 break;
376
377 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700378 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ret = putreg(child, addr, data);
380 break;
381 /* Disallows to set a breakpoint into the vsyscall */
382 case offsetof(struct user, u_debugreg[0]):
Suresh Siddha84929802005-06-21 17:14:32 -0700383 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 child->thread.debugreg0 = data;
385 ret = 0;
386 break;
387 case offsetof(struct user, u_debugreg[1]):
Suresh Siddha84929802005-06-21 17:14:32 -0700388 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 child->thread.debugreg1 = data;
390 ret = 0;
391 break;
392 case offsetof(struct user, u_debugreg[2]):
Suresh Siddha84929802005-06-21 17:14:32 -0700393 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 child->thread.debugreg2 = data;
395 ret = 0;
396 break;
397 case offsetof(struct user, u_debugreg[3]):
Suresh Siddha84929802005-06-21 17:14:32 -0700398 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 child->thread.debugreg3 = data;
400 ret = 0;
401 break;
402 case offsetof(struct user, u_debugreg[6]):
403 if (data >> 32)
404 break;
405 child->thread.debugreg6 = data;
406 ret = 0;
407 break;
408 case offsetof(struct user, u_debugreg[7]):
409 /* See arch/i386/kernel/ptrace.c for an explanation of
410 * this awkward check.*/
Jan Beulich893efca2006-03-25 16:29:19 +0100411 data &= ~DR_CONTROL_RESERVED;
412 for(i=0; i<4; i++)
413 if ((0x5554 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
415 if (i == 4) {
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200416 child->thread.debugreg7 = data;
417 if (data)
418 set_tsk_thread_flag(child, TIF_DEBUG);
419 else
420 clear_tsk_thread_flag(child, TIF_DEBUG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 ret = 0;
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200422 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
424 }
425 break;
Suresh Siddha84929802005-06-21 17:14:32 -0700426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700428 case PTRACE_CONT: /* restart after signal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700431 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 break;
433 if (request == PTRACE_SYSCALL)
434 set_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
435 else
436 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
437 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
438 child->exit_code = data;
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700439 /* make sure the single step bit is not set. */
440 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 wake_up_process(child);
442 ret = 0;
443 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445#ifdef CONFIG_IA32_EMULATION
446 /* This makes only sense with 32bit programs. Allow a
447 64bit debugger to fully examine them too. Better
448 don't use it against 64bit processes, use
449 PTRACE_ARCH_PRCTL instead. */
450 case PTRACE_SET_THREAD_AREA: {
451 struct user_desc __user *p;
452 int old;
453 p = (struct user_desc __user *)data;
454 get_user(old, &p->entry_number);
455 put_user(addr, &p->entry_number);
456 ret = do_set_thread_area(&child->thread, p);
457 put_user(old, &p->entry_number);
458 break;
459 case PTRACE_GET_THREAD_AREA:
460 p = (struct user_desc __user *)data;
461 get_user(old, &p->entry_number);
462 put_user(addr, &p->entry_number);
463 ret = do_get_thread_area(&child->thread, p);
464 put_user(old, &p->entry_number);
465 break;
466 }
467#endif
468 /* normal 64bit interface to access TLS data.
469 Works just like arch_prctl, except that the arguments
470 are reversed. */
471 case PTRACE_ARCH_PRCTL:
472 ret = do_arch_prctl(child, data, addr);
473 break;
474
475/*
476 * make the child exit. Best I can do is send it a sigkill.
477 * perhaps it should be put in the status that it wants to
478 * exit.
479 */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700480 case PTRACE_KILL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 ret = 0;
482 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
483 break;
484 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
485 child->exit_code = SIGKILL;
486 /* make sure the single step bit is not set. */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700487 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 wake_up_process(child);
489 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700491 case PTRACE_SINGLESTEP: /* set the trap flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700493 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 break;
495 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700496 set_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 child->exit_code = data;
498 /* give it a chance to run. */
499 wake_up_process(child);
500 ret = 0;
501 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
504 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
505 sizeof(struct user_regs_struct))) {
506 ret = -EIO;
507 break;
508 }
509 ret = 0;
510 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
511 ret |= __put_user(getreg(child, ui),(unsigned long __user *) data);
512 data += sizeof(long);
513 }
514 break;
515 }
516
517 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
518 unsigned long tmp;
519 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
520 sizeof(struct user_regs_struct))) {
521 ret = -EIO;
522 break;
523 }
524 ret = 0;
525 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
Andi Kleenf49481b2007-02-13 13:26:24 +0100526 ret = __get_user(tmp, (unsigned long __user *) data);
527 if (ret)
528 break;
529 ret = putreg(child, ui, tmp);
530 if (ret)
531 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 data += sizeof(long);
533 }
534 break;
535 }
536
537 case PTRACE_GETFPREGS: { /* Get the child extended FPU state. */
538 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
539 sizeof(struct user_i387_struct))) {
540 ret = -EIO;
541 break;
542 }
543 ret = get_fpregs((struct user_i387_struct __user *)data, child);
544 break;
545 }
546
547 case PTRACE_SETFPREGS: { /* Set the child extended FPU state. */
548 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
549 sizeof(struct user_i387_struct))) {
550 ret = -EIO;
551 break;
552 }
553 set_stopped_child_used_math(child);
554 ret = set_fpregs(child, (struct user_i387_struct __user *)data);
555 break;
556 }
557
558 default:
559 ret = ptrace_request(child, request, addr, data);
560 break;
561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 return ret;
563}
564
565static void syscall_trace(struct pt_regs *regs)
566{
567
568#if 0
569 printk("trace %s rip %lx rsp %lx rax %d origrax %d caller %lx tiflags %x ptrace %x\n",
570 current->comm,
571 regs->rip, regs->rsp, regs->rax, regs->orig_rax, __builtin_return_address(0),
572 current_thread_info()->flags, current->ptrace);
573#endif
574
575 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
576 ? 0x80 : 0));
577 /*
578 * this isn't the same as continuing with a signal, but it will do
579 * for normal use. strace only continues with a signal if the
580 * stopping signal is not SIGTRAP. -brl
581 */
582 if (current->exit_code) {
583 send_sig(current->exit_code, current, 1);
584 current->exit_code = 0;
585 }
586}
587
588asmlinkage void syscall_trace_enter(struct pt_regs *regs)
589{
590 /* do the secure computing check first */
591 secure_computing(regs->orig_rax);
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (test_thread_flag(TIF_SYSCALL_TRACE)
594 && (current->ptrace & PT_PTRACED))
595 syscall_trace(regs);
2fd6f582005-04-29 16:08:28 +0100596
David Woodhouse488f2ea2005-05-03 14:11:02 +0100597 if (unlikely(current->audit_context)) {
598 if (test_thread_flag(TIF_IA32)) {
Al Viro5411be52006-03-29 20:23:36 -0500599 audit_syscall_entry(AUDIT_ARCH_I386,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100600 regs->orig_rax,
601 regs->rbx, regs->rcx,
602 regs->rdx, regs->rsi);
603 } else {
Al Viro5411be52006-03-29 20:23:36 -0500604 audit_syscall_entry(AUDIT_ARCH_X86_64,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100605 regs->orig_rax,
606 regs->rdi, regs->rsi,
607 regs->rdx, regs->r10);
608 }
609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610}
611
612asmlinkage void syscall_trace_leave(struct pt_regs *regs)
613{
614 if (unlikely(current->audit_context))
Al Viro5411be52006-03-29 20:23:36 -0500615 audit_syscall_exit(AUDITSC_RESULT(regs->rax), regs->rax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 if ((test_thread_flag(TIF_SYSCALL_TRACE)
618 || test_thread_flag(TIF_SINGLESTEP))
619 && (current->ptrace & PT_PTRACED))
620 syscall_trace(regs);
621}