2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000-2003, Axis Communications AB.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/user.h>
|
2005-05-01 09:59:14 -06:00
|
|
|
#include <linux/signal.h>
|
2005-07-27 12:44:43 -06:00
|
|
|
#include <linux/security.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determines which bits in DCCR the user has access to.
|
|
|
|
* 1 = access, 0 = no access.
|
|
|
|
*/
|
|
|
|
#define DCCR_MASK 0x0000001f /* XNZVC */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get contents of register REGNO in task TASK.
|
|
|
|
*/
|
|
|
|
inline long get_reg(struct task_struct *task, unsigned int regno)
|
|
|
|
{
|
|
|
|
/* USP is a special case, it's not in the pt_regs struct but
|
|
|
|
* in the tasks thread struct
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (regno == PT_USP)
|
|
|
|
return task->thread.usp;
|
|
|
|
else if (regno < PT_MAX)
|
2006-01-12 02:06:03 -07:00
|
|
|
return ((unsigned long *)task_pt_regs(task))[regno];
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write contents of register REGNO in task TASK.
|
|
|
|
*/
|
|
|
|
inline int put_reg(struct task_struct *task, unsigned int regno,
|
|
|
|
unsigned long data)
|
|
|
|
{
|
|
|
|
if (regno == PT_USP)
|
|
|
|
task->thread.usp = data;
|
|
|
|
else if (regno < PT_MAX)
|
2006-01-12 02:06:03 -07:00
|
|
|
((unsigned long *)task_pt_regs(task))[regno] = data;
|
2005-04-16 16:20:36 -06:00
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called by kernel/ptrace.c when detaching.
|
|
|
|
*
|
|
|
|
* Make sure the single step bit is not set.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ptrace_disable(struct task_struct *child)
|
|
|
|
{
|
|
|
|
/* Todo - pending singlesteps? */
|
2008-01-21 06:06:32 -07:00
|
|
|
clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that this implementation of ptrace behaves differently from vanilla
|
|
|
|
* ptrace. Contrary to what the man page says, in the PTRACE_PEEKTEXT,
|
|
|
|
* PTRACE_PEEKDATA, and PTRACE_PEEKUSER requests the data variable is not
|
|
|
|
* ignored. Instead, the data variable is expected to point at a location
|
|
|
|
* (in user space) where the result of the ptrace call is written (instead of
|
|
|
|
* being returned).
|
|
|
|
*/
|
2010-10-27 16:33:47 -06:00
|
|
|
long arch_ptrace(struct task_struct *child, long request,
|
|
|
|
unsigned long addr, unsigned long data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int ret;
|
2010-10-27 16:33:51 -06:00
|
|
|
unsigned int regno = addr >> 2;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long __user *datap = (unsigned long __user *)data;
|
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
/* Read word at location address. */
|
|
|
|
case PTRACE_PEEKTEXT:
|
2007-07-17 05:03:43 -06:00
|
|
|
case PTRACE_PEEKDATA:
|
|
|
|
ret = generic_ptrace_peekdata(child, addr, data);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Read the word at location address in the USER area. */
|
|
|
|
case PTRACE_PEEKUSR: {
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
|
|
ret = -EIO;
|
2010-10-27 16:33:51 -06:00
|
|
|
if ((addr & 3) || regno > PT_MAX)
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
2010-10-27 16:33:51 -06:00
|
|
|
tmp = get_reg(child, regno);
|
2005-04-16 16:20:36 -06:00
|
|
|
ret = put_user(tmp, datap);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the word at location address. */
|
|
|
|
case PTRACE_POKETEXT:
|
|
|
|
case PTRACE_POKEDATA:
|
2007-07-17 05:03:44 -06:00
|
|
|
ret = generic_ptrace_pokedata(child, addr, data);
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Write the word at location address in the USER area. */
|
|
|
|
case PTRACE_POKEUSR:
|
|
|
|
ret = -EIO;
|
2010-10-27 16:33:51 -06:00
|
|
|
if ((addr & 3) || regno > PT_MAX)
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
|
2010-10-27 16:33:51 -06:00
|
|
|
if (regno == PT_DCCR) {
|
2005-04-16 16:20:36 -06:00
|
|
|
/* don't allow the tracing process to change stuff like
|
|
|
|
* interrupt enable, kernel/user bit, dma enables etc.
|
|
|
|
*/
|
|
|
|
data &= DCCR_MASK;
|
|
|
|
data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
|
|
|
|
}
|
2010-10-27 16:33:51 -06:00
|
|
|
if (put_reg(child, regno, data))
|
2005-04-16 16:20:36 -06:00
|
|
|
break;
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Get all GP registers from the child. */
|
|
|
|
case PTRACE_GETREGS: {
|
|
|
|
int i;
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2006-01-28 20:17:11 -07:00
|
|
|
ret = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
for (i = 0; i <= PT_MAX; i++) {
|
|
|
|
tmp = get_reg(child, i);
|
|
|
|
|
|
|
|
if (put_user(tmp, datap)) {
|
|
|
|
ret = -EFAULT;
|
2006-01-28 20:17:11 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-10-27 16:33:51 -06:00
|
|
|
datap++;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set all GP registers in the child. */
|
|
|
|
case PTRACE_SETREGS: {
|
|
|
|
int i;
|
|
|
|
unsigned long tmp;
|
|
|
|
|
2006-01-28 20:17:11 -07:00
|
|
|
ret = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
for (i = 0; i <= PT_MAX; i++) {
|
|
|
|
if (get_user(tmp, datap)) {
|
|
|
|
ret = -EFAULT;
|
2006-01-28 20:17:11 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == PT_DCCR) {
|
|
|
|
tmp &= DCCR_MASK;
|
|
|
|
tmp |= get_reg(child, PT_DCCR) & ~DCCR_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_reg(child, i, tmp);
|
2010-10-27 16:33:51 -06:00
|
|
|
datap++;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = ptrace_request(child, request, addr, data);
|
|
|
|
break;
|
|
|
|
}
|
2005-11-07 01:59:47 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_syscall_trace(void)
|
|
|
|
{
|
|
|
|
if (!test_thread_flag(TIF_SYSCALL_TRACE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(current->ptrace & PT_PTRACED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* the 0x80 provides a way for the tracing parent to distinguish
|
|
|
|
between a syscall stop and SIGTRAP delivery */
|
|
|
|
ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
|
|
|
|
? 0x80 : 0));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This isn't the same as continuing with a signal, but it will do for
|
|
|
|
* normal use.
|
|
|
|
*/
|
|
|
|
if (current->exit_code) {
|
|
|
|
send_sig(current->exit_code, current, 1);
|
|
|
|
current->exit_code = 0;
|
|
|
|
}
|
|
|
|
}
|