PTRACE_POKEDATA consolidation
[deliverable/linux.git] / arch / i386 / kernel / ptrace.c
CommitLineData
1da177e4
LT
1/* 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
8#include <linux/kernel.h>
9#include <linux/sched.h>
10#include <linux/mm.h>
11#include <linux/smp.h>
1da177e4
LT
12#include <linux/errno.h>
13#include <linux/ptrace.h>
14#include <linux/user.h>
15#include <linux/security.h>
16#include <linux/audit.h>
17#include <linux/seccomp.h>
7ed20e1a 18#include <linux/signal.h>
1da177e4
LT
19
20#include <asm/uaccess.h>
21#include <asm/pgtable.h>
22#include <asm/system.h>
23#include <asm/processor.h>
24#include <asm/i387.h>
25#include <asm/debugreg.h>
26#include <asm/ldt.h>
27#include <asm/desc.h>
28
29/*
30 * does not yet catch signals sent when the child dies.
31 * in exit.c or in signal.c.
32 */
33
9f155b98
CE
34/*
35 * Determines which flags the user has access to [1 = access, 0 = no access].
3c36c6aa 36 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), NT(14), IOPL(12-13), IF(9).
9f155b98
CE
37 * Also masks reserved bits (31-22, 15, 5, 3, 1).
38 */
3c36c6aa 39#define FLAG_MASK 0x00050dd5
1da177e4
LT
40
41/* set's the trap flag. */
42#define TRAP_FLAG 0x100
43
44/*
45 * Offset of eflags on child stack..
46 */
8701ea95 47#define EFL_OFFSET offsetof(struct pt_regs, eflags)
1da177e4
LT
48
49static inline struct pt_regs *get_child_regs(struct task_struct *task)
50{
51 void *stack_top = (void *)task->thread.esp0;
52 return stack_top - sizeof(struct pt_regs);
53}
54
55/*
8701ea95
JF
56 * This routine will get a word off of the processes privileged stack.
57 * the offset is bytes into the pt_regs structure on the stack.
58 * This routine assumes that all the privileged stacks are in our
1da177e4
LT
59 * data space.
60 */
61static inline int get_stack_long(struct task_struct *task, int offset)
62{
63 unsigned char *stack;
64
8701ea95 65 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
1da177e4
LT
66 stack += offset;
67 return (*((int *)stack));
68}
69
70/*
8701ea95
JF
71 * This routine will put a word on the processes privileged stack.
72 * the offset is bytes into the pt_regs structure on the stack.
73 * This routine assumes that all the privileged stacks are in our
1da177e4
LT
74 * data space.
75 */
76static inline int put_stack_long(struct task_struct *task, int offset,
77 unsigned long data)
78{
79 unsigned char * stack;
80
8701ea95 81 stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
1da177e4
LT
82 stack += offset;
83 *(unsigned long *) stack = data;
84 return 0;
85}
86
87static int putreg(struct task_struct *child,
88 unsigned long regno, unsigned long value)
89{
90 switch (regno >> 2) {
464d1a78 91 case GS:
1da177e4
LT
92 if (value && (value & 3) != 3)
93 return -EIO;
464d1a78 94 child->thread.gs = value;
1da177e4 95 return 0;
1da177e4
LT
96 case DS:
97 case ES:
464d1a78 98 case FS:
1da177e4
LT
99 if (value && (value & 3) != 3)
100 return -EIO;
101 value &= 0xffff;
102 break;
103 case SS:
104 case CS:
105 if ((value & 3) != 3)
106 return -EIO;
107 value &= 0xffff;
108 break;
109 case EFL:
110 value &= FLAG_MASK;
111 value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK;
112 break;
113 }
464d1a78 114 if (regno > FS*4)
66e10a44 115 regno -= 1*4;
8701ea95 116 put_stack_long(child, regno, value);
1da177e4
LT
117 return 0;
118}
119
120static unsigned long getreg(struct task_struct *child,
121 unsigned long regno)
122{
123 unsigned long retval = ~0UL;
124
125 switch (regno >> 2) {
464d1a78
JF
126 case GS:
127 retval = child->thread.gs;
1da177e4 128 break;
1da177e4
LT
129 case DS:
130 case ES:
464d1a78 131 case FS:
1da177e4
LT
132 case SS:
133 case CS:
134 retval = 0xffff;
135 /* fall through */
136 default:
464d1a78 137 if (regno > FS*4)
66e10a44 138 regno -= 1*4;
1da177e4
LT
139 retval &= get_stack_long(child, regno);
140 }
141 return retval;
142}
143
144#define LDT_SEGMENT 4
145
146static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_regs *regs)
147{
148 unsigned long addr, seg;
149
150 addr = regs->eip;
151 seg = regs->xcs & 0xffff;
152 if (regs->eflags & VM_MASK) {
153 addr = (addr & 0xffff) + (seg << 4);
154 return addr;
155 }
156
157 /*
158 * We'll assume that the code segments in the GDT
159 * are all zero-based. That is largely true: the
160 * TLS segments are used for data, and the PNPBIOS
161 * and APM bios ones we just ignore here.
162 */
163 if (seg & LDT_SEGMENT) {
164 u32 *desc;
165 unsigned long base;
166
167 down(&child->mm->context.sem);
168 desc = child->mm->context.ldt + (seg & ~7);
169 base = (desc[0] >> 16) | ((desc[1] & 0xff) << 16) | (desc[1] & 0xff000000);
170
171 /* 16-bit code segment? */
172 if (!((desc[1] >> 22) & 1))
173 addr &= 0xffff;
174 addr += base;
175 up(&child->mm->context.sem);
176 }
177 return addr;
178}
179
2ade2920 180static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
1da177e4
LT
181{
182 int i, copied;
2ade2920 183 unsigned char opcode[15];
1da177e4
LT
184 unsigned long addr = convert_eip_to_linear(child, regs);
185
186 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
187 for (i = 0; i < copied; i++) {
188 switch (opcode[i]) {
2ade2920
CE
189 /* popf and iret */
190 case 0x9d: case 0xcf:
1da177e4
LT
191 return 1;
192 /* opcode and address size prefixes */
193 case 0x66: case 0x67:
194 continue;
195 /* irrelevant prefixes (segment overrides and repeats) */
196 case 0x26: case 0x2e:
197 case 0x36: case 0x3e:
198 case 0x64: case 0x65:
199 case 0xf0: case 0xf2: case 0xf3:
200 continue;
201
202 /*
203 * pushf: NOTE! We should probably not let
204 * the user see the TF bit being set. But
205 * it's more pain than it's worth to avoid
206 * it, and a debugger could emulate this
207 * all in user space if it _really_ cares.
208 */
209 case 0x9c:
210 default:
211 return 0;
212 }
213 }
214 return 0;
215}
216
217static void set_singlestep(struct task_struct *child)
218{
219 struct pt_regs *regs = get_child_regs(child);
220
221 /*
222 * Always set TIF_SINGLESTEP - this guarantees that
223 * we single-step system calls etc.. This will also
224 * cause us to set TF when returning to user mode.
225 */
226 set_tsk_thread_flag(child, TIF_SINGLESTEP);
227
228 /*
229 * If TF was already set, don't do anything else
230 */
231 if (regs->eflags & TRAP_FLAG)
232 return;
233
234 /* Set TF on the kernel stack.. */
235 regs->eflags |= TRAP_FLAG;
236
237 /*
238 * ..but if TF is changed by the instruction we will trace,
239 * don't mark it as being "us" that set it, so that we
240 * won't clear it by hand later.
241 */
2ade2920 242 if (is_setting_trap_flag(child, regs))
1da177e4
LT
243 return;
244
245 child->ptrace |= PT_DTRACE;
246}
247
248static void clear_singlestep(struct task_struct *child)
249{
250 /* Always clear TIF_SINGLESTEP... */
251 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
252
253 /* But touch TF only if it was set by us.. */
254 if (child->ptrace & PT_DTRACE) {
255 struct pt_regs *regs = get_child_regs(child);
256 regs->eflags &= ~TRAP_FLAG;
257 child->ptrace &= ~PT_DTRACE;
258 }
259}
260
261/*
262 * Called by kernel/ptrace.c when detaching..
263 *
264 * Make sure the single step bit is not set.
265 */
266void ptrace_disable(struct task_struct *child)
267{
268 clear_singlestep(child);
ab1c23c2
BS
269 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
270 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
1da177e4
LT
271}
272
273/*
274 * Perform get_thread_area on behalf of the traced child.
275 */
276static int
277ptrace_get_thread_area(struct task_struct *child,
278 int idx, struct user_desc __user *user_desc)
279{
280 struct user_desc info;
281 struct desc_struct *desc;
282
283/*
284 * Get the current Thread-Local Storage area:
285 */
286
287#define GET_BASE(desc) ( \
288 (((desc)->a >> 16) & 0x0000ffff) | \
289 (((desc)->b << 16) & 0x00ff0000) | \
290 ( (desc)->b & 0xff000000) )
291
292#define GET_LIMIT(desc) ( \
293 ((desc)->a & 0x0ffff) | \
294 ((desc)->b & 0xf0000) )
295
296#define GET_32BIT(desc) (((desc)->b >> 22) & 1)
297#define GET_CONTENTS(desc) (((desc)->b >> 10) & 3)
298#define GET_WRITABLE(desc) (((desc)->b >> 9) & 1)
299#define GET_LIMIT_PAGES(desc) (((desc)->b >> 23) & 1)
300#define GET_PRESENT(desc) (((desc)->b >> 15) & 1)
301#define GET_USEABLE(desc) (((desc)->b >> 20) & 1)
302
303 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
304 return -EINVAL;
305
306 desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
307
308 info.entry_number = idx;
309 info.base_addr = GET_BASE(desc);
310 info.limit = GET_LIMIT(desc);
311 info.seg_32bit = GET_32BIT(desc);
312 info.contents = GET_CONTENTS(desc);
313 info.read_exec_only = !GET_WRITABLE(desc);
314 info.limit_in_pages = GET_LIMIT_PAGES(desc);
315 info.seg_not_present = !GET_PRESENT(desc);
316 info.useable = GET_USEABLE(desc);
317
318 if (copy_to_user(user_desc, &info, sizeof(info)))
319 return -EFAULT;
320
321 return 0;
322}
323
324/*
325 * Perform set_thread_area on behalf of the traced child.
326 */
327static int
328ptrace_set_thread_area(struct task_struct *child,
329 int idx, struct user_desc __user *user_desc)
330{
331 struct user_desc info;
332 struct desc_struct *desc;
333
334 if (copy_from_user(&info, user_desc, sizeof(info)))
335 return -EFAULT;
336
337 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
338 return -EINVAL;
339
340 desc = child->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
341 if (LDT_empty(&info)) {
342 desc->a = 0;
343 desc->b = 0;
344 } else {
345 desc->a = LDT_entry_a(&info);
346 desc->b = LDT_entry_b(&info);
347 }
348
349 return 0;
350}
351
481bed45 352long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1da177e4 353{
1da177e4
LT
354 struct user * dummy = NULL;
355 int i, ret;
356 unsigned long __user *datap = (unsigned long __user *)data;
357
1da177e4
LT
358 switch (request) {
359 /* when I and D space are separate, these will need to be fixed. */
360 case PTRACE_PEEKTEXT: /* read word at location addr. */
76647323
AD
361 case PTRACE_PEEKDATA:
362 ret = generic_ptrace_peekdata(child, addr, data);
1da177e4 363 break;
1da177e4
LT
364
365 /* read the word at location addr in the USER area. */
366 case PTRACE_PEEKUSR: {
367 unsigned long tmp;
368
369 ret = -EIO;
370 if ((addr & 3) || addr < 0 ||
371 addr > sizeof(struct user) - 3)
372 break;
373
374 tmp = 0; /* Default return condition */
375 if(addr < FRAME_SIZE*sizeof(long))
376 tmp = getreg(child, addr);
377 if(addr >= (long) &dummy->u_debugreg[0] &&
378 addr <= (long) &dummy->u_debugreg[7]){
379 addr -= (long) &dummy->u_debugreg[0];
380 addr = addr >> 2;
381 tmp = child->thread.debugreg[addr];
382 }
383 ret = put_user(tmp, datap);
384 break;
385 }
386
387 /* when I and D space are separate, this will have to be fixed. */
388 case PTRACE_POKETEXT: /* write the word at location addr. */
389 case PTRACE_POKEDATA:
f284ce72 390 ret = generic_ptrace_pokedata(child, addr, data);
1da177e4
LT
391 break;
392
393 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
394 ret = -EIO;
395 if ((addr & 3) || addr < 0 ||
396 addr > sizeof(struct user) - 3)
397 break;
398
399 if (addr < FRAME_SIZE*sizeof(long)) {
400 ret = putreg(child, addr, data);
401 break;
402 }
403 /* We need to be very careful here. We implicitly
404 want to modify a portion of the task_struct, and we
405 have to be selective about what portions we allow someone
406 to modify. */
407
408 ret = -EIO;
409 if(addr >= (long) &dummy->u_debugreg[0] &&
410 addr <= (long) &dummy->u_debugreg[7]){
411
412 if(addr == (long) &dummy->u_debugreg[4]) break;
413 if(addr == (long) &dummy->u_debugreg[5]) break;
414 if(addr < (long) &dummy->u_debugreg[4] &&
415 ((unsigned long) data) >= TASK_SIZE-3) break;
416
417 /* Sanity-check data. Take one half-byte at once with
418 * check = (val >> (16 + 4*i)) & 0xf. It contains the
419 * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits
420 * 2 and 3 are LENi. Given a list of invalid values,
421 * we do mask |= 1 << invalid_value, so that
422 * (mask >> check) & 1 is a correct test for invalid
423 * values.
424 *
425 * R/Wi contains the type of the breakpoint /
426 * watchpoint, LENi contains the length of the watched
427 * data in the watchpoint case.
428 *
429 * The invalid values are:
430 * - LENi == 0x10 (undefined), so mask |= 0x0f00.
431 * - R/Wi == 0x10 (break on I/O reads or writes), so
432 * mask |= 0x4444.
433 * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
434 * 0x1110.
435 *
436 * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
437 *
438 * See the Intel Manual "System Programming Guide",
439 * 15.2.4
440 *
441 * Note that LENi == 0x10 is defined on x86_64 in long
442 * mode (i.e. even for 32-bit userspace software, but
443 * 64-bit kernel), so the x86_64 mask value is 0x5454.
444 * See the AMD manual no. 24593 (AMD64 System
445 * Programming)*/
446
447 if(addr == (long) &dummy->u_debugreg[7]) {
448 data &= ~DR_CONTROL_RESERVED;
449 for(i=0; i<4; i++)
450 if ((0x5f54 >> ((data >> (16 + 4*i)) & 0xf)) & 1)
451 goto out_tsk;
b3cf2576
SE
452 if (data)
453 set_tsk_thread_flag(child, TIF_DEBUG);
454 else
455 clear_tsk_thread_flag(child, TIF_DEBUG);
1da177e4 456 }
1da177e4
LT
457 addr -= (long) &dummy->u_debugreg;
458 addr = addr >> 2;
459 child->thread.debugreg[addr] = data;
460 ret = 0;
461 }
462 break;
463
ed75e8d5 464 case PTRACE_SYSEMU: /* continue and stop at next syscall, which will not be executed */
1da177e4
LT
465 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */
466 case PTRACE_CONT: /* restart after signal. */
467 ret = -EIO;
7ed20e1a 468 if (!valid_signal(data))
1da177e4 469 break;
ed75e8d5
LV
470 if (request == PTRACE_SYSEMU) {
471 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
c8c86cec
BS
472 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
473 } else if (request == PTRACE_SYSCALL) {
1da177e4 474 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
c8c86cec 475 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
ed75e8d5 476 } else {
c8c86cec 477 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
1da177e4
LT
478 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
479 }
480 child->exit_code = data;
481 /* make sure the single step bit is not set. */
482 clear_singlestep(child);
483 wake_up_process(child);
484 ret = 0;
485 break;
486
487/*
488 * make the child exit. Best I can do is send it a sigkill.
489 * perhaps it should be put in the status that it wants to
490 * exit.
491 */
492 case PTRACE_KILL:
493 ret = 0;
494 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
495 break;
496 child->exit_code = SIGKILL;
497 /* make sure the single step bit is not set. */
498 clear_singlestep(child);
499 wake_up_process(child);
500 break;
501
1b38f006 502 case PTRACE_SYSEMU_SINGLESTEP: /* Same as SYSEMU, but singlestep if not syscall */
1da177e4
LT
503 case PTRACE_SINGLESTEP: /* set the trap flag. */
504 ret = -EIO;
7ed20e1a 505 if (!valid_signal(data))
1da177e4 506 break;
1b38f006
BS
507
508 if (request == PTRACE_SYSEMU_SINGLESTEP)
509 set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
510 else
511 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
512
1da177e4
LT
513 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
514 set_singlestep(child);
515 child->exit_code = data;
516 /* give it a chance to run. */
517 wake_up_process(child);
518 ret = 0;
519 break;
520
521 case PTRACE_DETACH:
522 /* detach a process that was attached. */
523 ret = ptrace_detach(child, data);
524 break;
525
526 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
527 if (!access_ok(VERIFY_WRITE, datap, FRAME_SIZE*sizeof(long))) {
528 ret = -EIO;
529 break;
530 }
531 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
532 __put_user(getreg(child, i), datap);
533 datap++;
534 }
535 ret = 0;
536 break;
537 }
538
539 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
540 unsigned long tmp;
541 if (!access_ok(VERIFY_READ, datap, FRAME_SIZE*sizeof(long))) {
542 ret = -EIO;
543 break;
544 }
545 for ( i = 0; i < FRAME_SIZE*sizeof(long); i += sizeof(long) ) {
546 __get_user(tmp, datap);
547 putreg(child, i, tmp);
548 datap++;
549 }
550 ret = 0;
551 break;
552 }
553
554 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
555 if (!access_ok(VERIFY_WRITE, datap,
556 sizeof(struct user_i387_struct))) {
557 ret = -EIO;
558 break;
559 }
560 ret = 0;
561 if (!tsk_used_math(child))
562 init_fpu(child);
563 get_fpregs((struct user_i387_struct __user *)data, child);
564 break;
565 }
566
567 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
568 if (!access_ok(VERIFY_READ, datap,
569 sizeof(struct user_i387_struct))) {
570 ret = -EIO;
571 break;
572 }
573 set_stopped_child_used_math(child);
574 set_fpregs(child, (struct user_i387_struct __user *)data);
575 ret = 0;
576 break;
577 }
578
579 case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
580 if (!access_ok(VERIFY_WRITE, datap,
581 sizeof(struct user_fxsr_struct))) {
582 ret = -EIO;
583 break;
584 }
585 if (!tsk_used_math(child))
586 init_fpu(child);
587 ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
588 break;
589 }
590
591 case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */
592 if (!access_ok(VERIFY_READ, datap,
593 sizeof(struct user_fxsr_struct))) {
594 ret = -EIO;
595 break;
596 }
597 set_stopped_child_used_math(child);
598 ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
599 break;
600 }
601
602 case PTRACE_GET_THREAD_AREA:
603 ret = ptrace_get_thread_area(child, addr,
604 (struct user_desc __user *) data);
605 break;
606
607 case PTRACE_SET_THREAD_AREA:
608 ret = ptrace_set_thread_area(child, addr,
609 (struct user_desc __user *) data);
610 break;
611
612 default:
613 ret = ptrace_request(child, request, addr, data);
614 break;
615 }
481bed45 616 out_tsk:
1da177e4
LT
617 return ret;
618}
619
620void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
621{
622 struct siginfo info;
623
624 tsk->thread.trap_no = 1;
625 tsk->thread.error_code = error_code;
626
627 memset(&info, 0, sizeof(info));
628 info.si_signo = SIGTRAP;
629 info.si_code = TRAP_BRKPT;
630
631 /* User-mode eip? */
fa1e1bdf 632 info.si_addr = user_mode_vm(regs) ? (void __user *) regs->eip : NULL;
1da177e4
LT
633
634 /* Send us the fakey SIGTRAP */
635 force_sig_info(SIGTRAP, &info, tsk);
636}
637
638/* notification of system call entry/exit
639 * - triggered by current->work.syscall_trace
640 */
641__attribute__((regparm(3)))
ed75e8d5 642int do_syscall_trace(struct pt_regs *regs, int entryexit)
1da177e4 643{
4c7fc722
AA
644 int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
645 /*
646 * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
647 * interception
648 */
1b38f006 649 int is_singlestep = !is_sysemu && test_thread_flag(TIF_SINGLESTEP);
4c7fc722 650 int ret = 0;
1b38f006 651
1da177e4 652 /* do the secure computing check first */
4c7fc722
AA
653 if (!entryexit)
654 secure_computing(regs->orig_eax);
1da177e4 655
ab1c23c2
BS
656 if (unlikely(current->audit_context)) {
657 if (entryexit)
5411be59 658 audit_syscall_exit(AUDITSC_RESULT(regs->eax),
4c7fc722 659 regs->eax);
ab1c23c2
BS
660 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
661 * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
662 * not used, entry.S will call us only on syscall exit, not
663 * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
664 * calling send_sigtrap() on syscall entry.
665 *
666 * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
667 * is_singlestep is false, despite his name, so we will still do
668 * the correct thing.
669 */
670 else if (is_singlestep)
671 goto out;
672 }
1da177e4
LT
673
674 if (!(current->ptrace & PT_PTRACED))
2fd6f58b 675 goto out;
1da177e4 676
1b38f006
BS
677 /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
678 * and then is resumed with SYSEMU_SINGLESTEP, it will come in
679 * here. We have to check this and return */
680 if (is_sysemu && entryexit)
681 return 0;
ed75e8d5 682
1da177e4 683 /* Fake a debug trap */
c8c86cec 684 if (is_singlestep)
1da177e4
LT
685 send_sigtrap(current, regs, 0);
686
c8c86cec 687 if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu)
2fd6f58b 688 goto out;
1da177e4
LT
689
690 /* the 0x80 provides a way for the tracing parent to distinguish
691 between a syscall stop and SIGTRAP delivery */
ed75e8d5 692 /* Note that the debugger could change the result of test_thread_flag!*/
4c7fc722 693 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) ? 0x80:0));
1da177e4
LT
694
695 /*
696 * this isn't the same as continuing with a signal, but it will do
697 * for normal use. strace only continues with a signal if the
698 * stopping signal is not SIGTRAP. -brl
699 */
700 if (current->exit_code) {
701 send_sig(current->exit_code, current, 1);
702 current->exit_code = 0;
703 }
ed75e8d5 704 ret = is_sysemu;
4c7fc722 705out:
2fd6f58b 706 if (unlikely(current->audit_context) && !entryexit)
5411be59 707 audit_syscall_entry(AUDIT_ARCH_I386, regs->orig_eax,
2fd6f58b 708 regs->ebx, regs->ecx, regs->edx, regs->esi);
c8c86cec
BS
709 if (ret == 0)
710 return 0;
711
1b38f006 712 regs->orig_eax = -1; /* force skip of syscall restarting */
c8c86cec 713 if (unlikely(current->audit_context))
5411be59 714 audit_syscall_exit(AUDITSC_RESULT(regs->eax), regs->eax);
c8c86cec 715 return 1;
1da177e4 716}
This page took 0.415851 seconds and 5 git commands to generate.