Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* ptrace.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) /* By Ross Biro 1/23/92 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) /* edited by Linus Torvalds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) /* mangled further by Bob Manson (manson@santafe.edu) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) /* more mutilation by David Mosberger (davidm@azstarnet.com) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/audit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/fpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include "proto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define DEBUG	DBG_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	DBG_MEM		= (1<<0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	DBG_BPT		= (1<<1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	DBG_MEM_ALL	= (1<<2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define DBG(fac,args)	{if ((fac) & DEBUG) printk args;}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define DBG(fac,args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define BREAKINST	0x00000080	/* call_pal bpt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * does not yet catch signals sent when the child dies.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * in exit.c or in signal.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Processes always block with the following stack-layout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  *  +================================+ <---- task + 2*PAGE_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  *  | PALcode saved frame (ps, pc,   | ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  *  | gp, a0, a1, a2)		     | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *  +================================+ | struct pt_regs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *  |	        		     | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  *  | frame generated by SAVE_ALL    | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  *  |	        		     | v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *  +================================+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  *  |	        		     | ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  *  | frame saved by do_switch_stack | | struct switch_stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  *  |	        		     | v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  *  +================================+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  * The following table maps a register index into the stack offset at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)  * which the register is saved.  Register indices are 0-31 for integer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)  * regs, 32-63 for fp regs, and 64 for the pc.  Notice that sp and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)  * zero have no stack-slot and need to be treated specially (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * get_reg/put_reg below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	REG_R0 = 0, REG_F0 = 32, REG_FPCR = 63, REG_PC = 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define PT_REG(reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)   (PAGE_SIZE*2 - sizeof(struct pt_regs) + offsetof(struct pt_regs, reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define SW_REG(reg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  (PAGE_SIZE*2 - sizeof(struct pt_regs) - sizeof(struct switch_stack) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)   + offsetof(struct switch_stack, reg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static int regoff[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	PT_REG(	   r0), PT_REG(	   r1), PT_REG(	   r2), PT_REG(	  r3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	PT_REG(	   r4), PT_REG(	   r5), PT_REG(	   r6), PT_REG(	  r7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	PT_REG(	   r8), SW_REG(	   r9), SW_REG(	  r10), SW_REG(	 r11),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	SW_REG(	  r12), SW_REG(	  r13), SW_REG(	  r14), SW_REG(	 r15),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	PT_REG(	  r16), PT_REG(	  r17), PT_REG(	  r18), PT_REG(	 r19),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	PT_REG(	  r20), PT_REG(	  r21), PT_REG(	  r22), PT_REG(	 r23),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	PT_REG(	  r24), PT_REG(	  r25), PT_REG(	  r26), PT_REG(	 r27),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	PT_REG(	  r28), PT_REG(	   gp),		   -1,		   -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	SW_REG(fp[ 0]), SW_REG(fp[ 1]), SW_REG(fp[ 2]), SW_REG(fp[ 3]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	SW_REG(fp[ 4]), SW_REG(fp[ 5]), SW_REG(fp[ 6]), SW_REG(fp[ 7]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	SW_REG(fp[ 8]), SW_REG(fp[ 9]), SW_REG(fp[10]), SW_REG(fp[11]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	SW_REG(fp[12]), SW_REG(fp[13]), SW_REG(fp[14]), SW_REG(fp[15]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	SW_REG(fp[16]), SW_REG(fp[17]), SW_REG(fp[18]), SW_REG(fp[19]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	SW_REG(fp[20]), SW_REG(fp[21]), SW_REG(fp[22]), SW_REG(fp[23]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	SW_REG(fp[24]), SW_REG(fp[25]), SW_REG(fp[26]), SW_REG(fp[27]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	SW_REG(fp[28]), SW_REG(fp[29]), SW_REG(fp[30]), SW_REG(fp[31]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	PT_REG(	   pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static unsigned long zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * Get address of register REGNO in task TASK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static unsigned long *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) get_reg_addr(struct task_struct * task, unsigned long regno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	unsigned long *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (regno == 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		addr = &task_thread_info(task)->pcb.usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	} else if (regno == 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		addr = &task_thread_info(task)->pcb.unique;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	} else if (regno == 31 || regno > 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		zero = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		addr = &zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		addr = task_stack_page(task) + regoff[regno];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * Get contents of register REGNO in task TASK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) get_reg(struct task_struct * task, unsigned long regno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	/* Special hack for fpcr -- combine hardware and software bits.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (regno == 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		unsigned long fpcr = *get_reg_addr(task, regno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		unsigned long swcr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		  = task_thread_info(task)->ieee_state & IEEE_SW_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		swcr = swcr_update_status(swcr, fpcr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		return fpcr | swcr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return *get_reg_addr(task, regno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * Write contents of register REGNO in task TASK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) put_reg(struct task_struct *task, unsigned long regno, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (regno == 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		task_thread_info(task)->ieee_state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		  = ((task_thread_info(task)->ieee_state & ~IEEE_SW_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		     | (data & IEEE_SW_MASK));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		data = (data & FPCR_DYN_MASK) | ieee_swcr_to_fpcr(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	*get_reg_addr(task, regno) = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) read_int(struct task_struct *task, unsigned long addr, int * data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int copied = access_process_vm(task, addr, data, sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			FOLL_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return (copied == sizeof(int)) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) write_int(struct task_struct *task, unsigned long addr, int data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	int copied = access_process_vm(task, addr, &data, sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			FOLL_FORCE | FOLL_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return (copied == sizeof(int)) ? 0 : -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * Set breakpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ptrace_set_bpt(struct task_struct * child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int displ, i, res, reg_b, nsaved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	unsigned int insn, op_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	unsigned long pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	pc  = get_reg(child, REG_PC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	res = read_int(child, pc, (int *) &insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	op_code = insn >> 26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (op_code >= 0x30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		 * It's a branch: instead of trying to figure out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		 * whether the branch will be taken or not, we'll put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		 * a breakpoint at either location.  This is simpler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		 * more reliable, and probably not a whole lot slower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		 * than the alternative approach of emulating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 * branch (emulation can be tricky for fp branches).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		displ = ((s32)(insn << 11)) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		task_thread_info(child)->bpt_addr[nsaved++] = pc + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (displ)		/* guard against unoptimized code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			task_thread_info(child)->bpt_addr[nsaved++]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			  = pc + 4 + displ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		DBG(DBG_BPT, ("execing branch\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	} else if (op_code == 0x1a) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		reg_b = (insn >> 16) & 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		task_thread_info(child)->bpt_addr[nsaved++] = get_reg(child, reg_b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		DBG(DBG_BPT, ("execing jump\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		task_thread_info(child)->bpt_addr[nsaved++] = pc + 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		DBG(DBG_BPT, ("execing normal insn\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/* install breakpoints: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	for (i = 0; i < nsaved; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		res = read_int(child, task_thread_info(child)->bpt_addr[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			       (int *) &insn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		task_thread_info(child)->bpt_insn[i] = insn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		DBG(DBG_BPT, ("    -> next_pc=%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			      task_thread_info(child)->bpt_addr[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		res = write_int(child, task_thread_info(child)->bpt_addr[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				BREAKINST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	task_thread_info(child)->bpt_nsaved = nsaved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * Ensure no single-step breakpoint is pending.  Returns non-zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * value if child was being single-stepped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ptrace_cancel_bpt(struct task_struct * child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int i, nsaved = task_thread_info(child)->bpt_nsaved;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	task_thread_info(child)->bpt_nsaved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (nsaved > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		printk("ptrace_cancel_bpt: bogus nsaved: %d!\n", nsaved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		nsaved = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	for (i = 0; i < nsaved; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		write_int(child, task_thread_info(child)->bpt_addr[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			  task_thread_info(child)->bpt_insn[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return (nsaved != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void user_enable_single_step(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	/* Mark single stepping.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	task_thread_info(child)->bpt_nsaved = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) void user_disable_single_step(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	ptrace_cancel_bpt(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * Called by kernel/ptrace.c when detaching..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * Make sure the single step bit is not set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) void ptrace_disable(struct task_struct *child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	user_disable_single_step(child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) long arch_ptrace(struct task_struct *child, long request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		 unsigned long addr, unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	unsigned long tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	size_t copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	switch (request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	/* When I and D space are separate, these will need to be fixed.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	case PTRACE_PEEKTEXT: /* read word at location addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	case PTRACE_PEEKDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		copied = ptrace_access_vm(child, addr, &tmp, sizeof(tmp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				FOLL_FORCE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		if (copied != sizeof(tmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		force_successful_syscall_return();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		ret = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	/* Read register number ADDR. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	case PTRACE_PEEKUSR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		force_successful_syscall_return();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		ret = get_reg(child, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		DBG(DBG_MEM, ("peek $%lu->%#lx\n", addr, ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/* When I and D space are separate, this will have to be fixed.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	case PTRACE_POKETEXT: /* write the word at location addr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	case PTRACE_POKEDATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		ret = generic_ptrace_pokedata(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	case PTRACE_POKEUSR: /* write the specified register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		DBG(DBG_MEM, ("poke $%lu<-%#lx\n", addr, data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		ret = put_reg(child, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		ret = ptrace_request(child, request, addr, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) asmlinkage unsigned long syscall_trace_enter(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	unsigned long ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	if (test_thread_flag(TIF_SYSCALL_TRACE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	    tracehook_report_syscall_entry(current_pt_regs()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		ret = -1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	audit_syscall_entry(regs->r0, regs->r16, regs->r17, regs->r18, regs->r19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	return ret ?: current_pt_regs()->r0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) asmlinkage void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) syscall_trace_leave(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	audit_syscall_exit(current_pt_regs());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (test_thread_flag(TIF_SYSCALL_TRACE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		tracehook_report_syscall_exit(current_pt_regs(), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }