1 /* By Ross Biro 1/23/92 */
3 * Pentium III FXSR, SSE support
4 * Gareth Hughes <gareth@valinux.com>, May 2000
7 * Markus Metzger <markus.t.metzger@intel.com>, Dec 2007
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
13 #include <linux/smp.h>
14 #include <linux/errno.h>
15 #include <linux/ptrace.h>
16 #include <linux/regset.h>
17 #include <linux/user.h>
18 #include <linux/elf.h>
19 #include <linux/security.h>
20 #include <linux/audit.h>
21 #include <linux/seccomp.h>
22 #include <linux/signal.h>
24 #include <asm/uaccess.h>
25 #include <asm/pgtable.h>
26 #include <asm/system.h>
27 #include <asm/processor.h>
29 #include <asm/debugreg.h>
32 #include <asm/prctl.h>
33 #include <asm/proto.h>
46 * does not yet catch signals sent when the child dies.
47 * in exit.c or in signal.c.
51 * Determines which flags the user has access to [1 = access, 0 = no access].
53 #define FLAG_MASK_32 ((unsigned long) \
54 (X86_EFLAGS_CF | X86_EFLAGS_PF | \
55 X86_EFLAGS_AF | X86_EFLAGS_ZF | \
56 X86_EFLAGS_SF | X86_EFLAGS_TF | \
57 X86_EFLAGS_DF | X86_EFLAGS_OF | \
58 X86_EFLAGS_RF | X86_EFLAGS_AC))
61 * Determines whether a value may be installed in a segment register.
63 static inline bool invalid_selector(u16 value
)
65 return unlikely(value
!= 0 && (value
& SEGMENT_RPL_MASK
) != USER_RPL
);
70 #define FLAG_MASK FLAG_MASK_32
72 static long *pt_regs_access(struct pt_regs
*regs
, unsigned long regno
)
74 BUILD_BUG_ON(offsetof(struct pt_regs
, bx
) != 0);
78 return ®s
->bx
+ regno
;
81 static u16
get_segment_reg(struct task_struct
*task
, unsigned long offset
)
84 * Returning the value truncates it to 16 bits.
87 if (offset
!= offsetof(struct user_regs_struct
, gs
))
88 retval
= *pt_regs_access(task_pt_regs(task
), offset
);
90 retval
= task
->thread
.gs
;
92 savesegment(gs
, retval
);
97 static int set_segment_reg(struct task_struct
*task
,
98 unsigned long offset
, u16 value
)
101 * The value argument was already truncated to 16 bits.
103 if (invalid_selector(value
))
107 * For %cs and %ss we cannot permit a null selector.
108 * We can permit a bogus selector as long as it has USER_RPL.
109 * Null selectors are fine for other segment registers, but
110 * we will never get back to user mode with invalid %cs or %ss
111 * and will take the trap in iret instead. Much code relies
112 * on user_mode() to distinguish a user trap frame (which can
113 * safely use invalid selectors) from a kernel trap frame.
116 case offsetof(struct user_regs_struct
, cs
):
117 case offsetof(struct user_regs_struct
, ss
):
118 if (unlikely(value
== 0))
122 *pt_regs_access(task_pt_regs(task
), offset
) = value
;
125 case offsetof(struct user_regs_struct
, gs
):
126 task
->thread
.gs
= value
;
129 * The user-mode %gs is not affected by
130 * kernel entry, so we must update the CPU.
132 loadsegment(gs
, value
);
138 static unsigned long debugreg_addr_limit(struct task_struct
*task
)
140 return TASK_SIZE
- 3;
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 ®s
->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.
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
));
167 return task
->thread
.fsindex
;
168 case offsetof(struct user_regs_struct
, gs
):
169 if (task
== current
) {
170 asm("movl %%gs,%0" : "=r" (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
));
179 return task
->thread
.ds
;
180 case offsetof(struct user_regs_struct
, es
):
181 if (task
== current
) {
182 asm("movl %%es,%0" : "=r" (seg
));
185 return task
->thread
.es
;
187 case offsetof(struct user_regs_struct
, cs
):
188 case offsetof(struct user_regs_struct
, ss
):
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
))
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))
214 task
->thread
.fsindex
= value
;
216 loadsegment(fs
, task
->thread
.fsindex
);
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))
228 task
->thread
.gsindex
= value
;
230 load_gs_index(task
->thread
.gsindex
);
232 case offsetof(struct user_regs_struct
,ds
):
233 task
->thread
.ds
= value
;
235 loadsegment(ds
, task
->thread
.ds
);
237 case offsetof(struct user_regs_struct
,es
):
238 task
->thread
.es
= value
;
240 loadsegment(es
, task
->thread
.es
);
244 * Can't actually change these in 64-bit mode.
246 case offsetof(struct user_regs_struct
,cs
):
247 if (unlikely(value
== 0))
249 #ifdef CONFIG_IA32_EMULATION
250 if (test_tsk_thread_flag(task
, TIF_IA32
))
251 task_pt_regs(task
)->cs
= value
;
254 case offsetof(struct user_regs_struct
,ss
):
255 if (unlikely(value
== 0))
257 #ifdef CONFIG_IA32_EMULATION
258 if (test_tsk_thread_flag(task
, TIF_IA32
))
259 task_pt_regs(task
)->ss
= value
;
267 static unsigned long debugreg_addr_limit(struct task_struct
*task
)
269 #ifdef CONFIG_IA32_EMULATION
270 if (test_tsk_thread_flag(task
, TIF_IA32
))
271 return IA32_PAGE_OFFSET
- 3;
273 return TASK_SIZE64
- 7;
276 #endif /* CONFIG_X86_32 */
278 static unsigned long get_flags(struct task_struct
*task
)
280 unsigned long retval
= task_pt_regs(task
)->flags
;
283 * If the debugger set TF, hide it from the readout.
285 if (test_tsk_thread_flag(task
, TIF_FORCED_TF
))
286 retval
&= ~X86_EFLAGS_TF
;
291 static int set_flags(struct task_struct
*task
, unsigned long value
)
293 struct pt_regs
*regs
= task_pt_regs(task
);
296 * If the user value contains TF, mark that
297 * it was not "us" (the debugger) that set it.
298 * If not, make sure it stays set if we had.
300 if (value
& X86_EFLAGS_TF
)
301 clear_tsk_thread_flag(task
, TIF_FORCED_TF
);
302 else if (test_tsk_thread_flag(task
, TIF_FORCED_TF
))
303 value
|= X86_EFLAGS_TF
;
305 regs
->flags
= (regs
->flags
& ~FLAG_MASK
) | (value
& FLAG_MASK
);
310 static int putreg(struct task_struct
*child
,
311 unsigned long offset
, unsigned long value
)
314 case offsetof(struct user_regs_struct
, cs
):
315 case offsetof(struct user_regs_struct
, ds
):
316 case offsetof(struct user_regs_struct
, es
):
317 case offsetof(struct user_regs_struct
, fs
):
318 case offsetof(struct user_regs_struct
, gs
):
319 case offsetof(struct user_regs_struct
, ss
):
320 return set_segment_reg(child
, offset
, value
);
322 case offsetof(struct user_regs_struct
, flags
):
323 return set_flags(child
, value
);
326 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
329 * Orig_ax is really just a flag with small positive and
330 * negative values, so make sure to always sign-extend it
331 * from 32 bits so that it works correctly regardless of
332 * whether we come from a 32-bit environment or not.
334 case offsetof(struct user_regs_struct
, orig_ax
):
335 value
= (long) (s32
) value
;
338 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
339 case offsetof(struct user_regs_struct
,fs_base
):
340 if (value
>= TASK_SIZE_OF(child
))
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
);
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
))
356 if (child
->thread
.gs
!= value
)
357 return do_arch_prctl(child
, ARCH_SET_GS
, value
);
362 *pt_regs_access(task_pt_regs(child
), offset
) = value
;
366 static unsigned long getreg(struct task_struct
*task
, unsigned long 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
);
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
;
391 asm("movl %%fs,%0" : "=r" (seg
));
392 if (seg
!= FS_TLS_SEL
)
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
;
404 asm("movl %%gs,%0" : "=r" (seg
));
405 if (seg
!= GS_TLS_SEL
)
407 return get_desc_base(&task
->thread
.tls_array
[GS_TLS
]);
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
)
421 unsigned long *k
= kbuf
;
423 *k
++ = getreg(target
, pos
);
428 unsigned long __user
*u
= ubuf
;
430 if (__put_user(getreg(target
, pos
), u
++))
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
)
447 const unsigned long *k
= kbuf
;
448 while (count
> 0 && !ret
) {
449 ret
= putreg(target
, pos
, *k
++);
454 const unsigned long __user
*u
= ubuf
;
455 while (count
> 0 && !ret
) {
457 ret
= __get_user(word
, u
++);
460 ret
= putreg(target
, pos
, word
);
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
)
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
;
486 static int ptrace_set_debugreg(struct task_struct
*child
,
487 int n
, unsigned long data
)
491 if (unlikely(n
== 4 || n
== 5))
494 if (n
< 4 && unlikely(data
>= debugreg_addr_limit(child
)))
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;
504 if ((data
& ~0xffffffffUL
) != 0)
506 child
->thread
.debugreg6
= data
;
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
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
527 * - R/Wi == 0x00 && LENi != 0x00, so we have mask |=
530 * Finally, mask = 0x0f00 | 0x4444 | 0x1110 == 0x5f54.
532 * See the Intel Manual "System Programming Guide",
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)
541 #define DR7_MASK 0x5f54
543 #define DR7_MASK 0x5554
545 data
&= ~DR_CONTROL_RESERVED
;
546 for (i
= 0; i
< 4; i
++)
547 if ((DR7_MASK
>> ((data
>> (16 + 4*i
)) & 0xf)) & 1)
549 child
->thread
.debugreg7
= data
;
551 set_tsk_thread_flag(child
, TIF_DEBUG
);
553 clear_tsk_thread_flag(child
, TIF_DEBUG
);
560 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
564 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
565 static int ptrace_bts_get_size(struct task_struct
*child
)
567 if (!child
->thread
.ds_area_msr
)
570 return ds_get_bts_index((void *)child
->thread
.ds_area_msr
);
573 static int ptrace_bts_read_record(struct task_struct
*child
,
575 struct bts_struct __user
*out
)
577 struct bts_struct ret
;
582 if (!child
->thread
.ds_area_msr
)
588 bts_end
= ds_get_bts_end((void *)child
->thread
.ds_area_msr
);
589 if (bts_end
<= index
)
592 /* translate the ptrace bts index into the ds bts index */
593 bts_index
= ds_get_bts_index((void *)child
->thread
.ds_area_msr
);
594 bts_index
-= (index
+ 1);
596 bts_index
+= bts_end
;
598 retval
= ds_read_bts((void *)child
->thread
.ds_area_msr
,
603 if (copy_to_user(out
, &ret
, sizeof(ret
)))
609 static int ptrace_bts_write_record(struct task_struct
*child
,
610 const struct bts_struct
*in
)
614 if (!child
->thread
.ds_area_msr
)
617 retval
= ds_write_bts((void *)child
->thread
.ds_area_msr
, in
);
624 static int ptrace_bts_clear(struct task_struct
*child
)
626 if (!child
->thread
.ds_area_msr
)
629 return ds_clear((void *)child
->thread
.ds_area_msr
);
632 static int ptrace_bts_drain(struct task_struct
*child
,
634 struct bts_struct __user
*out
)
637 void *ds
= (void *)child
->thread
.ds_area_msr
;
642 end
= ds_get_bts_index(ds
);
646 if (size
< (end
* sizeof(struct bts_struct
)))
649 for (i
= 0; i
< end
; i
++, out
++) {
650 struct bts_struct ret
;
653 retval
= ds_read_bts(ds
, i
, &ret
);
657 if (copy_to_user(out
, &ret
, sizeof(ret
)))
666 static int ptrace_bts_realloc(struct task_struct
*child
,
667 int size
, int reduce_size
)
669 unsigned long rlim
, vm
;
675 old_size
= ds_get_bts_size((void *)child
->thread
.ds_area_msr
);
679 ret
= ds_free((void **)&child
->thread
.ds_area_msr
);
684 old_size
>>= PAGE_SHIFT
;
686 current
->mm
->total_vm
-= old_size
;
687 current
->mm
->locked_vm
-= old_size
;
692 rlim
= current
->signal
->rlim
[RLIMIT_AS
].rlim_cur
>> PAGE_SHIFT
;
693 vm
= current
->mm
->total_vm
+ size
;
700 size
= rlim
- current
->mm
->total_vm
;
705 rlim
= current
->signal
->rlim
[RLIMIT_MEMLOCK
].rlim_cur
>> PAGE_SHIFT
;
706 vm
= current
->mm
->locked_vm
+ size
;
713 size
= rlim
- current
->mm
->locked_vm
;
718 ret
= ds_allocate((void **)&child
->thread
.ds_area_msr
,
723 current
->mm
->total_vm
+= size
;
724 current
->mm
->locked_vm
+= size
;
727 if (child
->thread
.ds_area_msr
)
728 set_tsk_thread_flag(child
, TIF_DS_AREA_MSR
);
730 clear_tsk_thread_flag(child
, TIF_DS_AREA_MSR
);
735 static int ptrace_bts_config(struct task_struct
*child
,
737 const struct ptrace_bts_config __user
*ucfg
)
739 struct ptrace_bts_config cfg
;
740 int bts_size
, ret
= 0;
743 if (cfg_size
< sizeof(cfg
))
746 if (copy_from_user(&cfg
, ucfg
, sizeof(cfg
)))
749 if ((int)cfg
.size
< 0)
753 ds
= (void *)child
->thread
.ds_area_msr
;
755 bts_size
= ds_get_bts_size(ds
);
759 cfg
.size
= PAGE_ALIGN(cfg
.size
);
761 if (bts_size
!= cfg
.size
) {
762 ret
= ptrace_bts_realloc(child
, cfg
.size
,
763 cfg
.flags
& PTRACE_BTS_O_CUT_SIZE
);
767 ds
= (void *)child
->thread
.ds_area_msr
;
770 if (cfg
.flags
& PTRACE_BTS_O_SIGNAL
)
771 ret
= ds_set_overflow(ds
, DS_O_SIGNAL
);
773 ret
= ds_set_overflow(ds
, DS_O_WRAP
);
777 if (cfg
.flags
& PTRACE_BTS_O_TRACE
)
778 child
->thread
.debugctlmsr
|= ds_debugctl_mask();
780 child
->thread
.debugctlmsr
&= ~ds_debugctl_mask();
782 if (cfg
.flags
& PTRACE_BTS_O_SCHED
)
783 set_tsk_thread_flag(child
, TIF_BTS_TRACE_TS
);
785 clear_tsk_thread_flag(child
, TIF_BTS_TRACE_TS
);
790 if (child
->thread
.debugctlmsr
)
791 set_tsk_thread_flag(child
, TIF_DEBUGCTLMSR
);
793 clear_tsk_thread_flag(child
, TIF_DEBUGCTLMSR
);
798 child
->thread
.debugctlmsr
&= ~ds_debugctl_mask();
799 clear_tsk_thread_flag(child
, TIF_BTS_TRACE_TS
);
803 static int ptrace_bts_status(struct task_struct
*child
,
805 struct ptrace_bts_config __user
*ucfg
)
807 void *ds
= (void *)child
->thread
.ds_area_msr
;
808 struct ptrace_bts_config cfg
;
810 if (cfg_size
< sizeof(cfg
))
813 memset(&cfg
, 0, sizeof(cfg
));
816 cfg
.size
= ds_get_bts_size(ds
);
818 if (ds_get_overflow(ds
) == DS_O_SIGNAL
)
819 cfg
.flags
|= PTRACE_BTS_O_SIGNAL
;
821 if (test_tsk_thread_flag(child
, TIF_DEBUGCTLMSR
) &&
822 child
->thread
.debugctlmsr
& ds_debugctl_mask())
823 cfg
.flags
|= PTRACE_BTS_O_TRACE
;
825 if (test_tsk_thread_flag(child
, TIF_BTS_TRACE_TS
))
826 cfg
.flags
|= PTRACE_BTS_O_SCHED
;
829 cfg
.bts_size
= sizeof(struct bts_struct
);
831 if (copy_to_user(ucfg
, &cfg
, sizeof(cfg
)))
837 void ptrace_bts_take_timestamp(struct task_struct
*tsk
,
838 enum bts_qualifier qualifier
)
840 struct bts_struct rec
= {
841 .qualifier
= qualifier
,
842 .variant
.jiffies
= jiffies_64
845 ptrace_bts_write_record(tsk
, &rec
);
847 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
850 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
853 * Called by kernel/ptrace.c when detaching..
855 * Make sure the single step bit is not set.
857 void ptrace_disable(struct task_struct
*child
)
859 user_disable_single_step(child
);
860 #ifdef TIF_SYSCALL_EMU
861 clear_tsk_thread_flag(child
, TIF_SYSCALL_EMU
);
863 if (child
->thread
.ds_area_msr
) {
864 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
867 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
868 ptrace_bts_realloc(child
, 0, 0);
869 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
872 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
873 child
->thread
.debugctlmsr
&= ~ds_debugctl_mask();
874 if (!child
->thread
.debugctlmsr
)
875 clear_tsk_thread_flag(child
, TIF_DEBUGCTLMSR
);
876 clear_tsk_thread_flag(child
, TIF_BTS_TRACE_TS
);
880 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
881 static const struct user_regset_view user_x86_32_view
; /* Initialized below. */
884 long arch_ptrace(struct task_struct
*child
, long request
, long addr
, long data
)
887 unsigned long __user
*datap
= (unsigned long __user
*)data
;
890 /* read the word at location addr in the USER area. */
891 case PTRACE_PEEKUSR
: {
895 if ((addr
& (sizeof(data
) - 1)) || addr
< 0 ||
896 addr
>= sizeof(struct user
))
899 tmp
= 0; /* Default return condition */
900 if (addr
< sizeof(struct user_regs_struct
))
901 tmp
= getreg(child
, addr
);
902 else if (addr
>= offsetof(struct user
, u_debugreg
[0]) &&
903 addr
<= offsetof(struct user
, u_debugreg
[7])) {
904 addr
-= offsetof(struct user
, u_debugreg
[0]);
905 tmp
= ptrace_get_debugreg(child
, addr
/ sizeof(data
));
907 ret
= put_user(tmp
, datap
);
911 case PTRACE_POKEUSR
: /* write the word at location addr in the USER area */
913 if ((addr
& (sizeof(data
) - 1)) || addr
< 0 ||
914 addr
>= sizeof(struct user
))
917 if (addr
< sizeof(struct user_regs_struct
))
918 ret
= putreg(child
, addr
, data
);
919 else if (addr
>= offsetof(struct user
, u_debugreg
[0]) &&
920 addr
<= offsetof(struct user
, u_debugreg
[7])) {
921 addr
-= offsetof(struct user
, u_debugreg
[0]);
922 ret
= ptrace_set_debugreg(child
,
923 addr
/ sizeof(data
), data
);
927 case PTRACE_GETREGS
: /* Get all gp regs from the child. */
928 return copy_regset_to_user(child
,
929 task_user_regset_view(current
),
931 0, sizeof(struct user_regs_struct
),
934 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
935 return copy_regset_from_user(child
,
936 task_user_regset_view(current
),
938 0, sizeof(struct user_regs_struct
),
941 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
942 return copy_regset_to_user(child
,
943 task_user_regset_view(current
),
945 0, sizeof(struct user_i387_struct
),
948 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
949 return copy_regset_from_user(child
,
950 task_user_regset_view(current
),
952 0, sizeof(struct user_i387_struct
),
956 case PTRACE_GETFPXREGS
: /* Get the child extended FPU state. */
957 return copy_regset_to_user(child
, &user_x86_32_view
,
959 0, sizeof(struct user_fxsr_struct
),
962 case PTRACE_SETFPXREGS
: /* Set the child extended FPU state. */
963 return copy_regset_from_user(child
, &user_x86_32_view
,
965 0, sizeof(struct user_fxsr_struct
),
969 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
970 case PTRACE_GET_THREAD_AREA
:
973 ret
= do_get_thread_area(child
, addr
,
974 (struct user_desc __user
*) data
);
977 case PTRACE_SET_THREAD_AREA
:
980 ret
= do_set_thread_area(child
, addr
,
981 (struct user_desc __user
*) data
, 0);
986 /* normal 64bit interface to access TLS data.
987 Works just like arch_prctl, except that the arguments
989 case PTRACE_ARCH_PRCTL
:
990 ret
= do_arch_prctl(child
, data
, addr
);
994 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
997 * These bits need more cooking - not enabled yet:
1000 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1001 case PTRACE_BTS_CONFIG
:
1002 ret
= ptrace_bts_config
1003 (child
, data
, (struct ptrace_bts_config __user
*)addr
);
1006 case PTRACE_BTS_STATUS
:
1007 ret
= ptrace_bts_status
1008 (child
, data
, (struct ptrace_bts_config __user
*)addr
);
1011 case PTRACE_BTS_SIZE
:
1012 ret
= ptrace_bts_get_size(child
);
1015 case PTRACE_BTS_GET
:
1016 ret
= ptrace_bts_read_record
1017 (child
, data
, (struct bts_struct __user
*) addr
);
1020 case PTRACE_BTS_CLEAR
:
1021 ret
= ptrace_bts_clear(child
);
1024 case PTRACE_BTS_DRAIN
:
1025 ret
= ptrace_bts_drain
1026 (child
, data
, (struct bts_struct __user
*) addr
);
1028 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1031 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1034 ret
= ptrace_request(child
, request
, addr
, data
);
1041 #ifdef CONFIG_IA32_EMULATION
1043 #include <linux/compat.h>
1044 #include <linux/syscalls.h>
1045 #include <asm/ia32.h>
1046 #include <asm/user32.h>
1049 case offsetof(struct user32, regs.l): \
1050 regs->q = value; break
1053 case offsetof(struct user32, regs.rs): \
1054 return set_segment_reg(child, \
1055 offsetof(struct user_regs_struct, rs), \
1059 static int putreg32(struct task_struct
*child
, unsigned regno
, u32 value
)
1061 struct pt_regs
*regs
= task_pt_regs(child
);
1079 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1080 R32(orig_eax
, orig_ax
);
1082 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1086 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1088 case offsetof(struct user32
, regs
.orig_eax
):
1090 * Sign-extend the value so that orig_eax = -1
1091 * causes (long)orig_ax < 0 tests to fire correctly.
1093 regs
->orig_ax
= (long) (s32
) value
;
1096 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1097 case offsetof(struct user32
, regs
.eflags
):
1098 return set_flags(child
, value
);
1100 case offsetof(struct user32
, u_debugreg
[0]) ...
1101 offsetof(struct user32
, u_debugreg
[7]):
1102 regno
-= offsetof(struct user32
, u_debugreg
[0]);
1103 return ptrace_set_debugreg(child
, regno
/ 4, value
);
1106 if (regno
> sizeof(struct user32
) || (regno
& 3))
1110 * Other dummy fields in the virtual user structure
1122 case offsetof(struct user32, regs.l): \
1123 *val = regs->q; break
1126 case offsetof(struct user32, regs.rs): \
1127 *val = get_segment_reg(child, \
1128 offsetof(struct user_regs_struct, rs)); \
1131 static int getreg32(struct task_struct
*child
, unsigned regno
, u32
*val
)
1133 struct pt_regs
*regs
= task_pt_regs(child
);
1151 R32(orig_eax
, orig_ax
);
1155 case offsetof(struct user32
, regs
.eflags
):
1156 *val
= get_flags(child
);
1159 case offsetof(struct user32
, u_debugreg
[0]) ...
1160 offsetof(struct user32
, u_debugreg
[7]):
1161 regno
-= offsetof(struct user32
, u_debugreg
[0]);
1162 *val
= ptrace_get_debugreg(child
, regno
/ 4);
1166 if (regno
> sizeof(struct user32
) || (regno
& 3))
1170 * Other dummy fields in the virtual user structure
1182 static int genregs32_get(struct task_struct
*target
,
1183 const struct user_regset
*regset
,
1184 unsigned int pos
, unsigned int count
,
1185 void *kbuf
, void __user
*ubuf
)
1188 compat_ulong_t
*k
= kbuf
;
1190 getreg32(target
, pos
, k
++);
1191 count
-= sizeof(*k
);
1195 compat_ulong_t __user
*u
= ubuf
;
1197 compat_ulong_t word
;
1198 getreg32(target
, pos
, &word
);
1199 if (__put_user(word
, u
++))
1201 count
-= sizeof(*u
);
1209 static int genregs32_set(struct task_struct
*target
,
1210 const struct user_regset
*regset
,
1211 unsigned int pos
, unsigned int count
,
1212 const void *kbuf
, const void __user
*ubuf
)
1216 const compat_ulong_t
*k
= kbuf
;
1217 while (count
> 0 && !ret
) {
1218 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1219 ret
= putreg(target
, pos
, *k
++);
1221 ret
= putreg32(target
, pos
, *k
++);
1222 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1223 count
-= sizeof(*k
);
1227 const compat_ulong_t __user
*u
= ubuf
;
1228 while (count
> 0 && !ret
) {
1229 compat_ulong_t word
;
1230 ret
= __get_user(word
, u
++);
1233 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1234 ret
= putreg(target
, pos
, word
);
1236 ret
= putreg32(target
, pos
, word
);
1237 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1238 count
-= sizeof(*u
);
1245 static long ptrace32_siginfo(unsigned request
, u32 pid
, u32 addr
, u32 data
)
1247 siginfo_t __user
*si
= compat_alloc_user_space(sizeof(siginfo_t
));
1248 compat_siginfo_t __user
*si32
= compat_ptr(data
);
1252 if (request
== PTRACE_SETSIGINFO
) {
1253 memset(&ssi
, 0, sizeof(siginfo_t
));
1254 ret
= copy_siginfo_from_user32(&ssi
, si32
);
1257 if (copy_to_user(si
, &ssi
, sizeof(siginfo_t
)))
1260 ret
= sys_ptrace(request
, pid
, addr
, (unsigned long)si
);
1263 if (request
== PTRACE_GETSIGINFO
) {
1264 if (copy_from_user(&ssi
, si
, sizeof(siginfo_t
)))
1266 ret
= copy_siginfo_to_user32(si32
, &ssi
);
1271 asmlinkage
long sys32_ptrace(long request
, u32 pid
, u32 addr
, u32 data
)
1273 struct task_struct
*child
;
1274 struct pt_regs
*childregs
;
1275 void __user
*datap
= compat_ptr(data
);
1280 case PTRACE_TRACEME
:
1284 case PTRACE_SINGLESTEP
:
1285 case PTRACE_SINGLEBLOCK
:
1287 case PTRACE_SYSCALL
:
1288 case PTRACE_OLDSETOPTIONS
:
1289 case PTRACE_SETOPTIONS
:
1290 case PTRACE_SET_THREAD_AREA
:
1291 case PTRACE_GET_THREAD_AREA
:
1292 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1295 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1296 case PTRACE_BTS_CONFIG
:
1297 case PTRACE_BTS_STATUS
:
1298 case PTRACE_BTS_SIZE
:
1299 case PTRACE_BTS_GET
:
1300 case PTRACE_BTS_CLEAR
:
1301 case PTRACE_BTS_DRAIN
:
1302 <<<<<<< HEAD
:arch
/x86
/kernel
/ptrace
.c
1305 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:arch
/x86
/kernel
/ptrace
.c
1306 return sys_ptrace(request
, pid
, addr
, data
);
1311 case PTRACE_PEEKTEXT
:
1312 case PTRACE_PEEKDATA
:
1313 case PTRACE_POKEDATA
:
1314 case PTRACE_POKETEXT
:
1315 case PTRACE_POKEUSR
:
1316 case PTRACE_PEEKUSR
:
1317 case PTRACE_GETREGS
:
1318 case PTRACE_SETREGS
:
1319 case PTRACE_SETFPREGS
:
1320 case PTRACE_GETFPREGS
:
1321 case PTRACE_SETFPXREGS
:
1322 case PTRACE_GETFPXREGS
:
1323 case PTRACE_GETEVENTMSG
:
1326 case PTRACE_SETSIGINFO
:
1327 case PTRACE_GETSIGINFO
:
1328 return ptrace32_siginfo(request
, pid
, addr
, data
);
1331 child
= ptrace_get_task_struct(pid
);
1333 return PTR_ERR(child
);
1335 ret
= ptrace_check_attach(child
, request
== PTRACE_KILL
);
1339 childregs
= task_pt_regs(child
);
1342 case PTRACE_PEEKUSR
:
1343 ret
= getreg32(child
, addr
, &val
);
1345 ret
= put_user(val
, (__u32 __user
*)datap
);
1348 case PTRACE_POKEUSR
:
1349 ret
= putreg32(child
, addr
, data
);
1352 case PTRACE_GETREGS
: /* Get all gp regs from the child. */
1353 return copy_regset_to_user(child
, &user_x86_32_view
,
1355 0, sizeof(struct user_regs_struct32
),
1358 case PTRACE_SETREGS
: /* Set all gp regs in the child. */
1359 return copy_regset_from_user(child
, &user_x86_32_view
,
1361 sizeof(struct user_regs_struct32
),
1364 case PTRACE_GETFPREGS
: /* Get the child FPU state. */
1365 return copy_regset_to_user(child
, &user_x86_32_view
,
1367 sizeof(struct user_i387_ia32_struct
),
1370 case PTRACE_SETFPREGS
: /* Set the child FPU state. */
1371 return copy_regset_from_user(
1372 child
, &user_x86_32_view
, REGSET_FP
,
1373 0, sizeof(struct user_i387_ia32_struct
), datap
);
1375 case PTRACE_GETFPXREGS
: /* Get the child extended FPU state. */
1376 return copy_regset_to_user(child
, &user_x86_32_view
,
1378 sizeof(struct user32_fxsr_struct
),
1381 case PTRACE_SETFPXREGS
: /* Set the child extended FPU state. */
1382 return copy_regset_from_user(child
, &user_x86_32_view
,
1384 sizeof(struct user32_fxsr_struct
),
1388 return compat_ptrace_request(child
, request
, addr
, data
);
1392 put_task_struct(child
);
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
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
1415 static const struct user_regset_view user_x86_64_view
= {
1416 .name
= "x86_64", .e_machine
= EM_X86_64
,
1417 .regsets
= x86_64_regsets
, .n
= ARRAY_SIZE(x86_64_regsets
)
1420 #else /* CONFIG_X86_32 */
1422 #define user_regs_struct32 user_regs_struct
1423 #define genregs32_get genregs_get
1424 #define genregs32_set genregs_set
1426 #endif /* CONFIG_X86_64 */
1428 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1429 static const struct user_regset x86_32_regsets
[] = {
1430 [REGSET_GENERAL
] = {
1431 .core_note_type
= NT_PRSTATUS
,
1432 .n
= sizeof(struct user_regs_struct32
) / sizeof(u32
),
1433 .size
= sizeof(u32
), .align
= sizeof(u32
),
1434 .get
= genregs32_get
, .set
= genregs32_set
1437 .core_note_type
= NT_PRFPREG
,
1438 .n
= sizeof(struct user_i387_struct
) / sizeof(u32
),
1439 .size
= sizeof(u32
), .align
= sizeof(u32
),
1440 .active
= fpregs_active
, .get
= fpregs_get
, .set
= fpregs_set
1443 .core_note_type
= NT_PRXFPREG
,
1444 .n
= sizeof(struct user_i387_struct
) / sizeof(u32
),
1445 .size
= sizeof(u32
), .align
= sizeof(u32
),
1446 .active
= xfpregs_active
, .get
= xfpregs_get
, .set
= xfpregs_set
1449 .core_note_type
= NT_386_TLS
,
1450 .n
= GDT_ENTRY_TLS_ENTRIES
, .bias
= GDT_ENTRY_TLS_MIN
,
1451 .size
= sizeof(struct user_desc
),
1452 .align
= sizeof(struct user_desc
),
1453 .active
= regset_tls_active
,
1454 .get
= regset_tls_get
, .set
= regset_tls_set
1458 static const struct user_regset_view user_x86_32_view
= {
1459 .name
= "i386", .e_machine
= EM_386
,
1460 .regsets
= x86_32_regsets
, .n
= ARRAY_SIZE(x86_32_regsets
)
1464 const struct user_regset_view
*task_user_regset_view(struct task_struct
*task
)
1466 #ifdef CONFIG_IA32_EMULATION
1467 if (test_tsk_thread_flag(task
, TIF_IA32
))
1469 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
1470 return &user_x86_32_view
;
1472 #ifdef CONFIG_X86_64
1473 return &user_x86_64_view
;
1477 #ifdef CONFIG_X86_32
1479 void send_sigtrap(struct task_struct
*tsk
, struct pt_regs
*regs
, int error_code
)
1481 struct siginfo info
;
1483 tsk
->thread
.trap_no
= 1;
1484 tsk
->thread
.error_code
= error_code
;
1486 memset(&info
, 0, sizeof(info
));
1487 info
.si_signo
= SIGTRAP
;
1488 info
.si_code
= TRAP_BRKPT
;
1491 info
.si_addr
= user_mode_vm(regs
) ? (void __user
*) regs
->ip
: NULL
;
1493 /* Send us the fake SIGTRAP */
1494 force_sig_info(SIGTRAP
, &info
, tsk
);
1497 /* notification of system call entry/exit
1498 * - triggered by current->work.syscall_trace
1500 __attribute__((regparm(3)))
1501 int do_syscall_trace(struct pt_regs
*regs
, int entryexit
)
1503 int is_sysemu
= test_thread_flag(TIF_SYSCALL_EMU
);
1505 * With TIF_SYSCALL_EMU set we want to ignore TIF_SINGLESTEP for syscall
1508 int is_singlestep
= !is_sysemu
&& test_thread_flag(TIF_SINGLESTEP
);
1511 /* do the secure computing check first */
1513 secure_computing(regs
->orig_ax
);
1515 if (unlikely(current
->audit_context
)) {
1517 audit_syscall_exit(AUDITSC_RESULT(regs
->ax
),
1519 /* Debug traps, when using PTRACE_SINGLESTEP, must be sent only
1520 * on the syscall exit path. Normally, when TIF_SYSCALL_AUDIT is
1521 * not used, entry.S will call us only on syscall exit, not
1522 * entry; so when TIF_SYSCALL_AUDIT is used we must avoid
1523 * calling send_sigtrap() on syscall entry.
1525 * Note that when PTRACE_SYSEMU_SINGLESTEP is used,
1526 * is_singlestep is false, despite his name, so we will still do
1527 * the correct thing.
1529 else if (is_singlestep
)
1533 if (!(current
->ptrace
& PT_PTRACED
))
1536 /* If a process stops on the 1st tracepoint with SYSCALL_TRACE
1537 * and then is resumed with SYSEMU_SINGLESTEP, it will come in
1538 * here. We have to check this and return */
1539 if (is_sysemu
&& entryexit
)
1542 /* Fake a debug trap */
1544 send_sigtrap(current
, regs
, 0);
1546 if (!test_thread_flag(TIF_SYSCALL_TRACE
) && !is_sysemu
)
1549 /* the 0x80 provides a way for the tracing parent to distinguish
1550 between a syscall stop and SIGTRAP delivery */
1551 /* Note that the debugger could change the result of test_thread_flag!*/
1552 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
) ? 0x80:0));
1555 * this isn't the same as continuing with a signal, but it will do
1556 * for normal use. strace only continues with a signal if the
1557 * stopping signal is not SIGTRAP. -brl
1559 if (current
->exit_code
) {
1560 send_sig(current
->exit_code
, current
, 1);
1561 current
->exit_code
= 0;
1565 if (unlikely(current
->audit_context
) && !entryexit
)
1566 audit_syscall_entry(AUDIT_ARCH_I386
, regs
->orig_ax
,
1567 regs
->bx
, regs
->cx
, regs
->dx
, regs
->si
);
1571 regs
->orig_ax
= -1; /* force skip of syscall restarting */
1572 if (unlikely(current
->audit_context
))
1573 audit_syscall_exit(AUDITSC_RESULT(regs
->ax
), regs
->ax
);
1577 #else /* CONFIG_X86_64 */
1579 static void syscall_trace(struct pt_regs
*regs
)
1583 printk("trace %s ip %lx sp %lx ax %d origrax %d caller %lx tiflags %x ptrace %x\n",
1585 regs
->ip
, regs
->sp
, regs
->ax
, regs
->orig_ax
, __builtin_return_address(0),
1586 current_thread_info()->flags
, current
->ptrace
);
1589 ptrace_notify(SIGTRAP
| ((current
->ptrace
& PT_TRACESYSGOOD
)
1592 * this isn't the same as continuing with a signal, but it will do
1593 * for normal use. strace only continues with a signal if the
1594 * stopping signal is not SIGTRAP. -brl
1596 if (current
->exit_code
) {
1597 send_sig(current
->exit_code
, current
, 1);
1598 current
->exit_code
= 0;
1602 asmlinkage
void syscall_trace_enter(struct pt_regs
*regs
)
1604 /* do the secure computing check first */
1605 secure_computing(regs
->orig_ax
);
1607 if (test_thread_flag(TIF_SYSCALL_TRACE
)
1608 && (current
->ptrace
& PT_PTRACED
))
1609 syscall_trace(regs
);
1611 if (unlikely(current
->audit_context
)) {
1612 if (test_thread_flag(TIF_IA32
)) {
1613 audit_syscall_entry(AUDIT_ARCH_I386
,
1616 regs
->dx
, regs
->si
);
1618 audit_syscall_entry(AUDIT_ARCH_X86_64
,
1621 regs
->dx
, regs
->r10
);
1626 asmlinkage
void syscall_trace_leave(struct pt_regs
*regs
)
1628 if (unlikely(current
->audit_context
))
1629 audit_syscall_exit(AUDITSC_RESULT(regs
->ax
), regs
->ax
);
1631 if ((test_thread_flag(TIF_SYSCALL_TRACE
)
1632 || test_thread_flag(TIF_SINGLESTEP
))
1633 && (current
->ptrace
& PT_PTRACED
))
1634 syscall_trace(regs
);
1637 #endif /* CONFIG_X86_32 */