/*1* `ptrace' system call2*3* Copyright (C) 2008-2009 Michal Simek <[email protected]>4* Copyright (C) 2007-2009 PetaLogix5* Copyright (C) 2004-2007 John Williams <[email protected]>6*7* derived from arch/v850/kernel/ptrace.c8*9* Copyright (C) 2002,03 NEC Electronics Corporation10* Copyright (C) 2002,03 Miles Bader <[email protected]>11*12* Derived from arch/mips/kernel/ptrace.c:13*14* Copyright (C) 1992 Ross Biro15* Copyright (C) Linus Torvalds16* Copyright (C) 1994, 95, 96, 97, 98, 2000 Ralf Baechle17* Copyright (C) 1996 David S. Miller18* Kevin D. Kissell, [email protected] and Carsten Langgaard, [email protected]19* Copyright (C) 1999 MIPS Technologies, Inc.20*21* This file is subject to the terms and conditions of the GNU General22* Public License. See the file COPYING in the main directory of this23* archive for more details.24*/2526#include <linux/kernel.h>27#include <linux/mm.h>28#include <linux/sched.h>29#include <linux/sched/task_stack.h>30#include <linux/ptrace.h>31#include <linux/signal.h>32#include <linux/elf.h>33#include <linux/audit.h>34#include <linux/seccomp.h>3536#include <linux/errno.h>37#include <asm/processor.h>38#include <linux/uaccess.h>39#include <asm/asm-offsets.h>40#include <asm/cacheflush.h>41#include <asm/syscall.h>42#include <linux/io.h>4344/* Returns the address where the register at REG_OFFS in P is stashed away. */45static microblaze_reg_t *reg_save_addr(unsigned reg_offs,46struct task_struct *t)47{48struct pt_regs *regs;4950/*51* Three basic cases:52*53* (1) A register normally saved before calling the scheduler, is54* available in the kernel entry pt_regs structure at the top55* of the kernel stack. The kernel trap/irq exit path takes56* care to save/restore almost all registers for ptrace'd57* processes.58*59* (2) A call-clobbered register, where the process P entered the60* kernel via [syscall] trap, is not stored anywhere; that's61* OK, because such registers are not expected to be preserved62* when the trap returns anyway (so we don't actually bother to63* test for this case).64*65* (3) A few registers not used at all by the kernel, and so66* normally never saved except by context-switches, are in the67* context switch state.68*/6970/* Register saved during kernel entry (or not available). */71regs = task_pt_regs(t);7273return (microblaze_reg_t *)((char *)regs + reg_offs);74}7576long arch_ptrace(struct task_struct *child, long request,77unsigned long addr, unsigned long data)78{79int rval;80unsigned long val = 0;8182switch (request) {83/* Read/write the word at location ADDR in the registers. */84case PTRACE_PEEKUSR:85case PTRACE_POKEUSR:86pr_debug("PEEKUSR/POKEUSR : 0x%08lx\n", addr);87rval = 0;88if (addr >= PT_SIZE && request == PTRACE_PEEKUSR) {89/*90* Special requests that don't actually correspond91* to offsets in struct pt_regs.92*/93if (addr == PT_TEXT_ADDR) {94val = child->mm->start_code;95} else if (addr == PT_DATA_ADDR) {96val = child->mm->start_data;97} else if (addr == PT_TEXT_LEN) {98val = child->mm->end_code99- child->mm->start_code;100} else {101rval = -EIO;102}103} else if (addr < PT_SIZE && (addr & 0x3) == 0) {104microblaze_reg_t *reg_addr = reg_save_addr(addr, child);105if (request == PTRACE_PEEKUSR)106val = *reg_addr;107else {108#if 1109*reg_addr = data;110#else111/* MS potential problem on WB system112* Be aware that reg_addr is virtual address113* virt_to_phys conversion is necessary.114* This could be sensible solution.115*/116u32 paddr = virt_to_phys((u32)reg_addr);117invalidate_icache_range(paddr, paddr + 4);118*reg_addr = data;119flush_dcache_range(paddr, paddr + 4);120#endif121}122} else123rval = -EIO;124125if (rval == 0 && request == PTRACE_PEEKUSR)126rval = put_user(val, (unsigned long __user *)data);127break;128default:129rval = ptrace_request(child, request, addr, data);130}131return rval;132}133134asmlinkage unsigned long do_syscall_trace_enter(struct pt_regs *regs)135{136unsigned long ret = 0;137138secure_computing_strict(regs->r12);139140if (test_thread_flag(TIF_SYSCALL_TRACE) &&141ptrace_report_syscall_entry(regs))142/*143* Tracing decided this syscall should not happen.144* We'll return a bogus call number to get an ENOSYS145* error, but leave the original number in regs->regs[0].146*/147ret = -1L;148149audit_syscall_entry(regs->r12, regs->r5, regs->r6, regs->r7, regs->r8);150151return ret ?: regs->r12;152}153154asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)155{156int step;157158audit_syscall_exit(regs);159160step = test_thread_flag(TIF_SINGLESTEP);161if (step || test_thread_flag(TIF_SYSCALL_TRACE))162ptrace_report_syscall_exit(regs, step);163}164165void ptrace_disable(struct task_struct *child)166{167/* nothing to do */168}169170171