xref: /linux/arch/sh/kernel/ptrace_32.c (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
15933f6d2SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
248b22cf9SPaul Mundt /*
3934135c1SPaul Mundt  * SuperH process tracing
448b22cf9SPaul Mundt  *
5934135c1SPaul Mundt  * Copyright (C) 1999, 2000  Kaz Kojima & Niibe Yutaka
634d0b5afSPaul Mundt  * Copyright (C) 2002 - 2009  Paul Mundt
748b22cf9SPaul Mundt  *
8934135c1SPaul Mundt  * Audit support by Yuichi Nakamura <ynakam@hitachisoft.jp>
948b22cf9SPaul Mundt  */
1048b22cf9SPaul Mundt #include <linux/kernel.h>
1148b22cf9SPaul Mundt #include <linux/sched.h>
1268db0cf1SIngo Molnar #include <linux/sched/task_stack.h>
1348b22cf9SPaul Mundt #include <linux/mm.h>
1448b22cf9SPaul Mundt #include <linux/smp.h>
1548b22cf9SPaul Mundt #include <linux/errno.h>
1648b22cf9SPaul Mundt #include <linux/ptrace.h>
1748b22cf9SPaul Mundt #include <linux/user.h>
1848b22cf9SPaul Mundt #include <linux/security.h>
1948b22cf9SPaul Mundt #include <linux/signal.h>
2048b22cf9SPaul Mundt #include <linux/io.h>
211322b9deSYuichi Nakamura #include <linux/audit.h>
22c4637d47SPaul Mundt #include <linux/seccomp.h>
23934135c1SPaul Mundt #include <linux/elf.h>
24934135c1SPaul Mundt #include <linux/regset.h>
2534d0b5afSPaul Mundt #include <linux/hw_breakpoint.h>
267c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
2748b22cf9SPaul Mundt #include <asm/processor.h>
2848b22cf9SPaul Mundt #include <asm/mmu_context.h>
29fa43972fSPaul Mundt #include <asm/syscalls.h>
30e7ab3cd2SPaul Mundt #include <asm/fpu.h>
3148b22cf9SPaul Mundt 
32a74f7e04SPaul Mundt #define CREATE_TRACE_POINTS
33a74f7e04SPaul Mundt #include <trace/events/syscalls.h>
34c652d780SMatt Fleming 
3548b22cf9SPaul Mundt /*
3648b22cf9SPaul Mundt  * This routine will get a word off of the process kernel stack.
3748b22cf9SPaul Mundt  */
get_stack_long(struct task_struct * task,int offset)3848b22cf9SPaul Mundt static inline int get_stack_long(struct task_struct *task, int offset)
3948b22cf9SPaul Mundt {
4048b22cf9SPaul Mundt 	unsigned char *stack;
4148b22cf9SPaul Mundt 
4248b22cf9SPaul Mundt 	stack = (unsigned char *)task_pt_regs(task);
4348b22cf9SPaul Mundt 	stack += offset;
4448b22cf9SPaul Mundt 	return (*((int *)stack));
4548b22cf9SPaul Mundt }
4648b22cf9SPaul Mundt 
4748b22cf9SPaul Mundt /*
4848b22cf9SPaul Mundt  * This routine will put a word on the process kernel stack.
4948b22cf9SPaul Mundt  */
put_stack_long(struct task_struct * task,int offset,unsigned long data)5048b22cf9SPaul Mundt static inline int put_stack_long(struct task_struct *task, int offset,
5148b22cf9SPaul Mundt 				 unsigned long data)
5248b22cf9SPaul Mundt {
5348b22cf9SPaul Mundt 	unsigned char *stack;
5448b22cf9SPaul Mundt 
5548b22cf9SPaul Mundt 	stack = (unsigned char *)task_pt_regs(task);
5648b22cf9SPaul Mundt 	stack += offset;
5748b22cf9SPaul Mundt 	*(unsigned long *) stack = data;
5848b22cf9SPaul Mundt 	return 0;
5948b22cf9SPaul Mundt }
6048b22cf9SPaul Mundt 
ptrace_triggered(struct perf_event * bp,struct perf_sample_data * data,struct pt_regs * regs)61a8b0ca17SPeter Zijlstra void ptrace_triggered(struct perf_event *bp,
6234d0b5afSPaul Mundt 		      struct perf_sample_data *data, struct pt_regs *regs)
6334d0b5afSPaul Mundt {
6434d0b5afSPaul Mundt 	struct perf_event_attr attr;
6534d0b5afSPaul Mundt 
6634d0b5afSPaul Mundt 	/*
6734d0b5afSPaul Mundt 	 * Disable the breakpoint request here since ptrace has defined a
6834d0b5afSPaul Mundt 	 * one-shot behaviour for breakpoint exceptions.
6934d0b5afSPaul Mundt 	 */
7034d0b5afSPaul Mundt 	attr = bp->attr;
7134d0b5afSPaul Mundt 	attr.disabled = true;
7234d0b5afSPaul Mundt 	modify_user_hw_breakpoint(bp, &attr);
7334d0b5afSPaul Mundt }
7434d0b5afSPaul Mundt 
set_single_step(struct task_struct * tsk,unsigned long addr)7534d0b5afSPaul Mundt static int set_single_step(struct task_struct *tsk, unsigned long addr)
7634d0b5afSPaul Mundt {
7734d0b5afSPaul Mundt 	struct thread_struct *thread = &tsk->thread;
7834d0b5afSPaul Mundt 	struct perf_event *bp;
7934d0b5afSPaul Mundt 	struct perf_event_attr attr;
8034d0b5afSPaul Mundt 
8134d0b5afSPaul Mundt 	bp = thread->ptrace_bps[0];
8234d0b5afSPaul Mundt 	if (!bp) {
8373266fc1SFrederic Weisbecker 		ptrace_breakpoint_init(&attr);
8434d0b5afSPaul Mundt 
8534d0b5afSPaul Mundt 		attr.bp_addr = addr;
8634d0b5afSPaul Mundt 		attr.bp_len = HW_BREAKPOINT_LEN_2;
8734d0b5afSPaul Mundt 		attr.bp_type = HW_BREAKPOINT_R;
8834d0b5afSPaul Mundt 
894dc0da86SAvi Kivity 		bp = register_user_hw_breakpoint(&attr, ptrace_triggered,
904dc0da86SAvi Kivity 						 NULL, tsk);
9134d0b5afSPaul Mundt 		if (IS_ERR(bp))
9234d0b5afSPaul Mundt 			return PTR_ERR(bp);
9334d0b5afSPaul Mundt 
9434d0b5afSPaul Mundt 		thread->ptrace_bps[0] = bp;
9534d0b5afSPaul Mundt 	} else {
9634d0b5afSPaul Mundt 		int err;
9734d0b5afSPaul Mundt 
9834d0b5afSPaul Mundt 		attr = bp->attr;
9934d0b5afSPaul Mundt 		attr.bp_addr = addr;
100fb7f045aSDavid Engraf 		/* reenable breakpoint */
101fb7f045aSDavid Engraf 		attr.disabled = false;
10234d0b5afSPaul Mundt 		err = modify_user_hw_breakpoint(bp, &attr);
10334d0b5afSPaul Mundt 		if (unlikely(err))
10434d0b5afSPaul Mundt 			return err;
10534d0b5afSPaul Mundt 	}
10634d0b5afSPaul Mundt 
10734d0b5afSPaul Mundt 	return 0;
10834d0b5afSPaul Mundt }
10934d0b5afSPaul Mundt 
user_enable_single_step(struct task_struct * child)110c459dbf2SPaul Mundt void user_enable_single_step(struct task_struct *child)
111c459dbf2SPaul Mundt {
11234d0b5afSPaul Mundt 	unsigned long pc = get_stack_long(child, offsetof(struct pt_regs, pc));
113c459dbf2SPaul Mundt 
114c459dbf2SPaul Mundt 	set_tsk_thread_flag(child, TIF_SINGLESTEP);
11534d0b5afSPaul Mundt 
11634d0b5afSPaul Mundt 	set_single_step(child, pc);
117c459dbf2SPaul Mundt }
118c459dbf2SPaul Mundt 
user_disable_single_step(struct task_struct * child)119c459dbf2SPaul Mundt void user_disable_single_step(struct task_struct *child)
12048b22cf9SPaul Mundt {
12148b22cf9SPaul Mundt 	clear_tsk_thread_flag(child, TIF_SINGLESTEP);
12248b22cf9SPaul Mundt }
12348b22cf9SPaul Mundt 
12448b22cf9SPaul Mundt /*
12548b22cf9SPaul Mundt  * Called by kernel/ptrace.c when detaching..
12648b22cf9SPaul Mundt  *
12748b22cf9SPaul Mundt  * Make sure single step bits etc are not set.
12848b22cf9SPaul Mundt  */
ptrace_disable(struct task_struct * child)12948b22cf9SPaul Mundt void ptrace_disable(struct task_struct *child)
13048b22cf9SPaul Mundt {
131c459dbf2SPaul Mundt 	user_disable_single_step(child);
13248b22cf9SPaul Mundt }
13348b22cf9SPaul Mundt 
genregs_get(struct task_struct * target,const struct user_regset * regset,struct membuf to)134934135c1SPaul Mundt static int genregs_get(struct task_struct *target,
135934135c1SPaul Mundt 		       const struct user_regset *regset,
1363399d90cSAl Viro 		       struct membuf to)
137934135c1SPaul Mundt {
138934135c1SPaul Mundt 	const struct pt_regs *regs = task_pt_regs(target);
139934135c1SPaul Mundt 
1403399d90cSAl Viro 	return membuf_write(&to, regs, sizeof(struct pt_regs));
141934135c1SPaul Mundt }
142934135c1SPaul Mundt 
genregs_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)143934135c1SPaul Mundt static int genregs_set(struct task_struct *target,
144934135c1SPaul Mundt 		       const struct user_regset *regset,
145934135c1SPaul Mundt 		       unsigned int pos, unsigned int count,
146934135c1SPaul Mundt 		       const void *kbuf, const void __user *ubuf)
147934135c1SPaul Mundt {
148934135c1SPaul Mundt 	struct pt_regs *regs = task_pt_regs(target);
149934135c1SPaul Mundt 	int ret;
150934135c1SPaul Mundt 
151934135c1SPaul Mundt 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
152934135c1SPaul Mundt 				 regs->regs,
153934135c1SPaul Mundt 				 0, 16 * sizeof(unsigned long));
154934135c1SPaul Mundt 	if (!ret && count > 0)
155934135c1SPaul Mundt 		ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
156934135c1SPaul Mundt 					 &regs->pc,
157934135c1SPaul Mundt 					 offsetof(struct pt_regs, pc),
158934135c1SPaul Mundt 					 sizeof(struct pt_regs));
159934135c1SPaul Mundt 	if (!ret)
160*aafdac9aSSergey Shtylyov 		user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
161934135c1SPaul Mundt 					  sizeof(struct pt_regs), -1);
162934135c1SPaul Mundt 
163934135c1SPaul Mundt 	return ret;
164934135c1SPaul Mundt }
165934135c1SPaul Mundt 
166e7ab3cd2SPaul Mundt #ifdef CONFIG_SH_FPU
fpregs_get(struct task_struct * target,const struct user_regset * regset,struct membuf to)167bb1a773dSAl Viro static int fpregs_get(struct task_struct *target,
168e7ab3cd2SPaul Mundt 	       const struct user_regset *regset,
1693399d90cSAl Viro 	       struct membuf to)
170e7ab3cd2SPaul Mundt {
171e7ab3cd2SPaul Mundt 	int ret;
172e7ab3cd2SPaul Mundt 
173e7ab3cd2SPaul Mundt 	ret = init_fpu(target);
174e7ab3cd2SPaul Mundt 	if (ret)
175e7ab3cd2SPaul Mundt 		return ret;
176e7ab3cd2SPaul Mundt 
1773399d90cSAl Viro 	return membuf_write(&to, target->thread.xstate,
1783399d90cSAl Viro 			    sizeof(struct user_fpu_struct));
179e7ab3cd2SPaul Mundt }
180e7ab3cd2SPaul Mundt 
fpregs_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)181e7ab3cd2SPaul Mundt static int fpregs_set(struct task_struct *target,
182e7ab3cd2SPaul Mundt 		       const struct user_regset *regset,
183e7ab3cd2SPaul Mundt 		       unsigned int pos, unsigned int count,
184e7ab3cd2SPaul Mundt 		       const void *kbuf, const void __user *ubuf)
185e7ab3cd2SPaul Mundt {
186e7ab3cd2SPaul Mundt 	int ret;
187e7ab3cd2SPaul Mundt 
188e7ab3cd2SPaul Mundt 	ret = init_fpu(target);
189e7ab3cd2SPaul Mundt 	if (ret)
190e7ab3cd2SPaul Mundt 		return ret;
191e7ab3cd2SPaul Mundt 
192e7ab3cd2SPaul Mundt 	set_stopped_child_used_math(target);
193e7ab3cd2SPaul Mundt 
194e7ab3cd2SPaul Mundt 	if ((boot_cpu_data.flags & CPU_HAS_FPU))
195e7ab3cd2SPaul Mundt 		return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1960ea820cfSPaul Mundt 					  &target->thread.xstate->hardfpu, 0, -1);
197e7ab3cd2SPaul Mundt 
198e7ab3cd2SPaul Mundt 	return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
1990ea820cfSPaul Mundt 				  &target->thread.xstate->softfpu, 0, -1);
200e7ab3cd2SPaul Mundt }
201e7ab3cd2SPaul Mundt 
fpregs_active(struct task_struct * target,const struct user_regset * regset)202e7ab3cd2SPaul Mundt static int fpregs_active(struct task_struct *target,
203e7ab3cd2SPaul Mundt 			 const struct user_regset *regset)
204e7ab3cd2SPaul Mundt {
205e7ab3cd2SPaul Mundt 	return tsk_used_math(target) ? regset->n : 0;
206e7ab3cd2SPaul Mundt }
207e7ab3cd2SPaul Mundt #endif
208e7ab3cd2SPaul Mundt 
2095dadb343SPaul Mundt #ifdef CONFIG_SH_DSP
dspregs_get(struct task_struct * target,const struct user_regset * regset,struct membuf to)2105dadb343SPaul Mundt static int dspregs_get(struct task_struct *target,
2115dadb343SPaul Mundt 		       const struct user_regset *regset,
2123399d90cSAl Viro 		       struct membuf to)
2135dadb343SPaul Mundt {
21401ab1039SMichael Trimarchi 	const struct pt_dspregs *regs =
21501ab1039SMichael Trimarchi 		(struct pt_dspregs *)&target->thread.dsp_status.dsp_regs;
2165dadb343SPaul Mundt 
2173399d90cSAl Viro 	return membuf_write(&to, regs, sizeof(struct pt_dspregs));
2185dadb343SPaul Mundt }
2195dadb343SPaul Mundt 
dspregs_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)2205dadb343SPaul Mundt static int dspregs_set(struct task_struct *target,
2215dadb343SPaul Mundt 		       const struct user_regset *regset,
2225dadb343SPaul Mundt 		       unsigned int pos, unsigned int count,
2235dadb343SPaul Mundt 		       const void *kbuf, const void __user *ubuf)
2245dadb343SPaul Mundt {
22501ab1039SMichael Trimarchi 	struct pt_dspregs *regs =
22601ab1039SMichael Trimarchi 		(struct pt_dspregs *)&target->thread.dsp_status.dsp_regs;
2275dadb343SPaul Mundt 	int ret;
2285dadb343SPaul Mundt 
2295dadb343SPaul Mundt 	ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, regs,
2305dadb343SPaul Mundt 				 0, sizeof(struct pt_dspregs));
2315dadb343SPaul Mundt 	if (!ret)
232*aafdac9aSSergey Shtylyov 		user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
2335dadb343SPaul Mundt 					  sizeof(struct pt_dspregs), -1);
2345dadb343SPaul Mundt 
2355dadb343SPaul Mundt 	return ret;
2365dadb343SPaul Mundt }
23772461997SPaul Mundt 
dspregs_active(struct task_struct * target,const struct user_regset * regset)23872461997SPaul Mundt static int dspregs_active(struct task_struct *target,
23972461997SPaul Mundt 			  const struct user_regset *regset)
24072461997SPaul Mundt {
24172461997SPaul Mundt 	struct pt_regs *regs = task_pt_regs(target);
24272461997SPaul Mundt 
24372461997SPaul Mundt 	return regs->sr & SR_DSP ? regset->n : 0;
24472461997SPaul Mundt }
2455dadb343SPaul Mundt #endif
2465dadb343SPaul Mundt 
247eaaaeef3SPaul Mundt const struct pt_regs_offset regoffset_table[] = {
248eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(0),
249eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(1),
250eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(2),
251eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(3),
252eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(4),
253eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(5),
254eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(6),
255eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(7),
256eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(8),
257eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(9),
258eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(10),
259eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(11),
260eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(12),
261eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(13),
262eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(14),
263eaaaeef3SPaul Mundt 	REGS_OFFSET_NAME(15),
264eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(pc),
265eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(pr),
266eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(sr),
267eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(gbr),
268eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(mach),
269eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(macl),
270eaaaeef3SPaul Mundt 	REG_OFFSET_NAME(tra),
271eaaaeef3SPaul Mundt 	REG_OFFSET_END,
272eaaaeef3SPaul Mundt };
273eaaaeef3SPaul Mundt 
274934135c1SPaul Mundt /*
275934135c1SPaul Mundt  * These are our native regset flavours.
276934135c1SPaul Mundt  */
277934135c1SPaul Mundt enum sh_regset {
278934135c1SPaul Mundt 	REGSET_GENERAL,
279e7ab3cd2SPaul Mundt #ifdef CONFIG_SH_FPU
280e7ab3cd2SPaul Mundt 	REGSET_FPU,
281e7ab3cd2SPaul Mundt #endif
2825dadb343SPaul Mundt #ifdef CONFIG_SH_DSP
2835dadb343SPaul Mundt 	REGSET_DSP,
2845dadb343SPaul Mundt #endif
285934135c1SPaul Mundt };
286934135c1SPaul Mundt 
287934135c1SPaul Mundt static const struct user_regset sh_regsets[] = {
288934135c1SPaul Mundt 	/*
289934135c1SPaul Mundt 	 * Format is:
290934135c1SPaul Mundt 	 *	R0 --> R15
291934135c1SPaul Mundt 	 *	PC, PR, SR, GBR, MACH, MACL, TRA
292934135c1SPaul Mundt 	 */
293934135c1SPaul Mundt 	[REGSET_GENERAL] = {
294934135c1SPaul Mundt 		.core_note_type	= NT_PRSTATUS,
295934135c1SPaul Mundt 		.n		= ELF_NGREG,
296934135c1SPaul Mundt 		.size		= sizeof(long),
297934135c1SPaul Mundt 		.align		= sizeof(long),
2983399d90cSAl Viro 		.regset_get		= genregs_get,
299934135c1SPaul Mundt 		.set		= genregs_set,
300934135c1SPaul Mundt 	},
3015dadb343SPaul Mundt 
302e7ab3cd2SPaul Mundt #ifdef CONFIG_SH_FPU
303e7ab3cd2SPaul Mundt 	[REGSET_FPU] = {
304e7ab3cd2SPaul Mundt 		.core_note_type	= NT_PRFPREG,
305e7ab3cd2SPaul Mundt 		.n		= sizeof(struct user_fpu_struct) / sizeof(long),
306e7ab3cd2SPaul Mundt 		.size		= sizeof(long),
307e7ab3cd2SPaul Mundt 		.align		= sizeof(long),
3083399d90cSAl Viro 		.regset_get		= fpregs_get,
309e7ab3cd2SPaul Mundt 		.set		= fpregs_set,
310e7ab3cd2SPaul Mundt 		.active		= fpregs_active,
311e7ab3cd2SPaul Mundt 	},
312e7ab3cd2SPaul Mundt #endif
313e7ab3cd2SPaul Mundt 
3145dadb343SPaul Mundt #ifdef CONFIG_SH_DSP
3155dadb343SPaul Mundt 	[REGSET_DSP] = {
3165dadb343SPaul Mundt 		.n		= sizeof(struct pt_dspregs) / sizeof(long),
3175dadb343SPaul Mundt 		.size		= sizeof(long),
3185dadb343SPaul Mundt 		.align		= sizeof(long),
3193399d90cSAl Viro 		.regset_get		= dspregs_get,
3205dadb343SPaul Mundt 		.set		= dspregs_set,
32172461997SPaul Mundt 		.active		= dspregs_active,
3225dadb343SPaul Mundt 	},
3235dadb343SPaul Mundt #endif
324934135c1SPaul Mundt };
325934135c1SPaul Mundt 
326934135c1SPaul Mundt static const struct user_regset_view user_sh_native_view = {
327934135c1SPaul Mundt 	.name		= "sh",
328934135c1SPaul Mundt 	.e_machine	= EM_SH,
329934135c1SPaul Mundt 	.regsets	= sh_regsets,
330934135c1SPaul Mundt 	.n		= ARRAY_SIZE(sh_regsets),
331934135c1SPaul Mundt };
332934135c1SPaul Mundt 
task_user_regset_view(struct task_struct * task)333f9540eceSPaul Mundt const struct user_regset_view *task_user_regset_view(struct task_struct *task)
334f9540eceSPaul Mundt {
335f9540eceSPaul Mundt 	return &user_sh_native_view;
336f9540eceSPaul Mundt }
337f9540eceSPaul Mundt 
arch_ptrace(struct task_struct * child,long request,unsigned long addr,unsigned long data)3389b05a69eSNamhyung Kim long arch_ptrace(struct task_struct *child, long request,
3399b05a69eSNamhyung Kim 		 unsigned long addr, unsigned long data)
34048b22cf9SPaul Mundt {
341fa43972fSPaul Mundt 	unsigned long __user *datap = (unsigned long __user *)data;
34248b22cf9SPaul Mundt 	int ret;
34348b22cf9SPaul Mundt 
34448b22cf9SPaul Mundt 	switch (request) {
34548b22cf9SPaul Mundt 	/* read the word at location addr in the USER area. */
34648b22cf9SPaul Mundt 	case PTRACE_PEEKUSR: {
34748b22cf9SPaul Mundt 		unsigned long tmp;
34848b22cf9SPaul Mundt 
34948b22cf9SPaul Mundt 		ret = -EIO;
35048b22cf9SPaul Mundt 		if ((addr & 3) || addr < 0 ||
35148b22cf9SPaul Mundt 		    addr > sizeof(struct user) - 3)
35248b22cf9SPaul Mundt 			break;
35348b22cf9SPaul Mundt 
35448b22cf9SPaul Mundt 		if (addr < sizeof(struct pt_regs))
35548b22cf9SPaul Mundt 			tmp = get_stack_long(child, addr);
3569e1cb206SNamhyung Kim 		else if (addr >= offsetof(struct user, fpu) &&
3579e1cb206SNamhyung Kim 			 addr < offsetof(struct user, u_fpvalid)) {
35848b22cf9SPaul Mundt 			if (!tsk_used_math(child)) {
3599e1cb206SNamhyung Kim 				if (addr == offsetof(struct user, fpu.fpscr))
36048b22cf9SPaul Mundt 					tmp = FPSCR_INIT;
36148b22cf9SPaul Mundt 				else
36248b22cf9SPaul Mundt 					tmp = 0;
3639e1cb206SNamhyung Kim 			} else {
3649e1cb206SNamhyung Kim 				unsigned long index;
365c49b6ecfSPhil Edworthy 				ret = init_fpu(child);
366c49b6ecfSPhil Edworthy 				if (ret)
367c49b6ecfSPhil Edworthy 					break;
3689e1cb206SNamhyung Kim 				index = addr - offsetof(struct user, fpu);
3699b05a69eSNamhyung Kim 				tmp = ((unsigned long *)child->thread.xstate)
3709e1cb206SNamhyung Kim 					[index >> 2];
3719e1cb206SNamhyung Kim 			}
3729e1cb206SNamhyung Kim 		} else if (addr == offsetof(struct user, u_fpvalid))
37348b22cf9SPaul Mundt 			tmp = !!tsk_used_math(child);
374ba0d4740SPeter Griffin 		else if (addr == PT_TEXT_ADDR)
375ba0d4740SPeter Griffin 			tmp = child->mm->start_code;
376ba0d4740SPeter Griffin 		else if (addr == PT_DATA_ADDR)
377ba0d4740SPeter Griffin 			tmp = child->mm->start_data;
378ba0d4740SPeter Griffin 		else if (addr == PT_TEXT_END_ADDR)
379ba0d4740SPeter Griffin 			tmp = child->mm->end_code;
380ba0d4740SPeter Griffin 		else if (addr == PT_TEXT_LEN)
381ba0d4740SPeter Griffin 			tmp = child->mm->end_code - child->mm->start_code;
38248b22cf9SPaul Mundt 		else
38348b22cf9SPaul Mundt 			tmp = 0;
384fa43972fSPaul Mundt 		ret = put_user(tmp, datap);
38548b22cf9SPaul Mundt 		break;
38648b22cf9SPaul Mundt 	}
38748b22cf9SPaul Mundt 
38848b22cf9SPaul Mundt 	case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
38948b22cf9SPaul Mundt 		ret = -EIO;
39048b22cf9SPaul Mundt 		if ((addr & 3) || addr < 0 ||
39148b22cf9SPaul Mundt 		    addr > sizeof(struct user) - 3)
39248b22cf9SPaul Mundt 			break;
39348b22cf9SPaul Mundt 
39448b22cf9SPaul Mundt 		if (addr < sizeof(struct pt_regs))
39548b22cf9SPaul Mundt 			ret = put_stack_long(child, addr, data);
3969e1cb206SNamhyung Kim 		else if (addr >= offsetof(struct user, fpu) &&
3979e1cb206SNamhyung Kim 			 addr < offsetof(struct user, u_fpvalid)) {
3989e1cb206SNamhyung Kim 			unsigned long index;
399c49b6ecfSPhil Edworthy 			ret = init_fpu(child);
400c49b6ecfSPhil Edworthy 			if (ret)
401c49b6ecfSPhil Edworthy 				break;
4029e1cb206SNamhyung Kim 			index = addr - offsetof(struct user, fpu);
40348b22cf9SPaul Mundt 			set_stopped_child_used_math(child);
4049b05a69eSNamhyung Kim 			((unsigned long *)child->thread.xstate)
4059e1cb206SNamhyung Kim 				[index >> 2] = data;
40648b22cf9SPaul Mundt 			ret = 0;
4079e1cb206SNamhyung Kim 		} else if (addr == offsetof(struct user, u_fpvalid)) {
40848b22cf9SPaul Mundt 			conditional_stopped_child_used_math(data, child);
40948b22cf9SPaul Mundt 			ret = 0;
41048b22cf9SPaul Mundt 		}
41148b22cf9SPaul Mundt 		break;
41248b22cf9SPaul Mundt 
413934135c1SPaul Mundt 	case PTRACE_GETREGS:
414934135c1SPaul Mundt 		return copy_regset_to_user(child, &user_sh_native_view,
415934135c1SPaul Mundt 					   REGSET_GENERAL,
416934135c1SPaul Mundt 					   0, sizeof(struct pt_regs),
4179e1cb206SNamhyung Kim 					   datap);
418934135c1SPaul Mundt 	case PTRACE_SETREGS:
419934135c1SPaul Mundt 		return copy_regset_from_user(child, &user_sh_native_view,
420934135c1SPaul Mundt 					     REGSET_GENERAL,
421934135c1SPaul Mundt 					     0, sizeof(struct pt_regs),
4229e1cb206SNamhyung Kim 					     datap);
423e7ab3cd2SPaul Mundt #ifdef CONFIG_SH_FPU
424e7ab3cd2SPaul Mundt 	case PTRACE_GETFPREGS:
425e7ab3cd2SPaul Mundt 		return copy_regset_to_user(child, &user_sh_native_view,
426e7ab3cd2SPaul Mundt 					   REGSET_FPU,
427e7ab3cd2SPaul Mundt 					   0, sizeof(struct user_fpu_struct),
4289e1cb206SNamhyung Kim 					   datap);
429e7ab3cd2SPaul Mundt 	case PTRACE_SETFPREGS:
430e7ab3cd2SPaul Mundt 		return copy_regset_from_user(child, &user_sh_native_view,
431e7ab3cd2SPaul Mundt 					     REGSET_FPU,
432e7ab3cd2SPaul Mundt 					     0, sizeof(struct user_fpu_struct),
4339e1cb206SNamhyung Kim 					     datap);
434e7ab3cd2SPaul Mundt #endif
43548b22cf9SPaul Mundt #ifdef CONFIG_SH_DSP
4365dadb343SPaul Mundt 	case PTRACE_GETDSPREGS:
4375dadb343SPaul Mundt 		return copy_regset_to_user(child, &user_sh_native_view,
4385dadb343SPaul Mundt 					   REGSET_DSP,
4395dadb343SPaul Mundt 					   0, sizeof(struct pt_dspregs),
4409e1cb206SNamhyung Kim 					   datap);
4415dadb343SPaul Mundt 	case PTRACE_SETDSPREGS:
4425dadb343SPaul Mundt 		return copy_regset_from_user(child, &user_sh_native_view,
4435dadb343SPaul Mundt 					     REGSET_DSP,
4445dadb343SPaul Mundt 					     0, sizeof(struct pt_dspregs),
4459e1cb206SNamhyung Kim 					     datap);
44648b22cf9SPaul Mundt #endif
44748b22cf9SPaul Mundt 	default:
44848b22cf9SPaul Mundt 		ret = ptrace_request(child, request, addr, data);
44948b22cf9SPaul Mundt 		break;
45048b22cf9SPaul Mundt 	}
45148b22cf9SPaul Mundt 
45248b22cf9SPaul Mundt 	return ret;
45348b22cf9SPaul Mundt }
45448b22cf9SPaul Mundt 
do_syscall_trace_enter(struct pt_regs * regs)455ab99c733SPaul Mundt asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
45648b22cf9SPaul Mundt {
457ab99c733SPaul Mundt 	if (test_thread_flag(TIF_SYSCALL_TRACE) &&
458153474baSEric W. Biederman 	    ptrace_report_syscall_entry(regs)) {
459b0cfc315SRich Felker 		regs->regs[0] = -ENOSYS;
460b0cfc315SRich Felker 		return -1;
461b0cfc315SRich Felker 	}
4621322b9deSYuichi Nakamura 
4630bb605c2SMichael Karcher 	if (secure_computing() == -1)
4640bb605c2SMichael Karcher 		return -1;
4650bb605c2SMichael Karcher 
466a74f7e04SPaul Mundt 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
467a74f7e04SPaul Mundt 		trace_sys_enter(regs, regs->regs[0]);
468c652d780SMatt Fleming 
46991397401SEric Paris 	audit_syscall_entry(regs->regs[3], regs->regs[4], regs->regs[5],
4701322b9deSYuichi Nakamura 			    regs->regs[6], regs->regs[7]);
4711322b9deSYuichi Nakamura 
472b0cfc315SRich Felker 	return 0;
473ab99c733SPaul Mundt }
474ab99c733SPaul Mundt 
do_syscall_trace_leave(struct pt_regs * regs)475ab99c733SPaul Mundt asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
476ab99c733SPaul Mundt {
477ab99c733SPaul Mundt 	int step;
478ab99c733SPaul Mundt 
479d7e7528bSEric Paris 	audit_syscall_exit(regs);
480ab99c733SPaul Mundt 
481a74f7e04SPaul Mundt 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
482a74f7e04SPaul Mundt 		trace_sys_exit(regs, regs->regs[0]);
483c652d780SMatt Fleming 
484ab99c733SPaul Mundt 	step = test_thread_flag(TIF_SINGLESTEP);
485ab99c733SPaul Mundt 	if (step || test_thread_flag(TIF_SYSCALL_TRACE))
486153474baSEric W. Biederman 		ptrace_report_syscall_exit(regs, step);
48748b22cf9SPaul Mundt }
488