hw-breakpoints: Rewrite the hw-breakpoints layer on top of perf events
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / kernel / ptrace.c
blobe79610d95971fe333305f469aae83492bf65a6e1
1 /* By Ross Biro 1/23/92 */
2 /*
3 * Pentium III FXSR, SSE support
4 * Gareth Hughes <gareth@valinux.com>, May 2000
6 * BTS tracing
7 * Markus Metzger <markus.t.metzger@intel.com>, Dec 2007
8 */
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/errno.h>
15 #include <linux/ptrace.h>
16 #include <linux/regset.h>
17 #include <linux/tracehook.h>
18 #include <linux/user.h>
19 #include <linux/elf.h>
20 #include <linux/security.h>
21 #include <linux/audit.h>
22 #include <linux/seccomp.h>
23 #include <linux/signal.h>
24 #include <linux/workqueue.h>
25 #include <linux/perf_event.h>
26 #include <linux/hw_breakpoint.h>
28 #include <asm/uaccess.h>
29 #include <asm/pgtable.h>
30 #include <asm/system.h>
31 #include <asm/processor.h>
32 #include <asm/i387.h>
33 #include <asm/debugreg.h>
34 #include <asm/ldt.h>
35 #include <asm/desc.h>
36 #include <asm/prctl.h>
37 #include <asm/proto.h>
38 #include <asm/ds.h>
39 #include <asm/hw_breakpoint.h>
41 #include "tls.h"
43 #define CREATE_TRACE_POINTS
44 #include <trace/events/syscalls.h>
46 enum x86_regset {
47 REGSET_GENERAL,
48 REGSET_FP,
49 REGSET_XFP,
50 REGSET_IOPERM64 = REGSET_XFP,
51 REGSET_TLS,
52 REGSET_IOPERM32,
56 * does not yet catch signals sent when the child dies.
57 * in exit.c or in signal.c.
61 * Determines which flags the user has access to [1 = access, 0 = no access].
63 #define FLAG_MASK_32 ((unsigned long) \
64 (X86_EFLAGS_CF | X86_EFLAGS_PF | \
65 X86_EFLAGS_AF | X86_EFLAGS_ZF | \
66 X86_EFLAGS_SF | X86_EFLAGS_TF | \
67 X86_EFLAGS_DF | X86_EFLAGS_OF | \
68 X86_EFLAGS_RF | X86_EFLAGS_AC))
71 * Determines whether a value may be installed in a segment register.
73 static inline bool invalid_selector(u16 value)
75 return unlikely(value != 0 && (value & SEGMENT_RPL_MASK) != USER_RPL);
78 #ifdef CONFIG_X86_32
80 #define FLAG_MASK FLAG_MASK_32
82 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long regno)
84 BUILD_BUG_ON(offsetof(struct pt_regs, bx) != 0);
85 return &regs->bx + (regno >> 2);
88 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
91 * Returning the value truncates it to 16 bits.
93 unsigned int retval;
94 if (offset != offsetof(struct user_regs_struct, gs))
95 retval = *pt_regs_access(task_pt_regs(task), offset);
96 else {
97 if (task == current)
98 retval = get_user_gs(task_pt_regs(task));
99 else
100 retval = task_user_gs(task);
102 return retval;
105 static int set_segment_reg(struct task_struct *task,
106 unsigned long offset, u16 value)
109 * The value argument was already truncated to 16 bits.
111 if (invalid_selector(value))
112 return -EIO;
115 * For %cs and %ss we cannot permit a null selector.
116 * We can permit a bogus selector as long as it has USER_RPL.
117 * Null selectors are fine for other segment registers, but
118 * we will never get back to user mode with invalid %cs or %ss
119 * and will take the trap in iret instead. Much code relies
120 * on user_mode() to distinguish a user trap frame (which can
121 * safely use invalid selectors) from a kernel trap frame.
123 switch (offset) {
124 case offsetof(struct user_regs_struct, cs):
125 case offsetof(struct user_regs_struct, ss):
126 if (unlikely(value == 0))
127 return -EIO;
129 default:
130 *pt_regs_access(task_pt_regs(task), offset) = value;
131 break;
133 case offsetof(struct user_regs_struct, gs):
134 if (task == current)
135 set_user_gs(task_pt_regs(task), value);
136 else
137 task_user_gs(task) = value;
140 return 0;
143 #else /* CONFIG_X86_64 */
145 #define FLAG_MASK (FLAG_MASK_32 | X86_EFLAGS_NT)
147 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long offset)
149 BUILD_BUG_ON(offsetof(struct pt_regs, r15) != 0);
150 return &regs->r15 + (offset / sizeof(regs->r15));
153 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
156 * Returning the value truncates it to 16 bits.
158 unsigned int seg;
160 switch (offset) {
161 case offsetof(struct user_regs_struct, fs):
162 if (task == current) {
163 /* Older gas can't assemble movq %?s,%r?? */
164 asm("movl %%fs,%0" : "=r" (seg));
165 return seg;
167 return task->thread.fsindex;
168 case offsetof(struct user_regs_struct, gs):
169 if (task == current) {
170 asm("movl %%gs,%0" : "=r" (seg));
171 return seg;
173 return task->thread.gsindex;
174 case offsetof(struct user_regs_struct, ds):
175 if (task == current) {
176 asm("movl %%ds,%0" : "=r" (seg));
177 return seg;
179 return task->thread.ds;
180 case offsetof(struct user_regs_struct, es):
181 if (task == current) {
182 asm("movl %%es,%0" : "=r" (seg));
183 return seg;
185 return task->thread.es;
187 case offsetof(struct user_regs_struct, cs):
188 case offsetof(struct user_regs_struct, ss):
189 break;
191 return *pt_regs_access(task_pt_regs(task), offset);
194 static int set_segment_reg(struct task_struct *task,
195 unsigned long offset, u16 value)
198 * The value argument was already truncated to 16 bits.
200 if (invalid_selector(value))
201 return -EIO;
203 switch (offset) {
204 case offsetof(struct user_regs_struct,fs):
206 * If this is setting fs as for normal 64-bit use but
207 * setting fs_base has implicitly changed it, leave it.
209 if ((value == FS_TLS_SEL && task->thread.fsindex == 0 &&
210 task->thread.fs != 0) ||
211 (value == 0 && task->thread.fsindex == FS_TLS_SEL &&
212 task->thread.fs == 0))
213 break;
214 task->thread.fsindex = value;
215 if (task == current)
216 loadsegment(fs, task->thread.fsindex);
217 break;
218 case offsetof(struct user_regs_struct,gs):
220 * If this is setting gs as for normal 64-bit use but
221 * setting gs_base has implicitly changed it, leave it.
223 if ((value == GS_TLS_SEL && task->thread.gsindex == 0 &&
224 task->thread.gs != 0) ||
225 (value == 0 && task->thread.gsindex == GS_TLS_SEL &&
226 task->thread.gs == 0))
227 break;
228 task->thread.gsindex = value;
229 if (task == current)
230 load_gs_index(task->thread.gsindex);
231 break;
232 case offsetof(struct user_regs_struct,ds):
233 task->thread.ds = value;
234 if (task == current)
235 loadsegment(ds, task->thread.ds);
236 break;
237 case offsetof(struct user_regs_struct,es):
238 task->thread.es = value;
239 if (task == current)
240 loadsegment(es, task->thread.es);
241 break;
244 * Can't actually change these in 64-bit mode.
246 case offsetof(struct user_regs_struct,cs):
247 if (unlikely(value == 0))
248 return -EIO;
249 #ifdef CONFIG_IA32_EMULATION
250 if (test_tsk_thread_flag(task, TIF_IA32))
251 task_pt_regs(task)->cs = value;
252 #endif
253 break;
254 case offsetof(struct user_regs_struct,ss):
255 if (unlikely(value == 0))
256 return -EIO;
257 #ifdef CONFIG_IA32_EMULATION
258 if (test_tsk_thread_flag(task, TIF_IA32))
259 task_pt_regs(task)->ss = value;
260 #endif
261 break;
264 return 0;
267 #endif /* CONFIG_X86_32 */
269 static unsigned long get_flags(struct task_struct *task)
271 unsigned long retval = task_pt_regs(task)->flags;
274 * If the debugger set TF, hide it from the readout.
276 if (test_tsk_thread_flag(task, TIF_FORCED_TF))
277 retval &= ~X86_EFLAGS_TF;
279 return retval;
282 static int set_flags(struct task_struct *task, unsigned long value)
284 struct pt_regs *regs = task_pt_regs(task);
287 * If the user value contains TF, mark that
288 * it was not "us" (the debugger) that set it.
289 * If not, make sure it stays set if we had.
291 if (value & X86_EFLAGS_TF)
292 clear_tsk_thread_flag(task, TIF_FORCED_TF);
293 else if (test_tsk_thread_flag(task, TIF_FORCED_TF))
294 value |= X86_EFLAGS_TF;
296 regs->flags = (regs->flags & ~FLAG_MASK) | (value & FLAG_MASK);
298 return 0;
301 static int putreg(struct task_struct *child,
302 unsigned long offset, unsigned long value)
304 switch (offset) {
305 case offsetof(struct user_regs_struct, cs):
306 case offsetof(struct user_regs_struct, ds):
307 case offsetof(struct user_regs_struct, es):
308 case offsetof(struct user_regs_struct, fs):
309 case offsetof(struct user_regs_struct, gs):
310 case offsetof(struct user_regs_struct, ss):
311 return set_segment_reg(child, offset, value);
313 case offsetof(struct user_regs_struct, flags):
314 return set_flags(child, value);
316 #ifdef CONFIG_X86_64
317 case offsetof(struct user_regs_struct,fs_base):
318 if (value >= TASK_SIZE_OF(child))
319 return -EIO;
321 * When changing the segment base, use do_arch_prctl
322 * to set either thread.fs or thread.fsindex and the
323 * corresponding GDT slot.
325 if (child->thread.fs != value)
326 return do_arch_prctl(child, ARCH_SET_FS, value);
327 return 0;
328 case offsetof(struct user_regs_struct,gs_base):
330 * Exactly the same here as the %fs handling above.
332 if (value >= TASK_SIZE_OF(child))
333 return -EIO;
334 if (child->thread.gs != value)
335 return do_arch_prctl(child, ARCH_SET_GS, value);
336 return 0;
337 #endif
340 *pt_regs_access(task_pt_regs(child), offset) = value;
341 return 0;
344 static unsigned long getreg(struct task_struct *task, unsigned long offset)
346 switch (offset) {
347 case offsetof(struct user_regs_struct, cs):
348 case offsetof(struct user_regs_struct, ds):
349 case offsetof(struct user_regs_struct, es):
350 case offsetof(struct user_regs_struct, fs):
351 case offsetof(struct user_regs_struct, gs):
352 case offsetof(struct user_regs_struct, ss):
353 return get_segment_reg(task, offset);
355 case offsetof(struct user_regs_struct, flags):
356 return get_flags(task);
358 #ifdef CONFIG_X86_64
359 case offsetof(struct user_regs_struct, fs_base): {
361 * do_arch_prctl may have used a GDT slot instead of
362 * the MSR. To userland, it appears the same either
363 * way, except the %fs segment selector might not be 0.
365 unsigned int seg = task->thread.fsindex;
366 if (task->thread.fs != 0)
367 return task->thread.fs;
368 if (task == current)
369 asm("movl %%fs,%0" : "=r" (seg));
370 if (seg != FS_TLS_SEL)
371 return 0;
372 return get_desc_base(&task->thread.tls_array[FS_TLS]);
374 case offsetof(struct user_regs_struct, gs_base): {
376 * Exactly the same here as the %fs handling above.
378 unsigned int seg = task->thread.gsindex;
379 if (task->thread.gs != 0)
380 return task->thread.gs;
381 if (task == current)
382 asm("movl %%gs,%0" : "=r" (seg));
383 if (seg != GS_TLS_SEL)
384 return 0;
385 return get_desc_base(&task->thread.tls_array[GS_TLS]);
387 #endif
390 return *pt_regs_access(task_pt_regs(task), offset);
393 static int genregs_get(struct task_struct *target,
394 const struct user_regset *regset,
395 unsigned int pos, unsigned int count,
396 void *kbuf, void __user *ubuf)
398 if (kbuf) {
399 unsigned long *k = kbuf;
400 while (count > 0) {
401 *k++ = getreg(target, pos);
402 count -= sizeof(*k);
403 pos += sizeof(*k);
405 } else {
406 unsigned long __user *u = ubuf;
407 while (count > 0) {
408 if (__put_user(getreg(target, pos), u++))
409 return -EFAULT;
410 count -= sizeof(*u);
411 pos += sizeof(*u);
415 return 0;
418 static int genregs_set(struct task_struct *target,
419 const struct user_regset *regset,
420 unsigned int pos, unsigned int count,
421 const void *kbuf, const void __user *ubuf)
423 int ret = 0;
424 if (kbuf) {
425 const unsigned long *k = kbuf;
426 while (count > 0 && !ret) {
427 ret = putreg(target, pos, *k++);
428 count -= sizeof(*k);
429 pos += sizeof(*k);
431 } else {
432 const unsigned long __user *u = ubuf;
433 while (count > 0 && !ret) {
434 unsigned long word;
435 ret = __get_user(word, u++);
436 if (ret)
437 break;
438 ret = putreg(target, pos, word);
439 count -= sizeof(*u);
440 pos += sizeof(*u);
443 return ret;
446 static void ptrace_triggered(struct perf_event *bp, void *data)
448 int i;
449 struct thread_struct *thread = &(current->thread);
452 * Store in the virtual DR6 register the fact that the breakpoint
453 * was hit so the thread's debugger will see it.
455 for (i = 0; i < HBP_NUM; i++) {
456 if (thread->ptrace_bps[i] == bp)
457 break;
460 thread->debugreg6 |= (DR_TRAP0 << i);
464 * Walk through every ptrace breakpoints for this thread and
465 * build the dr7 value on top of their attributes.
468 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
470 int i;
471 int dr7 = 0;
472 struct arch_hw_breakpoint *info;
474 for (i = 0; i < HBP_NUM; i++) {
475 if (bp[i] && !bp[i]->attr.disabled) {
476 info = counter_arch_bp(bp[i]);
477 dr7 |= encode_dr7(i, info->len, info->type);
481 return dr7;
485 * Handle ptrace writes to debug register 7.
487 static int ptrace_write_dr7(struct task_struct *tsk, unsigned long data)
489 struct thread_struct *thread = &(tsk->thread);
490 unsigned long old_dr7;
491 int i, orig_ret = 0, rc = 0;
492 int enabled, second_pass = 0;
493 unsigned len, type;
494 int gen_len, gen_type;
495 struct perf_event *bp;
497 data &= ~DR_CONTROL_RESERVED;
498 old_dr7 = ptrace_get_dr7(thread->ptrace_bps);
499 restore:
501 * Loop through all the hardware breakpoints, making the
502 * appropriate changes to each.
504 for (i = 0; i < HBP_NUM; i++) {
505 enabled = decode_dr7(data, i, &len, &type);
506 bp = thread->ptrace_bps[i];
508 if (!enabled) {
509 if (bp) {
511 * Don't unregister the breakpoints right-away,
512 * unless all register_user_hw_breakpoint()
513 * requests have succeeded. This prevents
514 * any window of opportunity for debug
515 * register grabbing by other users.
517 if (!second_pass)
518 continue;
519 thread->ptrace_bps[i] = NULL;
520 unregister_hw_breakpoint(bp);
522 continue;
526 * We shoud have at least an inactive breakpoint at this
527 * slot. It means the user is writing dr7 without having
528 * written the address register first
530 if (!bp) {
531 rc = -EINVAL;
532 break;
535 rc = arch_bp_generic_fields(len, type, &gen_len, &gen_type);
536 if (rc)
537 break;
540 * This is a temporary thing as bp is unregistered/registered
541 * to simulate modification
543 bp = modify_user_hw_breakpoint(bp, bp->attr.bp_addr, gen_len,
544 gen_type, bp->callback,
545 tsk, true);
546 thread->ptrace_bps[i] = NULL;
548 if (!bp) { /* incorrect bp, or we have a bug in bp API */
549 rc = -EINVAL;
550 break;
552 if (IS_ERR(bp)) {
553 rc = PTR_ERR(bp);
554 bp = NULL;
555 break;
557 thread->ptrace_bps[i] = bp;
560 * Make a second pass to free the remaining unused breakpoints
561 * or to restore the original breakpoints if an error occurred.
563 if (!second_pass) {
564 second_pass = 1;
565 if (rc < 0) {
566 orig_ret = rc;
567 data = old_dr7;
569 goto restore;
571 return ((orig_ret < 0) ? orig_ret : rc);
575 * Handle PTRACE_PEEKUSR calls for the debug register area.
577 static unsigned long ptrace_get_debugreg(struct task_struct *tsk, int n)
579 struct thread_struct *thread = &(tsk->thread);
580 unsigned long val = 0;
582 if (n < HBP_NUM) {
583 struct perf_event *bp;
584 bp = thread->ptrace_bps[n];
585 if (!bp)
586 return 0;
587 val = bp->hw.info.address;
588 } else if (n == 6) {
589 val = thread->debugreg6;
590 } else if (n == 7) {
591 val = ptrace_get_dr7(thread->ptrace_bps);
593 return val;
596 static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr,
597 unsigned long addr)
599 struct perf_event *bp;
600 struct thread_struct *t = &tsk->thread;
602 if (!t->ptrace_bps[nr]) {
604 * Put stub len and type to register (reserve) an inactive but
605 * correct bp
607 bp = register_user_hw_breakpoint(addr, HW_BREAKPOINT_LEN_1,
608 HW_BREAKPOINT_W,
609 ptrace_triggered, tsk,
610 false);
611 } else {
612 bp = t->ptrace_bps[nr];
613 t->ptrace_bps[nr] = NULL;
614 bp = modify_user_hw_breakpoint(bp, addr, bp->attr.bp_len,
615 bp->attr.bp_type,
616 bp->callback,
617 tsk,
618 bp->attr.disabled);
621 if (!bp)
622 return -EIO;
624 * CHECKME: the previous code returned -EIO if the addr wasn't a
625 * valid task virtual addr. The new one will return -EINVAL in this
626 * case.
627 * -EINVAL may be what we want for in-kernel breakpoints users, but
628 * -EIO looks better for ptrace, since we refuse a register writing
629 * for the user. And anyway this is the previous behaviour.
631 if (IS_ERR(bp))
632 return PTR_ERR(bp);
634 t->ptrace_bps[nr] = bp;
636 return 0;
640 * Handle PTRACE_POKEUSR calls for the debug register area.
642 int ptrace_set_debugreg(struct task_struct *tsk, int n, unsigned long val)
644 struct thread_struct *thread = &(tsk->thread);
645 int rc = 0;
647 /* There are no DR4 or DR5 registers */
648 if (n == 4 || n == 5)
649 return -EIO;
651 if (n == 6) {
652 thread->debugreg6 = val;
653 goto ret_path;
655 if (n < HBP_NUM) {
656 rc = ptrace_set_breakpoint_addr(tsk, n, val);
657 if (rc)
658 return rc;
660 /* All that's left is DR7 */
661 if (n == 7)
662 rc = ptrace_write_dr7(tsk, val);
664 ret_path:
665 return rc;
669 * These access the current or another (stopped) task's io permission
670 * bitmap for debugging or core dump.
672 static int ioperm_active(struct task_struct *target,
673 const struct user_regset *regset)
675 return target->thread.io_bitmap_max / regset->size;
678 static int ioperm_get(struct task_struct *target,
679 const struct user_regset *regset,
680 unsigned int pos, unsigned int count,
681 void *kbuf, void __user *ubuf)
683 if (!target->thread.io_bitmap_ptr)
684 return -ENXIO;
686 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
687 target->thread.io_bitmap_ptr,
688 0, IO_BITMAP_BYTES);
691 #ifdef CONFIG_X86_PTRACE_BTS
693 * A branch trace store context.
695 * Contexts may only be installed by ptrace_bts_config() and only for
696 * ptraced tasks.
698 * Contexts are destroyed when the tracee is detached from the tracer.
699 * The actual destruction work requires interrupts enabled, so the
700 * work is deferred and will be scheduled during __ptrace_unlink().
702 * Contexts hold an additional task_struct reference on the traced
703 * task, as well as a reference on the tracer's mm.
705 * Ptrace already holds a task_struct for the duration of ptrace operations,
706 * but since destruction is deferred, it may be executed after both
707 * tracer and tracee exited.
709 struct bts_context {
710 /* The branch trace handle. */
711 struct bts_tracer *tracer;
713 /* The buffer used to store the branch trace and its size. */
714 void *buffer;
715 unsigned int size;
717 /* The mm that paid for the above buffer. */
718 struct mm_struct *mm;
720 /* The task this context belongs to. */
721 struct task_struct *task;
723 /* The signal to send on a bts buffer overflow. */
724 unsigned int bts_ovfl_signal;
726 /* The work struct to destroy a context. */
727 struct work_struct work;
730 static int alloc_bts_buffer(struct bts_context *context, unsigned int size)
732 void *buffer = NULL;
733 int err = -ENOMEM;
735 err = account_locked_memory(current->mm, current->signal->rlim, size);
736 if (err < 0)
737 return err;
739 buffer = kzalloc(size, GFP_KERNEL);
740 if (!buffer)
741 goto out_refund;
743 context->buffer = buffer;
744 context->size = size;
745 context->mm = get_task_mm(current);
747 return 0;
749 out_refund:
750 refund_locked_memory(current->mm, size);
751 return err;
754 static inline void free_bts_buffer(struct bts_context *context)
756 if (!context->buffer)
757 return;
759 kfree(context->buffer);
760 context->buffer = NULL;
762 refund_locked_memory(context->mm, context->size);
763 context->size = 0;
765 mmput(context->mm);
766 context->mm = NULL;
769 static void free_bts_context_work(struct work_struct *w)
771 struct bts_context *context;
773 context = container_of(w, struct bts_context, work);
775 ds_release_bts(context->tracer);
776 put_task_struct(context->task);
777 free_bts_buffer(context);
778 kfree(context);
781 static inline void free_bts_context(struct bts_context *context)
783 INIT_WORK(&context->work, free_bts_context_work);
784 schedule_work(&context->work);
787 static inline struct bts_context *alloc_bts_context(struct task_struct *task)
789 struct bts_context *context = kzalloc(sizeof(*context), GFP_KERNEL);
790 if (context) {
791 context->task = task;
792 task->bts = context;
794 get_task_struct(task);
797 return context;
800 static int ptrace_bts_read_record(struct task_struct *child, size_t index,
801 struct bts_struct __user *out)
803 struct bts_context *context;
804 const struct bts_trace *trace;
805 struct bts_struct bts;
806 const unsigned char *at;
807 int error;
809 context = child->bts;
810 if (!context)
811 return -ESRCH;
813 trace = ds_read_bts(context->tracer);
814 if (!trace)
815 return -ESRCH;
817 at = trace->ds.top - ((index + 1) * trace->ds.size);
818 if ((void *)at < trace->ds.begin)
819 at += (trace->ds.n * trace->ds.size);
821 if (!trace->read)
822 return -EOPNOTSUPP;
824 error = trace->read(context->tracer, at, &bts);
825 if (error < 0)
826 return error;
828 if (copy_to_user(out, &bts, sizeof(bts)))
829 return -EFAULT;
831 return sizeof(bts);
834 static int ptrace_bts_drain(struct task_struct *child,
835 long size,
836 struct bts_struct __user *out)
838 struct bts_context *context;
839 const struct bts_trace *trace;
840 const unsigned char *at;
841 int error, drained = 0;
843 context = child->bts;
844 if (!context)
845 return -ESRCH;
847 trace = ds_read_bts(context->tracer);
848 if (!trace)
849 return -ESRCH;
851 if (!trace->read)
852 return -EOPNOTSUPP;
854 if (size < (trace->ds.top - trace->ds.begin))
855 return -EIO;
857 for (at = trace->ds.begin; (void *)at < trace->ds.top;
858 out++, drained++, at += trace->ds.size) {
859 struct bts_struct bts;
861 error = trace->read(context->tracer, at, &bts);
862 if (error < 0)
863 return error;
865 if (copy_to_user(out, &bts, sizeof(bts)))
866 return -EFAULT;
869 memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
871 error = ds_reset_bts(context->tracer);
872 if (error < 0)
873 return error;
875 return drained;
878 static int ptrace_bts_config(struct task_struct *child,
879 long cfg_size,
880 const struct ptrace_bts_config __user *ucfg)
882 struct bts_context *context;
883 struct ptrace_bts_config cfg;
884 unsigned int flags = 0;
886 if (cfg_size < sizeof(cfg))
887 return -EIO;
889 if (copy_from_user(&cfg, ucfg, sizeof(cfg)))
890 return -EFAULT;
892 context = child->bts;
893 if (!context)
894 context = alloc_bts_context(child);
895 if (!context)
896 return -ENOMEM;
898 if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
899 if (!cfg.signal)
900 return -EINVAL;
902 return -EOPNOTSUPP;
903 context->bts_ovfl_signal = cfg.signal;
906 ds_release_bts(context->tracer);
907 context->tracer = NULL;
909 if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) {
910 int err;
912 free_bts_buffer(context);
913 if (!cfg.size)
914 return 0;
916 err = alloc_bts_buffer(context, cfg.size);
917 if (err < 0)
918 return err;
921 if (cfg.flags & PTRACE_BTS_O_TRACE)
922 flags |= BTS_USER;
924 if (cfg.flags & PTRACE_BTS_O_SCHED)
925 flags |= BTS_TIMESTAMPS;
927 context->tracer =
928 ds_request_bts_task(child, context->buffer, context->size,
929 NULL, (size_t)-1, flags);
930 if (unlikely(IS_ERR(context->tracer))) {
931 int error = PTR_ERR(context->tracer);
933 free_bts_buffer(context);
934 context->tracer = NULL;
935 return error;
938 return sizeof(cfg);
941 static int ptrace_bts_status(struct task_struct *child,
942 long cfg_size,
943 struct ptrace_bts_config __user *ucfg)
945 struct bts_context *context;
946 const struct bts_trace *trace;
947 struct ptrace_bts_config cfg;
949 context = child->bts;
950 if (!context)
951 return -ESRCH;
953 if (cfg_size < sizeof(cfg))
954 return -EIO;
956 trace = ds_read_bts(context->tracer);
957 if (!trace)
958 return -ESRCH;
960 memset(&cfg, 0, sizeof(cfg));
961 cfg.size = trace->ds.end - trace->ds.begin;
962 cfg.signal = context->bts_ovfl_signal;
963 cfg.bts_size = sizeof(struct bts_struct);
965 if (cfg.signal)
966 cfg.flags |= PTRACE_BTS_O_SIGNAL;
968 if (trace->ds.flags & BTS_USER)
969 cfg.flags |= PTRACE_BTS_O_TRACE;
971 if (trace->ds.flags & BTS_TIMESTAMPS)
972 cfg.flags |= PTRACE_BTS_O_SCHED;
974 if (copy_to_user(ucfg, &cfg, sizeof(cfg)))
975 return -EFAULT;
977 return sizeof(cfg);
980 static int ptrace_bts_clear(struct task_struct *child)
982 struct bts_context *context;
983 const struct bts_trace *trace;
985 context = child->bts;
986 if (!context)
987 return -ESRCH;
989 trace = ds_read_bts(context->tracer);
990 if (!trace)
991 return -ESRCH;
993 memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
995 return ds_reset_bts(context->tracer);
998 static int ptrace_bts_size(struct task_struct *child)
1000 struct bts_context *context;
1001 const struct bts_trace *trace;
1003 context = child->bts;
1004 if (!context)
1005 return -ESRCH;
1007 trace = ds_read_bts(context->tracer);
1008 if (!trace)
1009 return -ESRCH;
1011 return (trace->ds.top - trace->ds.begin) / trace->ds.size;
1015 * Called from __ptrace_unlink() after the child has been moved back
1016 * to its original parent.
1018 void ptrace_bts_untrace(struct task_struct *child)
1020 if (unlikely(child->bts)) {
1021 free_bts_context(child->bts);
1022 child->bts = NULL;
1025 #endif /* CONFIG_X86_PTRACE_BTS */
1028 * Called by kernel/ptrace.c when detaching..
1030 * Make sure the single step bit is not set.
1032 void ptrace_disable(struct task_struct *child)
1034 user_disable_single_step(child);
1035 #ifdef TIF_SYSCALL_EMU
1036 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
1037 #endif
1040 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1041 static const struct user_regset_view user_x86_32_view; /* Initialized below. */
1042 #endif
1044 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
1046 int ret;
1047 unsigned long __user *datap = (unsigned long __user *)data;
1049 switch (request) {
1050 /* read the word at location addr in the USER area. */
1051 case PTRACE_PEEKUSR: {
1052 unsigned long tmp;
1054 ret = -EIO;
1055 if ((addr & (sizeof(data) - 1)) || addr < 0 ||
1056 addr >= sizeof(struct user))
1057 break;
1059 tmp = 0; /* Default return condition */
1060 if (addr < sizeof(struct user_regs_struct))
1061 tmp = getreg(child, addr);
1062 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1063 addr <= offsetof(struct user, u_debugreg[7])) {
1064 addr -= offsetof(struct user, u_debugreg[0]);
1065 tmp = ptrace_get_debugreg(child, addr / sizeof(data));
1067 ret = put_user(tmp, datap);
1068 break;
1071 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
1072 ret = -EIO;
1073 if ((addr & (sizeof(data) - 1)) || addr < 0 ||
1074 addr >= sizeof(struct user))
1075 break;
1077 if (addr < sizeof(struct user_regs_struct))
1078 ret = putreg(child, addr, data);
1079 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1080 addr <= offsetof(struct user, u_debugreg[7])) {
1081 addr -= offsetof(struct user, u_debugreg[0]);
1082 ret = ptrace_set_debugreg(child,
1083 addr / sizeof(data), data);
1085 break;
1087 case PTRACE_GETREGS: /* Get all gp regs from the child. */
1088 return copy_regset_to_user(child,
1089 task_user_regset_view(current),
1090 REGSET_GENERAL,
1091 0, sizeof(struct user_regs_struct),
1092 datap);
1094 case PTRACE_SETREGS: /* Set all gp regs in the child. */
1095 return copy_regset_from_user(child,
1096 task_user_regset_view(current),
1097 REGSET_GENERAL,
1098 0, sizeof(struct user_regs_struct),
1099 datap);
1101 case PTRACE_GETFPREGS: /* Get the child FPU state. */
1102 return copy_regset_to_user(child,
1103 task_user_regset_view(current),
1104 REGSET_FP,
1105 0, sizeof(struct user_i387_struct),
1106 datap);
1108 case PTRACE_SETFPREGS: /* Set the child FPU state. */
1109 return copy_regset_from_user(child,
1110 task_user_regset_view(current),
1111 REGSET_FP,
1112 0, sizeof(struct user_i387_struct),
1113 datap);
1115 #ifdef CONFIG_X86_32
1116 case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
1117 return copy_regset_to_user(child, &user_x86_32_view,
1118 REGSET_XFP,
1119 0, sizeof(struct user_fxsr_struct),
1120 datap) ? -EIO : 0;
1122 case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
1123 return copy_regset_from_user(child, &user_x86_32_view,
1124 REGSET_XFP,
1125 0, sizeof(struct user_fxsr_struct),
1126 datap) ? -EIO : 0;
1127 #endif
1129 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1130 case PTRACE_GET_THREAD_AREA:
1131 if (addr < 0)
1132 return -EIO;
1133 ret = do_get_thread_area(child, addr,
1134 (struct user_desc __user *) data);
1135 break;
1137 case PTRACE_SET_THREAD_AREA:
1138 if (addr < 0)
1139 return -EIO;
1140 ret = do_set_thread_area(child, addr,
1141 (struct user_desc __user *) data, 0);
1142 break;
1143 #endif
1145 #ifdef CONFIG_X86_64
1146 /* normal 64bit interface to access TLS data.
1147 Works just like arch_prctl, except that the arguments
1148 are reversed. */
1149 case PTRACE_ARCH_PRCTL:
1150 ret = do_arch_prctl(child, data, addr);
1151 break;
1152 #endif
1155 * These bits need more cooking - not enabled yet:
1157 #ifdef CONFIG_X86_PTRACE_BTS
1158 case PTRACE_BTS_CONFIG:
1159 ret = ptrace_bts_config
1160 (child, data, (struct ptrace_bts_config __user *)addr);
1161 break;
1163 case PTRACE_BTS_STATUS:
1164 ret = ptrace_bts_status
1165 (child, data, (struct ptrace_bts_config __user *)addr);
1166 break;
1168 case PTRACE_BTS_SIZE:
1169 ret = ptrace_bts_size(child);
1170 break;
1172 case PTRACE_BTS_GET:
1173 ret = ptrace_bts_read_record
1174 (child, data, (struct bts_struct __user *) addr);
1175 break;
1177 case PTRACE_BTS_CLEAR:
1178 ret = ptrace_bts_clear(child);
1179 break;
1181 case PTRACE_BTS_DRAIN:
1182 ret = ptrace_bts_drain
1183 (child, data, (struct bts_struct __user *) addr);
1184 break;
1185 #endif /* CONFIG_X86_PTRACE_BTS */
1187 default:
1188 ret = ptrace_request(child, request, addr, data);
1189 break;
1192 return ret;
1195 #ifdef CONFIG_IA32_EMULATION
1197 #include <linux/compat.h>
1198 #include <linux/syscalls.h>
1199 #include <asm/ia32.h>
1200 #include <asm/user32.h>
1202 #define R32(l,q) \
1203 case offsetof(struct user32, regs.l): \
1204 regs->q = value; break
1206 #define SEG32(rs) \
1207 case offsetof(struct user32, regs.rs): \
1208 return set_segment_reg(child, \
1209 offsetof(struct user_regs_struct, rs), \
1210 value); \
1211 break
1213 static int putreg32(struct task_struct *child, unsigned regno, u32 value)
1215 struct pt_regs *regs = task_pt_regs(child);
1217 switch (regno) {
1219 SEG32(cs);
1220 SEG32(ds);
1221 SEG32(es);
1222 SEG32(fs);
1223 SEG32(gs);
1224 SEG32(ss);
1226 R32(ebx, bx);
1227 R32(ecx, cx);
1228 R32(edx, dx);
1229 R32(edi, di);
1230 R32(esi, si);
1231 R32(ebp, bp);
1232 R32(eax, ax);
1233 R32(eip, ip);
1234 R32(esp, sp);
1236 case offsetof(struct user32, regs.orig_eax):
1238 * A 32-bit debugger setting orig_eax means to restore
1239 * the state of the task restarting a 32-bit syscall.
1240 * Make sure we interpret the -ERESTART* codes correctly
1241 * in case the task is not actually still sitting at the
1242 * exit from a 32-bit syscall with TS_COMPAT still set.
1244 regs->orig_ax = value;
1245 if (syscall_get_nr(child, regs) >= 0)
1246 task_thread_info(child)->status |= TS_COMPAT;
1247 break;
1249 case offsetof(struct user32, regs.eflags):
1250 return set_flags(child, value);
1252 case offsetof(struct user32, u_debugreg[0]) ...
1253 offsetof(struct user32, u_debugreg[7]):
1254 regno -= offsetof(struct user32, u_debugreg[0]);
1255 return ptrace_set_debugreg(child, regno / 4, value);
1257 default:
1258 if (regno > sizeof(struct user32) || (regno & 3))
1259 return -EIO;
1262 * Other dummy fields in the virtual user structure
1263 * are ignored
1265 break;
1267 return 0;
1270 #undef R32
1271 #undef SEG32
1273 #define R32(l,q) \
1274 case offsetof(struct user32, regs.l): \
1275 *val = regs->q; break
1277 #define SEG32(rs) \
1278 case offsetof(struct user32, regs.rs): \
1279 *val = get_segment_reg(child, \
1280 offsetof(struct user_regs_struct, rs)); \
1281 break
1283 static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
1285 struct pt_regs *regs = task_pt_regs(child);
1287 switch (regno) {
1289 SEG32(ds);
1290 SEG32(es);
1291 SEG32(fs);
1292 SEG32(gs);
1294 R32(cs, cs);
1295 R32(ss, ss);
1296 R32(ebx, bx);
1297 R32(ecx, cx);
1298 R32(edx, dx);
1299 R32(edi, di);
1300 R32(esi, si);
1301 R32(ebp, bp);
1302 R32(eax, ax);
1303 R32(orig_eax, orig_ax);
1304 R32(eip, ip);
1305 R32(esp, sp);
1307 case offsetof(struct user32, regs.eflags):
1308 *val = get_flags(child);
1309 break;
1311 case offsetof(struct user32, u_debugreg[0]) ...
1312 offsetof(struct user32, u_debugreg[7]):
1313 regno -= offsetof(struct user32, u_debugreg[0]);
1314 *val = ptrace_get_debugreg(child, regno / 4);
1315 break;
1317 default:
1318 if (regno > sizeof(struct user32) || (regno & 3))
1319 return -EIO;
1322 * Other dummy fields in the virtual user structure
1323 * are ignored
1325 *val = 0;
1326 break;
1328 return 0;
1331 #undef R32
1332 #undef SEG32
1334 static int genregs32_get(struct task_struct *target,
1335 const struct user_regset *regset,
1336 unsigned int pos, unsigned int count,
1337 void *kbuf, void __user *ubuf)
1339 if (kbuf) {
1340 compat_ulong_t *k = kbuf;
1341 while (count > 0) {
1342 getreg32(target, pos, k++);
1343 count -= sizeof(*k);
1344 pos += sizeof(*k);
1346 } else {
1347 compat_ulong_t __user *u = ubuf;
1348 while (count > 0) {
1349 compat_ulong_t word;
1350 getreg32(target, pos, &word);
1351 if (__put_user(word, u++))
1352 return -EFAULT;
1353 count -= sizeof(*u);
1354 pos += sizeof(*u);
1358 return 0;
1361 static int genregs32_set(struct task_struct *target,
1362 const struct user_regset *regset,
1363 unsigned int pos, unsigned int count,
1364 const void *kbuf, const void __user *ubuf)
1366 int ret = 0;
1367 if (kbuf) {
1368 const compat_ulong_t *k = kbuf;
1369 while (count > 0 && !ret) {
1370 ret = putreg32(target, pos, *k++);
1371 count -= sizeof(*k);
1372 pos += sizeof(*k);
1374 } else {
1375 const compat_ulong_t __user *u = ubuf;
1376 while (count > 0 && !ret) {
1377 compat_ulong_t word;
1378 ret = __get_user(word, u++);
1379 if (ret)
1380 break;
1381 ret = putreg32(target, pos, word);
1382 count -= sizeof(*u);
1383 pos += sizeof(*u);
1386 return ret;
1389 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1390 compat_ulong_t caddr, compat_ulong_t cdata)
1392 unsigned long addr = caddr;
1393 unsigned long data = cdata;
1394 void __user *datap = compat_ptr(data);
1395 int ret;
1396 __u32 val;
1398 switch (request) {
1399 case PTRACE_PEEKUSR:
1400 ret = getreg32(child, addr, &val);
1401 if (ret == 0)
1402 ret = put_user(val, (__u32 __user *)datap);
1403 break;
1405 case PTRACE_POKEUSR:
1406 ret = putreg32(child, addr, data);
1407 break;
1409 case PTRACE_GETREGS: /* Get all gp regs from the child. */
1410 return copy_regset_to_user(child, &user_x86_32_view,
1411 REGSET_GENERAL,
1412 0, sizeof(struct user_regs_struct32),
1413 datap);
1415 case PTRACE_SETREGS: /* Set all gp regs in the child. */
1416 return copy_regset_from_user(child, &user_x86_32_view,
1417 REGSET_GENERAL, 0,
1418 sizeof(struct user_regs_struct32),
1419 datap);
1421 case PTRACE_GETFPREGS: /* Get the child FPU state. */
1422 return copy_regset_to_user(child, &user_x86_32_view,
1423 REGSET_FP, 0,
1424 sizeof(struct user_i387_ia32_struct),
1425 datap);
1427 case PTRACE_SETFPREGS: /* Set the child FPU state. */
1428 return copy_regset_from_user(
1429 child, &user_x86_32_view, REGSET_FP,
1430 0, sizeof(struct user_i387_ia32_struct), datap);
1432 case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
1433 return copy_regset_to_user(child, &user_x86_32_view,
1434 REGSET_XFP, 0,
1435 sizeof(struct user32_fxsr_struct),
1436 datap);
1438 case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
1439 return copy_regset_from_user(child, &user_x86_32_view,
1440 REGSET_XFP, 0,
1441 sizeof(struct user32_fxsr_struct),
1442 datap);
1444 case PTRACE_GET_THREAD_AREA:
1445 case PTRACE_SET_THREAD_AREA:
1446 #ifdef CONFIG_X86_PTRACE_BTS
1447 case PTRACE_BTS_CONFIG:
1448 case PTRACE_BTS_STATUS:
1449 case PTRACE_BTS_SIZE:
1450 case PTRACE_BTS_GET:
1451 case PTRACE_BTS_CLEAR:
1452 case PTRACE_BTS_DRAIN:
1453 #endif /* CONFIG_X86_PTRACE_BTS */
1454 return arch_ptrace(child, request, addr, data);
1456 default:
1457 return compat_ptrace_request(child, request, addr, data);
1460 return ret;
1463 #endif /* CONFIG_IA32_EMULATION */
1465 #ifdef CONFIG_X86_64
1467 static const struct user_regset x86_64_regsets[] = {
1468 [REGSET_GENERAL] = {
1469 .core_note_type = NT_PRSTATUS,
1470 .n = sizeof(struct user_regs_struct) / sizeof(long),
1471 .size = sizeof(long), .align = sizeof(long),
1472 .get = genregs_get, .set = genregs_set
1474 [REGSET_FP] = {
1475 .core_note_type = NT_PRFPREG,
1476 .n = sizeof(struct user_i387_struct) / sizeof(long),
1477 .size = sizeof(long), .align = sizeof(long),
1478 .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set
1480 [REGSET_IOPERM64] = {
1481 .core_note_type = NT_386_IOPERM,
1482 .n = IO_BITMAP_LONGS,
1483 .size = sizeof(long), .align = sizeof(long),
1484 .active = ioperm_active, .get = ioperm_get
1488 static const struct user_regset_view user_x86_64_view = {
1489 .name = "x86_64", .e_machine = EM_X86_64,
1490 .regsets = x86_64_regsets, .n = ARRAY_SIZE(x86_64_regsets)
1493 #else /* CONFIG_X86_32 */
1495 #define user_regs_struct32 user_regs_struct
1496 #define genregs32_get genregs_get
1497 #define genregs32_set genregs_set
1499 #define user_i387_ia32_struct user_i387_struct
1500 #define user32_fxsr_struct user_fxsr_struct
1502 #endif /* CONFIG_X86_64 */
1504 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1505 static const struct user_regset x86_32_regsets[] = {
1506 [REGSET_GENERAL] = {
1507 .core_note_type = NT_PRSTATUS,
1508 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
1509 .size = sizeof(u32), .align = sizeof(u32),
1510 .get = genregs32_get, .set = genregs32_set
1512 [REGSET_FP] = {
1513 .core_note_type = NT_PRFPREG,
1514 .n = sizeof(struct user_i387_ia32_struct) / sizeof(u32),
1515 .size = sizeof(u32), .align = sizeof(u32),
1516 .active = fpregs_active, .get = fpregs_get, .set = fpregs_set
1518 [REGSET_XFP] = {
1519 .core_note_type = NT_PRXFPREG,
1520 .n = sizeof(struct user32_fxsr_struct) / sizeof(u32),
1521 .size = sizeof(u32), .align = sizeof(u32),
1522 .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set
1524 [REGSET_TLS] = {
1525 .core_note_type = NT_386_TLS,
1526 .n = GDT_ENTRY_TLS_ENTRIES, .bias = GDT_ENTRY_TLS_MIN,
1527 .size = sizeof(struct user_desc),
1528 .align = sizeof(struct user_desc),
1529 .active = regset_tls_active,
1530 .get = regset_tls_get, .set = regset_tls_set
1532 [REGSET_IOPERM32] = {
1533 .core_note_type = NT_386_IOPERM,
1534 .n = IO_BITMAP_BYTES / sizeof(u32),
1535 .size = sizeof(u32), .align = sizeof(u32),
1536 .active = ioperm_active, .get = ioperm_get
1540 static const struct user_regset_view user_x86_32_view = {
1541 .name = "i386", .e_machine = EM_386,
1542 .regsets = x86_32_regsets, .n = ARRAY_SIZE(x86_32_regsets)
1544 #endif
1546 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1548 #ifdef CONFIG_IA32_EMULATION
1549 if (test_tsk_thread_flag(task, TIF_IA32))
1550 #endif
1551 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1552 return &user_x86_32_view;
1553 #endif
1554 #ifdef CONFIG_X86_64
1555 return &user_x86_64_view;
1556 #endif
1559 void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
1560 int error_code, int si_code)
1562 struct siginfo info;
1564 tsk->thread.trap_no = 1;
1565 tsk->thread.error_code = error_code;
1567 memset(&info, 0, sizeof(info));
1568 info.si_signo = SIGTRAP;
1569 info.si_code = si_code;
1571 /* User-mode ip? */
1572 info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
1574 /* Send us the fake SIGTRAP */
1575 force_sig_info(SIGTRAP, &info, tsk);
1579 #ifdef CONFIG_X86_32
1580 # define IS_IA32 1
1581 #elif defined CONFIG_IA32_EMULATION
1582 # define IS_IA32 is_compat_task()
1583 #else
1584 # define IS_IA32 0
1585 #endif
1588 * We must return the syscall number to actually look up in the table.
1589 * This can be -1L to skip running any syscall at all.
1591 asmregparm long syscall_trace_enter(struct pt_regs *regs)
1593 long ret = 0;
1596 * If we stepped into a sysenter/syscall insn, it trapped in
1597 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
1598 * If user-mode had set TF itself, then it's still clear from
1599 * do_debug() and we need to set it again to restore the user
1600 * state. If we entered on the slow path, TF was already set.
1602 if (test_thread_flag(TIF_SINGLESTEP))
1603 regs->flags |= X86_EFLAGS_TF;
1605 /* do the secure computing check first */
1606 secure_computing(regs->orig_ax);
1608 if (unlikely(test_thread_flag(TIF_SYSCALL_EMU)))
1609 ret = -1L;
1611 if ((ret || test_thread_flag(TIF_SYSCALL_TRACE)) &&
1612 tracehook_report_syscall_entry(regs))
1613 ret = -1L;
1615 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1616 trace_sys_enter(regs, regs->orig_ax);
1618 if (unlikely(current->audit_context)) {
1619 if (IS_IA32)
1620 audit_syscall_entry(AUDIT_ARCH_I386,
1621 regs->orig_ax,
1622 regs->bx, regs->cx,
1623 regs->dx, regs->si);
1624 #ifdef CONFIG_X86_64
1625 else
1626 audit_syscall_entry(AUDIT_ARCH_X86_64,
1627 regs->orig_ax,
1628 regs->di, regs->si,
1629 regs->dx, regs->r10);
1630 #endif
1633 return ret ?: regs->orig_ax;
1636 asmregparm void syscall_trace_leave(struct pt_regs *regs)
1638 if (unlikely(current->audit_context))
1639 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
1641 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
1642 trace_sys_exit(regs, regs->ax);
1644 if (test_thread_flag(TIF_SYSCALL_TRACE))
1645 tracehook_report_syscall_exit(regs, 0);
1648 * If TIF_SYSCALL_EMU is set, we only get here because of
1649 * TIF_SINGLESTEP (i.e. this is PTRACE_SYSEMU_SINGLESTEP).
1650 * We already reported this syscall instruction in
1651 * syscall_trace_enter(), so don't do any more now.
1653 if (unlikely(test_thread_flag(TIF_SYSCALL_EMU)))
1654 return;
1657 * If we are single-stepping, synthesize a trap to follow the
1658 * system call instruction.
1660 if (test_thread_flag(TIF_SINGLESTEP) &&
1661 tracehook_consider_fatal_signal(current, SIGTRAP))
1662 send_sigtrap(current, regs, 0, TRAP_BRKPT);