aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2010-01-26 02:33:53 -0500
committerMike Frysinger <vapier@gentoo.org>2010-03-09 00:30:51 -0500
commite8f263dfd32a784a816fe68956e564f8ede4a9fc (patch)
tree58fcc786db192f13c3df7febee705adaaf61012c /arch
parente50e2f25c5b90abd00a1e5871c45094cf5207afc (diff)
Blackfin: initial tracehook support
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/blackfin/Kconfig1
-rw-r--r--arch/blackfin/include/asm/ptrace.h23
-rw-r--r--arch/blackfin/include/asm/syscall.h96
-rw-r--r--arch/blackfin/kernel/ptrace.c66
-rw-r--r--arch/blackfin/kernel/signal.c14
-rw-r--r--arch/blackfin/mach-common/entry.S6
6 files changed, 144 insertions, 62 deletions
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 970df5b5c525..c078849df7f9 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -24,6 +24,7 @@ config RWSEM_XCHGADD_ALGORITHM
24config BLACKFIN 24config BLACKFIN
25 def_bool y 25 def_bool y
26 select HAVE_ARCH_KGDB 26 select HAVE_ARCH_KGDB
27 select HAVE_ARCH_TRACEHOOK
27 select HAVE_FUNCTION_GRAPH_TRACER 28 select HAVE_FUNCTION_GRAPH_TRACER
28 select HAVE_FUNCTION_TRACER 29 select HAVE_FUNCTION_TRACER
29 select HAVE_FUNCTION_TRACE_MCOUNT_TEST 30 select HAVE_FUNCTION_TRACE_MCOUNT_TEST
diff --git a/arch/blackfin/include/asm/ptrace.h b/arch/blackfin/include/asm/ptrace.h
index c1aebdb981c7..aaa1c6c2bc19 100644
--- a/arch/blackfin/include/asm/ptrace.h
+++ b/arch/blackfin/include/asm/ptrace.h
@@ -24,6 +24,8 @@
24 24
25#ifndef __ASSEMBLY__ 25#ifndef __ASSEMBLY__
26 26
27struct task_struct;
28
27/* this struct defines the way the registers are stored on the 29/* this struct defines the way the registers are stored on the
28 stack during a system call. */ 30 stack during a system call. */
29 31
@@ -101,9 +103,30 @@ struct pt_regs {
101 master interrupt enable. */ 103 master interrupt enable. */
102#define user_mode(regs) (!(((regs)->ipend & ~0x10) & (((regs)->ipend & ~0x10) - 1))) 104#define user_mode(regs) (!(((regs)->ipend & ~0x10) & (((regs)->ipend & ~0x10) - 1)))
103#define instruction_pointer(regs) ((regs)->pc) 105#define instruction_pointer(regs) ((regs)->pc)
106#define user_stack_pointer(regs) ((regs)->usp)
104#define profile_pc(regs) instruction_pointer(regs) 107#define profile_pc(regs) instruction_pointer(regs)
105extern void show_regs(struct pt_regs *); 108extern void show_regs(struct pt_regs *);
106 109
110#define arch_has_single_step() (1)
111extern void user_enable_single_step(struct task_struct *child);
112extern void user_disable_single_step(struct task_struct *child);
113/* common code demands this function */
114#define ptrace_disable(child) user_disable_single_step(child)
115
116/*
117 * Get the address of the live pt_regs for the specified task.
118 * These are saved onto the top kernel stack when the process
119 * is not running.
120 *
121 * Note: if a user thread is execve'd from kernel space, the
122 * kernel stack will not be empty on entry to the kernel, so
123 * ptracing these tasks will fail.
124 */
125#define task_pt_regs(task) \
126 (struct pt_regs *) \
127 ((unsigned long)task_stack_page(task) + \
128 (THREAD_SIZE - sizeof(struct pt_regs)))
129
107#endif /* __KERNEL__ */ 130#endif /* __KERNEL__ */
108 131
109#endif /* __ASSEMBLY__ */ 132#endif /* __ASSEMBLY__ */
diff --git a/arch/blackfin/include/asm/syscall.h b/arch/blackfin/include/asm/syscall.h
new file mode 100644
index 000000000000..4921a4815cce
--- /dev/null
+++ b/arch/blackfin/include/asm/syscall.h
@@ -0,0 +1,96 @@
1/*
2 * Magic syscall break down functions
3 *
4 * Copyright 2010 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef __ASM_BLACKFIN_SYSCALL_H__
10#define __ASM_BLACKFIN_SYSCALL_H__
11
12/*
13 * Blackfin syscalls are simple:
14 * enter:
15 * p0: syscall number
16 * r{0,1,2,3,4,5}: syscall args 0,1,2,3,4,5
17 * exit:
18 * r0: return/error value
19 */
20
21#include <linux/err.h>
22#include <linux/sched.h>
23#include <asm/ptrace.h>
24
25static inline long
26syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
27{
28 return regs->p0;
29}
30
31static inline void
32syscall_rollback(struct task_struct *task, struct pt_regs *regs)
33{
34 regs->p0 = regs->orig_p0;
35}
36
37static inline long
38syscall_get_error(struct task_struct *task, struct pt_regs *regs)
39{
40 return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
41}
42
43static inline long
44syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
45{
46 return regs->r0;
47}
48
49static inline void
50syscall_set_return_value(struct task_struct *task, struct pt_regs *regs,
51 int error, long val)
52{
53 regs->r0 = error ? -error : val;
54}
55
56/**
57 * syscall_get_arguments()
58 * @task: unused
59 * @regs: the register layout to extract syscall arguments from
60 * @i: first syscall argument to extract
61 * @n: number of syscall arguments to extract
62 * @args: array to return the syscall arguments in
63 *
64 * args[0] gets i'th argument, args[n - 1] gets the i+n-1'th argument
65 */
66static inline void
67syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
68 unsigned int i, unsigned int n, unsigned long *args)
69{
70 /*
71 * Assume the ptrace layout doesn't change -- r5 is first in memory,
72 * then r4, ..., then r0. So we simply reverse the ptrace register
73 * array in memory to store into the args array.
74 */
75 long *aregs = &regs->r0 - i;
76
77 BUG_ON(i > 5 || i + n > 6);
78
79 while (n--)
80 *args++ = *aregs--;
81}
82
83/* See syscall_get_arguments() comments */
84static inline void
85syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
86 unsigned int i, unsigned int n, const unsigned long *args)
87{
88 long *aregs = &regs->r0 - i;
89
90 BUG_ON(i > 5 || i + n > 6);
91
92 while (n--)
93 *aregs-- = *args++;
94}
95
96#endif
diff --git a/arch/blackfin/kernel/ptrace.c b/arch/blackfin/kernel/ptrace.c
index 92b4ca0b5af6..0618b8287e34 100644
--- a/arch/blackfin/kernel/ptrace.c
+++ b/arch/blackfin/kernel/ptrace.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds 2 * linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds
3 * these modifications are Copyright 2004-2009 Analog Devices Inc. 3 * these modifications are Copyright 2004-2010 Analog Devices Inc.
4 * 4 *
5 * Licensed under the GPL-2 5 * Licensed under the GPL-2
6 */ 6 */
@@ -15,6 +15,7 @@
15#include <linux/user.h> 15#include <linux/user.h>
16#include <linux/regset.h> 16#include <linux/regset.h>
17#include <linux/signal.h> 17#include <linux/signal.h>
18#include <linux/tracehook.h>
18#include <linux/uaccess.h> 19#include <linux/uaccess.h>
19 20
20#include <asm/page.h> 21#include <asm/page.h>
@@ -32,25 +33,6 @@
32 * in exit.c or in signal.c. 33 * in exit.c or in signal.c.
33 */ 34 */
34 35
35/* Find the stack offset for a register, relative to thread.esp0. */
36#define PT_REG(reg) ((long)&((struct pt_regs *)0)->reg)
37
38/*
39 * Get the address of the live pt_regs for the specified task.
40 * These are saved onto the top kernel stack when the process
41 * is not running.
42 *
43 * Note: if a user thread is execve'd from kernel space, the
44 * kernel stack will not be empty on entry to the kernel, so
45 * ptracing these tasks will fail.
46 */
47static inline struct pt_regs *task_pt_regs(struct task_struct *task)
48{
49 return (struct pt_regs *)
50 ((unsigned long)task_stack_page(task) +
51 (THREAD_SIZE - sizeof(struct pt_regs)));
52}
53
54/* 36/*
55 * Get contents of register REGNO in task TASK. 37 * Get contents of register REGNO in task TASK.
56 */ 38 */
@@ -234,18 +216,13 @@ const struct user_regset_view *task_user_regset_view(struct task_struct *task)
234 return &user_bfin_native_view; 216 return &user_bfin_native_view;
235} 217}
236 218
237void ptrace_enable(struct task_struct *child) 219void user_enable_single_step(struct task_struct *child)
238{ 220{
239 struct pt_regs *regs = task_pt_regs(child); 221 struct pt_regs *regs = task_pt_regs(child);
240 regs->syscfg |= SYSCFG_SSSTEP; 222 regs->syscfg |= SYSCFG_SSSTEP;
241} 223}
242 224
243/* 225void user_disable_single_step(struct task_struct *child)
244 * Called by kernel/ptrace.c when detaching..
245 *
246 * Make sure the single step bit is not set.
247 */
248void ptrace_disable(struct task_struct *child)
249{ 226{
250 struct pt_regs *regs = task_pt_regs(child); 227 struct pt_regs *regs = task_pt_regs(child);
251 regs->syscfg &= ~SYSCFG_SSSTEP; 228 regs->syscfg &= ~SYSCFG_SSSTEP;
@@ -412,27 +389,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
412 return ret; 389 return ret;
413} 390}
414 391
415asmlinkage void syscall_trace(void) 392asmlinkage int syscall_trace_enter(struct pt_regs *regs)
416{ 393{
417 if (!test_thread_flag(TIF_SYSCALL_TRACE)) 394 int ret = 0;
418 return; 395
419 396 if (test_thread_flag(TIF_SYSCALL_TRACE))
420 if (!(current->ptrace & PT_PTRACED)) 397 ret = tracehook_report_syscall_entry(regs);
421 return; 398
422 399 return ret;
423 /* the 0x80 provides a way for the tracing parent to distinguish 400}
424 * between a syscall stop and SIGTRAP delivery 401
425 */ 402asmlinkage void syscall_trace_leave(struct pt_regs *regs)
426 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) 403{
427 ? 0x80 : 0)); 404 if (test_thread_flag(TIF_SYSCALL_TRACE))
428 405 tracehook_report_syscall_exit(regs, 0);
429 /*
430 * this isn't the same as continuing with a signal, but it will do
431 * for normal use. strace only continues with a signal if the
432 * stopping signal is not SIGTRAP. -brl
433 */
434 if (current->exit_code) {
435 send_sig(current->exit_code, current, 1);
436 current->exit_code = 0;
437 }
438} 406}
diff --git a/arch/blackfin/kernel/signal.c b/arch/blackfin/kernel/signal.c
index e0fd63e9e38a..e60990c0a1f0 100644
--- a/arch/blackfin/kernel/signal.c
+++ b/arch/blackfin/kernel/signal.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright 2004-2009 Analog Devices Inc. 2 * Copyright 2004-2010 Analog Devices Inc.
3 * 3 *
4 * Licensed under the GPL-2 or later 4 * Licensed under the GPL-2 or later
5 */ 5 */
@@ -206,16 +206,6 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
206 regs->r1 = (unsigned long)(&frame->info); 206 regs->r1 = (unsigned long)(&frame->info);
207 regs->r2 = (unsigned long)(&frame->uc); 207 regs->r2 = (unsigned long)(&frame->uc);
208 208
209 /*
210 * Clear the trace flag when entering the signal handler, but
211 * notify any tracer that was single-stepping it. The tracer
212 * may want to single-step inside the handler too.
213 */
214 if (regs->syscfg & TRACE_BITS) {
215 regs->syscfg &= ~TRACE_BITS;
216 ptrace_notify(SIGTRAP);
217 }
218
219 return 0; 209 return 0;
220 210
221 give_sigsegv: 211 give_sigsegv:
@@ -315,6 +305,8 @@ asmlinkage void do_signal(struct pt_regs *regs)
315 * clear the TIF_RESTORE_SIGMASK flag */ 305 * clear the TIF_RESTORE_SIGMASK flag */
316 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 306 if (test_thread_flag(TIF_RESTORE_SIGMASK))
317 clear_thread_flag(TIF_RESTORE_SIGMASK); 307 clear_thread_flag(TIF_RESTORE_SIGMASK);
308
309 tracehook_signal_handler(signr, &info, &ka, regs, 1);
318 } 310 }
319 311
320 return; 312 return;
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index 1fa414f7852f..0df5b834d34e 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -736,7 +736,8 @@ ENDPROC(_system_call)
736 * this symbol need not be global anyways, so ... 736 * this symbol need not be global anyways, so ...
737 */ 737 */
738_sys_trace: 738_sys_trace:
739 pseudo_long_call _syscall_trace, p5; 739 r0 = sp;
740 pseudo_long_call _syscall_trace_enter, p5;
740 741
741 /* Execute the appropriate system call */ 742 /* Execute the appropriate system call */
742 743
@@ -760,7 +761,8 @@ _sys_trace:
760 SP += 24; 761 SP += 24;
761 [sp + PT_R0] = r0; 762 [sp + PT_R0] = r0;
762 763
763 pseudo_long_call _syscall_trace, p5; 764 r0 = sp;
765 pseudo_long_call _syscall_trace_leave, p5;
764 jump .Lresume_userspace; 766 jump .Lresume_userspace;
765ENDPROC(_sys_trace) 767ENDPROC(_sys_trace)
766 768