aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/kernel/ptrace_32.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sh/kernel/ptrace_32.c')
-rw-r--r--arch/sh/kernel/ptrace_32.c298
1 files changed, 252 insertions, 46 deletions
diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c
index 035cb300d3dc..29ca09d24ef8 100644
--- a/arch/sh/kernel/ptrace_32.c
+++ b/arch/sh/kernel/ptrace_32.c
@@ -1,12 +1,14 @@
1/* 1/*
2 * linux/arch/sh/kernel/ptrace.c 2 * SuperH process tracing
3 * 3 *
4 * Original x86 implementation: 4 * Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka
5 * By Ross Biro 1/23/92 5 * Copyright (C) 2002 - 2008 Paul Mundt
6 * edited by Linus Torvalds
7 * 6 *
8 * SuperH version: Copyright (C) 1999, 2000 Kaz Kojima & Niibe Yutaka 7 * Audit support by Yuichi Nakamura <ynakam@hitachisoft.jp>
9 * Audit support: Yuichi Nakamura <ynakam@hitachisoft.jp> 8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
10 */ 12 */
11#include <linux/kernel.h> 13#include <linux/kernel.h>
12#include <linux/sched.h> 14#include <linux/sched.h>
@@ -22,16 +24,15 @@
22#include <linux/audit.h> 24#include <linux/audit.h>
23#include <linux/seccomp.h> 25#include <linux/seccomp.h>
24#include <linux/tracehook.h> 26#include <linux/tracehook.h>
27#include <linux/elf.h>
28#include <linux/regset.h>
25#include <asm/uaccess.h> 29#include <asm/uaccess.h>
26#include <asm/pgtable.h> 30#include <asm/pgtable.h>
27#include <asm/system.h> 31#include <asm/system.h>
28#include <asm/processor.h> 32#include <asm/processor.h>
29#include <asm/mmu_context.h> 33#include <asm/mmu_context.h>
30 34#include <asm/syscalls.h>
31/* 35#include <asm/fpu.h>
32 * does not yet catch signals sent when the child dies.
33 * in exit.c or in signal.c.
34 */
35 36
36/* 37/*
37 * This routine will get a word off of the process kernel stack. 38 * This routine will get a word off of the process kernel stack.
@@ -61,16 +62,12 @@ static inline int put_stack_long(struct task_struct *task, int offset,
61 62
62void user_enable_single_step(struct task_struct *child) 63void user_enable_single_step(struct task_struct *child)
63{ 64{
64 struct pt_regs *regs = task_pt_regs(child);
65 long pc;
66
67 pc = get_stack_long(child, (long)&regs->pc);
68
69 /* Next scheduling will set up UBC */ 65 /* Next scheduling will set up UBC */
70 if (child->thread.ubc_pc == 0) 66 if (child->thread.ubc_pc == 0)
71 ubc_usercnt += 1; 67 ubc_usercnt += 1;
72 68
73 child->thread.ubc_pc = pc; 69 child->thread.ubc_pc = get_stack_long(child,
70 offsetof(struct pt_regs, pc));
74 71
75 set_tsk_thread_flag(child, TIF_SINGLESTEP); 72 set_tsk_thread_flag(child, TIF_SINGLESTEP);
76} 73}
@@ -102,9 +99,213 @@ void ptrace_disable(struct task_struct *child)
102 user_disable_single_step(child); 99 user_disable_single_step(child);
103} 100}
104 101
102static int genregs_get(struct task_struct *target,
103 const struct user_regset *regset,
104 unsigned int pos, unsigned int count,
105 void *kbuf, void __user *ubuf)
106{
107 const struct pt_regs *regs = task_pt_regs(target);
108 int ret;
109
110 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
111 regs->regs,
112 0, 16 * sizeof(unsigned long));
113 if (!ret)
114 /* PC, PR, SR, GBR, MACH, MACL, TRA */
115 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
116 &regs->pc,
117 offsetof(struct pt_regs, pc),
118 sizeof(struct pt_regs));
119 if (!ret)
120 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
121 sizeof(struct pt_regs), -1);
122
123 return ret;
124}
125
126static int genregs_set(struct task_struct *target,
127 const struct user_regset *regset,
128 unsigned int pos, unsigned int count,
129 const void *kbuf, const void __user *ubuf)
130{
131 struct pt_regs *regs = task_pt_regs(target);
132 int ret;
133
134 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
135 regs->regs,
136 0, 16 * sizeof(unsigned long));
137 if (!ret && count > 0)
138 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
139 &regs->pc,
140 offsetof(struct pt_regs, pc),
141 sizeof(struct pt_regs));
142 if (!ret)
143 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
144 sizeof(struct pt_regs), -1);
145
146 return ret;
147}
148
149#ifdef CONFIG_SH_FPU
150int fpregs_get(struct task_struct *target,
151 const struct user_regset *regset,
152 unsigned int pos, unsigned int count,
153 void *kbuf, void __user *ubuf)
154{
155 int ret;
156
157 ret = init_fpu(target);
158 if (ret)
159 return ret;
160
161 if ((boot_cpu_data.flags & CPU_HAS_FPU))
162 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
163 &target->thread.fpu.hard, 0, -1);
164
165 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
166 &target->thread.fpu.soft, 0, -1);
167}
168
169static int fpregs_set(struct task_struct *target,
170 const struct user_regset *regset,
171 unsigned int pos, unsigned int count,
172 const void *kbuf, const void __user *ubuf)
173{
174 int ret;
175
176 ret = init_fpu(target);
177 if (ret)
178 return ret;
179
180 set_stopped_child_used_math(target);
181
182 if ((boot_cpu_data.flags & CPU_HAS_FPU))
183 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
184 &target->thread.fpu.hard, 0, -1);
185
186 return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
187 &target->thread.fpu.soft, 0, -1);
188}
189
190static int fpregs_active(struct task_struct *target,
191 const struct user_regset *regset)
192{
193 return tsk_used_math(target) ? regset->n : 0;
194}
195#endif
196
197#ifdef CONFIG_SH_DSP
198static int dspregs_get(struct task_struct *target,
199 const struct user_regset *regset,
200 unsigned int pos, unsigned int count,
201 void *kbuf, void __user *ubuf)
202{
203 const struct pt_dspregs *regs = task_pt_dspregs(target);
204 int ret;
205
206 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, regs,
207 0, sizeof(struct pt_dspregs));
208 if (!ret)
209 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
210 sizeof(struct pt_dspregs), -1);
211
212 return ret;
213}
214
215static int dspregs_set(struct task_struct *target,
216 const struct user_regset *regset,
217 unsigned int pos, unsigned int count,
218 const void *kbuf, const void __user *ubuf)
219{
220 struct pt_dspregs *regs = task_pt_dspregs(target);
221 int ret;
222
223 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, regs,
224 0, sizeof(struct pt_dspregs));
225 if (!ret)
226 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
227 sizeof(struct pt_dspregs), -1);
228
229 return ret;
230}
231
232static int dspregs_active(struct task_struct *target,
233 const struct user_regset *regset)
234{
235 struct pt_regs *regs = task_pt_regs(target);
236
237 return regs->sr & SR_DSP ? regset->n : 0;
238}
239#endif
240
241/*
242 * These are our native regset flavours.
243 */
244enum sh_regset {
245 REGSET_GENERAL,
246#ifdef CONFIG_SH_FPU
247 REGSET_FPU,
248#endif
249#ifdef CONFIG_SH_DSP
250 REGSET_DSP,
251#endif
252};
253
254static const struct user_regset sh_regsets[] = {
255 /*
256 * Format is:
257 * R0 --> R15
258 * PC, PR, SR, GBR, MACH, MACL, TRA
259 */
260 [REGSET_GENERAL] = {
261 .core_note_type = NT_PRSTATUS,
262 .n = ELF_NGREG,
263 .size = sizeof(long),
264 .align = sizeof(long),
265 .get = genregs_get,
266 .set = genregs_set,
267 },
268
269#ifdef CONFIG_SH_FPU
270 [REGSET_FPU] = {
271 .core_note_type = NT_PRFPREG,
272 .n = sizeof(struct user_fpu_struct) / sizeof(long),
273 .size = sizeof(long),
274 .align = sizeof(long),
275 .get = fpregs_get,
276 .set = fpregs_set,
277 .active = fpregs_active,
278 },
279#endif
280
281#ifdef CONFIG_SH_DSP
282 [REGSET_DSP] = {
283 .n = sizeof(struct pt_dspregs) / sizeof(long),
284 .size = sizeof(long),
285 .align = sizeof(long),
286 .get = dspregs_get,
287 .set = dspregs_set,
288 .active = dspregs_active,
289 },
290#endif
291};
292
293static const struct user_regset_view user_sh_native_view = {
294 .name = "sh",
295 .e_machine = EM_SH,
296 .regsets = sh_regsets,
297 .n = ARRAY_SIZE(sh_regsets),
298};
299
300const struct user_regset_view *task_user_regset_view(struct task_struct *task)
301{
302 return &user_sh_native_view;
303}
304
105long arch_ptrace(struct task_struct *child, long request, long addr, long data) 305long arch_ptrace(struct task_struct *child, long request, long addr, long data)
106{ 306{
107 struct user * dummy = NULL; 307 struct user * dummy = NULL;
308 unsigned long __user *datap = (unsigned long __user *)data;
108 int ret; 309 int ret;
109 310
110 switch (request) { 311 switch (request) {
@@ -133,7 +334,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
133 tmp = !!tsk_used_math(child); 334 tmp = !!tsk_used_math(child);
134 else 335 else
135 tmp = 0; 336 tmp = 0;
136 ret = put_user(tmp, (unsigned long __user *)data); 337 ret = put_user(tmp, datap);
137 break; 338 break;
138 } 339 }
139 340
@@ -157,34 +358,39 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
157 } 358 }
158 break; 359 break;
159 360
361 case PTRACE_GETREGS:
362 return copy_regset_to_user(child, &user_sh_native_view,
363 REGSET_GENERAL,
364 0, sizeof(struct pt_regs),
365 (void __user *)data);
366 case PTRACE_SETREGS:
367 return copy_regset_from_user(child, &user_sh_native_view,
368 REGSET_GENERAL,
369 0, sizeof(struct pt_regs),
370 (const void __user *)data);
371#ifdef CONFIG_SH_FPU
372 case PTRACE_GETFPREGS:
373 return copy_regset_to_user(child, &user_sh_native_view,
374 REGSET_FPU,
375 0, sizeof(struct user_fpu_struct),
376 (void __user *)data);
377 case PTRACE_SETFPREGS:
378 return copy_regset_from_user(child, &user_sh_native_view,
379 REGSET_FPU,
380 0, sizeof(struct user_fpu_struct),
381 (const void __user *)data);
382#endif
160#ifdef CONFIG_SH_DSP 383#ifdef CONFIG_SH_DSP
161 case PTRACE_GETDSPREGS: { 384 case PTRACE_GETDSPREGS:
162 unsigned long dp; 385 return copy_regset_to_user(child, &user_sh_native_view,
163 386 REGSET_DSP,
164 ret = -EIO; 387 0, sizeof(struct pt_dspregs),
165 dp = ((unsigned long) child) + THREAD_SIZE - 388 (void __user *)data);
166 sizeof(struct pt_dspregs); 389 case PTRACE_SETDSPREGS:
167 if (*((int *) (dp - 4)) == SR_FD) { 390 return copy_regset_from_user(child, &user_sh_native_view,
168 copy_to_user((void *)addr, (void *) dp, 391 REGSET_DSP,
169 sizeof(struct pt_dspregs)); 392 0, sizeof(struct pt_dspregs),
170 ret = 0; 393 (const void __user *)data);
171 }
172 break;
173 }
174
175 case PTRACE_SETDSPREGS: {
176 unsigned long dp;
177
178 ret = -EIO;
179 dp = ((unsigned long) child) + THREAD_SIZE -
180 sizeof(struct pt_dspregs);
181 if (*((int *) (dp - 4)) == SR_FD) {
182 copy_from_user((void *) dp, (void *)addr,
183 sizeof(struct pt_dspregs));
184 ret = 0;
185 }
186 break;
187 }
188#endif 394#endif
189#ifdef CONFIG_BINFMT_ELF_FDPIC 395#ifdef CONFIG_BINFMT_ELF_FDPIC
190 case PTRACE_GETFDPIC: { 396 case PTRACE_GETFDPIC: {
@@ -202,7 +408,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
202 } 408 }
203 409
204 ret = 0; 410 ret = 0;
205 if (put_user(tmp, (unsigned long *) data)) { 411 if (put_user(tmp, datap)) {
206 ret = -EFAULT; 412 ret = -EFAULT;
207 break; 413 break;
208 } 414 }