| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  *  PowerPC version | 
 | 3 |  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) | 
 | 4 |  * | 
 | 5 |  *  Derived from "arch/m68k/kernel/ptrace.c" | 
 | 6 |  *  Copyright (C) 1994 by Hamish Macdonald | 
 | 7 |  *  Taken from linux/kernel/ptrace.c and modified for M680x0. | 
 | 8 |  *  linux/kernel/ptrace.c is by Ross Biro 1/23/92, edited by Linus Torvalds | 
 | 9 |  * | 
 | 10 |  * Modified by Cort Dougan (cort@hq.fsmlabs.com) | 
| Paul Mackerras | b123923 | 2005-10-20 09:11:29 +1000 | [diff] [blame] | 11 |  * and Paul Mackerras (paulus@samba.org). | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 |  * | 
 | 13 |  * This file is subject to the terms and conditions of the GNU General | 
 | 14 |  * Public License.  See the file README.legal in the main directory of | 
 | 15 |  * this archive for more details. | 
 | 16 |  */ | 
 | 17 |  | 
 | 18 | #include <linux/kernel.h> | 
 | 19 | #include <linux/sched.h> | 
 | 20 | #include <linux/mm.h> | 
 | 21 | #include <linux/smp.h> | 
 | 22 | #include <linux/smp_lock.h> | 
 | 23 | #include <linux/errno.h> | 
 | 24 | #include <linux/ptrace.h> | 
 | 25 | #include <linux/user.h> | 
 | 26 | #include <linux/security.h> | 
| Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 27 | #include <linux/signal.h> | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 28 | #include <linux/seccomp.h> | 
 | 29 | #include <linux/audit.h> | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 30 | #ifdef CONFIG_PPC32 | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 31 | #include <linux/module.h> | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 32 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 |  | 
 | 34 | #include <asm/uaccess.h> | 
 | 35 | #include <asm/page.h> | 
 | 36 | #include <asm/pgtable.h> | 
 | 37 | #include <asm/system.h> | 
| Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 38 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 39 | #ifdef CONFIG_PPC64 | 
| Paul Mackerras | 21a6290 | 2005-11-19 20:47:22 +1100 | [diff] [blame] | 40 | #include "ptrace-common.h" | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 41 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 43 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | /* | 
 | 45 |  * Set of msr bits that gdb can change on behalf of a process. | 
 | 46 |  */ | 
 | 47 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) | 
 | 48 | #define MSR_DEBUGCHANGE	0 | 
 | 49 | #else | 
 | 50 | #define MSR_DEBUGCHANGE	(MSR_SE | MSR_BE) | 
 | 51 | #endif | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 52 | #endif /* CONFIG_PPC32 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 |  | 
 | 54 | /* | 
 | 55 |  * does not yet catch signals sent when the child dies. | 
 | 56 |  * in exit.c or in signal.c. | 
 | 57 |  */ | 
 | 58 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 59 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* | 
 | 61 |  * Get contents of register REGNO in task TASK. | 
 | 62 |  */ | 
 | 63 | static inline unsigned long get_reg(struct task_struct *task, int regno) | 
 | 64 | { | 
 | 65 | 	if (regno < sizeof(struct pt_regs) / sizeof(unsigned long) | 
 | 66 | 	    && task->thread.regs != NULL) | 
 | 67 | 		return ((unsigned long *)task->thread.regs)[regno]; | 
 | 68 | 	return (0); | 
 | 69 | } | 
 | 70 |  | 
 | 71 | /* | 
 | 72 |  * Write contents of register REGNO in task TASK. | 
 | 73 |  */ | 
 | 74 | static inline int put_reg(struct task_struct *task, int regno, | 
 | 75 | 			  unsigned long data) | 
 | 76 | { | 
 | 77 | 	if (regno <= PT_MQ && task->thread.regs != NULL) { | 
 | 78 | 		if (regno == PT_MSR) | 
 | 79 | 			data = (data & MSR_DEBUGCHANGE) | 
 | 80 | 				| (task->thread.regs->msr & ~MSR_DEBUGCHANGE); | 
 | 81 | 		((unsigned long *)task->thread.regs)[regno] = data; | 
 | 82 | 		return 0; | 
 | 83 | 	} | 
 | 84 | 	return -EIO; | 
 | 85 | } | 
 | 86 |  | 
 | 87 | #ifdef CONFIG_ALTIVEC | 
 | 88 | /* | 
 | 89 |  * Get contents of AltiVec register state in task TASK | 
 | 90 |  */ | 
 | 91 | static inline int get_vrregs(unsigned long __user *data, struct task_struct *task) | 
 | 92 | { | 
 | 93 | 	int i, j; | 
 | 94 |  | 
 | 95 | 	if (!access_ok(VERIFY_WRITE, data, 133 * sizeof(unsigned long))) | 
 | 96 | 		return -EFAULT; | 
 | 97 |  | 
 | 98 | 	/* copy AltiVec registers VR[0] .. VR[31] */ | 
 | 99 | 	for (i = 0; i < 32; i++) | 
 | 100 | 		for (j = 0; j < 4; j++, data++) | 
 | 101 | 			if (__put_user(task->thread.vr[i].u[j], data)) | 
 | 102 | 				return -EFAULT; | 
 | 103 |  | 
 | 104 | 	/* copy VSCR */ | 
 | 105 | 	for (i = 0; i < 4; i++, data++) | 
 | 106 | 		if (__put_user(task->thread.vscr.u[i], data)) | 
 | 107 | 			return -EFAULT; | 
 | 108 |  | 
 | 109 |         /* copy VRSAVE */ | 
 | 110 | 	if (__put_user(task->thread.vrsave, data)) | 
 | 111 | 		return -EFAULT; | 
 | 112 |  | 
 | 113 | 	return 0; | 
 | 114 | } | 
 | 115 |  | 
 | 116 | /* | 
 | 117 |  * Write contents of AltiVec register state into task TASK. | 
 | 118 |  */ | 
 | 119 | static inline int set_vrregs(struct task_struct *task, unsigned long __user *data) | 
 | 120 | { | 
 | 121 | 	int i, j; | 
 | 122 |  | 
 | 123 | 	if (!access_ok(VERIFY_READ, data, 133 * sizeof(unsigned long))) | 
 | 124 | 		return -EFAULT; | 
 | 125 |  | 
 | 126 | 	/* copy AltiVec registers VR[0] .. VR[31] */ | 
 | 127 | 	for (i = 0; i < 32; i++) | 
 | 128 | 		for (j = 0; j < 4; j++, data++) | 
 | 129 | 			if (__get_user(task->thread.vr[i].u[j], data)) | 
 | 130 | 				return -EFAULT; | 
 | 131 |  | 
 | 132 | 	/* copy VSCR */ | 
 | 133 | 	for (i = 0; i < 4; i++, data++) | 
 | 134 | 		if (__get_user(task->thread.vscr.u[i], data)) | 
 | 135 | 			return -EFAULT; | 
 | 136 |  | 
 | 137 | 	/* copy VRSAVE */ | 
 | 138 | 	if (__get_user(task->thread.vrsave, data)) | 
 | 139 | 		return -EFAULT; | 
 | 140 |  | 
 | 141 | 	return 0; | 
 | 142 | } | 
 | 143 | #endif | 
 | 144 |  | 
 | 145 | #ifdef CONFIG_SPE | 
 | 146 |  | 
 | 147 | /* | 
 | 148 |  * For get_evrregs/set_evrregs functions 'data' has the following layout: | 
 | 149 |  * | 
 | 150 |  * struct { | 
 | 151 |  *   u32 evr[32]; | 
 | 152 |  *   u64 acc; | 
 | 153 |  *   u32 spefscr; | 
 | 154 |  * } | 
 | 155 |  */ | 
 | 156 |  | 
 | 157 | /* | 
 | 158 |  * Get contents of SPE register state in task TASK. | 
 | 159 |  */ | 
 | 160 | static inline int get_evrregs(unsigned long *data, struct task_struct *task) | 
 | 161 | { | 
 | 162 | 	int i; | 
 | 163 |  | 
 | 164 | 	if (!access_ok(VERIFY_WRITE, data, 35 * sizeof(unsigned long))) | 
 | 165 | 		return -EFAULT; | 
 | 166 |  | 
 | 167 | 	/* copy SPEFSCR */ | 
 | 168 | 	if (__put_user(task->thread.spefscr, &data[34])) | 
 | 169 | 		return -EFAULT; | 
 | 170 |  | 
 | 171 | 	/* copy SPE registers EVR[0] .. EVR[31] */ | 
 | 172 | 	for (i = 0; i < 32; i++, data++) | 
 | 173 | 		if (__put_user(task->thread.evr[i], data)) | 
 | 174 | 			return -EFAULT; | 
 | 175 |  | 
 | 176 | 	/* copy ACC */ | 
 | 177 | 	if (__put_user64(task->thread.acc, (unsigned long long *)data)) | 
 | 178 | 		return -EFAULT; | 
 | 179 |  | 
 | 180 | 	return 0; | 
 | 181 | } | 
 | 182 |  | 
 | 183 | /* | 
 | 184 |  * Write contents of SPE register state into task TASK. | 
 | 185 |  */ | 
 | 186 | static inline int set_evrregs(struct task_struct *task, unsigned long *data) | 
 | 187 | { | 
 | 188 | 	int i; | 
 | 189 |  | 
 | 190 | 	if (!access_ok(VERIFY_READ, data, 35 * sizeof(unsigned long))) | 
 | 191 | 		return -EFAULT; | 
 | 192 |  | 
 | 193 | 	/* copy SPEFSCR */ | 
 | 194 | 	if (__get_user(task->thread.spefscr, &data[34])) | 
 | 195 | 		return -EFAULT; | 
 | 196 |  | 
 | 197 | 	/* copy SPE registers EVR[0] .. EVR[31] */ | 
 | 198 | 	for (i = 0; i < 32; i++, data++) | 
 | 199 | 		if (__get_user(task->thread.evr[i], data)) | 
 | 200 | 			return -EFAULT; | 
 | 201 | 	/* copy ACC */ | 
 | 202 | 	if (__get_user64(task->thread.acc, (unsigned long long*)data)) | 
 | 203 | 		return -EFAULT; | 
 | 204 |  | 
 | 205 | 	return 0; | 
 | 206 | } | 
 | 207 | #endif /* CONFIG_SPE */ | 
 | 208 |  | 
 | 209 | static inline void | 
 | 210 | set_single_step(struct task_struct *task) | 
 | 211 | { | 
 | 212 | 	struct pt_regs *regs = task->thread.regs; | 
 | 213 |  | 
 | 214 | 	if (regs != NULL) { | 
 | 215 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) | 
 | 216 | 		task->thread.dbcr0 = DBCR0_IDM | DBCR0_IC; | 
 | 217 | 		regs->msr |= MSR_DE; | 
 | 218 | #else | 
 | 219 | 		regs->msr |= MSR_SE; | 
 | 220 | #endif | 
 | 221 | 	} | 
 | 222 | } | 
 | 223 |  | 
 | 224 | static inline void | 
 | 225 | clear_single_step(struct task_struct *task) | 
 | 226 | { | 
 | 227 | 	struct pt_regs *regs = task->thread.regs; | 
 | 228 |  | 
 | 229 | 	if (regs != NULL) { | 
 | 230 | #if defined(CONFIG_40x) || defined(CONFIG_BOOKE) | 
 | 231 | 		task->thread.dbcr0 = 0; | 
 | 232 | 		regs->msr &= ~MSR_DE; | 
 | 233 | #else | 
 | 234 | 		regs->msr &= ~MSR_SE; | 
 | 235 | #endif | 
 | 236 | 	} | 
 | 237 | } | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 238 | #endif /* CONFIG_PPC32 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 |  | 
 | 240 | /* | 
 | 241 |  * Called by kernel/ptrace.c when detaching.. | 
 | 242 |  * | 
 | 243 |  * Make sure single step bits etc are not set. | 
 | 244 |  */ | 
 | 245 | void ptrace_disable(struct task_struct *child) | 
 | 246 | { | 
 | 247 | 	/* make sure the single step bit is not set. */ | 
 | 248 | 	clear_single_step(child); | 
 | 249 | } | 
 | 250 |  | 
| Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 251 | long arch_ptrace(struct task_struct *child, long request, long addr, long data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	int ret = -EPERM; | 
 | 254 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | 	switch (request) { | 
 | 256 | 	/* when I and D space are separate, these will need to be fixed. */ | 
 | 257 | 	case PTRACE_PEEKTEXT: /* read word at location addr. */ | 
 | 258 | 	case PTRACE_PEEKDATA: { | 
 | 259 | 		unsigned long tmp; | 
 | 260 | 		int copied; | 
 | 261 |  | 
 | 262 | 		copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0); | 
 | 263 | 		ret = -EIO; | 
 | 264 | 		if (copied != sizeof(tmp)) | 
 | 265 | 			break; | 
 | 266 | 		ret = put_user(tmp,(unsigned long __user *) data); | 
 | 267 | 		break; | 
 | 268 | 	} | 
 | 269 |  | 
 | 270 | 	/* read the word at location addr in the USER area. */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 	case PTRACE_PEEKUSR: { | 
 | 272 | 		unsigned long index, tmp; | 
 | 273 |  | 
 | 274 | 		ret = -EIO; | 
 | 275 | 		/* convert to index and check */ | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 276 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | 		index = (unsigned long) addr >> 2; | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 278 | 		if ((addr & 3) || (index > PT_FPSCR) | 
 | 279 | 		    || (child->thread.regs == NULL)) | 
 | 280 | #else | 
 | 281 | 		index = (unsigned long) addr >> 3; | 
 | 282 | 		if ((addr & 7) || (index > PT_FPSCR)) | 
 | 283 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | 			break; | 
 | 285 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 286 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | 		CHECK_FULL_REGS(child->thread.regs); | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 288 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 		if (index < PT_FPR0) { | 
 | 290 | 			tmp = get_reg(child, (int) index); | 
 | 291 | 		} else { | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 292 | 			flush_fp_to_thread(child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | 			tmp = ((unsigned long *)child->thread.fpr)[index - PT_FPR0]; | 
 | 294 | 		} | 
 | 295 | 		ret = put_user(tmp,(unsigned long __user *) data); | 
 | 296 | 		break; | 
 | 297 | 	} | 
 | 298 |  | 
 | 299 | 	/* If I and D space are separate, this will have to be fixed. */ | 
 | 300 | 	case PTRACE_POKETEXT: /* write the word at location addr. */ | 
 | 301 | 	case PTRACE_POKEDATA: | 
 | 302 | 		ret = 0; | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 303 | 		if (access_process_vm(child, addr, &data, sizeof(data), 1) | 
 | 304 | 				== sizeof(data)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | 			break; | 
 | 306 | 		ret = -EIO; | 
 | 307 | 		break; | 
 | 308 |  | 
 | 309 | 	/* write the word at location addr in the USER area */ | 
 | 310 | 	case PTRACE_POKEUSR: { | 
 | 311 | 		unsigned long index; | 
 | 312 |  | 
 | 313 | 		ret = -EIO; | 
 | 314 | 		/* convert to index and check */ | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 315 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | 		index = (unsigned long) addr >> 2; | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 317 | 		if ((addr & 3) || (index > PT_FPSCR) | 
 | 318 | 		    || (child->thread.regs == NULL)) | 
 | 319 | #else | 
 | 320 | 		index = (unsigned long) addr >> 3; | 
 | 321 | 		if ((addr & 7) || (index > PT_FPSCR)) | 
 | 322 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | 			break; | 
 | 324 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 325 | #ifdef CONFIG_PPC32 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 		CHECK_FULL_REGS(child->thread.regs); | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 327 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | 		if (index == PT_ORIG_R3) | 
 | 329 | 			break; | 
 | 330 | 		if (index < PT_FPR0) { | 
 | 331 | 			ret = put_reg(child, index, data); | 
 | 332 | 		} else { | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 333 | 			flush_fp_to_thread(child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | 			((unsigned long *)child->thread.fpr)[index - PT_FPR0] = data; | 
 | 335 | 			ret = 0; | 
 | 336 | 		} | 
 | 337 | 		break; | 
 | 338 | 	} | 
 | 339 |  | 
 | 340 | 	case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ | 
 | 341 | 	case PTRACE_CONT: { /* restart after signal. */ | 
 | 342 | 		ret = -EIO; | 
| Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 343 | 		if (!valid_signal(data)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | 			break; | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 345 | 		if (request == PTRACE_SYSCALL) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | 			set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 347 | 		else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 			clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | 		child->exit_code = data; | 
 | 350 | 		/* make sure the single step bit is not set. */ | 
 | 351 | 		clear_single_step(child); | 
 | 352 | 		wake_up_process(child); | 
 | 353 | 		ret = 0; | 
 | 354 | 		break; | 
 | 355 | 	} | 
 | 356 |  | 
 | 357 | /* | 
 | 358 |  * make the child exit.  Best I can do is send it a sigkill. | 
 | 359 |  * perhaps it should be put in the status that it wants to | 
 | 360 |  * exit. | 
 | 361 |  */ | 
 | 362 | 	case PTRACE_KILL: { | 
 | 363 | 		ret = 0; | 
 | 364 | 		if (child->exit_state == EXIT_ZOMBIE)	/* already dead */ | 
 | 365 | 			break; | 
 | 366 | 		child->exit_code = SIGKILL; | 
 | 367 | 		/* make sure the single step bit is not set. */ | 
 | 368 | 		clear_single_step(child); | 
 | 369 | 		wake_up_process(child); | 
 | 370 | 		break; | 
 | 371 | 	} | 
 | 372 |  | 
 | 373 | 	case PTRACE_SINGLESTEP: {  /* set the trap flag. */ | 
 | 374 | 		ret = -EIO; | 
| Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 375 | 		if (!valid_signal(data)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 			break; | 
 | 377 | 		clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); | 
 | 378 | 		set_single_step(child); | 
 | 379 | 		child->exit_code = data; | 
 | 380 | 		/* give it a chance to run. */ | 
 | 381 | 		wake_up_process(child); | 
 | 382 | 		ret = 0; | 
 | 383 | 		break; | 
 | 384 | 	} | 
 | 385 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 386 | #ifdef CONFIG_PPC64 | 
 | 387 | 	case PTRACE_GET_DEBUGREG: { | 
 | 388 | 		ret = -EINVAL; | 
 | 389 | 		/* We only support one DABR and no IABRS at the moment */ | 
 | 390 | 		if (addr > 0) | 
 | 391 | 			break; | 
 | 392 | 		ret = put_user(child->thread.dabr, | 
 | 393 | 			       (unsigned long __user *)data); | 
 | 394 | 		break; | 
 | 395 | 	} | 
 | 396 |  | 
 | 397 | 	case PTRACE_SET_DEBUGREG: | 
 | 398 | 		ret = ptrace_set_debugreg(child, addr, data); | 
 | 399 | 		break; | 
 | 400 | #endif | 
 | 401 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | 	case PTRACE_DETACH: | 
 | 403 | 		ret = ptrace_detach(child, data); | 
 | 404 | 		break; | 
 | 405 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 406 | 	case PPC_PTRACE_GETREGS: { /* Get GPRs 0 - 31. */ | 
 | 407 | 		int i; | 
 | 408 | 		unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; | 
 | 409 | 		unsigned long __user *tmp = (unsigned long __user *)addr; | 
 | 410 |  | 
 | 411 | 		for (i = 0; i < 32; i++) { | 
 | 412 | 			ret = put_user(*reg, tmp); | 
 | 413 | 			if (ret) | 
 | 414 | 				break; | 
 | 415 | 			reg++; | 
 | 416 | 			tmp++; | 
 | 417 | 		} | 
 | 418 | 		break; | 
 | 419 | 	} | 
 | 420 |  | 
 | 421 | 	case PPC_PTRACE_SETREGS: { /* Set GPRs 0 - 31. */ | 
 | 422 | 		int i; | 
 | 423 | 		unsigned long *reg = &((unsigned long *)child->thread.regs)[0]; | 
 | 424 | 		unsigned long __user *tmp = (unsigned long __user *)addr; | 
 | 425 |  | 
 | 426 | 		for (i = 0; i < 32; i++) { | 
 | 427 | 			ret = get_user(*reg, tmp); | 
 | 428 | 			if (ret) | 
 | 429 | 				break; | 
 | 430 | 			reg++; | 
 | 431 | 			tmp++; | 
 | 432 | 		} | 
 | 433 | 		break; | 
 | 434 | 	} | 
 | 435 |  | 
 | 436 | 	case PPC_PTRACE_GETFPREGS: { /* Get FPRs 0 - 31. */ | 
 | 437 | 		int i; | 
 | 438 | 		unsigned long *reg = &((unsigned long *)child->thread.fpr)[0]; | 
 | 439 | 		unsigned long __user *tmp = (unsigned long __user *)addr; | 
 | 440 |  | 
 | 441 | 		flush_fp_to_thread(child); | 
 | 442 |  | 
 | 443 | 		for (i = 0; i < 32; i++) { | 
 | 444 | 			ret = put_user(*reg, tmp); | 
 | 445 | 			if (ret) | 
 | 446 | 				break; | 
 | 447 | 			reg++; | 
 | 448 | 			tmp++; | 
 | 449 | 		} | 
 | 450 | 		break; | 
 | 451 | 	} | 
 | 452 |  | 
 | 453 | 	case PPC_PTRACE_SETFPREGS: { /* Get FPRs 0 - 31. */ | 
 | 454 | 		int i; | 
 | 455 | 		unsigned long *reg = &((unsigned long *)child->thread.fpr)[0]; | 
 | 456 | 		unsigned long __user *tmp = (unsigned long __user *)addr; | 
 | 457 |  | 
 | 458 | 		flush_fp_to_thread(child); | 
 | 459 |  | 
 | 460 | 		for (i = 0; i < 32; i++) { | 
 | 461 | 			ret = get_user(*reg, tmp); | 
 | 462 | 			if (ret) | 
 | 463 | 				break; | 
 | 464 | 			reg++; | 
 | 465 | 			tmp++; | 
 | 466 | 		} | 
 | 467 | 		break; | 
 | 468 | 	} | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 469 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | #ifdef CONFIG_ALTIVEC | 
 | 471 | 	case PTRACE_GETVRREGS: | 
 | 472 | 		/* Get the child altivec register state. */ | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 473 | 		flush_altivec_to_thread(child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 		ret = get_vrregs((unsigned long __user *)data, child); | 
 | 475 | 		break; | 
 | 476 |  | 
 | 477 | 	case PTRACE_SETVRREGS: | 
 | 478 | 		/* Set the child altivec register state. */ | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 479 | 		flush_altivec_to_thread(child); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | 		ret = set_vrregs(child, (unsigned long __user *)data); | 
 | 481 | 		break; | 
 | 482 | #endif | 
 | 483 | #ifdef CONFIG_SPE | 
 | 484 | 	case PTRACE_GETEVRREGS: | 
 | 485 | 		/* Get the child spe register state. */ | 
 | 486 | 		if (child->thread.regs->msr & MSR_SPE) | 
 | 487 | 			giveup_spe(child); | 
 | 488 | 		ret = get_evrregs((unsigned long __user *)data, child); | 
 | 489 | 		break; | 
 | 490 |  | 
 | 491 | 	case PTRACE_SETEVRREGS: | 
 | 492 | 		/* Set the child spe register state. */ | 
 | 493 | 		/* this is to clear the MSR_SPE bit to force a reload | 
 | 494 | 		 * of register state from memory */ | 
 | 495 | 		if (child->thread.regs->msr & MSR_SPE) | 
 | 496 | 			giveup_spe(child); | 
 | 497 | 		ret = set_evrregs(child, (unsigned long __user *)data); | 
 | 498 | 		break; | 
 | 499 | #endif | 
 | 500 |  | 
 | 501 | 	default: | 
 | 502 | 		ret = ptrace_request(child, request, addr, data); | 
 | 503 | 		break; | 
 | 504 | 	} | 
| Christoph Hellwig | 481bed4 | 2005-11-07 00:59:47 -0800 | [diff] [blame] | 505 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | 	return ret; | 
 | 507 | } | 
 | 508 |  | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 509 | static void do_syscall_trace(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 511 | 	/* the 0x80 provides a way for the tracing parent to distinguish | 
 | 512 | 	   between a syscall stop and SIGTRAP delivery */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 	ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD) | 
 | 514 | 				 ? 0x80 : 0)); | 
 | 515 |  | 
 | 516 | 	/* | 
 | 517 | 	 * this isn't the same as continuing with a signal, but it will do | 
 | 518 | 	 * for normal use.  strace only continues with a signal if the | 
 | 519 | 	 * stopping signal is not SIGTRAP.  -brl | 
 | 520 | 	 */ | 
 | 521 | 	if (current->exit_code) { | 
 | 522 | 		send_sig(current->exit_code, current, 1); | 
 | 523 | 		current->exit_code = 0; | 
 | 524 | 	} | 
 | 525 | } | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 526 |  | 
 | 527 | void do_syscall_trace_enter(struct pt_regs *regs) | 
 | 528 | { | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 529 | 	secure_computing(regs->gpr[0]); | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 530 |  | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 531 | 	if (test_thread_flag(TIF_SYSCALL_TRACE) | 
 | 532 | 	    && (current->ptrace & PT_PTRACED)) | 
 | 533 | 		do_syscall_trace(); | 
 | 534 |  | 
 | 535 | 	if (unlikely(current->audit_context)) | 
| Al Viro | 5411be5 | 2006-03-29 20:23:36 -0500 | [diff] [blame] | 536 | 		audit_syscall_entry( | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 537 | #ifdef CONFIG_PPC32 | 
 | 538 | 				    AUDIT_ARCH_PPC, | 
 | 539 | #else | 
 | 540 | 				    test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64, | 
 | 541 | #endif | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 542 | 				    regs->gpr[0], | 
 | 543 | 				    regs->gpr[3], regs->gpr[4], | 
 | 544 | 				    regs->gpr[5], regs->gpr[6]); | 
 | 545 | } | 
 | 546 |  | 
 | 547 | void do_syscall_trace_leave(struct pt_regs *regs) | 
 | 548 | { | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 549 | 	if (unlikely(current->audit_context)) | 
| David Woodhouse | 4b9c876 | 2006-09-22 09:23:53 +0100 | [diff] [blame] | 550 | 		audit_syscall_exit((regs->ccr&0x10000000)?AUDITSC_FAILURE:AUDITSC_SUCCESS, | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 551 | 				   regs->result); | 
 | 552 |  | 
| Stephen Rothwell | e8a3030 | 2005-10-13 15:52:04 +1000 | [diff] [blame] | 553 | 	if ((test_thread_flag(TIF_SYSCALL_TRACE) | 
| Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 554 | 	     || test_thread_flag(TIF_SINGLESTEP)) | 
| David Woodhouse | ea9c102 | 2005-05-08 15:56:09 +0100 | [diff] [blame] | 555 | 	    && (current->ptrace & PT_PTRACED)) | 
 | 556 | 		do_syscall_trace(); | 
 | 557 | } |