airport: remove useless return in a function returning void
[linux/fpc-iii.git] / arch / x86 / kernel / ptrace.c
blob0a6d8c12e10dc7742c2e33dd29475874cb9f2b50
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>
25 #include <asm/uaccess.h>
26 #include <asm/pgtable.h>
27 #include <asm/system.h>
28 #include <asm/processor.h>
29 #include <asm/i387.h>
30 #include <asm/debugreg.h>
31 #include <asm/ldt.h>
32 #include <asm/desc.h>
33 #include <asm/prctl.h>
34 #include <asm/proto.h>
35 #include <asm/ds.h>
37 #include "tls.h"
39 enum x86_regset {
40 REGSET_GENERAL,
41 REGSET_FP,
42 REGSET_XFP,
43 REGSET_IOPERM64 = REGSET_XFP,
44 REGSET_TLS,
45 REGSET_IOPERM32,
49 * does not yet catch signals sent when the child dies.
50 * in exit.c or in signal.c.
54 * Determines which flags the user has access to [1 = access, 0 = no access].
56 #define FLAG_MASK_32 ((unsigned long) \
57 (X86_EFLAGS_CF | X86_EFLAGS_PF | \
58 X86_EFLAGS_AF | X86_EFLAGS_ZF | \
59 X86_EFLAGS_SF | X86_EFLAGS_TF | \
60 X86_EFLAGS_DF | X86_EFLAGS_OF | \
61 X86_EFLAGS_RF | X86_EFLAGS_AC))
64 * Determines whether a value may be installed in a segment register.
66 static inline bool invalid_selector(u16 value)
68 return unlikely(value != 0 && (value & SEGMENT_RPL_MASK) != USER_RPL);
71 #ifdef CONFIG_X86_32
73 #define FLAG_MASK FLAG_MASK_32
75 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long regno)
77 BUILD_BUG_ON(offsetof(struct pt_regs, bx) != 0);
78 regno >>= 2;
79 if (regno > FS)
80 --regno;
81 return &regs->bx + regno;
84 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
87 * Returning the value truncates it to 16 bits.
89 unsigned int retval;
90 if (offset != offsetof(struct user_regs_struct, gs))
91 retval = *pt_regs_access(task_pt_regs(task), offset);
92 else {
93 retval = task->thread.gs;
94 if (task == current)
95 savesegment(gs, retval);
97 return retval;
100 static int set_segment_reg(struct task_struct *task,
101 unsigned long offset, u16 value)
104 * The value argument was already truncated to 16 bits.
106 if (invalid_selector(value))
107 return -EIO;
110 * For %cs and %ss we cannot permit a null selector.
111 * We can permit a bogus selector as long as it has USER_RPL.
112 * Null selectors are fine for other segment registers, but
113 * we will never get back to user mode with invalid %cs or %ss
114 * and will take the trap in iret instead. Much code relies
115 * on user_mode() to distinguish a user trap frame (which can
116 * safely use invalid selectors) from a kernel trap frame.
118 switch (offset) {
119 case offsetof(struct user_regs_struct, cs):
120 case offsetof(struct user_regs_struct, ss):
121 if (unlikely(value == 0))
122 return -EIO;
124 default:
125 *pt_regs_access(task_pt_regs(task), offset) = value;
126 break;
128 case offsetof(struct user_regs_struct, gs):
129 task->thread.gs = value;
130 if (task == current)
132 * The user-mode %gs is not affected by
133 * kernel entry, so we must update the CPU.
135 loadsegment(gs, value);
138 return 0;
141 static unsigned long debugreg_addr_limit(struct task_struct *task)
143 return TASK_SIZE - 3;
146 #else /* CONFIG_X86_64 */
148 #define FLAG_MASK (FLAG_MASK_32 | X86_EFLAGS_NT)
150 static unsigned long *pt_regs_access(struct pt_regs *regs, unsigned long offset)
152 BUILD_BUG_ON(offsetof(struct pt_regs, r15) != 0);
153 return &regs->r15 + (offset / sizeof(regs->r15));
156 static u16 get_segment_reg(struct task_struct *task, unsigned long offset)
159 * Returning the value truncates it to 16 bits.
161 unsigned int seg;
163 switch (offset) {
164 case offsetof(struct user_regs_struct, fs):
165 if (task == current) {
166 /* Older gas can't assemble movq %?s,%r?? */
167 asm("movl %%fs,%0" : "=r" (seg));
168 return seg;
170 return task->thread.fsindex;
171 case offsetof(struct user_regs_struct, gs):
172 if (task == current) {
173 asm("movl %%gs,%0" : "=r" (seg));
174 return seg;
176 return task->thread.gsindex;
177 case offsetof(struct user_regs_struct, ds):
178 if (task == current) {
179 asm("movl %%ds,%0" : "=r" (seg));
180 return seg;
182 return task->thread.ds;
183 case offsetof(struct user_regs_struct, es):
184 if (task == current) {
185 asm("movl %%es,%0" : "=r" (seg));
186 return seg;
188 return task->thread.es;
190 case offsetof(struct user_regs_struct, cs):
191 case offsetof(struct user_regs_struct, ss):
192 break;
194 return *pt_regs_access(task_pt_regs(task), offset);
197 static int set_segment_reg(struct task_struct *task,
198 unsigned long offset, u16 value)
201 * The value argument was already truncated to 16 bits.
203 if (invalid_selector(value))
204 return -EIO;
206 switch (offset) {
207 case offsetof(struct user_regs_struct,fs):
209 * If this is setting fs as for normal 64-bit use but
210 * setting fs_base has implicitly changed it, leave it.
212 if ((value == FS_TLS_SEL && task->thread.fsindex == 0 &&
213 task->thread.fs != 0) ||
214 (value == 0 && task->thread.fsindex == FS_TLS_SEL &&
215 task->thread.fs == 0))
216 break;
217 task->thread.fsindex = value;
218 if (task == current)
219 loadsegment(fs, task->thread.fsindex);
220 break;
221 case offsetof(struct user_regs_struct,gs):
223 * If this is setting gs as for normal 64-bit use but
224 * setting gs_base has implicitly changed it, leave it.
226 if ((value == GS_TLS_SEL && task->thread.gsindex == 0 &&
227 task->thread.gs != 0) ||
228 (value == 0 && task->thread.gsindex == GS_TLS_SEL &&
229 task->thread.gs == 0))
230 break;
231 task->thread.gsindex = value;
232 if (task == current)
233 load_gs_index(task->thread.gsindex);
234 break;
235 case offsetof(struct user_regs_struct,ds):
236 task->thread.ds = value;
237 if (task == current)
238 loadsegment(ds, task->thread.ds);
239 break;
240 case offsetof(struct user_regs_struct,es):
241 task->thread.es = value;
242 if (task == current)
243 loadsegment(es, task->thread.es);
244 break;
247 * Can't actually change these in 64-bit mode.
249 case offsetof(struct user_regs_struct,cs):
250 if (unlikely(value == 0))
251 return -EIO;
252 #ifdef CONFIG_IA32_EMULATION
253 if (test_tsk_thread_flag(task, TIF_IA32))
254 task_pt_regs(task)->cs = value;
255 #endif
256 break;
257 case offsetof(struct user_regs_struct,ss):
258 if (unlikely(value == 0))
259 return -EIO;
260 #ifdef CONFIG_IA32_EMULATION
261 if (test_tsk_thread_flag(task, TIF_IA32))
262 task_pt_regs(task)->ss = value;
263 #endif
264 break;
267 return 0;
270 static unsigned long debugreg_addr_limit(struct task_struct *task)
272 #ifdef CONFIG_IA32_EMULATION
273 if (test_tsk_thread_flag(task, TIF_IA32))
274 return IA32_PAGE_OFFSET - 3;
275 #endif
276 return TASK_SIZE64 - 7;
279 #endif /* CONFIG_X86_32 */
281 static unsigned long get_flags(struct task_struct *task)
283 unsigned long retval = task_pt_regs(task)->flags;
286 * If the debugger set TF, hide it from the readout.
288 if (test_tsk_thread_flag(task, TIF_FORCED_TF))
289 retval &= ~X86_EFLAGS_TF;
291 return retval;
294 static int set_flags(struct task_struct *task, unsigned long value)
296 struct pt_regs *regs = task_pt_regs(task);
299 * If the user value contains TF, mark that
300 * it was not "us" (the debugger) that set it.
301 * If not, make sure it stays set if we had.
303 if (value & X86_EFLAGS_TF)
304 clear_tsk_thread_flag(task, TIF_FORCED_TF);
305 else if (test_tsk_thread_flag(task, TIF_FORCED_TF))
306 value |= X86_EFLAGS_TF;
308 regs->flags = (regs->flags & ~FLAG_MASK) | (value & FLAG_MASK);
310 return 0;
313 static int putreg(struct task_struct *child,
314 unsigned long offset, unsigned long value)
316 switch (offset) {
317 case offsetof(struct user_regs_struct, cs):
318 case offsetof(struct user_regs_struct, ds):
319 case offsetof(struct user_regs_struct, es):
320 case offsetof(struct user_regs_struct, fs):
321 case offsetof(struct user_regs_struct, gs):
322 case offsetof(struct user_regs_struct, ss):
323 return set_segment_reg(child, offset, value);
325 case offsetof(struct user_regs_struct, flags):
326 return set_flags(child, value);
328 #ifdef CONFIG_X86_64
330 * Orig_ax is really just a flag with small positive and
331 * negative values, so make sure to always sign-extend it
332 * from 32 bits so that it works correctly regardless of
333 * whether we come from a 32-bit environment or not.
335 case offsetof(struct user_regs_struct, orig_ax):
336 value = (long) (s32) value;
337 break;
339 case offsetof(struct user_regs_struct,fs_base):
340 if (value >= TASK_SIZE_OF(child))
341 return -EIO;
343 * When changing the segment base, use do_arch_prctl
344 * to set either thread.fs or thread.fsindex and the
345 * corresponding GDT slot.
347 if (child->thread.fs != value)
348 return do_arch_prctl(child, ARCH_SET_FS, value);
349 return 0;
350 case offsetof(struct user_regs_struct,gs_base):
352 * Exactly the same here as the %fs handling above.
354 if (value >= TASK_SIZE_OF(child))
355 return -EIO;
356 if (child->thread.gs != value)
357 return do_arch_prctl(child, ARCH_SET_GS, value);
358 return 0;
359 #endif
362 *pt_regs_access(task_pt_regs(child), offset) = value;
363 return 0;
366 static unsigned long getreg(struct task_struct *task, unsigned long offset)
368 switch (offset) {
369 case offsetof(struct user_regs_struct, cs):
370 case offsetof(struct user_regs_struct, ds):
371 case offsetof(struct user_regs_struct, es):
372 case offsetof(struct user_regs_struct, fs):
373 case offsetof(struct user_regs_struct, gs):
374 case offsetof(struct user_regs_struct, ss):
375 return get_segment_reg(task, offset);
377 case offsetof(struct user_regs_struct, flags):
378 return get_flags(task);
380 #ifdef CONFIG_X86_64
381 case offsetof(struct user_regs_struct, fs_base): {
383 * do_arch_prctl may have used a GDT slot instead of
384 * the MSR. To userland, it appears the same either
385 * way, except the %fs segment selector might not be 0.
387 unsigned int seg = task->thread.fsindex;
388 if (task->thread.fs != 0)
389 return task->thread.fs;
390 if (task == current)
391 asm("movl %%fs,%0" : "=r" (seg));
392 if (seg != FS_TLS_SEL)
393 return 0;
394 return get_desc_base(&task->thread.tls_array[FS_TLS]);
396 case offsetof(struct user_regs_struct, gs_base): {
398 * Exactly the same here as the %fs handling above.
400 unsigned int seg = task->thread.gsindex;
401 if (task->thread.gs != 0)
402 return task->thread.gs;
403 if (task == current)
404 asm("movl %%gs,%0" : "=r" (seg));
405 if (seg != GS_TLS_SEL)
406 return 0;
407 return get_desc_base(&task->thread.tls_array[GS_TLS]);
409 #endif
412 return *pt_regs_access(task_pt_regs(task), offset);
415 static int genregs_get(struct task_struct *target,
416 const struct user_regset *regset,
417 unsigned int pos, unsigned int count,
418 void *kbuf, void __user *ubuf)
420 if (kbuf) {
421 unsigned long *k = kbuf;
422 while (count > 0) {
423 *k++ = getreg(target, pos);
424 count -= sizeof(*k);
425 pos += sizeof(*k);
427 } else {
428 unsigned long __user *u = ubuf;
429 while (count > 0) {
430 if (__put_user(getreg(target, pos), u++))
431 return -EFAULT;
432 count -= sizeof(*u);
433 pos += sizeof(*u);
437 return 0;
440 static int genregs_set(struct task_struct *target,
441 const struct user_regset *regset,
442 unsigned int pos, unsigned int count,
443 const void *kbuf, const void __user *ubuf)
445 int ret = 0;
446 if (kbuf) {
447 const unsigned long *k = kbuf;
448 while (count > 0 && !ret) {
449 ret = putreg(target, pos, *k++);
450 count -= sizeof(*k);
451 pos += sizeof(*k);
453 } else {
454 const unsigned long __user *u = ubuf;
455 while (count > 0 && !ret) {
456 unsigned long word;
457 ret = __get_user(word, u++);
458 if (ret)
459 break;
460 ret = putreg(target, pos, word);
461 count -= sizeof(*u);
462 pos += sizeof(*u);
465 return ret;
469 * This function is trivial and will be inlined by the compiler.
470 * Having it separates the implementation details of debug
471 * registers from the interface details of ptrace.
473 static unsigned long ptrace_get_debugreg(struct task_struct *child, int n)
475 switch (n) {
476 case 0: return child->thread.debugreg0;
477 case 1: return child->thread.debugreg1;
478 case 2: return child->thread.debugreg2;
479 case 3: return child->thread.debugreg3;
480 case 6: return child->thread.debugreg6;
481 case 7: return child->thread.debugreg7;
483 return 0;
486 static int ptrace_set_debugreg(struct task_struct *child,
487 int n, unsigned long data)
489 int i;
491 if (unlikely(n == 4 || n == 5))
492 return -EIO;
494 if (n < 4 && unlikely(data >= debugreg_addr_limit(child)))
495 return -EIO;
497 switch (n) {
498 case 0: child->thread.debugreg0 = data; break;
499 case 1: child->thread.debugreg1 = data; break;
500 case 2: child->thread.debugreg2 = data; break;
501 case 3: child->thread.debugreg3 = data; break;
503 case 6:
504 if ((data & ~0xffffffffUL) != 0)
505 return -EIO;
506 child->thread.debugreg6 = data;
507 break;
509 case 7:
511 * Sanity-check data. Take one half-byte at once with
512 * check = (val >> (16 + 4*i)) & 0xf. It contains the
513 * R/Wi and LENi bits; bits 0 and 1 are R/Wi, and bits
514 * 2 and 3 are LENi. Given a list of invalid values,
515 * we do mask |= 1 << invalid_value, so that
516 * (mask >> check) & 1 is a correct test for invalid
517 * values.
519 * R/Wi contains the type of the breakpoint /
520 * watchpoint, LENi contains the length of the watched
521 * data in the watchpoint case.
523 * The invalid values are:
524 * - LENi == 0x10 (undefined), so mask |= 0x0f00. [32-bit]
525 * - R/Wi == 0x10 (break on I/O reads or writes), so
526 * mask |= 0x4444.
527 * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
528 * 0x1110.
530 * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
532 * See the Intel Manual "System Programming Guide",
533 * 15.2.4
535 * Note that LENi == 0x10 is defined on x86_64 in long
536 * mode (i.e. even for 32-bit userspace software, but
537 * 64-bit kernel), so the x86_64 mask value is 0x5454.
538 * See the AMD manual no. 24593 (AMD64 System Programming)
540 #ifdef CONFIG_X86_32
541 #define DR7_MASK 0x5f54
542 #else
543 #define DR7_MASK 0x5554
544 #endif
545 data &= ~DR_CONTROL_RESERVED;
546 for (i = 0; i < 4; i++)
547 if ((DR7_MASK >> ((data >> (16 + 4*i)) & 0xf)) & 1)
548 return -EIO;
549 child->thread.debugreg7 = data;
550 if (data)
551 set_tsk_thread_flag(child, TIF_DEBUG);
552 else
553 clear_tsk_thread_flag(child, TIF_DEBUG);
554 break;
557 return 0;
561 * These access the current or another (stopped) task's io permission
562 * bitmap for debugging or core dump.
564 static int ioperm_active(struct task_struct *target,
565 const struct user_regset *regset)
567 return target->thread.io_bitmap_max / regset->size;
570 static int ioperm_get(struct task_struct *target,
571 const struct user_regset *regset,
572 unsigned int pos, unsigned int count,
573 void *kbuf, void __user *ubuf)
575 if (!target->thread.io_bitmap_ptr)
576 return -ENXIO;
578 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
579 target->thread.io_bitmap_ptr,
580 0, IO_BITMAP_BYTES);
583 #ifdef CONFIG_X86_PTRACE_BTS
585 * The configuration for a particular BTS hardware implementation.
587 struct bts_configuration {
588 /* the size of a BTS record in bytes; at most BTS_MAX_RECORD_SIZE */
589 unsigned char sizeof_bts;
590 /* the size of a field in the BTS record in bytes */
591 unsigned char sizeof_field;
592 /* a bitmask to enable/disable BTS in DEBUGCTL MSR */
593 unsigned long debugctl_mask;
595 static struct bts_configuration bts_cfg;
597 #define BTS_MAX_RECORD_SIZE (8 * 3)
601 * Branch Trace Store (BTS) uses the following format. Different
602 * architectures vary in the size of those fields.
603 * - source linear address
604 * - destination linear address
605 * - flags
607 * Later architectures use 64bit pointers throughout, whereas earlier
608 * architectures use 32bit pointers in 32bit mode.
610 * We compute the base address for the first 8 fields based on:
611 * - the field size stored in the DS configuration
612 * - the relative field position
614 * In order to store additional information in the BTS buffer, we use
615 * a special source address to indicate that the record requires
616 * special interpretation.
618 * Netburst indicated via a bit in the flags field whether the branch
619 * was predicted; this is ignored.
622 enum bts_field {
623 bts_from = 0,
624 bts_to,
625 bts_flags,
627 bts_escape = (unsigned long)-1,
628 bts_qual = bts_to,
629 bts_jiffies = bts_flags
632 static inline unsigned long bts_get(const char *base, enum bts_field field)
634 base += (bts_cfg.sizeof_field * field);
635 return *(unsigned long *)base;
638 static inline void bts_set(char *base, enum bts_field field, unsigned long val)
640 base += (bts_cfg.sizeof_field * field);;
641 (*(unsigned long *)base) = val;
645 * Translate a BTS record from the raw format into the bts_struct format
647 * out (out): bts_struct interpretation
648 * raw: raw BTS record
650 static void ptrace_bts_translate_record(struct bts_struct *out, const void *raw)
652 memset(out, 0, sizeof(*out));
653 if (bts_get(raw, bts_from) == bts_escape) {
654 out->qualifier = bts_get(raw, bts_qual);
655 out->variant.jiffies = bts_get(raw, bts_jiffies);
656 } else {
657 out->qualifier = BTS_BRANCH;
658 out->variant.lbr.from_ip = bts_get(raw, bts_from);
659 out->variant.lbr.to_ip = bts_get(raw, bts_to);
663 static int ptrace_bts_read_record(struct task_struct *child, size_t index,
664 struct bts_struct __user *out)
666 struct bts_struct ret;
667 const void *bts_record;
668 size_t bts_index, bts_end;
669 int error;
671 error = ds_get_bts_end(child, &bts_end);
672 if (error < 0)
673 return error;
675 if (bts_end <= index)
676 return -EINVAL;
678 error = ds_get_bts_index(child, &bts_index);
679 if (error < 0)
680 return error;
682 /* translate the ptrace bts index into the ds bts index */
683 bts_index += bts_end - (index + 1);
684 if (bts_end <= bts_index)
685 bts_index -= bts_end;
687 error = ds_access_bts(child, bts_index, &bts_record);
688 if (error < 0)
689 return error;
691 ptrace_bts_translate_record(&ret, bts_record);
693 if (copy_to_user(out, &ret, sizeof(ret)))
694 return -EFAULT;
696 return sizeof(ret);
699 static int ptrace_bts_drain(struct task_struct *child,
700 long size,
701 struct bts_struct __user *out)
703 struct bts_struct ret;
704 const unsigned char *raw;
705 size_t end, i;
706 int error;
708 error = ds_get_bts_index(child, &end);
709 if (error < 0)
710 return error;
712 if (size < (end * sizeof(struct bts_struct)))
713 return -EIO;
715 error = ds_access_bts(child, 0, (const void **)&raw);
716 if (error < 0)
717 return error;
719 for (i = 0; i < end; i++, out++, raw += bts_cfg.sizeof_bts) {
720 ptrace_bts_translate_record(&ret, raw);
722 if (copy_to_user(out, &ret, sizeof(ret)))
723 return -EFAULT;
726 error = ds_clear_bts(child);
727 if (error < 0)
728 return error;
730 return end;
733 static void ptrace_bts_ovfl(struct task_struct *child)
735 send_sig(child->thread.bts_ovfl_signal, child, 0);
738 static int ptrace_bts_config(struct task_struct *child,
739 long cfg_size,
740 const struct ptrace_bts_config __user *ucfg)
742 struct ptrace_bts_config cfg;
743 int error = 0;
745 error = -EOPNOTSUPP;
746 if (!bts_cfg.sizeof_bts)
747 goto errout;
749 error = -EIO;
750 if (cfg_size < sizeof(cfg))
751 goto errout;
753 error = -EFAULT;
754 if (copy_from_user(&cfg, ucfg, sizeof(cfg)))
755 goto errout;
757 error = -EINVAL;
758 if ((cfg.flags & PTRACE_BTS_O_SIGNAL) &&
759 !(cfg.flags & PTRACE_BTS_O_ALLOC))
760 goto errout;
762 if (cfg.flags & PTRACE_BTS_O_ALLOC) {
763 ds_ovfl_callback_t ovfl = NULL;
764 unsigned int sig = 0;
766 /* we ignore the error in case we were not tracing child */
767 (void)ds_release_bts(child);
769 if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
770 if (!cfg.signal)
771 goto errout;
773 sig = cfg.signal;
774 ovfl = ptrace_bts_ovfl;
777 error = ds_request_bts(child, /* base = */ NULL, cfg.size, ovfl);
778 if (error < 0)
779 goto errout;
781 child->thread.bts_ovfl_signal = sig;
784 error = -EINVAL;
785 if (!child->thread.ds_ctx && cfg.flags)
786 goto errout;
788 if (cfg.flags & PTRACE_BTS_O_TRACE)
789 child->thread.debugctlmsr |= bts_cfg.debugctl_mask;
790 else
791 child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
793 if (cfg.flags & PTRACE_BTS_O_SCHED)
794 set_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
795 else
796 clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
798 error = sizeof(cfg);
800 out:
801 if (child->thread.debugctlmsr)
802 set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
803 else
804 clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
806 return error;
808 errout:
809 child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
810 clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
811 goto out;
814 static int ptrace_bts_status(struct task_struct *child,
815 long cfg_size,
816 struct ptrace_bts_config __user *ucfg)
818 struct ptrace_bts_config cfg;
819 size_t end;
820 const void *base, *max;
821 int error;
823 if (cfg_size < sizeof(cfg))
824 return -EIO;
826 error = ds_get_bts_end(child, &end);
827 if (error < 0)
828 return error;
830 error = ds_access_bts(child, /* index = */ 0, &base);
831 if (error < 0)
832 return error;
834 error = ds_access_bts(child, /* index = */ end, &max);
835 if (error < 0)
836 return error;
838 memset(&cfg, 0, sizeof(cfg));
839 cfg.size = (max - base);
840 cfg.signal = child->thread.bts_ovfl_signal;
841 cfg.bts_size = sizeof(struct bts_struct);
843 if (cfg.signal)
844 cfg.flags |= PTRACE_BTS_O_SIGNAL;
846 if (test_tsk_thread_flag(child, TIF_DEBUGCTLMSR) &&
847 child->thread.debugctlmsr & bts_cfg.debugctl_mask)
848 cfg.flags |= PTRACE_BTS_O_TRACE;
850 if (test_tsk_thread_flag(child, TIF_BTS_TRACE_TS))
851 cfg.flags |= PTRACE_BTS_O_SCHED;
853 if (copy_to_user(ucfg, &cfg, sizeof(cfg)))
854 return -EFAULT;
856 return sizeof(cfg);
859 static int ptrace_bts_write_record(struct task_struct *child,
860 const struct bts_struct *in)
862 unsigned char bts_record[BTS_MAX_RECORD_SIZE];
864 BUG_ON(BTS_MAX_RECORD_SIZE < bts_cfg.sizeof_bts);
866 memset(bts_record, 0, bts_cfg.sizeof_bts);
867 switch (in->qualifier) {
868 case BTS_INVALID:
869 break;
871 case BTS_BRANCH:
872 bts_set(bts_record, bts_from, in->variant.lbr.from_ip);
873 bts_set(bts_record, bts_to, in->variant.lbr.to_ip);
874 break;
876 case BTS_TASK_ARRIVES:
877 case BTS_TASK_DEPARTS:
878 bts_set(bts_record, bts_from, bts_escape);
879 bts_set(bts_record, bts_qual, in->qualifier);
880 bts_set(bts_record, bts_jiffies, in->variant.jiffies);
881 break;
883 default:
884 return -EINVAL;
887 /* The writing task will be the switched-to task on a context
888 * switch. It needs to write into the switched-from task's BTS
889 * buffer. */
890 return ds_unchecked_write_bts(child, bts_record, bts_cfg.sizeof_bts);
893 void ptrace_bts_take_timestamp(struct task_struct *tsk,
894 enum bts_qualifier qualifier)
896 struct bts_struct rec = {
897 .qualifier = qualifier,
898 .variant.jiffies = jiffies_64
901 ptrace_bts_write_record(tsk, &rec);
904 static const struct bts_configuration bts_cfg_netburst = {
905 .sizeof_bts = sizeof(long) * 3,
906 .sizeof_field = sizeof(long),
907 .debugctl_mask = (1<<2)|(1<<3)|(1<<5)
910 static const struct bts_configuration bts_cfg_pentium_m = {
911 .sizeof_bts = sizeof(long) * 3,
912 .sizeof_field = sizeof(long),
913 .debugctl_mask = (1<<6)|(1<<7)
916 static const struct bts_configuration bts_cfg_core2 = {
917 .sizeof_bts = 8 * 3,
918 .sizeof_field = 8,
919 .debugctl_mask = (1<<6)|(1<<7)|(1<<9)
922 static inline void bts_configure(const struct bts_configuration *cfg)
924 bts_cfg = *cfg;
927 void __cpuinit ptrace_bts_init_intel(struct cpuinfo_x86 *c)
929 switch (c->x86) {
930 case 0x6:
931 switch (c->x86_model) {
932 case 0xD:
933 case 0xE: /* Pentium M */
934 bts_configure(&bts_cfg_pentium_m);
935 break;
936 case 0xF: /* Core2 */
937 case 0x1C: /* Atom */
938 bts_configure(&bts_cfg_core2);
939 break;
940 default:
941 /* sorry, don't know about them */
942 break;
944 break;
945 case 0xF:
946 switch (c->x86_model) {
947 case 0x0:
948 case 0x1:
949 case 0x2: /* Netburst */
950 bts_configure(&bts_cfg_netburst);
951 break;
952 default:
953 /* sorry, don't know about them */
954 break;
956 break;
957 default:
958 /* sorry, don't know about them */
959 break;
962 #endif /* CONFIG_X86_PTRACE_BTS */
965 * Called by kernel/ptrace.c when detaching..
967 * Make sure the single step bit is not set.
969 void ptrace_disable(struct task_struct *child)
971 user_disable_single_step(child);
972 #ifdef TIF_SYSCALL_EMU
973 clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
974 #endif
975 #ifdef CONFIG_X86_PTRACE_BTS
976 (void)ds_release_bts(child);
978 child->thread.debugctlmsr &= ~bts_cfg.debugctl_mask;
979 if (!child->thread.debugctlmsr)
980 clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
982 clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
983 #endif /* CONFIG_X86_PTRACE_BTS */
986 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
987 static const struct user_regset_view user_x86_32_view; /* Initialized below. */
988 #endif
990 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
992 int ret;
993 unsigned long __user *datap = (unsigned long __user *)data;
995 switch (request) {
996 /* read the word at location addr in the USER area. */
997 case PTRACE_PEEKUSR: {
998 unsigned long tmp;
1000 ret = -EIO;
1001 if ((addr & (sizeof(data) - 1)) || addr < 0 ||
1002 addr >= sizeof(struct user))
1003 break;
1005 tmp = 0; /* Default return condition */
1006 if (addr < sizeof(struct user_regs_struct))
1007 tmp = getreg(child, addr);
1008 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1009 addr <= offsetof(struct user, u_debugreg[7])) {
1010 addr -= offsetof(struct user, u_debugreg[0]);
1011 tmp = ptrace_get_debugreg(child, addr / sizeof(data));
1013 ret = put_user(tmp, datap);
1014 break;
1017 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
1018 ret = -EIO;
1019 if ((addr & (sizeof(data) - 1)) || addr < 0 ||
1020 addr >= sizeof(struct user))
1021 break;
1023 if (addr < sizeof(struct user_regs_struct))
1024 ret = putreg(child, addr, data);
1025 else if (addr >= offsetof(struct user, u_debugreg[0]) &&
1026 addr <= offsetof(struct user, u_debugreg[7])) {
1027 addr -= offsetof(struct user, u_debugreg[0]);
1028 ret = ptrace_set_debugreg(child,
1029 addr / sizeof(data), data);
1031 break;
1033 case PTRACE_GETREGS: /* Get all gp regs from the child. */
1034 return copy_regset_to_user(child,
1035 task_user_regset_view(current),
1036 REGSET_GENERAL,
1037 0, sizeof(struct user_regs_struct),
1038 datap);
1040 case PTRACE_SETREGS: /* Set all gp regs in the child. */
1041 return copy_regset_from_user(child,
1042 task_user_regset_view(current),
1043 REGSET_GENERAL,
1044 0, sizeof(struct user_regs_struct),
1045 datap);
1047 case PTRACE_GETFPREGS: /* Get the child FPU state. */
1048 return copy_regset_to_user(child,
1049 task_user_regset_view(current),
1050 REGSET_FP,
1051 0, sizeof(struct user_i387_struct),
1052 datap);
1054 case PTRACE_SETFPREGS: /* Set the child FPU state. */
1055 return copy_regset_from_user(child,
1056 task_user_regset_view(current),
1057 REGSET_FP,
1058 0, sizeof(struct user_i387_struct),
1059 datap);
1061 #ifdef CONFIG_X86_32
1062 case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
1063 return copy_regset_to_user(child, &user_x86_32_view,
1064 REGSET_XFP,
1065 0, sizeof(struct user_fxsr_struct),
1066 datap) ? -EIO : 0;
1068 case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
1069 return copy_regset_from_user(child, &user_x86_32_view,
1070 REGSET_XFP,
1071 0, sizeof(struct user_fxsr_struct),
1072 datap) ? -EIO : 0;
1073 #endif
1075 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1076 case PTRACE_GET_THREAD_AREA:
1077 if (addr < 0)
1078 return -EIO;
1079 ret = do_get_thread_area(child, addr,
1080 (struct user_desc __user *) data);
1081 break;
1083 case PTRACE_SET_THREAD_AREA:
1084 if (addr < 0)
1085 return -EIO;
1086 ret = do_set_thread_area(child, addr,
1087 (struct user_desc __user *) data, 0);
1088 break;
1089 #endif
1091 #ifdef CONFIG_X86_64
1092 /* normal 64bit interface to access TLS data.
1093 Works just like arch_prctl, except that the arguments
1094 are reversed. */
1095 case PTRACE_ARCH_PRCTL:
1096 ret = do_arch_prctl(child, data, addr);
1097 break;
1098 #endif
1101 * These bits need more cooking - not enabled yet:
1103 #ifdef CONFIG_X86_PTRACE_BTS
1104 case PTRACE_BTS_CONFIG:
1105 ret = ptrace_bts_config
1106 (child, data, (struct ptrace_bts_config __user *)addr);
1107 break;
1109 case PTRACE_BTS_STATUS:
1110 ret = ptrace_bts_status
1111 (child, data, (struct ptrace_bts_config __user *)addr);
1112 break;
1114 case PTRACE_BTS_SIZE:
1115 ret = ds_get_bts_index(child, /* pos = */ NULL);
1116 break;
1118 case PTRACE_BTS_GET:
1119 ret = ptrace_bts_read_record
1120 (child, data, (struct bts_struct __user *) addr);
1121 break;
1123 case PTRACE_BTS_CLEAR:
1124 ret = ds_clear_bts(child);
1125 break;
1127 case PTRACE_BTS_DRAIN:
1128 ret = ptrace_bts_drain
1129 (child, data, (struct bts_struct __user *) addr);
1130 break;
1131 #endif /* CONFIG_X86_PTRACE_BTS */
1133 default:
1134 ret = ptrace_request(child, request, addr, data);
1135 break;
1138 return ret;
1141 #ifdef CONFIG_IA32_EMULATION
1143 #include <linux/compat.h>
1144 #include <linux/syscalls.h>
1145 #include <asm/ia32.h>
1146 #include <asm/user32.h>
1148 #define R32(l,q) \
1149 case offsetof(struct user32, regs.l): \
1150 regs->q = value; break
1152 #define SEG32(rs) \
1153 case offsetof(struct user32, regs.rs): \
1154 return set_segment_reg(child, \
1155 offsetof(struct user_regs_struct, rs), \
1156 value); \
1157 break
1159 static int putreg32(struct task_struct *child, unsigned regno, u32 value)
1161 struct pt_regs *regs = task_pt_regs(child);
1163 switch (regno) {
1165 SEG32(cs);
1166 SEG32(ds);
1167 SEG32(es);
1168 SEG32(fs);
1169 SEG32(gs);
1170 SEG32(ss);
1172 R32(ebx, bx);
1173 R32(ecx, cx);
1174 R32(edx, dx);
1175 R32(edi, di);
1176 R32(esi, si);
1177 R32(ebp, bp);
1178 R32(eax, ax);
1179 R32(eip, ip);
1180 R32(esp, sp);
1182 case offsetof(struct user32, regs.orig_eax):
1184 * Sign-extend the value so that orig_eax = -1
1185 * causes (long)orig_ax < 0 tests to fire correctly.
1187 regs->orig_ax = (long) (s32) value;
1188 break;
1190 case offsetof(struct user32, regs.eflags):
1191 return set_flags(child, value);
1193 case offsetof(struct user32, u_debugreg[0]) ...
1194 offsetof(struct user32, u_debugreg[7]):
1195 regno -= offsetof(struct user32, u_debugreg[0]);
1196 return ptrace_set_debugreg(child, regno / 4, value);
1198 default:
1199 if (regno > sizeof(struct user32) || (regno & 3))
1200 return -EIO;
1203 * Other dummy fields in the virtual user structure
1204 * are ignored
1206 break;
1208 return 0;
1211 #undef R32
1212 #undef SEG32
1214 #define R32(l,q) \
1215 case offsetof(struct user32, regs.l): \
1216 *val = regs->q; break
1218 #define SEG32(rs) \
1219 case offsetof(struct user32, regs.rs): \
1220 *val = get_segment_reg(child, \
1221 offsetof(struct user_regs_struct, rs)); \
1222 break
1224 static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
1226 struct pt_regs *regs = task_pt_regs(child);
1228 switch (regno) {
1230 SEG32(ds);
1231 SEG32(es);
1232 SEG32(fs);
1233 SEG32(gs);
1235 R32(cs, cs);
1236 R32(ss, ss);
1237 R32(ebx, bx);
1238 R32(ecx, cx);
1239 R32(edx, dx);
1240 R32(edi, di);
1241 R32(esi, si);
1242 R32(ebp, bp);
1243 R32(eax, ax);
1244 R32(orig_eax, orig_ax);
1245 R32(eip, ip);
1246 R32(esp, sp);
1248 case offsetof(struct user32, regs.eflags):
1249 *val = get_flags(child);
1250 break;
1252 case offsetof(struct user32, u_debugreg[0]) ...
1253 offsetof(struct user32, u_debugreg[7]):
1254 regno -= offsetof(struct user32, u_debugreg[0]);
1255 *val = ptrace_get_debugreg(child, regno / 4);
1256 break;
1258 default:
1259 if (regno > sizeof(struct user32) || (regno & 3))
1260 return -EIO;
1263 * Other dummy fields in the virtual user structure
1264 * are ignored
1266 *val = 0;
1267 break;
1269 return 0;
1272 #undef R32
1273 #undef SEG32
1275 static int genregs32_get(struct task_struct *target,
1276 const struct user_regset *regset,
1277 unsigned int pos, unsigned int count,
1278 void *kbuf, void __user *ubuf)
1280 if (kbuf) {
1281 compat_ulong_t *k = kbuf;
1282 while (count > 0) {
1283 getreg32(target, pos, k++);
1284 count -= sizeof(*k);
1285 pos += sizeof(*k);
1287 } else {
1288 compat_ulong_t __user *u = ubuf;
1289 while (count > 0) {
1290 compat_ulong_t word;
1291 getreg32(target, pos, &word);
1292 if (__put_user(word, u++))
1293 return -EFAULT;
1294 count -= sizeof(*u);
1295 pos += sizeof(*u);
1299 return 0;
1302 static int genregs32_set(struct task_struct *target,
1303 const struct user_regset *regset,
1304 unsigned int pos, unsigned int count,
1305 const void *kbuf, const void __user *ubuf)
1307 int ret = 0;
1308 if (kbuf) {
1309 const compat_ulong_t *k = kbuf;
1310 while (count > 0 && !ret) {
1311 ret = putreg32(target, pos, *k++);
1312 count -= sizeof(*k);
1313 pos += sizeof(*k);
1315 } else {
1316 const compat_ulong_t __user *u = ubuf;
1317 while (count > 0 && !ret) {
1318 compat_ulong_t word;
1319 ret = __get_user(word, u++);
1320 if (ret)
1321 break;
1322 ret = putreg32(target, pos, word);
1323 count -= sizeof(*u);
1324 pos += sizeof(*u);
1327 return ret;
1330 long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
1331 compat_ulong_t caddr, compat_ulong_t cdata)
1333 unsigned long addr = caddr;
1334 unsigned long data = cdata;
1335 void __user *datap = compat_ptr(data);
1336 int ret;
1337 __u32 val;
1339 switch (request) {
1340 case PTRACE_PEEKUSR:
1341 ret = getreg32(child, addr, &val);
1342 if (ret == 0)
1343 ret = put_user(val, (__u32 __user *)datap);
1344 break;
1346 case PTRACE_POKEUSR:
1347 ret = putreg32(child, addr, data);
1348 break;
1350 case PTRACE_GETREGS: /* Get all gp regs from the child. */
1351 return copy_regset_to_user(child, &user_x86_32_view,
1352 REGSET_GENERAL,
1353 0, sizeof(struct user_regs_struct32),
1354 datap);
1356 case PTRACE_SETREGS: /* Set all gp regs in the child. */
1357 return copy_regset_from_user(child, &user_x86_32_view,
1358 REGSET_GENERAL, 0,
1359 sizeof(struct user_regs_struct32),
1360 datap);
1362 case PTRACE_GETFPREGS: /* Get the child FPU state. */
1363 return copy_regset_to_user(child, &user_x86_32_view,
1364 REGSET_FP, 0,
1365 sizeof(struct user_i387_ia32_struct),
1366 datap);
1368 case PTRACE_SETFPREGS: /* Set the child FPU state. */
1369 return copy_regset_from_user(
1370 child, &user_x86_32_view, REGSET_FP,
1371 0, sizeof(struct user_i387_ia32_struct), datap);
1373 case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
1374 return copy_regset_to_user(child, &user_x86_32_view,
1375 REGSET_XFP, 0,
1376 sizeof(struct user32_fxsr_struct),
1377 datap);
1379 case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
1380 return copy_regset_from_user(child, &user_x86_32_view,
1381 REGSET_XFP, 0,
1382 sizeof(struct user32_fxsr_struct),
1383 datap);
1385 case PTRACE_GET_THREAD_AREA:
1386 case PTRACE_SET_THREAD_AREA:
1387 return arch_ptrace(child, request, addr, data);
1389 default:
1390 return compat_ptrace_request(child, request, addr, data);
1393 return ret;
1396 #endif /* CONFIG_IA32_EMULATION */
1398 #ifdef CONFIG_X86_64
1400 static const struct user_regset x86_64_regsets[] = {
1401 [REGSET_GENERAL] = {
1402 .core_note_type = NT_PRSTATUS,
1403 .n = sizeof(struct user_regs_struct) / sizeof(long),
1404 .size = sizeof(long), .align = sizeof(long),
1405 .get = genregs_get, .set = genregs_set
1407 [REGSET_FP] = {
1408 .core_note_type = NT_PRFPREG,
1409 .n = sizeof(struct user_i387_struct) / sizeof(long),
1410 .size = sizeof(long), .align = sizeof(long),
1411 .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set
1413 [REGSET_IOPERM64] = {
1414 .core_note_type = NT_386_IOPERM,
1415 .n = IO_BITMAP_LONGS,
1416 .size = sizeof(long), .align = sizeof(long),
1417 .active = ioperm_active, .get = ioperm_get
1421 static const struct user_regset_view user_x86_64_view = {
1422 .name = "x86_64", .e_machine = EM_X86_64,
1423 .regsets = x86_64_regsets, .n = ARRAY_SIZE(x86_64_regsets)
1426 #else /* CONFIG_X86_32 */
1428 #define user_regs_struct32 user_regs_struct
1429 #define genregs32_get genregs_get
1430 #define genregs32_set genregs_set
1432 #define user_i387_ia32_struct user_i387_struct
1433 #define user32_fxsr_struct user_fxsr_struct
1435 #endif /* CONFIG_X86_64 */
1437 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1438 static const struct user_regset x86_32_regsets[] = {
1439 [REGSET_GENERAL] = {
1440 .core_note_type = NT_PRSTATUS,
1441 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
1442 .size = sizeof(u32), .align = sizeof(u32),
1443 .get = genregs32_get, .set = genregs32_set
1445 [REGSET_FP] = {
1446 .core_note_type = NT_PRFPREG,
1447 .n = sizeof(struct user_i387_ia32_struct) / sizeof(u32),
1448 .size = sizeof(u32), .align = sizeof(u32),
1449 .active = fpregs_active, .get = fpregs_get, .set = fpregs_set
1451 [REGSET_XFP] = {
1452 .core_note_type = NT_PRXFPREG,
1453 .n = sizeof(struct user32_fxsr_struct) / sizeof(u32),
1454 .size = sizeof(u32), .align = sizeof(u32),
1455 .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set
1457 [REGSET_TLS] = {
1458 .core_note_type = NT_386_TLS,
1459 .n = GDT_ENTRY_TLS_ENTRIES, .bias = GDT_ENTRY_TLS_MIN,
1460 .size = sizeof(struct user_desc),
1461 .align = sizeof(struct user_desc),
1462 .active = regset_tls_active,
1463 .get = regset_tls_get, .set = regset_tls_set
1465 [REGSET_IOPERM32] = {
1466 .core_note_type = NT_386_IOPERM,
1467 .n = IO_BITMAP_BYTES / sizeof(u32),
1468 .size = sizeof(u32), .align = sizeof(u32),
1469 .active = ioperm_active, .get = ioperm_get
1473 static const struct user_regset_view user_x86_32_view = {
1474 .name = "i386", .e_machine = EM_386,
1475 .regsets = x86_32_regsets, .n = ARRAY_SIZE(x86_32_regsets)
1477 #endif
1479 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
1481 #ifdef CONFIG_IA32_EMULATION
1482 if (test_tsk_thread_flag(task, TIF_IA32))
1483 #endif
1484 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1485 return &user_x86_32_view;
1486 #endif
1487 #ifdef CONFIG_X86_64
1488 return &user_x86_64_view;
1489 #endif
1492 void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
1493 int error_code, int si_code)
1495 struct siginfo info;
1497 tsk->thread.trap_no = 1;
1498 tsk->thread.error_code = error_code;
1500 memset(&info, 0, sizeof(info));
1501 info.si_signo = SIGTRAP;
1502 info.si_code = si_code;
1504 /* User-mode ip? */
1505 info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
1507 /* Send us the fake SIGTRAP */
1508 force_sig_info(SIGTRAP, &info, tsk);
1512 #ifdef CONFIG_X86_32
1513 # define IS_IA32 1
1514 #elif defined CONFIG_IA32_EMULATION
1515 # define IS_IA32 test_thread_flag(TIF_IA32)
1516 #else
1517 # define IS_IA32 0
1518 #endif
1521 * We must return the syscall number to actually look up in the table.
1522 * This can be -1L to skip running any syscall at all.
1524 asmregparm long syscall_trace_enter(struct pt_regs *regs)
1526 long ret = 0;
1529 * If we stepped into a sysenter/syscall insn, it trapped in
1530 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
1531 * If user-mode had set TF itself, then it's still clear from
1532 * do_debug() and we need to set it again to restore the user
1533 * state. If we entered on the slow path, TF was already set.
1535 if (test_thread_flag(TIF_SINGLESTEP))
1536 regs->flags |= X86_EFLAGS_TF;
1538 /* do the secure computing check first */
1539 secure_computing(regs->orig_ax);
1541 if (unlikely(test_thread_flag(TIF_SYSCALL_EMU)))
1542 ret = -1L;
1544 if ((ret || test_thread_flag(TIF_SYSCALL_TRACE)) &&
1545 tracehook_report_syscall_entry(regs))
1546 ret = -1L;
1548 if (unlikely(current->audit_context)) {
1549 if (IS_IA32)
1550 audit_syscall_entry(AUDIT_ARCH_I386,
1551 regs->orig_ax,
1552 regs->bx, regs->cx,
1553 regs->dx, regs->si);
1554 #ifdef CONFIG_X86_64
1555 else
1556 audit_syscall_entry(AUDIT_ARCH_X86_64,
1557 regs->orig_ax,
1558 regs->di, regs->si,
1559 regs->dx, regs->r10);
1560 #endif
1563 return ret ?: regs->orig_ax;
1566 asmregparm void syscall_trace_leave(struct pt_regs *regs)
1568 if (unlikely(current->audit_context))
1569 audit_syscall_exit(AUDITSC_RESULT(regs->ax), regs->ax);
1571 if (test_thread_flag(TIF_SYSCALL_TRACE))
1572 tracehook_report_syscall_exit(regs, 0);
1575 * If TIF_SYSCALL_EMU is set, we only get here because of
1576 * TIF_SINGLESTEP (i.e. this is PTRACE_SYSEMU_SINGLESTEP).
1577 * We already reported this syscall instruction in
1578 * syscall_trace_enter(), so don't do any more now.
1580 if (unlikely(test_thread_flag(TIF_SYSCALL_EMU)))
1581 return;
1584 * If we are single-stepping, synthesize a trap to follow the
1585 * system call instruction.
1587 if (test_thread_flag(TIF_SINGLESTEP) &&
1588 tracehook_consider_fatal_signal(current, SIGTRAP, SIG_DFL))
1589 send_sigtrap(current, regs, 0, TRAP_BRKPT);