• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1992 Ross Biro
7  * Copyright (C) Linus Torvalds
8  * Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle
9  * Copyright (C) 1996 David S. Miller
10  * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
11  * Copyright (C) 1999 MIPS Technologies, Inc.
12  * Copyright (C) 2000 Ulf Carlsson
13  *
14  * At this time Linux/MIPS64 only supports syscall tracing, even for 32-bit
15  * binaries.
16  */
17 #include <linux/compiler.h>
18 #include <linux/context_tracking.h>
19 #include <linux/elf.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/mm.h>
23 #include <linux/errno.h>
24 #include <linux/ptrace.h>
25 #include <linux/regset.h>
26 #include <linux/smp.h>
27 #include <linux/security.h>
28 #include <linux/tracehook.h>
29 #include <linux/audit.h>
30 #include <linux/seccomp.h>
31 #include <linux/ftrace.h>
32 
33 #include <asm/byteorder.h>
34 #include <asm/cpu.h>
35 #include <asm/dsp.h>
36 #include <asm/fpu.h>
37 #include <asm/mipsregs.h>
38 #include <asm/mipsmtregs.h>
39 #include <asm/pgtable.h>
40 #include <asm/page.h>
41 #include <asm/syscall.h>
42 #include <asm/uaccess.h>
43 #include <asm/bootinfo.h>
44 #include <asm/reg.h>
45 
46 #define CREATE_TRACE_POINTS
47 #include <trace/events/syscalls.h>
48 
49 /*
50  * Called by kernel/ptrace.c when detaching..
51  *
52  * Make sure single step bits etc are not set.
53  */
ptrace_disable(struct task_struct * child)54 void ptrace_disable(struct task_struct *child)
55 {
56 	/* Don't load the watchpoint registers for the ex-child. */
57 	clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
58 }
59 
60 /*
61  * Read a general register set.	 We always use the 64-bit format, even
62  * for 32-bit kernels and for 32-bit processes on a 64-bit kernel.
63  * Registers are sign extended to fill the available space.
64  */
ptrace_getregs(struct task_struct * child,struct user_pt_regs __user * data)65 int ptrace_getregs(struct task_struct *child, struct user_pt_regs __user *data)
66 {
67 	struct pt_regs *regs;
68 	int i;
69 
70 	if (!access_ok(VERIFY_WRITE, data, 38 * 8))
71 		return -EIO;
72 
73 	regs = task_pt_regs(child);
74 
75 	for (i = 0; i < 32; i++)
76 		__put_user((long)regs->regs[i], (__s64 __user *)&data->regs[i]);
77 	__put_user((long)regs->lo, (__s64 __user *)&data->lo);
78 	__put_user((long)regs->hi, (__s64 __user *)&data->hi);
79 	__put_user((long)regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
80 	__put_user((long)regs->cp0_badvaddr, (__s64 __user *)&data->cp0_badvaddr);
81 	__put_user((long)regs->cp0_status, (__s64 __user *)&data->cp0_status);
82 	__put_user((long)regs->cp0_cause, (__s64 __user *)&data->cp0_cause);
83 
84 	return 0;
85 }
86 
87 /*
88  * Write a general register set.  As for PTRACE_GETREGS, we always use
89  * the 64-bit format.  On a 32-bit kernel only the lower order half
90  * (according to endianness) will be used.
91  */
ptrace_setregs(struct task_struct * child,struct user_pt_regs __user * data)92 int ptrace_setregs(struct task_struct *child, struct user_pt_regs __user *data)
93 {
94 	struct pt_regs *regs;
95 	int i;
96 
97 	if (!access_ok(VERIFY_READ, data, 38 * 8))
98 		return -EIO;
99 
100 	regs = task_pt_regs(child);
101 
102 	for (i = 0; i < 32; i++)
103 		__get_user(regs->regs[i], (__s64 __user *)&data->regs[i]);
104 	__get_user(regs->lo, (__s64 __user *)&data->lo);
105 	__get_user(regs->hi, (__s64 __user *)&data->hi);
106 	__get_user(regs->cp0_epc, (__s64 __user *)&data->cp0_epc);
107 
108 	/* badvaddr, status, and cause may not be written.  */
109 
110 	return 0;
111 }
112 
ptrace_getfpregs(struct task_struct * child,__u32 __user * data)113 int ptrace_getfpregs(struct task_struct *child, __u32 __user *data)
114 {
115 	int i;
116 
117 	if (!access_ok(VERIFY_WRITE, data, 33 * 8))
118 		return -EIO;
119 
120 	if (tsk_used_math(child)) {
121 		union fpureg *fregs = get_fpu_regs(child);
122 		for (i = 0; i < NUM_FPU_REGS; i++)
123 			__put_user(get_fpr64(&fregs[i], 0),
124 				   i + (__u64 __user *)data);
125 	} else {
126 		for (i = 0; i < NUM_FPU_REGS; i++)
127 			__put_user((__u64) -1, i + (__u64 __user *) data);
128 	}
129 
130 	__put_user(child->thread.fpu.fcr31, data + 64);
131 	__put_user(boot_cpu_data.fpu_id, data + 65);
132 
133 	return 0;
134 }
135 
ptrace_setfpregs(struct task_struct * child,__u32 __user * data)136 int ptrace_setfpregs(struct task_struct *child, __u32 __user *data)
137 {
138 	union fpureg *fregs;
139 	u64 fpr_val;
140 	int i;
141 
142 	if (!access_ok(VERIFY_READ, data, 33 * 8))
143 		return -EIO;
144 
145 	init_fp_ctx(child);
146 	fregs = get_fpu_regs(child);
147 
148 	for (i = 0; i < NUM_FPU_REGS; i++) {
149 		__get_user(fpr_val, i + (__u64 __user *)data);
150 		set_fpr64(&fregs[i], 0, fpr_val);
151 	}
152 
153 	__get_user(child->thread.fpu.fcr31, data + 64);
154 	child->thread.fpu.fcr31 &= ~FPU_CSR_ALL_X;
155 
156 	/* FIR may not be written.  */
157 
158 	return 0;
159 }
160 
ptrace_get_watch_regs(struct task_struct * child,struct pt_watch_regs __user * addr)161 int ptrace_get_watch_regs(struct task_struct *child,
162 			  struct pt_watch_regs __user *addr)
163 {
164 	enum pt_watch_style style;
165 	int i;
166 
167 	if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
168 		return -EIO;
169 	if (!access_ok(VERIFY_WRITE, addr, sizeof(struct pt_watch_regs)))
170 		return -EIO;
171 
172 #ifdef CONFIG_32BIT
173 	style = pt_watch_style_mips32;
174 #define WATCH_STYLE mips32
175 #else
176 	style = pt_watch_style_mips64;
177 #define WATCH_STYLE mips64
178 #endif
179 
180 	__put_user(style, &addr->style);
181 	__put_user(boot_cpu_data.watch_reg_use_cnt,
182 		   &addr->WATCH_STYLE.num_valid);
183 	for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
184 		__put_user(child->thread.watch.mips3264.watchlo[i],
185 			   &addr->WATCH_STYLE.watchlo[i]);
186 		__put_user(child->thread.watch.mips3264.watchhi[i] & 0xfff,
187 			   &addr->WATCH_STYLE.watchhi[i]);
188 		__put_user(boot_cpu_data.watch_reg_masks[i],
189 			   &addr->WATCH_STYLE.watch_masks[i]);
190 	}
191 	for (; i < 8; i++) {
192 		__put_user(0, &addr->WATCH_STYLE.watchlo[i]);
193 		__put_user(0, &addr->WATCH_STYLE.watchhi[i]);
194 		__put_user(0, &addr->WATCH_STYLE.watch_masks[i]);
195 	}
196 
197 	return 0;
198 }
199 
ptrace_set_watch_regs(struct task_struct * child,struct pt_watch_regs __user * addr)200 int ptrace_set_watch_regs(struct task_struct *child,
201 			  struct pt_watch_regs __user *addr)
202 {
203 	int i;
204 	int watch_active = 0;
205 	unsigned long lt[NUM_WATCH_REGS];
206 	u16 ht[NUM_WATCH_REGS];
207 
208 	if (!cpu_has_watch || boot_cpu_data.watch_reg_use_cnt == 0)
209 		return -EIO;
210 	if (!access_ok(VERIFY_READ, addr, sizeof(struct pt_watch_regs)))
211 		return -EIO;
212 	/* Check the values. */
213 	for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
214 		__get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
215 #ifdef CONFIG_32BIT
216 		if (lt[i] & USER_DS.seg)
217 			return -EINVAL;
218 #else
219 		if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
220 			if (lt[i] & 0xffffffff80000000UL)
221 				return -EINVAL;
222 		} else {
223 			if (lt[i] & USER_DS.seg)
224 				return -EINVAL;
225 		}
226 #endif
227 		__get_user(ht[i], &addr->WATCH_STYLE.watchhi[i]);
228 		if (ht[i] & ~0xff8)
229 			return -EINVAL;
230 	}
231 	/* Install them. */
232 	for (i = 0; i < boot_cpu_data.watch_reg_use_cnt; i++) {
233 		if (lt[i] & 7)
234 			watch_active = 1;
235 		child->thread.watch.mips3264.watchlo[i] = lt[i];
236 		/* Set the G bit. */
237 		child->thread.watch.mips3264.watchhi[i] = ht[i];
238 	}
239 
240 	if (watch_active)
241 		set_tsk_thread_flag(child, TIF_LOAD_WATCH);
242 	else
243 		clear_tsk_thread_flag(child, TIF_LOAD_WATCH);
244 
245 	return 0;
246 }
247 
mips_vdso_ptrace_get(struct task_struct * child,unsigned long addr,unsigned long data,int size)248 int mips_vdso_ptrace_get(struct task_struct *child, unsigned long addr,
249 			 unsigned long data, int size)
250 {
251 	unsigned long uLong;
252 	u32 uInt;
253 	int len;
254 	int pos;
255 	int ret;
256 	void * space;
257 
258 	if (size == sizeof(unsigned long))
259 		space = (void *)&uLong;
260 	else
261 		space = (void *)&uInt;
262 
263 	len = (unsigned long)child->mm->context.vdso - addr;
264 	if (len > 0) {
265 		ret = access_process_vm(child, addr, &space, len, 0);
266 		if (ret != len)
267 			return -EIO;
268 		pos = len;
269 		len = size - len;
270 	} else {
271 		pos = 0;
272 		len = size;
273 	}
274 
275 	memcpy(space + pos,
276 	       (void *)addr - child->mm->context.vdso +
277 		current->mm->context.vdso + pos,
278 	       len);
279 
280 	if (size == sizeof(unsigned long)) {
281 		ret = put_user(uLong, (unsigned long __user *) data);
282 	} else {
283 		ret = put_user(uInt, (u32 __user *) data);
284 	}
285 	return ret;
286 }
287 
288 /* regset get/set implementations */
289 
290 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
291 
gpr32_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)292 static int gpr32_get(struct task_struct *target,
293 		     const struct user_regset *regset,
294 		     unsigned int pos, unsigned int count,
295 		     void *kbuf, void __user *ubuf)
296 {
297 	struct pt_regs *regs = task_pt_regs(target);
298 	u32 uregs[ELF_NGREG] = {};
299 	unsigned i;
300 
301 	for (i = MIPS32_EF_R1; i <= MIPS32_EF_R31; i++) {
302 		/* k0/k1 are copied as zero. */
303 		if (i == MIPS32_EF_R26 || i == MIPS32_EF_R27)
304 			continue;
305 
306 		uregs[i] = regs->regs[i - MIPS32_EF_R0];
307 	}
308 
309 	uregs[MIPS32_EF_LO] = regs->lo;
310 	uregs[MIPS32_EF_HI] = regs->hi;
311 	uregs[MIPS32_EF_CP0_EPC] = regs->cp0_epc;
312 	uregs[MIPS32_EF_CP0_BADVADDR] = regs->cp0_badvaddr;
313 	uregs[MIPS32_EF_CP0_STATUS] = regs->cp0_status;
314 	uregs[MIPS32_EF_CP0_CAUSE] = regs->cp0_cause;
315 
316 	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
317 				   sizeof(uregs));
318 }
319 
gpr32_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)320 static int gpr32_set(struct task_struct *target,
321 		     const struct user_regset *regset,
322 		     unsigned int pos, unsigned int count,
323 		     const void *kbuf, const void __user *ubuf)
324 {
325 	struct pt_regs *regs = task_pt_regs(target);
326 	u32 uregs[ELF_NGREG];
327 	unsigned start, num_regs, i;
328 	int err;
329 
330 	start = pos / sizeof(u32);
331 	num_regs = count / sizeof(u32);
332 
333 	if (start + num_regs > ELF_NGREG)
334 		return -EIO;
335 
336 	err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
337 				 sizeof(uregs));
338 	if (err)
339 		return err;
340 
341 	for (i = start; i < num_regs; i++) {
342 		/*
343 		 * Cast all values to signed here so that if this is a 64-bit
344 		 * kernel, the supplied 32-bit values will be sign extended.
345 		 */
346 		switch (i) {
347 		case MIPS32_EF_R1 ... MIPS32_EF_R25:
348 			/* k0/k1 are ignored. */
349 		case MIPS32_EF_R28 ... MIPS32_EF_R31:
350 			regs->regs[i - MIPS32_EF_R0] = (s32)uregs[i];
351 			break;
352 		case MIPS32_EF_LO:
353 			regs->lo = (s32)uregs[i];
354 			break;
355 		case MIPS32_EF_HI:
356 			regs->hi = (s32)uregs[i];
357 			break;
358 		case MIPS32_EF_CP0_EPC:
359 			regs->cp0_epc = (s32)uregs[i];
360 			break;
361 		}
362 	}
363 
364 	return 0;
365 }
366 
367 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
368 
369 #ifdef CONFIG_64BIT
370 
gpr64_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)371 static int gpr64_get(struct task_struct *target,
372 		     const struct user_regset *regset,
373 		     unsigned int pos, unsigned int count,
374 		     void *kbuf, void __user *ubuf)
375 {
376 	struct pt_regs *regs = task_pt_regs(target);
377 	u64 uregs[ELF_NGREG] = {};
378 	unsigned i;
379 
380 	for (i = MIPS64_EF_R1; i <= MIPS64_EF_R31; i++) {
381 		/* k0/k1 are copied as zero. */
382 		if (i == MIPS64_EF_R26 || i == MIPS64_EF_R27)
383 			continue;
384 
385 		uregs[i] = regs->regs[i - MIPS64_EF_R0];
386 	}
387 
388 	uregs[MIPS64_EF_LO] = regs->lo;
389 	uregs[MIPS64_EF_HI] = regs->hi;
390 	uregs[MIPS64_EF_CP0_EPC] = regs->cp0_epc;
391 	uregs[MIPS64_EF_CP0_BADVADDR] = regs->cp0_badvaddr;
392 	uregs[MIPS64_EF_CP0_STATUS] = regs->cp0_status;
393 	uregs[MIPS64_EF_CP0_CAUSE] = regs->cp0_cause;
394 
395 	return user_regset_copyout(&pos, &count, &kbuf, &ubuf, uregs, 0,
396 				   sizeof(uregs));
397 }
398 
gpr64_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)399 static int gpr64_set(struct task_struct *target,
400 		     const struct user_regset *regset,
401 		     unsigned int pos, unsigned int count,
402 		     const void *kbuf, const void __user *ubuf)
403 {
404 	struct pt_regs *regs = task_pt_regs(target);
405 	u64 uregs[ELF_NGREG];
406 	unsigned start, num_regs, i;
407 	int err;
408 
409 	start = pos / sizeof(u64);
410 	num_regs = count / sizeof(u64);
411 
412 	if (start + num_regs > ELF_NGREG)
413 		return -EIO;
414 
415 	err = user_regset_copyin(&pos, &count, &kbuf, &ubuf, uregs, 0,
416 				 sizeof(uregs));
417 	if (err)
418 		return err;
419 
420 	for (i = start; i < num_regs; i++) {
421 		switch (i) {
422 		case MIPS64_EF_R1 ... MIPS64_EF_R25:
423 			/* k0/k1 are ignored. */
424 		case MIPS64_EF_R28 ... MIPS64_EF_R31:
425 			regs->regs[i - MIPS64_EF_R0] = uregs[i];
426 			break;
427 		case MIPS64_EF_LO:
428 			regs->lo = uregs[i];
429 			break;
430 		case MIPS64_EF_HI:
431 			regs->hi = uregs[i];
432 			break;
433 		case MIPS64_EF_CP0_EPC:
434 			regs->cp0_epc = uregs[i];
435 			break;
436 		}
437 	}
438 
439 	return 0;
440 }
441 
442 #endif /* CONFIG_64BIT */
443 
fpr_get(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,void * kbuf,void __user * ubuf)444 static int fpr_get(struct task_struct *target,
445 		   const struct user_regset *regset,
446 		   unsigned int pos, unsigned int count,
447 		   void *kbuf, void __user *ubuf)
448 {
449 	unsigned i;
450 	int err;
451 	u64 fpr_val;
452 
453 	/* XXX fcr31  */
454 
455 	if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
456 		return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
457 					   &target->thread.fpu,
458 					   0, sizeof(elf_fpregset_t));
459 
460 	for (i = 0; i < NUM_FPU_REGS; i++) {
461 		fpr_val = get_fpr64(&target->thread.fpu.fpr[i], 0);
462 		err = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
463 					  &fpr_val, i * sizeof(elf_fpreg_t),
464 					  (i + 1) * sizeof(elf_fpreg_t));
465 		if (err)
466 			return err;
467 	}
468 
469 	return 0;
470 }
471 
fpr_set(struct task_struct * target,const struct user_regset * regset,unsigned int pos,unsigned int count,const void * kbuf,const void __user * ubuf)472 static int fpr_set(struct task_struct *target,
473 		   const struct user_regset *regset,
474 		   unsigned int pos, unsigned int count,
475 		   const void *kbuf, const void __user *ubuf)
476 {
477 	unsigned i;
478 	int err;
479 	u64 fpr_val;
480 
481 	/* XXX fcr31  */
482 
483 	if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t))
484 		return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
485 					  &target->thread.fpu,
486 					  0, sizeof(elf_fpregset_t));
487 
488 	for (i = 0; i < NUM_FPU_REGS; i++) {
489 		err = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
490 					 &fpr_val, i * sizeof(elf_fpreg_t),
491 					 (i + 1) * sizeof(elf_fpreg_t));
492 		if (err)
493 			return err;
494 		set_fpr64(&target->thread.fpu.fpr[i], 0, fpr_val);
495 	}
496 
497 	return 0;
498 }
499 
500 enum mips_regset {
501 	REGSET_GPR,
502 	REGSET_FPR,
503 };
504 
505 #if defined(CONFIG_32BIT) || defined(CONFIG_MIPS32_O32)
506 
507 static const struct user_regset mips_regsets[] = {
508 	[REGSET_GPR] = {
509 		.core_note_type	= NT_PRSTATUS,
510 		.n		= ELF_NGREG,
511 		.size		= sizeof(unsigned int),
512 		.align		= sizeof(unsigned int),
513 		.get		= gpr32_get,
514 		.set		= gpr32_set,
515 	},
516 	[REGSET_FPR] = {
517 		.core_note_type	= NT_PRFPREG,
518 		.n		= ELF_NFPREG,
519 		.size		= sizeof(elf_fpreg_t),
520 		.align		= sizeof(elf_fpreg_t),
521 		.get		= fpr_get,
522 		.set		= fpr_set,
523 	},
524 };
525 
526 static const struct user_regset_view user_mips_view = {
527 	.name		= "mips",
528 	.e_machine	= ELF_ARCH,
529 	.ei_osabi	= ELF_OSABI,
530 	.regsets	= mips_regsets,
531 	.n		= ARRAY_SIZE(mips_regsets),
532 };
533 
534 #endif /* CONFIG_32BIT || CONFIG_MIPS32_O32 */
535 
536 #ifdef CONFIG_64BIT
537 
538 static const struct user_regset mips64_regsets[] = {
539 	[REGSET_GPR] = {
540 		.core_note_type	= NT_PRSTATUS,
541 		.n		= ELF_NGREG,
542 		.size		= sizeof(unsigned long),
543 		.align		= sizeof(unsigned long),
544 		.get		= gpr64_get,
545 		.set		= gpr64_set,
546 	},
547 	[REGSET_FPR] = {
548 		.core_note_type	= NT_PRFPREG,
549 		.n		= ELF_NFPREG,
550 		.size		= sizeof(elf_fpreg_t),
551 		.align		= sizeof(elf_fpreg_t),
552 		.get		= fpr_get,
553 		.set		= fpr_set,
554 	},
555 };
556 
557 static const struct user_regset_view user_mips64_view = {
558 	.name		= "mips64",
559 	.e_machine	= ELF_ARCH,
560 	.ei_osabi	= ELF_OSABI,
561 	.regsets	= mips64_regsets,
562 	.n		= ARRAY_SIZE(mips64_regsets),
563 };
564 
565 #endif /* CONFIG_64BIT */
566 
task_user_regset_view(struct task_struct * task)567 const struct user_regset_view *task_user_regset_view(struct task_struct *task)
568 {
569 #ifdef CONFIG_32BIT
570 	return &user_mips_view;
571 #else
572 #ifdef CONFIG_MIPS32_O32
573 	if (test_tsk_thread_flag(task, TIF_32BIT_REGS))
574 		return &user_mips_view;
575 #endif
576 	return &user_mips64_view;
577 #endif
578 }
579 
arch_ptrace(struct task_struct * child,long request,unsigned long addr,unsigned long data)580 long arch_ptrace(struct task_struct *child, long request,
581 		 unsigned long addr, unsigned long data)
582 {
583 	int ret;
584 	void __user *addrp = (void __user *) addr;
585 	void __user *datavp = (void __user *) data;
586 	unsigned long __user *datalp = (void __user *) data;
587 
588 	switch (request) {
589 	/* when I and D space are separate, these will need to be fixed. */
590 	case PTRACE_PEEKTEXT: /* read word at location addr. */
591 	case PTRACE_PEEKDATA:
592 		if (task_thread_info(child)->vdso_page) {
593 			if (((child->mm->context.vdso - sizeof(unsigned long)) <
594 			     addrp) &&
595 			    ((child->mm->context.vdso + PAGE_SIZE) > addrp)) {
596 				if ((child->mm->context.vdso + PAGE_SIZE -
597 				     addrp) < sizeof(unsigned long)) {
598 					ret = -EIO;
599 					break;
600 				}
601 				ret = mips_vdso_ptrace_get(child, addr, data, sizeof(unsigned long));
602 				break;
603 			}
604 		}
605 		ret = generic_ptrace_peekdata(child, addr, data);
606 		break;
607 
608 	/* Read the word at location addr in the USER area. */
609 	case PTRACE_PEEKUSR: {
610 		struct pt_regs *regs;
611 		union fpureg *fregs;
612 		unsigned long tmp = 0;
613 
614 		regs = task_pt_regs(child);
615 		ret = 0;  /* Default return value. */
616 
617 		switch (addr) {
618 		case 0 ... 31:
619 			tmp = regs->regs[addr];
620 			break;
621 		case FPR_BASE ... FPR_BASE + 31:
622 			if (!tsk_used_math(child)) {
623 				/* FP not yet used */
624 				tmp = -1;
625 				break;
626 			}
627 			fregs = get_fpu_regs(child);
628 
629 #ifdef CONFIG_32BIT
630 			if (!test_thread_local_flags(LTIF_FPU_FR)) {
631 				/*
632 				 * The odd registers are actually the high
633 				 * order bits of the values stored in the even
634 				 * registers - unless we're using r2k_switch.S.
635 				 */
636 				tmp = get_fpr32(&fregs[(addr & ~1) - FPR_BASE],
637 						addr & 1);
638 				break;
639 			}
640 #endif
641 			tmp = get_fpr32(&fregs[addr - FPR_BASE], 0);
642 			break;
643 		case PC:
644 			tmp = regs->cp0_epc;
645 			break;
646 		case CAUSE:
647 			tmp = regs->cp0_cause;
648 			break;
649 		case BADVADDR:
650 			tmp = regs->cp0_badvaddr;
651 			break;
652 		case MMHI:
653 			tmp = regs->hi;
654 			break;
655 		case MMLO:
656 			tmp = regs->lo;
657 			break;
658 #ifdef CONFIG_CPU_HAS_SMARTMIPS
659 		case ACX:
660 			tmp = regs->acx;
661 			break;
662 #endif
663 		case FPC_CSR:
664 			tmp = child->thread.fpu.fcr31;
665 			break;
666 		case FPC_EIR:
667 			/* implementation / version register */
668 			tmp = boot_cpu_data.fpu_id;
669 			break;
670 #ifndef CONFIG_CPU_MIPSR6
671 		case DSP_BASE ... DSP_BASE + 5: {
672 			dspreg_t *dregs;
673 
674 			if (!cpu_has_dsp) {
675 				tmp = 0;
676 				ret = -EIO;
677 				goto out;
678 			}
679 			dregs = __get_dsp_regs(child);
680 			tmp = (unsigned long) (dregs[addr - DSP_BASE]);
681 			break;
682 		}
683 		case DSP_CONTROL:
684 			if (!cpu_has_dsp) {
685 				tmp = 0;
686 				ret = -EIO;
687 				goto out;
688 			}
689 			tmp = child->thread.dsp.dspcontrol;
690 			break;
691 #endif /* CONFIG_CPU_MIPSR6 */
692 		default:
693 			tmp = 0;
694 			ret = -EIO;
695 			goto out;
696 		}
697 		ret = put_user(tmp, datalp);
698 		break;
699 	}
700 
701 	/* when I and D space are separate, this will have to be fixed. */
702 	case PTRACE_POKETEXT: /* write the word at location addr. */
703 	case PTRACE_POKEDATA:
704 		if (task_thread_info(child)->vdso_page) {
705 			if (((child->mm->context.vdso - sizeof(unsigned long)) <
706 			     addrp) &&
707 			    ((child->mm->context.vdso + PAGE_SIZE) > addrp)) {
708 				ret = -EIO;
709 				break;
710 			}
711 		}
712 		ret = generic_ptrace_pokedata(child, addr, data);
713 		break;
714 
715 	case PTRACE_POKEUSR: {
716 		struct pt_regs *regs;
717 		ret = 0;
718 		regs = task_pt_regs(child);
719 
720 		switch (addr) {
721 		case 0 ... 31:
722 			regs->regs[addr] = data;
723 			break;
724 		case FPR_BASE ... FPR_BASE + 31: {
725 			union fpureg *fregs = get_fpu_regs(child);
726 
727 			init_fp_ctx(child);
728 #ifdef CONFIG_32BIT
729 			if (!test_thread_local_flags(LTIF_FPU_FR)) {
730 				/*
731 				 * The odd registers are actually the high
732 				 * order bits of the values stored in the even
733 				 * registers - unless we're using r2k_switch.S.
734 				 */
735 				set_fpr32(&fregs[(addr & ~1) - FPR_BASE],
736 					  addr & 1, data);
737 				break;
738 			}
739 #endif
740 			set_fpr64(&fregs[addr - FPR_BASE], 0, data);
741 			break;
742 		}
743 		case PC:
744 			regs->cp0_epc = data;
745 			break;
746 		case MMHI:
747 			regs->hi = data;
748 			break;
749 		case MMLO:
750 			regs->lo = data;
751 			break;
752 #ifdef CONFIG_CPU_HAS_SMARTMIPS
753 		case ACX:
754 			regs->acx = data;
755 			break;
756 #endif
757 		case FPC_CSR:
758 			child->thread.fpu.fcr31 = data & ~FPU_CSR_ALL_X;
759 			break;
760 #ifndef CONFIG_CPU_MIPSR6
761 		case DSP_BASE ... DSP_BASE + 5: {
762 			dspreg_t *dregs;
763 
764 			if (!cpu_has_dsp) {
765 				ret = -EIO;
766 				break;
767 			}
768 
769 			dregs = __get_dsp_regs(child);
770 			dregs[addr - DSP_BASE] = data;
771 			break;
772 		}
773 		case DSP_CONTROL:
774 			if (!cpu_has_dsp) {
775 				ret = -EIO;
776 				break;
777 			}
778 			child->thread.dsp.dspcontrol = data;
779 			break;
780 #endif /* CONFIG_CPU_MIPSR6 */
781 		default:
782 			/* The rest are not allowed. */
783 			ret = -EIO;
784 			break;
785 		}
786 		break;
787 		}
788 
789 	case PTRACE_GETREGS:
790 		ret = ptrace_getregs(child, datavp);
791 		break;
792 
793 	case PTRACE_SETREGS:
794 		ret = ptrace_setregs(child, datavp);
795 		break;
796 
797 	case PTRACE_GETFPREGS:
798 		ret = ptrace_getfpregs(child, datavp);
799 		break;
800 
801 	case PTRACE_SETFPREGS:
802 		ret = ptrace_setfpregs(child, datavp);
803 		break;
804 
805 	case PTRACE_GET_THREAD_AREA:
806 		ret = put_user(task_thread_info(child)->tp_value, datalp);
807 		break;
808 
809 	case PTRACE_GET_WATCH_REGS:
810 		ret = ptrace_get_watch_regs(child, addrp);
811 		break;
812 
813 	case PTRACE_SET_WATCH_REGS:
814 		ret = ptrace_set_watch_regs(child, addrp);
815 		break;
816 
817 	default:
818 		ret = ptrace_request(child, request, addr, data);
819 		break;
820 	}
821  out:
822 	return ret;
823 }
824 
825 /*
826  * Notification of system call entry/exit
827  * - triggered by current->work.syscall_trace
828  */
syscall_trace_enter(struct pt_regs * regs,long syscall)829 asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
830 {
831 	long ret = 0;
832 	user_exit();
833 
834 	if (secure_computing(syscall) == -1)
835 		return -1;
836 
837 	if (test_thread_flag(TIF_SYSCALL_TRACE) &&
838 	    tracehook_report_syscall_entry(regs))
839 		ret = -1;
840 
841 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
842 		trace_sys_enter(regs, regs->regs[2]);
843 
844 	audit_syscall_entry(syscall_get_arch(),
845 			    syscall,
846 			    regs->regs[4], regs->regs[5],
847 			    regs->regs[6], regs->regs[7]);
848 	return syscall;
849 }
850 
851 /*
852  * Notification of system call entry/exit
853  * - triggered by current->work.syscall_trace
854  */
syscall_trace_leave(struct pt_regs * regs)855 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
856 {
857         /*
858 	 * We may come here right after calling schedule_user()
859 	 * or do_notify_resume(), in which case we can be in RCU
860 	 * user mode.
861 	 */
862 	user_exit();
863 
864 	audit_syscall_exit(regs);
865 
866 	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
867 		trace_sys_exit(regs, regs->regs[2]);
868 
869 	if (test_thread_flag(TIF_SYSCALL_TRACE))
870 		tracehook_report_syscall_exit(regs, 0);
871 
872 	user_enter();
873 }
874