Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / unicore32 / kernel / ptrace.c
bloba102c2b4f35804caf956b8566de45f455e6118e1
1 /*
2 * linux/arch/unicore32/kernel/ptrace.c
4 * Code specific to PKUnity SoC and UniCore ISA
6 * Copyright (C) 2001-2010 GUAN Xue-tao
8 * By Ross Biro 1/23/92
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 #include <linux/kernel.h>
15 #include <linux/ptrace.h>
16 #include <linux/signal.h>
17 #include <linux/uaccess.h>
18 #include <linux/sched/task_stack.h>
21 * this routine will get a word off of the processes privileged stack.
22 * the offset is how far from the base addr as stored in the THREAD.
23 * this routine assumes that all the privileged stacks are in our
24 * data space.
26 static inline long get_user_reg(struct task_struct *task, int offset)
28 return task_pt_regs(task)->uregs[offset];
32 * this routine will put a word on the processes privileged stack.
33 * the offset is how far from the base addr as stored in the THREAD.
34 * this routine assumes that all the privileged stacks are in our
35 * data space.
37 static inline int
38 put_user_reg(struct task_struct *task, int offset, long data)
40 struct pt_regs newregs, *regs = task_pt_regs(task);
41 int ret = -EINVAL;
43 newregs = *regs;
44 newregs.uregs[offset] = data;
46 if (valid_user_regs(&newregs)) {
47 regs->uregs[offset] = data;
48 ret = 0;
51 return ret;
55 * Called by kernel/ptrace.c when detaching..
57 void ptrace_disable(struct task_struct *child)
62 * We actually access the pt_regs stored on the kernel stack.
64 static int ptrace_read_user(struct task_struct *tsk, unsigned long off,
65 unsigned long __user *ret)
67 unsigned long tmp;
69 tmp = 0;
70 if (off < sizeof(struct pt_regs))
71 tmp = get_user_reg(tsk, off >> 2);
73 return put_user(tmp, ret);
77 * We actually access the pt_regs stored on the kernel stack.
79 static int ptrace_write_user(struct task_struct *tsk, unsigned long off,
80 unsigned long val)
82 if (off >= sizeof(struct pt_regs))
83 return 0;
85 return put_user_reg(tsk, off >> 2, val);
88 long arch_ptrace(struct task_struct *child, long request,
89 unsigned long addr, unsigned long data)
91 int ret;
92 unsigned long __user *datap = (unsigned long __user *) data;
94 switch (request) {
95 case PTRACE_PEEKUSR:
96 ret = ptrace_read_user(child, addr, datap);
97 break;
99 case PTRACE_POKEUSR:
100 ret = ptrace_write_user(child, addr, data);
101 break;
103 case PTRACE_GET_THREAD_AREA:
104 ret = put_user(task_pt_regs(child)->UCreg_16,
105 datap);
106 break;
108 default:
109 ret = ptrace_request(child, request, addr, data);
110 break;
113 return ret;
116 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
118 unsigned long ip;
120 if (!test_thread_flag(TIF_SYSCALL_TRACE))
121 return scno;
122 if (!(current->ptrace & PT_PTRACED))
123 return scno;
126 * Save IP. IP is used to denote syscall entry/exit:
127 * IP = 0 -> entry, = 1 -> exit
129 ip = regs->UCreg_ip;
130 regs->UCreg_ip = why;
132 current_thread_info()->syscall = scno;
134 /* the 0x80 provides a way for the tracing parent to distinguish
135 between a syscall stop and SIGTRAP delivery */
136 ptrace_notify(SIGTRAP | ((current->ptrace & PT_TRACESYSGOOD)
137 ? 0x80 : 0));
139 * this isn't the same as continuing with a signal, but it will do
140 * for normal use. strace only continues with a signal if the
141 * stopping signal is not SIGTRAP. -brl
143 if (current->exit_code) {
144 send_sig(current->exit_code, current, 1);
145 current->exit_code = 0;
147 regs->UCreg_ip = ip;
149 return current_thread_info()->syscall;