Path: blob/master/arch/cris/arch-v10/kernel/ptrace.c
15125 views
/*1* Copyright (C) 2000-2003, Axis Communications AB.2*/34#include <linux/kernel.h>5#include <linux/sched.h>6#include <linux/mm.h>7#include <linux/smp.h>8#include <linux/errno.h>9#include <linux/ptrace.h>10#include <linux/user.h>11#include <linux/signal.h>12#include <linux/security.h>1314#include <asm/uaccess.h>15#include <asm/page.h>16#include <asm/pgtable.h>17#include <asm/system.h>18#include <asm/processor.h>1920/*21* Determines which bits in DCCR the user has access to.22* 1 = access, 0 = no access.23*/24#define DCCR_MASK 0x0000001f /* XNZVC */2526/*27* Get contents of register REGNO in task TASK.28*/29inline long get_reg(struct task_struct *task, unsigned int regno)30{31/* USP is a special case, it's not in the pt_regs struct but32* in the tasks thread struct33*/3435if (regno == PT_USP)36return task->thread.usp;37else if (regno < PT_MAX)38return ((unsigned long *)task_pt_regs(task))[regno];39else40return 0;41}4243/*44* Write contents of register REGNO in task TASK.45*/46inline int put_reg(struct task_struct *task, unsigned int regno,47unsigned long data)48{49if (regno == PT_USP)50task->thread.usp = data;51else if (regno < PT_MAX)52((unsigned long *)task_pt_regs(task))[regno] = data;53else54return -1;55return 0;56}5758/*59* Called by kernel/ptrace.c when detaching.60*61* Make sure the single step bit is not set.62*/63void64ptrace_disable(struct task_struct *child)65{66/* Todo - pending singlesteps? */67clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);68}6970/*71* Note that this implementation of ptrace behaves differently from vanilla72* ptrace. Contrary to what the man page says, in the PTRACE_PEEKTEXT,73* PTRACE_PEEKDATA, and PTRACE_PEEKUSER requests the data variable is not74* ignored. Instead, the data variable is expected to point at a location75* (in user space) where the result of the ptrace call is written (instead of76* being returned).77*/78long arch_ptrace(struct task_struct *child, long request,79unsigned long addr, unsigned long data)80{81int ret;82unsigned int regno = addr >> 2;83unsigned long __user *datap = (unsigned long __user *)data;8485switch (request) {86/* Read word at location address. */87case PTRACE_PEEKTEXT:88case PTRACE_PEEKDATA:89ret = generic_ptrace_peekdata(child, addr, data);90break;9192/* Read the word at location address in the USER area. */93case PTRACE_PEEKUSR: {94unsigned long tmp;9596ret = -EIO;97if ((addr & 3) || regno > PT_MAX)98break;99100tmp = get_reg(child, regno);101ret = put_user(tmp, datap);102break;103}104105/* Write the word at location address. */106case PTRACE_POKETEXT:107case PTRACE_POKEDATA:108ret = generic_ptrace_pokedata(child, addr, data);109break;110111/* Write the word at location address in the USER area. */112case PTRACE_POKEUSR:113ret = -EIO;114if ((addr & 3) || regno > PT_MAX)115break;116117if (regno == PT_DCCR) {118/* don't allow the tracing process to change stuff like119* interrupt enable, kernel/user bit, dma enables etc.120*/121data &= DCCR_MASK;122data |= get_reg(child, PT_DCCR) & ~DCCR_MASK;123}124if (put_reg(child, regno, data))125break;126ret = 0;127break;128129/* Get all GP registers from the child. */130case PTRACE_GETREGS: {131int i;132unsigned long tmp;133134ret = 0;135for (i = 0; i <= PT_MAX; i++) {136tmp = get_reg(child, i);137138if (put_user(tmp, datap)) {139ret = -EFAULT;140break;141}142143datap++;144}145146break;147}148149/* Set all GP registers in the child. */150case PTRACE_SETREGS: {151int i;152unsigned long tmp;153154ret = 0;155for (i = 0; i <= PT_MAX; i++) {156if (get_user(tmp, datap)) {157ret = -EFAULT;158break;159}160161if (i == PT_DCCR) {162tmp &= DCCR_MASK;163tmp |= get_reg(child, PT_DCCR) & ~DCCR_MASK;164}165166put_reg(child, i, tmp);167datap++;168}169170break;171}172173default:174ret = ptrace_request(child, request, addr, data);175break;176}177178return ret;179}180181void do_syscall_trace(void)182{183if (!test_thread_flag(TIF_SYSCALL_TRACE))184return;185186if (!(current->ptrace & PT_PTRACED))187return;188189/* the 0x80 provides a way for the tracing parent to distinguish190between a syscall stop and SIGTRAP delivery */191ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)192? 0x80 : 0));193194/*195* This isn't the same as continuing with a signal, but it will do for196* normal use.197*/198if (current->exit_code) {199send_sig(current->exit_code, current, 1);200current->exit_code = 0;201}202}203204205