diff options
author | Vineet Gupta <vgupta@synopsys.com> | 2013-01-18 04:42:22 -0500 |
---|---|---|
committer | Vineet Gupta <vgupta@synopsys.com> | 2013-02-15 12:45:59 -0500 |
commit | 547f112571904da03589beb8434185294c77896a (patch) | |
tree | 0cf125fec3110091a208c0243173cfd150e332cd /arch/arc/kernel/ptrace.c | |
parent | 080c37473eb671a037b3e9a315303851f0675be5 (diff) |
ARC: ptrace support
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/arc/kernel/ptrace.c')
-rw-r--r-- | arch/arc/kernel/ptrace.c | 136 |
1 files changed, 134 insertions, 2 deletions
diff --git a/arch/arc/kernel/ptrace.c b/arch/arc/kernel/ptrace.c index 1cf944a77f33..c6a81c58d0f3 100644 --- a/arch/arc/kernel/ptrace.c +++ b/arch/arc/kernel/ptrace.c | |||
@@ -7,6 +7,122 @@ | |||
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/ptrace.h> | 9 | #include <linux/ptrace.h> |
10 | #include <linux/tracehook.h> | ||
11 | #include <linux/regset.h> | ||
12 | #include <linux/unistd.h> | ||
13 | #include <linux/elf.h> | ||
14 | |||
15 | static struct callee_regs *task_callee_regs(struct task_struct *tsk) | ||
16 | { | ||
17 | struct callee_regs *tmp = (struct callee_regs *)tsk->thread.callee_reg; | ||
18 | return tmp; | ||
19 | } | ||
20 | |||
21 | static int genregs_get(struct task_struct *target, | ||
22 | const struct user_regset *regset, | ||
23 | unsigned int pos, unsigned int count, | ||
24 | void *kbuf, void __user *ubuf) | ||
25 | { | ||
26 | const struct pt_regs *ptregs = task_pt_regs(target); | ||
27 | const struct callee_regs *cregs = task_callee_regs(target); | ||
28 | int ret = 0; | ||
29 | unsigned int stop_pc_val; | ||
30 | |||
31 | #define REG_O_CHUNK(START, END, PTR) \ | ||
32 | if (!ret) \ | ||
33 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ | ||
34 | offsetof(struct user_regs_struct, START), \ | ||
35 | offsetof(struct user_regs_struct, END)); | ||
36 | |||
37 | #define REG_O_ONE(LOC, PTR) \ | ||
38 | if (!ret) \ | ||
39 | ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \ | ||
40 | offsetof(struct user_regs_struct, LOC), \ | ||
41 | offsetof(struct user_regs_struct, LOC) + 4); | ||
42 | |||
43 | REG_O_CHUNK(scratch, callee, ptregs); | ||
44 | REG_O_CHUNK(callee, efa, cregs); | ||
45 | REG_O_CHUNK(efa, stop_pc, &target->thread.fault_address); | ||
46 | |||
47 | if (!ret) { | ||
48 | if (in_brkpt_trap(ptregs)) { | ||
49 | stop_pc_val = target->thread.fault_address; | ||
50 | pr_debug("\t\tstop_pc (brk-pt)\n"); | ||
51 | } else { | ||
52 | stop_pc_val = ptregs->ret; | ||
53 | pr_debug("\t\tstop_pc (others)\n"); | ||
54 | } | ||
55 | |||
56 | REG_O_ONE(stop_pc, &stop_pc_val); | ||
57 | } | ||
58 | |||
59 | return ret; | ||
60 | } | ||
61 | |||
62 | static int genregs_set(struct task_struct *target, | ||
63 | const struct user_regset *regset, | ||
64 | unsigned int pos, unsigned int count, | ||
65 | const void *kbuf, const void __user *ubuf) | ||
66 | { | ||
67 | const struct pt_regs *ptregs = task_pt_regs(target); | ||
68 | const struct callee_regs *cregs = task_callee_regs(target); | ||
69 | int ret = 0; | ||
70 | |||
71 | #define REG_IN_CHUNK(FIRST, NEXT, PTR) \ | ||
72 | if (!ret) \ | ||
73 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \ | ||
74 | (void *)(PTR), \ | ||
75 | offsetof(struct user_regs_struct, FIRST), \ | ||
76 | offsetof(struct user_regs_struct, NEXT)); | ||
77 | |||
78 | #define REG_IN_ONE(LOC, PTR) \ | ||
79 | if (!ret) \ | ||
80 | ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \ | ||
81 | (void *)(PTR), \ | ||
82 | offsetof(struct user_regs_struct, LOC), \ | ||
83 | offsetof(struct user_regs_struct, LOC) + 4); | ||
84 | |||
85 | #define REG_IGNORE_ONE(LOC) \ | ||
86 | if (!ret) \ | ||
87 | ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \ | ||
88 | offsetof(struct user_regs_struct, LOC), \ | ||
89 | offsetof(struct user_regs_struct, LOC) + 4); | ||
90 | |||
91 | /* TBD: disallow updates to STATUS32, orig_r8 etc*/ | ||
92 | REG_IN_CHUNK(scratch, callee, ptregs); /* pt_regs[bta..orig_r8] */ | ||
93 | REG_IN_CHUNK(callee, efa, cregs); /* callee_regs[r25..r13] */ | ||
94 | REG_IGNORE_ONE(efa); /* efa update invalid */ | ||
95 | REG_IN_ONE(stop_pc, &ptregs->ret); /* stop_pc: PC update */ | ||
96 | |||
97 | return ret; | ||
98 | } | ||
99 | |||
100 | enum arc_getset { | ||
101 | REGSET_GENERAL, | ||
102 | }; | ||
103 | |||
104 | static const struct user_regset arc_regsets[] = { | ||
105 | [REGSET_GENERAL] = { | ||
106 | .core_note_type = NT_PRSTATUS, | ||
107 | .n = ELF_NGREG, | ||
108 | .size = sizeof(unsigned long), | ||
109 | .align = sizeof(unsigned long), | ||
110 | .get = genregs_get, | ||
111 | .set = genregs_set, | ||
112 | } | ||
113 | }; | ||
114 | |||
115 | static const struct user_regset_view user_arc_view = { | ||
116 | .name = UTS_MACHINE, | ||
117 | .e_machine = EM_ARCOMPACT, | ||
118 | .regsets = arc_regsets, | ||
119 | .n = ARRAY_SIZE(arc_regsets) | ||
120 | }; | ||
121 | |||
122 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | ||
123 | { | ||
124 | return &user_arc_view; | ||
125 | } | ||
10 | 126 | ||
11 | void ptrace_disable(struct task_struct *child) | 127 | void ptrace_disable(struct task_struct *child) |
12 | { | 128 | { |
@@ -16,11 +132,27 @@ long arch_ptrace(struct task_struct *child, long request, | |||
16 | unsigned long addr, unsigned long data) | 132 | unsigned long addr, unsigned long data) |
17 | { | 133 | { |
18 | int ret = -EIO; | 134 | int ret = -EIO; |
135 | |||
136 | pr_debug("REQ=%ld: ADDR =0x%lx, DATA=0x%lx)\n", request, addr, data); | ||
137 | |||
138 | switch (request) { | ||
139 | default: | ||
140 | ret = ptrace_request(child, request, addr, data); | ||
141 | break; | ||
142 | } | ||
143 | |||
19 | return ret; | 144 | return ret; |
20 | } | 145 | } |
21 | 146 | ||
147 | asmlinkage int syscall_trace_entry(struct pt_regs *regs) | ||
148 | { | ||
149 | if (tracehook_report_syscall_entry(regs)) | ||
150 | return ULONG_MAX; | ||
22 | 151 | ||
23 | const struct user_regset_view *task_user_regset_view(struct task_struct *task) | 152 | return regs->r8; |
153 | } | ||
154 | |||
155 | asmlinkage void syscall_trace_exit(struct pt_regs *regs) | ||
24 | { | 156 | { |
25 | return (const struct user_regset_view *)NULL; | 157 | tracehook_report_syscall_exit(regs, 0); |
26 | } | 158 | } |