blob: 9409117b9f1901c357a1e47c75909e8fa146d34e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* ptrace.c */
2/* By Ross Biro 1/23/92 */
3/*
4 * Pentium III FXSR, SSE support
5 * Gareth Hughes <gareth@valinux.com>, May 2000
6 *
7 * x86-64 port 2000-2002 Andi Kleen
8 */
9
10#include <linux/kernel.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/errno.h>
15#include <linux/ptrace.h>
16#include <linux/user.h>
17#include <linux/security.h>
18#include <linux/audit.h>
19#include <linux/seccomp.h>
Jesper Juhl7ed20e12005-05-01 08:59:14 -070020#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/uaccess.h>
23#include <asm/pgtable.h>
24#include <asm/system.h>
25#include <asm/processor.h>
26#include <asm/i387.h>
27#include <asm/debugreg.h>
28#include <asm/ldt.h>
29#include <asm/desc.h>
30#include <asm/proto.h>
31#include <asm/ia32.h>
32
33/*
34 * does not yet catch signals sent when the child dies.
35 * in exit.c or in signal.c.
36 */
37
Chuck Ebbert60923df2006-01-11 22:46:03 +010038/*
39 * Determines which flags the user has access to [1 = access, 0 = no access].
40 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
41 * Also masks reserved bits (63-22, 15, 5, 3, 1).
42 */
43#define FLAG_MASK 0x54dd5UL
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* set's the trap flag. */
46#define TRAP_FLAG 0x100UL
47
48/*
49 * eflags and offset of eflags on child stack..
50 */
51#define EFLAGS offsetof(struct pt_regs, eflags)
52#define EFL_OFFSET ((int)(EFLAGS-sizeof(struct pt_regs)))
53
54/*
55 * this routine will get a word off of the processes privileged stack.
56 * the offset is how far from the base addr as stored in the TSS.
57 * this routine assumes that all the privileged stacks are in our
58 * data space.
59 */
60static inline unsigned long get_stack_long(struct task_struct *task, int offset)
61{
62 unsigned char *stack;
63
64 stack = (unsigned char *)task->thread.rsp0;
65 stack += offset;
66 return (*((unsigned long *)stack));
67}
68
69/*
70 * this routine will put a word on the processes privileged stack.
71 * the offset is how far from the base addr as stored in the TSS.
72 * this routine assumes that all the privileged stacks are in our
73 * data space.
74 */
75static inline long put_stack_long(struct task_struct *task, int offset,
76 unsigned long data)
77{
78 unsigned char * stack;
79
80 stack = (unsigned char *) task->thread.rsp0;
81 stack += offset;
82 *(unsigned long *) stack = data;
83 return 0;
84}
85
Andi Kleene502cdd2005-04-16 15:24:58 -070086#define LDT_SEGMENT 4
87
88unsigned long convert_rip_to_linear(struct task_struct *child, struct pt_regs *regs)
89{
90 unsigned long addr, seg;
91
92 addr = regs->rip;
93 seg = regs->cs & 0xffff;
94
95 /*
96 * We'll assume that the code segments in the GDT
97 * are all zero-based. That is largely true: the
98 * TLS segments are used for data, and the PNPBIOS
99 * and APM bios ones we just ignore here.
100 */
101 if (seg & LDT_SEGMENT) {
102 u32 *desc;
103 unsigned long base;
104
105 down(&child->mm->context.sem);
106 desc = child->mm->context.ldt + (seg & ~7);
107 base = (desc[0] >> 16) | ((desc[1] & 0xff) << 16) | (desc[1] & 0xff000000);
108
109 /* 16-bit code segment? */
110 if (!((desc[1] >> 22) & 1))
111 addr &= 0xffff;
112 addr += base;
113 up(&child->mm->context.sem);
114 }
115 return addr;
116}
117
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200118static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
Andi Kleene502cdd2005-04-16 15:24:58 -0700119{
120 int i, copied;
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200121 unsigned char opcode[15];
Andi Kleene502cdd2005-04-16 15:24:58 -0700122 unsigned long addr = convert_rip_to_linear(child, regs);
123
124 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
125 for (i = 0; i < copied; i++) {
126 switch (opcode[i]) {
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200127 /* popf and iret */
128 case 0x9d: case 0xcf:
Andi Kleene502cdd2005-04-16 15:24:58 -0700129 return 1;
130
131 /* CHECKME: 64 65 */
132
133 /* opcode and address size prefixes */
134 case 0x66: case 0x67:
135 continue;
136 /* irrelevant prefixes (segment overrides and repeats) */
137 case 0x26: case 0x2e:
138 case 0x36: case 0x3e:
139 case 0x64: case 0x65:
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200140 case 0xf2: case 0xf3:
Andi Kleene502cdd2005-04-16 15:24:58 -0700141 continue;
142
Andi Kleene502cdd2005-04-16 15:24:58 -0700143 case 0x40 ... 0x4f:
Chuck Ebberta752d712006-09-26 10:52:32 +0200144 if (regs->cs != __USER_CS)
145 /* 32-bit mode: register increment */
146 return 0;
147 /* 64-bit mode: REX prefix */
Andi Kleene502cdd2005-04-16 15:24:58 -0700148 continue;
149
Chuck Ebbertd4d35852006-09-26 10:52:32 +0200150 /* CHECKME: f2, f3 */
Andi Kleene502cdd2005-04-16 15:24:58 -0700151
152 /*
153 * pushf: NOTE! We should probably not let
154 * the user see the TF bit being set. But
155 * it's more pain than it's worth to avoid
156 * it, and a debugger could emulate this
157 * all in user space if it _really_ cares.
158 */
159 case 0x9c:
160 default:
161 return 0;
162 }
163 }
164 return 0;
165}
166
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700167static void set_singlestep(struct task_struct *child)
168{
Al Virobb049232006-01-12 01:05:38 -0800169 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700170
171 /*
172 * Always set TIF_SINGLESTEP - this guarantees that
173 * we single-step system calls etc.. This will also
174 * cause us to set TF when returning to user mode.
175 */
176 set_tsk_thread_flag(child, TIF_SINGLESTEP);
177
178 /*
179 * If TF was already set, don't do anything else
180 */
181 if (regs->eflags & TRAP_FLAG)
182 return;
183
184 /* Set TF on the kernel stack.. */
185 regs->eflags |= TRAP_FLAG;
186
Andi Kleene502cdd2005-04-16 15:24:58 -0700187 /*
188 * ..but if TF is changed by the instruction we will trace,
189 * don't mark it as being "us" that set it, so that we
190 * won't clear it by hand later.
Andi Kleene502cdd2005-04-16 15:24:58 -0700191 */
Chuck Ebbert2ade2922006-09-26 10:52:33 +0200192 if (is_setting_trap_flag(child, regs))
Andi Kleene502cdd2005-04-16 15:24:58 -0700193 return;
194
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700195 child->ptrace |= PT_DTRACE;
196}
197
198static void clear_singlestep(struct task_struct *child)
199{
200 /* Always clear TIF_SINGLESTEP... */
201 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
202
203 /* But touch TF only if it was set by us.. */
204 if (child->ptrace & PT_DTRACE) {
Al Virobb049232006-01-12 01:05:38 -0800205 struct pt_regs *regs = task_pt_regs(child);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700206 regs->eflags &= ~TRAP_FLAG;
207 child->ptrace &= ~PT_DTRACE;
208 }
209}
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/*
212 * Called by kernel/ptrace.c when detaching..
213 *
214 * Make sure the single step bit is not set.
215 */
216void ptrace_disable(struct task_struct *child)
217{
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700218 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221static int putreg(struct task_struct *child,
222 unsigned long regno, unsigned long value)
223{
224 unsigned long tmp;
225
226 /* Some code in the 64bit emulation may not be 64bit clean.
227 Don't take any chances. */
228 if (test_tsk_thread_flag(child, TIF_IA32))
229 value &= 0xffffffff;
230 switch (regno) {
231 case offsetof(struct user_regs_struct,fs):
232 if (value && (value & 3) != 3)
233 return -EIO;
234 child->thread.fsindex = value & 0xffff;
235 return 0;
236 case offsetof(struct user_regs_struct,gs):
237 if (value && (value & 3) != 3)
238 return -EIO;
239 child->thread.gsindex = value & 0xffff;
240 return 0;
241 case offsetof(struct user_regs_struct,ds):
242 if (value && (value & 3) != 3)
243 return -EIO;
244 child->thread.ds = value & 0xffff;
245 return 0;
246 case offsetof(struct user_regs_struct,es):
247 if (value && (value & 3) != 3)
248 return -EIO;
249 child->thread.es = value & 0xffff;
250 return 0;
251 case offsetof(struct user_regs_struct,ss):
252 if ((value & 3) != 3)
253 return -EIO;
254 value &= 0xffff;
255 return 0;
256 case offsetof(struct user_regs_struct,fs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700257 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 child->thread.fs = value;
260 return 0;
261 case offsetof(struct user_regs_struct,gs_base):
Suresh Siddha84929802005-06-21 17:14:32 -0700262 if (value >= TASK_SIZE_OF(child))
Andi Kleenf6b8d472005-05-16 21:53:30 -0700263 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 child->thread.gs = value;
265 return 0;
266 case offsetof(struct user_regs_struct, eflags):
267 value &= FLAG_MASK;
268 tmp = get_stack_long(child, EFL_OFFSET);
269 tmp &= ~FLAG_MASK;
270 value |= tmp;
271 break;
272 case offsetof(struct user_regs_struct,cs):
273 if ((value & 3) != 3)
274 return -EIO;
275 value &= 0xffff;
276 break;
277 }
278 put_stack_long(child, regno - sizeof(struct pt_regs), value);
279 return 0;
280}
281
282static unsigned long getreg(struct task_struct *child, unsigned long regno)
283{
284 unsigned long val;
285 switch (regno) {
286 case offsetof(struct user_regs_struct, fs):
287 return child->thread.fsindex;
288 case offsetof(struct user_regs_struct, gs):
289 return child->thread.gsindex;
290 case offsetof(struct user_regs_struct, ds):
291 return child->thread.ds;
292 case offsetof(struct user_regs_struct, es):
293 return child->thread.es;
294 case offsetof(struct user_regs_struct, fs_base):
295 return child->thread.fs;
296 case offsetof(struct user_regs_struct, gs_base):
297 return child->thread.gs;
298 default:
299 regno = regno - sizeof(struct pt_regs);
300 val = get_stack_long(child, regno);
301 if (test_tsk_thread_flag(child, TIF_IA32))
302 val &= 0xffffffff;
303 return val;
304 }
305
306}
307
Christoph Hellwig481bed42005-11-07 00:59:47 -0800308long arch_ptrace(struct task_struct *child, long request, long addr, long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 long i, ret;
311 unsigned ui;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 switch (request) {
314 /* when I and D space are separate, these will need to be fixed. */
315 case PTRACE_PEEKTEXT: /* read word at location addr. */
316 case PTRACE_PEEKDATA: {
317 unsigned long tmp;
318 int copied;
319
320 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
321 ret = -EIO;
322 if (copied != sizeof(tmp))
323 break;
324 ret = put_user(tmp,(unsigned long __user *) data);
325 break;
326 }
327
328 /* read the word at location addr in the USER area. */
329 case PTRACE_PEEKUSR: {
330 unsigned long tmp;
331
332 ret = -EIO;
333 if ((addr & 7) ||
334 addr > sizeof(struct user) - 7)
335 break;
336
337 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700338 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 tmp = getreg(child, addr);
340 break;
341 case offsetof(struct user, u_debugreg[0]):
342 tmp = child->thread.debugreg0;
343 break;
344 case offsetof(struct user, u_debugreg[1]):
345 tmp = child->thread.debugreg1;
346 break;
347 case offsetof(struct user, u_debugreg[2]):
348 tmp = child->thread.debugreg2;
349 break;
350 case offsetof(struct user, u_debugreg[3]):
351 tmp = child->thread.debugreg3;
352 break;
353 case offsetof(struct user, u_debugreg[6]):
354 tmp = child->thread.debugreg6;
355 break;
356 case offsetof(struct user, u_debugreg[7]):
357 tmp = child->thread.debugreg7;
358 break;
359 default:
360 tmp = 0;
361 break;
362 }
363 ret = put_user(tmp,(unsigned long __user *) data);
364 break;
365 }
366
367 /* when I and D space are separate, this will have to be fixed. */
368 case PTRACE_POKETEXT: /* write the word at location addr. */
369 case PTRACE_POKEDATA:
370 ret = 0;
371 if (access_process_vm(child, addr, &data, sizeof(data), 1) == sizeof(data))
372 break;
373 ret = -EIO;
374 break;
375
376 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
Suresh Siddha84929802005-06-21 17:14:32 -0700377 {
378 int dsize = test_tsk_thread_flag(child, TIF_IA32) ? 3 : 7;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 ret = -EIO;
380 if ((addr & 7) ||
381 addr > sizeof(struct user) - 7)
382 break;
383
384 switch (addr) {
Andi Kleenc4d1fcf2005-05-20 14:27:56 -0700385 case 0 ... sizeof(struct user_regs_struct) - sizeof(long):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 ret = putreg(child, addr, data);
387 break;
388 /* Disallows to set a breakpoint into the vsyscall */
389 case offsetof(struct user, u_debugreg[0]):
Suresh Siddha84929802005-06-21 17:14:32 -0700390 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 child->thread.debugreg0 = data;
392 ret = 0;
393 break;
394 case offsetof(struct user, u_debugreg[1]):
Suresh Siddha84929802005-06-21 17:14:32 -0700395 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 child->thread.debugreg1 = data;
397 ret = 0;
398 break;
399 case offsetof(struct user, u_debugreg[2]):
Suresh Siddha84929802005-06-21 17:14:32 -0700400 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 child->thread.debugreg2 = data;
402 ret = 0;
403 break;
404 case offsetof(struct user, u_debugreg[3]):
Suresh Siddha84929802005-06-21 17:14:32 -0700405 if (data >= TASK_SIZE_OF(child) - dsize) break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 child->thread.debugreg3 = data;
407 ret = 0;
408 break;
409 case offsetof(struct user, u_debugreg[6]):
410 if (data >> 32)
411 break;
412 child->thread.debugreg6 = data;
413 ret = 0;
414 break;
415 case offsetof(struct user, u_debugreg[7]):
416 /* See arch/i386/kernel/ptrace.c for an explanation of
417 * this awkward check.*/
Jan Beulich893efca2006-03-25 16:29:19 +0100418 data &= ~DR_CONTROL_RESERVED;
419 for(i=0; i<4; i++)
420 if ((0x5554 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 break;
422 if (i == 4) {
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200423 child->thread.debugreg7 = data;
424 if (data)
425 set_tsk_thread_flag(child, TIF_DEBUG);
426 else
427 clear_tsk_thread_flag(child, TIF_DEBUG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 ret = 0;
Stephane Eraniand3a4f482006-09-26 10:52:28 +0200429 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 break;
431 }
432 break;
Suresh Siddha84929802005-06-21 17:14:32 -0700433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700435 case PTRACE_CONT: /* restart after signal. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700438 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440 if (request == PTRACE_SYSCALL)
441 set_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
442 else
443 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
444 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
445 child->exit_code = data;
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700446 /* make sure the single step bit is not set. */
447 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 wake_up_process(child);
449 ret = 0;
450 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452#ifdef CONFIG_IA32_EMULATION
453 /* This makes only sense with 32bit programs. Allow a
454 64bit debugger to fully examine them too. Better
455 don't use it against 64bit processes, use
456 PTRACE_ARCH_PRCTL instead. */
457 case PTRACE_SET_THREAD_AREA: {
458 struct user_desc __user *p;
459 int old;
460 p = (struct user_desc __user *)data;
461 get_user(old, &p->entry_number);
462 put_user(addr, &p->entry_number);
463 ret = do_set_thread_area(&child->thread, p);
464 put_user(old, &p->entry_number);
465 break;
466 case PTRACE_GET_THREAD_AREA:
467 p = (struct user_desc __user *)data;
468 get_user(old, &p->entry_number);
469 put_user(addr, &p->entry_number);
470 ret = do_get_thread_area(&child->thread, p);
471 put_user(old, &p->entry_number);
472 break;
473 }
474#endif
475 /* normal 64bit interface to access TLS data.
476 Works just like arch_prctl, except that the arguments
477 are reversed. */
478 case PTRACE_ARCH_PRCTL:
479 ret = do_arch_prctl(child, data, addr);
480 break;
481
482/*
483 * make the child exit. Best I can do is send it a sigkill.
484 * perhaps it should be put in the status that it wants to
485 * exit.
486 */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700487 case PTRACE_KILL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 ret = 0;
489 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
490 break;
491 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
492 child->exit_code = SIGKILL;
493 /* make sure the single step bit is not set. */
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700494 clear_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 wake_up_process(child);
496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700498 case PTRACE_SINGLESTEP: /* set the trap flag. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 ret = -EIO;
Jesper Juhl7ed20e12005-05-01 08:59:14 -0700500 if (!valid_signal(data))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 break;
502 clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
Andi Kleenaa85b9a2005-04-16 15:24:56 -0700503 set_singlestep(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 child->exit_code = data;
505 /* give it a chance to run. */
506 wake_up_process(child);
507 ret = 0;
508 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 case PTRACE_DETACH:
511 /* detach a process that was attached. */
512 ret = ptrace_detach(child, data);
513 break;
514
515 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
516 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
517 sizeof(struct user_regs_struct))) {
518 ret = -EIO;
519 break;
520 }
521 ret = 0;
522 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
523 ret |= __put_user(getreg(child, ui),(unsigned long __user *) data);
524 data += sizeof(long);
525 }
526 break;
527 }
528
529 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
530 unsigned long tmp;
531 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
532 sizeof(struct user_regs_struct))) {
533 ret = -EIO;
534 break;
535 }
536 ret = 0;
537 for (ui = 0; ui < sizeof(struct user_regs_struct); ui += sizeof(long)) {
Andi Kleenf49481b2007-02-13 13:26:24 +0100538 ret = __get_user(tmp, (unsigned long __user *) data);
539 if (ret)
540 break;
541 ret = putreg(child, ui, tmp);
542 if (ret)
543 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 data += sizeof(long);
545 }
546 break;
547 }
548
549 case PTRACE_GETFPREGS: { /* Get the child extended FPU state. */
550 if (!access_ok(VERIFY_WRITE, (unsigned __user *)data,
551 sizeof(struct user_i387_struct))) {
552 ret = -EIO;
553 break;
554 }
555 ret = get_fpregs((struct user_i387_struct __user *)data, child);
556 break;
557 }
558
559 case PTRACE_SETFPREGS: { /* Set the child extended FPU state. */
560 if (!access_ok(VERIFY_READ, (unsigned __user *)data,
561 sizeof(struct user_i387_struct))) {
562 ret = -EIO;
563 break;
564 }
565 set_stopped_child_used_math(child);
566 ret = set_fpregs(child, (struct user_i387_struct __user *)data);
567 break;
568 }
569
570 default:
571 ret = ptrace_request(child, request, addr, data);
572 break;
573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return ret;
575}
576
577static void syscall_trace(struct pt_regs *regs)
578{
579
580#if 0
581 printk("trace %s rip %lx rsp %lx rax %d origrax %d caller %lx tiflags %x ptrace %x\n",
582 current->comm,
583 regs->rip, regs->rsp, regs->rax, regs->orig_rax, __builtin_return_address(0),
584 current_thread_info()->flags, current->ptrace);
585#endif
586
587 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
588 ? 0x80 : 0));
589 /*
590 * this isn't the same as continuing with a signal, but it will do
591 * for normal use. strace only continues with a signal if the
592 * stopping signal is not SIGTRAP. -brl
593 */
594 if (current->exit_code) {
595 send_sig(current->exit_code, current, 1);
596 current->exit_code = 0;
597 }
598}
599
600asmlinkage void syscall_trace_enter(struct pt_regs *regs)
601{
602 /* do the secure computing check first */
603 secure_computing(regs->orig_rax);
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (test_thread_flag(TIF_SYSCALL_TRACE)
606 && (current->ptrace & PT_PTRACED))
607 syscall_trace(regs);
2fd6f582005-04-29 16:08:28 +0100608
David Woodhouse488f2ea2005-05-03 14:11:02 +0100609 if (unlikely(current->audit_context)) {
610 if (test_thread_flag(TIF_IA32)) {
Al Viro5411be52006-03-29 20:23:36 -0500611 audit_syscall_entry(AUDIT_ARCH_I386,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100612 regs->orig_rax,
613 regs->rbx, regs->rcx,
614 regs->rdx, regs->rsi);
615 } else {
Al Viro5411be52006-03-29 20:23:36 -0500616 audit_syscall_entry(AUDIT_ARCH_X86_64,
David Woodhouse488f2ea2005-05-03 14:11:02 +0100617 regs->orig_rax,
618 regs->rdi, regs->rsi,
619 regs->rdx, regs->r10);
620 }
621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
624asmlinkage void syscall_trace_leave(struct pt_regs *regs)
625{
626 if (unlikely(current->audit_context))
Al Viro5411be52006-03-29 20:23:36 -0500627 audit_syscall_exit(AUDITSC_RESULT(regs->rax), regs->rax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 if ((test_thread_flag(TIF_SYSCALL_TRACE)
630 || test_thread_flag(TIF_SINGLESTEP))
631 && (current->ptrace & PT_PTRACED))
632 syscall_trace(regs);
633}